servo: Merge #16294 - Make word spacing animatable (from hiikezoe:make-word-spacing-animatable); r=emilio
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Thu, 06 Apr 2017 22:11:18 -0500
changeset 558324 b691dd46057bd1b939f85afa0ea07b05b2888910
parent 558323 1c7215aa1bfe00f0506389e84a7f42ec0d244a0a
child 558325 7c7029cf53f5cdb061d7e0abc087852de663c76a
push id52860
push userbmo:walkingice0204@gmail.com
push dateFri, 07 Apr 2017 13:29:26 +0000
reviewersemilio
milestone55.0a1
servo: Merge #16294 - Make word spacing animatable (from hiikezoe:make-word-spacing-animatable); r=emilio <!-- Please describe your changes on the following line: --> This is a PR for https://bugzilla.mozilla.org/show_bug.cgi?id=1354053 --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors <!-- Either: --> - [X] There are tests for these changes, a test case will be landed in web-platform-tests in https://bugzilla.mozilla.org/show_bug.cgi?id=1354053 <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 1b6c3e06bb431c3cf2b218890fea6d5a7593d035
servo/components/style/properties/gecko.mako.rs
servo/components/style/properties/helpers.mako.rs
servo/components/style/properties/longhand/inherited_text.mako.rs
--- a/servo/components/style/properties/gecko.mako.rs
+++ b/servo/components/style/properties/gecko.mako.rs
@@ -2880,33 +2880,47 @@ fn static_assert() {
         match v.0 {
             Some(au) => self.gecko.mLetterSpacing.set(au),
             None => self.gecko.mLetterSpacing.set_value(CoordDataValue::Normal)
         }
     }
 
     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')"></%call>
 
     pub fn set_word_spacing(&mut self, v: longhands::word_spacing::computed_value::T) {
         match v.0 {
             Some(lop) => self.gecko.mWordSpacing.set(lop),
             // https://drafts.csswg.org/css-text-3/#valdef-word-spacing-normal
             None => self.gecko.mWordSpacing.set_value(CoordDataValue::Coord(0)),
         }
     }
 
+    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')"></%call>
 
     fn clear_text_emphasis_style_if_string(&mut self) {
         use nsstring::nsString;
         if self.gecko.mTextEmphasisStyle == structs::NS_STYLE_TEXT_EMPHASIS_STYLE_STRING as u8 {
             self.gecko.mTextEmphasisStyleString.assign(&nsString::new());
             self.gecko.mTextEmphasisStyle = structs::NS_STYLE_TEXT_EMPHASIS_STYLE_NONE as u8;
         }
--- a/servo/components/style/properties/helpers.mako.rs
+++ b/servo/components/style/properties/helpers.mako.rs
@@ -731,8 +731,31 @@
 <%def name="to_nscsspropertyid(ident)">
     <%
         if ident == "float":
             ident = "float_"
         return "nsCSSPropertyID::eCSSProperty_%s" % ident
     %>
 </%def>
 
+/// Macro for defining Interpolate trait for tuple struct which has Option<T>,
+/// e.g. struct T(pub Option<Au>).
+<%def name="impl_interpolate_for_option_tuple(value_for_none)">
+    impl Interpolate for T {
+        #[inline]
+        fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
+            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))
+                },
+            }
+        }
+    }
+</%def>
--- a/servo/components/style/properties/longhand/inherited_text.mako.rs
+++ b/servo/components/style/properties/longhand/inherited_text.mako.rs
@@ -440,36 +440,17 @@
     pub mod computed_value {
         use app_units::Au;
         use properties::animated_properties::Interpolate;
 
         #[derive(Debug, Clone, PartialEq)]
         #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
         pub struct T(pub Option<Au>);
 
-        impl Interpolate for T {
-            #[inline]
-            fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
-                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 {
         fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
             match self.0 {
                 None => dest.write_str("normal"),
                 Some(l) => l.to_css(dest),
             }
@@ -505,17 +486,17 @@
         if input.try(|input| input.expect_ident_matching("normal")).is_ok() {
             Ok(SpecifiedValue::Normal)
         } else {
             specified::Length::parse(context, input).map(SpecifiedValue::Specified)
         }
     }
 </%helpers:longhand>
 
-<%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;
     use values::HasViewportPercentage;
 
     impl HasViewportPercentage for SpecifiedValue {
         fn has_viewport_percentage(&self) -> bool {
             match *self {
@@ -537,20 +518,23 @@
             match *self {
                 SpecifiedValue::Normal => dest.write_str("normal"),
                 SpecifiedValue::Specified(ref l) => l.to_css(dest),
             }
         }
     }
 
     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<LengthOrPercentage>);
+
+        ${helpers.impl_interpolate_for_option_tuple('LengthOrPercentage::zero()')}
     }
 
     impl ToCss for computed_value::T {
         fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
             match self.0 {
                 None => dest.write_str("normal"),
                 Some(l) => l.to_css(dest),
             }