Bug 1374233 - Part 7: Add NonNegativeLengthOrPercentage.

For padding-{*} and grid-{*}-gap.

MozReview-Commit-ID: 81G0b1k6JnD
This commit is contained in:
Boris Chiou 2017-07-21 10:52:34 +08:00
parent 9d69cb2866
commit e72a0f126e
14 changed files with 123 additions and 20 deletions

View file

@ -13,6 +13,7 @@ use std::cmp::max;
use values::computed::Angle as ComputedAngle;
use values::computed::GreaterThanOrEqualToOneNumber as ComputedGreaterThanOrEqualToOneNumber;
use values::computed::NonNegativeAu;
use values::computed::NonNegativeLengthOrPercentage as ComputedNonNegativeLengthOrPercentage;
use values::computed::NonNegativeNumber as ComputedNonNegativeNumber;
use values::computed::PositiveInteger as ComputedPositiveInteger;
use values::specified::url::SpecifiedUrl;
@ -149,6 +150,27 @@ impl ToAnimatedValue for ComputedPositiveInteger {
}
}
impl ToAnimatedValue for ComputedNonNegativeLengthOrPercentage {
type AnimatedValue = Self;
#[inline]
fn to_animated_value(self) -> Self {
self
}
#[inline]
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
use values::computed::{LengthOrPercentage, Percentage};
match animated.0 {
LengthOrPercentage::Length(au) => LengthOrPercentage::Length(max(au, Au(0))).into(),
LengthOrPercentage::Percentage(percentage) => {
LengthOrPercentage::Percentage(Percentage(percentage.0.max(0.))).into()
},
_ => 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