From b79dc269f70b98bf2fbe34bc167db6de029d2b71 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Mon, 12 Feb 2018 23:35:18 +0100 Subject: [PATCH 1/4] Change AnimatedValue for PositiveInteger to CSSInteger --- components/style/values/animated/mod.rs | 16 ---------------- components/style/values/computed/mod.rs | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/components/style/values/animated/mod.rs b/components/style/values/animated/mod.rs index 17151a51d17..084dbc8bb6b 100644 --- a/components/style/values/animated/mod.rs +++ b/components/style/values/animated/mod.rs @@ -11,7 +11,6 @@ use app_units::Au; use euclid::{Point2D, Size2D}; use smallvec::SmallVec; -use std::cmp::max; use values::computed::Angle as ComputedAngle; use values::computed::BorderCornerRadius as ComputedBorderCornerRadius; #[cfg(feature = "servo")] @@ -22,7 +21,6 @@ use values::computed::MozLength as ComputedMozLength; use values::computed::NonNegativeLength as ComputedNonNegativeLength; use values::computed::NonNegativeLengthOrPercentage as ComputedNonNegativeLengthOrPercentage; use values::computed::NonNegativeNumber as ComputedNonNegativeNumber; -use values::computed::PositiveInteger as ComputedPositiveInteger; use values::specified::url::SpecifiedUrl; pub mod color; @@ -308,20 +306,6 @@ impl ToAnimatedValue for ComputedNonNegativeLength { } } -impl ToAnimatedValue for ComputedPositiveInteger { - type AnimatedValue = Self; - - #[inline] - fn to_animated_value(self) -> Self { - self - } - - #[inline] - fn from_animated_value(animated: Self::AnimatedValue) -> Self { - max(animated.0, 1).into() - } -} - impl ToAnimatedValue for ComputedNonNegativeLengthOrPercentage { type AnimatedValue = Self; diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index 8caed3ad3fe..c8db13e8b99 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -18,6 +18,7 @@ use rule_cache::RuleCacheConditions; #[cfg(feature = "servo")] use servo_url::ServoUrl; use std::cell::RefCell; +use std::cmp; use std::f32; use std::fmt::{self, Write}; #[cfg(feature = "servo")] @@ -25,6 +26,7 @@ use std::sync::Arc; use style_traits::{CssWriter, ToCss}; use style_traits::cursor::CursorKind; use super::{CSSFloat, CSSInteger}; +use super::animated::ToAnimatedValue; use super::generics::{GreaterThanOrEqualToOne, NonNegative}; use super::generics::grid::{GridLine as GenericGridLine, TrackBreadth as GenericTrackBreadth}; use super::generics::grid::{TrackSize as GenericTrackSize, TrackList as GenericTrackList}; @@ -511,6 +513,20 @@ impl IntegerOrAuto { /// A wrapper of Integer, but only accept a value >= 1. pub type PositiveInteger = GreaterThanOrEqualToOne; +impl ToAnimatedValue for PositiveInteger { + type AnimatedValue = CSSInteger; + + #[inline] + fn to_animated_value(self) -> Self::AnimatedValue { + self.0 + } + + #[inline] + fn from_animated_value(animated: Self::AnimatedValue) -> Self { + cmp::max(animated, 1).into() + } +} + impl From for PositiveInteger { #[inline] fn from(int: CSSInteger) -> PositiveInteger { From da5acc81d2c6739f910de3d89f4583ca563247b4 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Mon, 12 Feb 2018 23:35:18 +0100 Subject: [PATCH 2/4] Change AnimatedValue for NonNegativeLengthOrPercentage to its inner type --- .../helpers/animated_properties.mako.rs | 2 +- components/style/values/animated/mod.rs | 15 --------------- components/style/values/computed/length.rs | 16 +++++++++++++++- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index b44bc15c4fc..6ce41696e64 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -789,7 +789,7 @@ impl ToAnimatedZero for AnimationValue { impl RepeatableListAnimatable for LengthOrPercentage {} impl RepeatableListAnimatable for Either {} impl RepeatableListAnimatable for Either {} -impl RepeatableListAnimatable for SvgLengthOrPercentageOrNumber {} +impl RepeatableListAnimatable for SvgLengthOrPercentageOrNumber {} macro_rules! repeated_vec_impl { ($($ty:ty),*) => { diff --git a/components/style/values/animated/mod.rs b/components/style/values/animated/mod.rs index 084dbc8bb6b..9272db6d22e 100644 --- a/components/style/values/animated/mod.rs +++ b/components/style/values/animated/mod.rs @@ -19,7 +19,6 @@ use values::computed::GreaterThanOrEqualToOneNumber as ComputedGreaterThanOrEqua use values::computed::MaxLength as ComputedMaxLength; use values::computed::MozLength as ComputedMozLength; use values::computed::NonNegativeLength as ComputedNonNegativeLength; -use values::computed::NonNegativeLengthOrPercentage as ComputedNonNegativeLengthOrPercentage; use values::computed::NonNegativeNumber as ComputedNonNegativeNumber; use values::specified::url::SpecifiedUrl; @@ -306,20 +305,6 @@ impl ToAnimatedValue for ComputedNonNegativeLength { } } -impl ToAnimatedValue for ComputedNonNegativeLengthOrPercentage { - type AnimatedValue = Self; - - #[inline] - fn to_animated_value(self) -> Self { - self - } - - #[inline] - fn from_animated_value(animated: Self::AnimatedValue) -> Self { - animated.0.clamp_to_non_negative().into() - } -} - impl ToAnimatedValue for ComputedBorderCornerRadius { type AnimatedValue = Self; diff --git a/components/style/values/computed/length.rs b/components/style/values/computed/length.rs index a9d211a235e..8c00d330222 100644 --- a/components/style/values/computed/length.rs +++ b/components/style/values/computed/length.rs @@ -14,7 +14,7 @@ use style_traits::{CssWriter, ToCss}; use style_traits::values::specified::AllowedNumericType; use super::{Number, ToComputedValue, Context, Percentage}; use values::{Auto, CSSFloat, Either, None_, Normal, specified}; -use values::animated::{Animate, Procedure, ToAnimatedZero}; +use values::animated::{Animate, Procedure, ToAnimatedValue, ToAnimatedZero}; use values::computed::NonNegativeNumber; use values::distance::{ComputeSquaredDistance, SquaredDistance}; use values::generics::NonNegative; @@ -664,6 +664,20 @@ impl ToComputedValue for specified::LengthOrPercentageOrNone { /// A wrapper of LengthOrPercentage, whose value must be >= 0. pub type NonNegativeLengthOrPercentage = NonNegative; +impl ToAnimatedValue for NonNegativeLengthOrPercentage { + type AnimatedValue = LengthOrPercentage; + + #[inline] + fn to_animated_value(self) -> Self::AnimatedValue { + self.into() + } + + #[inline] + fn from_animated_value(animated: Self::AnimatedValue) -> Self { + animated.clamp_to_non_negative().into() + } +} + impl From for NonNegativeLengthOrPercentage { #[inline] fn from(length: NonNegativeLength) -> Self { From f89ebf7fe9d72968c274c47205e8889ba6442f16 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Mon, 12 Feb 2018 23:35:18 +0100 Subject: [PATCH 3/4] Change AnimatedValue for NonNegativeNumber to CSSFloat --- .../helpers/animated_properties.mako.rs | 13 ++++-------- components/style/values/animated/effects.rs | 20 +++---------------- components/style/values/animated/mod.rs | 15 -------------- components/style/values/computed/mod.rs | 14 +++++++++++++ components/style/values/mod.rs | 2 +- 5 files changed, 22 insertions(+), 42 deletions(-) diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index 6ce41696e64..0d6fa24af2c 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -55,7 +55,6 @@ use values::distance::{ComputeSquaredDistance, SquaredDistance}; use values::generics::font::FontSettings as GenericFontSettings; use values::computed::font::FontVariationSettings; use values::generics::font::VariationValue; -use values::generics::NonNegative; use values::generics::effects::Filter; use values::generics::position as generic_position; use values::generics::svg::{SVGLength, SvgLengthOrPercentageOrNumber, SVGPaint}; @@ -789,7 +788,7 @@ impl ToAnimatedZero for AnimationValue { impl RepeatableListAnimatable for LengthOrPercentage {} impl RepeatableListAnimatable for Either {} impl RepeatableListAnimatable for Either {} -impl RepeatableListAnimatable for SvgLengthOrPercentageOrNumber {} +impl RepeatableListAnimatable for SvgLengthOrPercentageOrNumber {} macro_rules! repeated_vec_impl { ($($ty:ty),*) => { @@ -3012,12 +3011,8 @@ impl Animate for AnimatedFilter { }, % endfor % for func in ['Brightness', 'Contrast', 'Opacity', 'Saturate']: - (&Filter::${func}(ref this), &Filter::${func}(ref other)) => { - Ok(Filter::${func}(NonNegative(animate_multiplicative_factor( - this.0, - other.0, - procedure, - )?))) + (&Filter::${func}(this), &Filter::${func}(other)) => { + Ok(Filter::${func}(animate_multiplicative_factor(this, other, procedure)?)) }, % endfor % if product == "gecko": @@ -3038,7 +3033,7 @@ impl ToAnimatedZero for AnimatedFilter { Filter::${func}(ref this) => Ok(Filter::${func}(this.to_animated_zero()?)), % endfor % for func in ['Brightness', 'Contrast', 'Opacity', 'Saturate']: - Filter::${func}(_) => Ok(Filter::${func}(NonNegative(1.))), + Filter::${func}(_) => Ok(Filter::${func}(1.)), % endfor % if product == "gecko": Filter::DropShadow(ref this) => Ok(Filter::DropShadow(this.to_animated_zero()?)), diff --git a/components/style/values/animated/effects.rs b/components/style/values/animated/effects.rs index e677d5a1a8e..4e3aeb4fde8 100644 --- a/components/style/values/animated/effects.rs +++ b/components/style/values/animated/effects.rs @@ -12,7 +12,7 @@ use std::cmp; use values::Impossible; use values::animated::{Animate, Procedure, ToAnimatedValue, ToAnimatedZero}; use values::animated::color::RGBA; -use values::computed::{Angle, NonNegativeNumber}; +use values::computed::{Angle, Number}; use values::computed::length::{Length, NonNegativeLength}; use values::distance::{ComputeSquaredDistance, SquaredDistance}; use values::generics::effects::BoxShadow as GenericBoxShadow; @@ -42,11 +42,11 @@ pub struct FilterList(pub Vec); /// An animated value for a single `filter`. #[cfg(feature = "gecko")] -pub type Filter = GenericFilter; +pub type Filter = GenericFilter; /// An animated value for a single `filter`. #[cfg(not(feature = "gecko"))] -pub type Filter = GenericFilter; +pub type Filter = GenericFilter; /// An animated value for the `drop-shadow()` filter. pub type SimpleShadow = GenericSimpleShadow, Length, NonNegativeLength>; @@ -155,25 +155,11 @@ impl ComputeSquaredDistance for BoxShadow { impl ToAnimatedValue for ComputedFilterList { type AnimatedValue = FilterList; - #[cfg(not(feature = "gecko"))] - #[inline] - fn to_animated_value(self) -> Self::AnimatedValue { - FilterList(self.0) - } - - #[cfg(feature = "gecko")] #[inline] fn to_animated_value(self) -> Self::AnimatedValue { FilterList(self.0.to_animated_value()) } - #[cfg(not(feature = "gecko"))] - #[inline] - fn from_animated_value(animated: Self::AnimatedValue) -> Self { - ComputedFilterList(animated.0) - } - - #[cfg(feature = "gecko")] #[inline] fn from_animated_value(animated: Self::AnimatedValue) -> Self { ComputedFilterList(ToAnimatedValue::from_animated_value(animated.0)) diff --git a/components/style/values/animated/mod.rs b/components/style/values/animated/mod.rs index 9272db6d22e..bcb6dc46954 100644 --- a/components/style/values/animated/mod.rs +++ b/components/style/values/animated/mod.rs @@ -19,7 +19,6 @@ use values::computed::GreaterThanOrEqualToOneNumber as ComputedGreaterThanOrEqua use values::computed::MaxLength as ComputedMaxLength; use values::computed::MozLength as ComputedMozLength; use values::computed::NonNegativeLength as ComputedNonNegativeLength; -use values::computed::NonNegativeNumber as ComputedNonNegativeNumber; use values::specified::url::SpecifiedUrl; pub mod color; @@ -263,20 +262,6 @@ trivial_to_animated_value!(ComputedUrl); trivial_to_animated_value!(bool); trivial_to_animated_value!(f32); -impl ToAnimatedValue for ComputedNonNegativeNumber { - type AnimatedValue = Self; - - #[inline] - fn to_animated_value(self) -> Self { - self - } - - #[inline] - fn from_animated_value(animated: Self::AnimatedValue) -> Self { - animated.0.max(0.).into() - } -} - impl ToAnimatedValue for ComputedGreaterThanOrEqualToOneNumber { type AnimatedValue = Self; diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index c8db13e8b99..dca7354e3bf 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -429,6 +429,20 @@ pub type Number = CSSFloat; /// A wrapper of Number, but the value >= 0. pub type NonNegativeNumber = NonNegative; +impl ToAnimatedValue for NonNegativeNumber { + type AnimatedValue = CSSFloat; + + #[inline] + fn to_animated_value(self) -> Self::AnimatedValue { + self.0 + } + + #[inline] + fn from_animated_value(animated: Self::AnimatedValue) -> Self { + animated.max(0.).into() + } +} + impl From for NonNegativeNumber { #[inline] fn from(number: CSSFloat) -> NonNegativeNumber { diff --git a/components/style/values/mod.rs b/components/style/values/mod.rs index 95a9f7ef817..369d12eb800 100644 --- a/components/style/values/mod.rs +++ b/components/style/values/mod.rs @@ -64,7 +64,7 @@ where /// Convenience void type to disable some properties and values through types. #[cfg_attr(feature = "servo", derive(Deserialize, MallocSizeOf, Serialize))] -#[derive(Clone, Copy, Debug, PartialEq, ToComputedValue, ToCss)] +#[derive(Clone, Copy, Debug, PartialEq, ToAnimatedValue, ToComputedValue, ToCss)] pub enum Impossible {} // FIXME(nox): This should be derived but the derive code cannot cope From 056abcbf5f12e7ea855e4342502f527689a7b09f Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Mon, 12 Feb 2018 23:35:18 +0100 Subject: [PATCH 4/4] Change AnimatedValue for GreaterThanOrEqualToOneNumber to CSSFloat --- components/style/values/animated/mod.rs | 15 --------------- components/style/values/computed/mod.rs | 14 ++++++++++++++ components/style/values/computed/text.rs | 6 ------ components/style/values/generics/text.rs | 5 +++++ 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/components/style/values/animated/mod.rs b/components/style/values/animated/mod.rs index bcb6dc46954..5946168f52f 100644 --- a/components/style/values/animated/mod.rs +++ b/components/style/values/animated/mod.rs @@ -15,7 +15,6 @@ use values::computed::Angle as ComputedAngle; use values::computed::BorderCornerRadius as ComputedBorderCornerRadius; #[cfg(feature = "servo")] use values::computed::ComputedUrl; -use values::computed::GreaterThanOrEqualToOneNumber as ComputedGreaterThanOrEqualToOneNumber; use values::computed::MaxLength as ComputedMaxLength; use values::computed::MozLength as ComputedMozLength; use values::computed::NonNegativeLength as ComputedNonNegativeLength; @@ -262,20 +261,6 @@ trivial_to_animated_value!(ComputedUrl); trivial_to_animated_value!(bool); trivial_to_animated_value!(f32); -impl ToAnimatedValue for ComputedGreaterThanOrEqualToOneNumber { - type AnimatedValue = Self; - - #[inline] - fn to_animated_value(self) -> Self { - self - } - - #[inline] - fn from_animated_value(animated: Self::AnimatedValue) -> Self { - animated.0.max(1.).into() - } -} - impl ToAnimatedValue for ComputedNonNegativeLength { type AnimatedValue = Self; diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index dca7354e3bf..14548efc909 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -460,6 +460,20 @@ impl From for CSSFloat { /// A wrapper of Number, but the value >= 1. pub type GreaterThanOrEqualToOneNumber = GreaterThanOrEqualToOne; +impl ToAnimatedValue for GreaterThanOrEqualToOneNumber { + type AnimatedValue = CSSFloat; + + #[inline] + fn to_animated_value(self) -> Self::AnimatedValue { + self.0 + } + + #[inline] + fn from_animated_value(animated: Self::AnimatedValue) -> Self { + animated.max(1.).into() + } +} + impl From for GreaterThanOrEqualToOneNumber { #[inline] fn from(number: CSSFloat) -> GreaterThanOrEqualToOneNumber { diff --git a/components/style/values/computed/text.rs b/components/style/values/computed/text.rs index bd97bd780d4..5de5e450cb6 100644 --- a/components/style/values/computed/text.rs +++ b/components/style/values/computed/text.rs @@ -9,7 +9,6 @@ use properties::StyleBuilder; use std::fmt::{self, Write}; use style_traits::{CssWriter, ToCss}; use values::{CSSInteger, CSSFloat}; -use values::animated::ToAnimatedZero; use values::computed::{NonNegativeLength, NonNegativeNumber}; use values::computed::length::{Length, LengthOrPercentage}; use values::generics::text::InitialLetter as GenericInitialLetter; @@ -31,11 +30,6 @@ pub type WordSpacing = Spacing; /// A computed value for the `line-height` property. pub type LineHeight = GenericLineHeight; -impl ToAnimatedZero for LineHeight { - #[inline] - fn to_animated_zero(&self) -> Result { Err(()) } -} - #[derive(Clone, Debug, MallocSizeOf, PartialEq)] /// text-overflow. /// When the specified value only has one side, that's the "second" diff --git a/components/style/values/generics/text.rs b/components/style/values/generics/text.rs index 4ff582f811f..94955a58b02 100644 --- a/components/style/values/generics/text.rs +++ b/components/style/values/generics/text.rs @@ -121,6 +121,11 @@ pub enum LineHeight { Length(LengthOrPercentage), } +impl ToAnimatedZero for LineHeight { + #[inline] + fn to_animated_zero(&self) -> Result { Err(()) } +} + impl LineHeight { /// Returns `normal`. #[inline]