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
--- 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