Animate NonNegativeLength as its inner type

This commit is contained in:
Anthony Ramine 2018-02-15 10:54:03 +01:00
parent 52f0fcabad
commit d8c43ac855
3 changed files with 19 additions and 20 deletions

View file

@ -13,7 +13,7 @@ use values::Impossible;
use values::animated::{Animate, Procedure, ToAnimatedValue, ToAnimatedZero}; use values::animated::{Animate, Procedure, ToAnimatedValue, ToAnimatedZero};
use values::animated::color::RGBA; use values::animated::color::RGBA;
use values::computed::{Angle, Number}; use values::computed::{Angle, Number};
use values::computed::length::{Length, NonNegativeLength}; use values::computed::length::Length;
use values::distance::{ComputeSquaredDistance, SquaredDistance}; use values::distance::{ComputeSquaredDistance, SquaredDistance};
use values::generics::effects::BoxShadow as GenericBoxShadow; use values::generics::effects::BoxShadow as GenericBoxShadow;
use values::generics::effects::Filter as GenericFilter; use values::generics::effects::Filter as GenericFilter;
@ -33,7 +33,7 @@ pub type TextShadowList = ShadowList<SimpleShadow>;
pub struct ShadowList<Shadow>(Vec<Shadow>); pub struct ShadowList<Shadow>(Vec<Shadow>);
/// An animated value for a single `box-shadow`. /// An animated value for a single `box-shadow`.
pub type BoxShadow = GenericBoxShadow<Option<RGBA>, Length, NonNegativeLength, Length>; pub type BoxShadow = GenericBoxShadow<Option<RGBA>, Length, Length, Length>;
/// An animated value for the `filter` property. /// An animated value for the `filter` property.
#[cfg_attr(feature = "servo", derive(MallocSizeOf))] #[cfg_attr(feature = "servo", derive(MallocSizeOf))]
@ -42,14 +42,14 @@ pub struct FilterList(pub Vec<Filter>);
/// An animated value for a single `filter`. /// An animated value for a single `filter`.
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
pub type Filter = GenericFilter<Angle, Number, NonNegativeLength, SimpleShadow>; pub type Filter = GenericFilter<Angle, Number, Length, SimpleShadow>;
/// An animated value for a single `filter`. /// An animated value for a single `filter`.
#[cfg(not(feature = "gecko"))] #[cfg(not(feature = "gecko"))]
pub type Filter = GenericFilter<Angle, Number, NonNegativeLength, Impossible>; pub type Filter = GenericFilter<Angle, Number, Length, Impossible>;
/// An animated value for the `drop-shadow()` filter. /// An animated value for the `drop-shadow()` filter.
pub type SimpleShadow = GenericSimpleShadow<Option<RGBA>, Length, NonNegativeLength>; pub type SimpleShadow = GenericSimpleShadow<Option<RGBA>, Length, Length>;
impl ToAnimatedValue for ComputedBoxShadowList { impl ToAnimatedValue for ComputedBoxShadowList {
type AnimatedValue = BoxShadowList; type AnimatedValue = BoxShadowList;

View file

@ -17,7 +17,6 @@ use values::computed::BorderCornerRadius as ComputedBorderCornerRadius;
use values::computed::ComputedUrl; use values::computed::ComputedUrl;
use values::computed::MaxLength as ComputedMaxLength; use values::computed::MaxLength as ComputedMaxLength;
use values::computed::MozLength as ComputedMozLength; use values::computed::MozLength as ComputedMozLength;
use values::computed::NonNegativeLength as ComputedNonNegativeLength;
use values::specified::url::SpecifiedUrl; use values::specified::url::SpecifiedUrl;
pub mod color; pub mod color;
@ -261,20 +260,6 @@ trivial_to_animated_value!(ComputedUrl);
trivial_to_animated_value!(bool); trivial_to_animated_value!(bool);
trivial_to_animated_value!(f32); trivial_to_animated_value!(f32);
impl ToAnimatedValue for ComputedNonNegativeLength {
type AnimatedValue = Self;
#[inline]
fn to_animated_value(self) -> Self {
self
}
#[inline]
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
ComputedNonNegativeLength::new(animated.px().max(0.))
}
}
impl ToAnimatedValue for ComputedBorderCornerRadius { impl ToAnimatedValue for ComputedBorderCornerRadius {
type AnimatedValue = Self; type AnimatedValue = Self;

View file

@ -815,6 +815,20 @@ pub type LengthOrNormal = Either<Length, Normal>;
/// A wrapper of Length, whose value must be >= 0. /// A wrapper of Length, whose value must be >= 0.
pub type NonNegativeLength = NonNegative<Length>; pub type NonNegativeLength = NonNegative<Length>;
impl ToAnimatedValue for NonNegativeLength {
type AnimatedValue = Length;
#[inline]
fn to_animated_value(self) -> Self::AnimatedValue {
self.0
}
#[inline]
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
NonNegativeLength::new(animated.px().max(0.))
}
}
impl NonNegativeLength { impl NonNegativeLength {
/// Create a NonNegativeLength. /// Create a NonNegativeLength.
#[inline] #[inline]