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
This commit is contained in:
Boris Chiou 2017-07-21 17:53:16 +08:00
parent bd0a098ef1
commit 1e79e5fe1b
2 changed files with 64 additions and 4 deletions

View file

@ -166,7 +166,7 @@ ${helpers.predefined_type("order", "Integer", "0",
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",
@ -187,17 +187,17 @@ ${helpers.predefined_type("order", "Integer", "0",
${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,

View file

@ -13,6 +13,8 @@ use std::cmp::max;
use values::computed::Angle as ComputedAngle;
use values::computed::BorderCornerRadius as ComputedBorderCornerRadius;
use values::computed::GreaterThanOrEqualToOneNumber as ComputedGreaterThanOrEqualToOneNumber;
use values::computed::MaxLength as ComputedMaxLength;
use values::computed::MozLength as ComputedMozLength;
use values::computed::NonNegativeAu;
use values::computed::NonNegativeLengthOrPercentage as ComputedNonNegativeLengthOrPercentage;
use values::computed::NonNegativeNumber as ComputedNonNegativeNumber;
@ -180,6 +182,64 @@ impl ToAnimatedValue for ComputedBorderCornerRadius {
}
}
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(au) => {
LengthOrPercentageOrNone::Length(max(au, Au(0)))
},
LengthOrPercentageOrNone::Percentage(percentage) => {
LengthOrPercentageOrNone::Percentage(Percentage(percentage.0.max(0.)))
}
_ => lopn
};
ComputedMaxLength::LengthOrPercentageOrNone(result)
},
_ => animated
}
}
}
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(au) => {
LengthOrPercentageOrAuto::Length(max(au, Au(0)))
},
LengthOrPercentageOrAuto::Percentage(percentage) => {
LengthOrPercentageOrAuto::Percentage(Percentage(percentage.0.max(0.)))
}
_ => lopa
};
ComputedMozLength::LengthOrPercentageOrAuto(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