Bug 1374233 - Part 10: Implement ToAnimatedValue for MozLength and MaxLength. draft
authorBoris Chiou <boris.chiou@gmail.com>
Fri, 21 Jul 2017 17:53:16 +0800
changeset 615001 21536b9f0691482825763767254aee527d917ffd
parent 615000 aa97c1697ad28ea7be9a9ac28dff40d987355c61
child 615002 08021c6fe85f8410f739deb72cef6bded7841b70
push id70205
push userbmo:boris.chiou@gmail.com
push dateTue, 25 Jul 2017 08:53:17 +0000
bugs1374233
milestone56.0a1
Bug 1374233 - Part 10: Implement ToAnimatedValue for MozLength and MaxLength. For flex-basis, width/height, {max|min}-width, {max|min}-height. MozReview-Commit-ID: 4gGYSXoBS8e
servo/components/style/properties/longhand/position.mako.rs
servo/components/style/values/animated/mod.rs
--- a/servo/components/style/properties/longhand/position.mako.rs
+++ b/servo/components/style/properties/longhand/position.mako.rs
@@ -161,17 +161,17 @@ macro_rules! impl_align_conversions {
                           spec="https://drafts.csswg.org/css-flexbox/#order-property")}
 
 % if product == "gecko":
     // FIXME: Gecko doesn't support content value yet.
     ${helpers.gecko_size_type("flex-basis", "MozLength", "auto()",
                               logical=False,
                               spec="https://drafts.csswg.org/css-flexbox/#flex-basis-property",
                               extra_prefixes="webkit",
-                              animation_value_type="ComputedValue")}
+                              animation_value_type="MozLength")}
 % else:
     // FIXME: This property should be animatable.
     ${helpers.predefined_type("flex-basis",
                               "FlexBasis",
                               "computed::FlexBasis::auto()",
                               spec="https://drafts.csswg.org/css-flexbox/#flex-basis-property",
                               extra_prefixes="webkit",
                               animation_value_type="none")}
@@ -182,27 +182,27 @@ macro_rules! impl_align_conversions {
       if logical:
         spec = "https://drafts.csswg.org/css-logical-props/#propdef-%s"
     %>
     % if product == "gecko":
         // width, height, block-size, inline-size
         ${helpers.gecko_size_type("%s" % size, "MozLength", "auto()",
                                   logical,
                                   spec=spec % size,
-                                  animation_value_type="ComputedValue")}
+                                  animation_value_type="MozLength")}
         // min-width, min-height, min-block-size, min-inline-size,
         // max-width, max-height, max-block-size, max-inline-size
         ${helpers.gecko_size_type("min-%s" % size, "MozLength", "auto()",
                                   logical,
                                   spec=spec % size,
-                                  animation_value_type="ComputedValue")}
+                                  animation_value_type="MozLength")}
         ${helpers.gecko_size_type("max-%s" % size, "MaxLength", "none()",
                                   logical,
                                   spec=spec % size,
-                                  animation_value_type="ComputedValue")}
+                                  animation_value_type="MaxLength")}
     % else:
         // servo versions (no keyword support)
         ${helpers.predefined_type("%s" % size,
                                   "LengthOrPercentageOrAuto",
                                   "computed::LengthOrPercentageOrAuto::Auto",
                                   "parse_non_negative",
                                   spec=spec % size,
                                   allow_quirks=not logical,
--- a/servo/components/style/values/animated/mod.rs
+++ b/servo/components/style/values/animated/mod.rs
@@ -10,16 +10,18 @@
 
 use app_units::Au;
 use values::computed::Angle as ComputedAngle;
 use values::computed::BorderCornerRadius as ComputedBorderCornerRadius;
 use values::computed::NonNegativeAu;
 use values::computed::NonNegativeNumber as ComputedNonNegativeNumber;
 use values::computed::GreaterThanOrEqualToOneNumber as ComputedGreaterThanOrEqualToOneNumber;
 use values::computed::PositiveInteger as ComputedPositiveInteger;
+use values::computed::MaxLength as ComputedMaxLength;
+use values::computed::MozLength as ComputedMozLength;
 use values::computed::NonNegativeLengthOrPercentage as ComputedNonNegativeLengthOrPercentage;
 use values::specified::url::SpecifiedUrl;
 
 pub mod effects;
 
 /// Conversion between computed values and intermediate values for animations.
 ///
 /// Notably, colors are represented as four floats during animations.
@@ -174,16 +176,74 @@ impl ToAnimatedValue for ComputedBorderC
 
     #[inline]
     fn from_animated_value(animated: Self::AnimatedValue) -> Self {
         ComputedBorderCornerRadius::new(animated.0.width.clamp_to_non_negative(),
                                         animated.0.height.clamp_to_non_negative())
     }
 }
 
+impl ToAnimatedValue for ComputedMozLength {
+    type AnimatedValue = Self;
+
+    #[inline]
+    fn to_animated_value(self) -> Self {
+        self
+    }
+
+    #[inline]
+    fn from_animated_value(animated: Self::AnimatedValue) -> Self {
+        use values::computed::{LengthOrPercentageOrAuto, Percentage};
+        match animated {
+            ComputedMozLength::LengthOrPercentageOrAuto(lopa) => {
+                let result = match lopa {
+                    LengthOrPercentageOrAuto::Length(length) => {
+                        LengthOrPercentageOrAuto::Length(Au(::std::cmp::max(length.0, 0)))
+                    },
+                    LengthOrPercentageOrAuto::Percentage(percentage) => {
+                        LengthOrPercentageOrAuto::Percentage(Percentage(percentage.0.max(0.)))
+                    }
+                    _ => lopa
+                };
+                ComputedMozLength::LengthOrPercentageOrAuto(result)
+            },
+            _ => animated
+        }
+    }
+}
+
+impl ToAnimatedValue for ComputedMaxLength {
+    type AnimatedValue = Self;
+
+    #[inline]
+    fn to_animated_value(self) -> Self {
+        self
+    }
+
+    #[inline]
+    fn from_animated_value(animated: Self::AnimatedValue) -> Self {
+        use values::computed::{LengthOrPercentageOrNone, Percentage};
+        match animated {
+            ComputedMaxLength::LengthOrPercentageOrNone(lopn) => {
+                let result = match lopn {
+                    LengthOrPercentageOrNone::Length(length) => {
+                        LengthOrPercentageOrNone::Length(Au(::std::cmp::max(length.0, 0)))
+                    },
+                    LengthOrPercentageOrNone::Percentage(percentage) => {
+                        LengthOrPercentageOrNone::Percentage(Percentage(percentage.0.max(0.)))
+                    }
+                    _ => lopn
+                };
+                ComputedMaxLength::LengthOrPercentageOrNone(result)
+            },
+            _ => animated
+        }
+    }
+}
+
 /// Returns a value similar to `self` that represents zero.
 pub trait ToAnimatedZero: Sized {
     /// Returns a value that, when added with an underlying value, will produce the underlying
     /// value. This is used for SMIL animation's "by-animation" where SMIL first interpolates from
     /// the zero value to the 'by' value, and then adds the result to the underlying value.
     ///
     /// This is not the necessarily the same as the initial value of a property. For example, the
     /// initial value of 'stroke-width' is 1, but the zero value is 0, since adding 1 to the