From c120b0b701db6dc90f67a0e9d2109805a254b6a6 Mon Sep 17 00:00:00 2001 From: Hiroyuki Ikezoe Date: Fri, 7 Apr 2017 10:59:27 +0900 Subject: [PATCH 1/3] Introduce a macro to define Interpolate trait for tuple struct which has Option. The computed value of word-spacing is T(pub Option), the computed value of letter-spacing is similar to this, T(pub Option). It would be nice to have re-usable macro for these kind of struct. --- components/style/properties/helpers.mako.rs | 23 +++++++++++++++++++ .../longhand/inherited_text.mako.rs | 21 +---------------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index 39b41ab9a4db..35911564ca7f 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -736,3 +736,26 @@ %> +/// Macro for defining Interpolate trait for tuple struct which has Option, +/// e.g. struct T(pub Option). +<%def name="impl_interpolate_for_option_tuple(value_for_none)"> + impl Interpolate for T { + #[inline] + fn interpolate(&self, other: &Self, progress: f64) -> Result { + match (self, other) { + (&T(Some(ref this)), &T(Some(ref other))) => { + Ok(T(this.interpolate(other, progress).ok())) + }, + (&T(Some(ref this)), &T(None)) => { + Ok(T(this.interpolate(&${value_for_none}, progress).ok())) + }, + (&T(None), &T(Some(ref other))) => { + Ok(T(${value_for_none}.interpolate(other, progress).ok())) + }, + (&T(None), &T(None)) => { + Ok(T(None)) + }, + } + } + } + diff --git a/components/style/properties/longhand/inherited_text.mako.rs b/components/style/properties/longhand/inherited_text.mako.rs index d1557ff70e83..383ea8380315 100644 --- a/components/style/properties/longhand/inherited_text.mako.rs +++ b/components/style/properties/longhand/inherited_text.mako.rs @@ -445,26 +445,7 @@ ${helpers.single_keyword("text-align-last", #[cfg_attr(feature = "servo", derive(HeapSizeOf))] pub struct T(pub Option); - impl Interpolate for T { - #[inline] - fn interpolate(&self, other: &Self, progress: f64) -> Result { - match (self, other) { - (&T(Some(ref this)), &T(Some(ref other))) => { - Ok(T(this.interpolate(other, progress).ok())) - }, - (&T(Some(ref this)), &T(None)) => { - Ok(T(this.interpolate(&Au(0), progress).ok())) - }, - (&T(None), &T(Some(ref other))) => { - Ok(T(Au(0).interpolate(other, progress).ok())) - }, - (&T(None), &T(None)) => { - Ok(T(None)) - }, - } - } - } - + ${helpers.impl_interpolate_for_option_tuple('Au(0)')} } impl ToCss for computed_value::T { From f1642eb7a691ea2c09e7d988555f56a6f494815b Mon Sep 17 00:00:00 2001 From: Hiroyuki Ikezoe Date: Fri, 7 Apr 2017 10:59:42 +0900 Subject: [PATCH 2/3] Make word-spacing animatable. --- components/style/properties/gecko.mako.rs | 13 +++++++++++++ .../properties/longhand/inherited_text.mako.rs | 5 ++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 6941dbbb1521..096d0611c3ca 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -2902,6 +2902,19 @@ fn static_assert() { } } + pub fn clone_word_spacing(&self) -> longhands::word_spacing::computed_value::T { + use properties::longhands::word_spacing::computed_value::T; + use values::computed::LengthOrPercentage; + debug_assert!( + matches!(self.gecko.mWordSpacing.as_value(), + CoordDataValue::Normal | + CoordDataValue::Coord(_) | + CoordDataValue::Percent(_) | + CoordDataValue::Calc(_)), + "Unexpected computed value for word-spacing"); + T(LengthOrPercentage::from_gecko_style_coord(&self.gecko.mWordSpacing)) + } + <%call expr="impl_coord_copy('word_spacing', 'mWordSpacing')"> fn clear_text_emphasis_style_if_string(&mut self) { diff --git a/components/style/properties/longhand/inherited_text.mako.rs b/components/style/properties/longhand/inherited_text.mako.rs index 383ea8380315..07054fbbd56c 100644 --- a/components/style/properties/longhand/inherited_text.mako.rs +++ b/components/style/properties/longhand/inherited_text.mako.rs @@ -491,7 +491,7 @@ ${helpers.single_keyword("text-align-last", } -<%helpers:longhand name="word-spacing" animation_type="none" +<%helpers:longhand name="word-spacing" animation_type="normal" spec="https://drafts.csswg.org/css-text/#propdef-word-spacing"> use std::fmt; use style_traits::ToCss; @@ -523,10 +523,13 @@ ${helpers.single_keyword("text-align-last", } pub mod computed_value { + use properties::animated_properties::Interpolate; use values::computed::LengthOrPercentage; #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] pub struct T(pub Option); + + ${helpers.impl_interpolate_for_option_tuple('LengthOrPercentage::zero()')} } impl ToCss for computed_value::T { From 933a5d2f9cc672823735c77f9c67b41185f22a43 Mon Sep 17 00:00:00 2001 From: Hiroyuki Ikezoe Date: Fri, 7 Apr 2017 10:59:53 +0900 Subject: [PATCH 3/3] Use from_gecko_style_coord() to convert CoordDataValue to Option for letter-spacing. --- components/style/properties/gecko.mako.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 096d0611c3ca..ff3529bb53b7 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -2885,11 +2885,12 @@ fn static_assert() { pub fn clone_letter_spacing(&self) -> longhands::letter_spacing::computed_value::T { use properties::longhands::letter_spacing::computed_value::T; - match self.gecko.mLetterSpacing.as_value() { - CoordDataValue::Normal => T(None), - CoordDataValue::Coord(coord) => T(Some(Au(coord))), - _ => unreachable!("Unexpected computed value for letter-spacing"), - } + debug_assert!( + matches!(self.gecko.mLetterSpacing.as_value(), + CoordDataValue::Normal | + CoordDataValue::Coord(_)), + "Unexpected computed value for letter-spacing"); + T(Au::from_gecko_style_coord(&self.gecko.mLetterSpacing)) } <%call expr="impl_coord_copy('letter_spacing', 'mLetterSpacing')">