diff options
-rw-r--r-- | components/style/properties/data.py | 2 | ||||
-rw-r--r-- | components/style/properties/helpers.mako.rs | 8 | ||||
-rw-r--r-- | components/style/properties/helpers/animated_properties.mako.rs | 1 | ||||
-rw-r--r-- | components/style/properties/longhand/background.mako.rs | 3 | ||||
-rw-r--r-- | components/style/values/animated/mod.rs | 18 | ||||
-rw-r--r-- | components/style/values/computed/background.rs | 52 |
6 files changed, 78 insertions, 6 deletions
diff --git a/components/style/properties/data.py b/components/style/properties/data.py index d6aa4a016ad..7e08b079ad8 100644 --- a/components/style/properties/data.py +++ b/components/style/properties/data.py @@ -157,7 +157,7 @@ class Longhand(object): allowed_in_keyframe_block=True, cast_type='u8', has_uncacheable_values=False, logical=False, alias=None, extra_prefixes=None, boxed=False, flags=None, allowed_in_page_rule=False, allow_quirks=False, ignored_when_colors_disabled=False, - gecko_pref_ident=None, vector=False): + gecko_pref_ident=None, vector=False, need_animatable=False): self.name = name if not spec: raise TypeError("Spec should be specified for %s" % name) diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index 4e285bf3092..82eeb653e16 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -76,8 +76,10 @@ We assume that the default/initial value is an empty vector for these. `initial_value` need not be defined for these. </%doc> -<%def name="vector_longhand(name, animation_value_type=None, allow_empty=False, separator='Comma', **kwargs)"> - <%call expr="longhand(name, animation_value_type=animation_value_type, vector=True, **kwargs)"> +<%def name="vector_longhand(name, animation_value_type=None, allow_empty=False, separator='Comma', + need_animatable=False, **kwargs)"> + <%call expr="longhand(name, animation_value_type=animation_value_type, vector=True, + need_animatable=need_animatable, **kwargs)"> #[allow(unused_imports)] use smallvec::SmallVec; use std::fmt; @@ -127,7 +129,7 @@ % endif ); - % if animation_value_type == "ComputedValue": + % if need_animatable or animation_value_type == "ComputedValue": use properties::animated_properties::Animatable; use values::animated::ToAnimatedZero; diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index 38906e1e458..710f1dc7802 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -16,6 +16,7 @@ use euclid::{Point2D, Size2D}; #[cfg(feature = "gecko")] use gecko_string_cache::Atom; use properties::{CSSWideKeyword, PropertyDeclaration}; use properties::longhands; +use properties::longhands::background_size::computed_value::T as BackgroundSizeList; use properties::longhands::border_spacing::computed_value::T as BorderSpacing; use properties::longhands::font_weight::computed_value::T as FontWeight; use properties::longhands::font_stretch::computed_value::T as FontStretch; diff --git a/components/style/properties/longhand/background.mako.rs b/components/style/properties/longhand/background.mako.rs index 1fed8b37f40..b2de4e38fc6 100644 --- a/components/style/properties/longhand/background.mako.rs +++ b/components/style/properties/longhand/background.mako.rs @@ -167,7 +167,8 @@ ${helpers.predefined_type("background-size", "BackgroundSize", initial_specified_value="specified::LengthOrPercentageOrAuto::Auto.into()", spec="https://drafts.csswg.org/css-backgrounds/#the-background-size", vector=True, - animation_value_type="ComputedValue", + animation_value_type="BackgroundSizeList", + need_animatable=True, flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", extra_prefixes="webkit")} diff --git a/components/style/values/animated/mod.rs b/components/style/values/animated/mod.rs index 32dfdb7a6b6..49a53938e1e 100644 --- a/components/style/values/animated/mod.rs +++ b/components/style/values/animated/mod.rs @@ -9,6 +9,7 @@ //! module's raison d'être is to ultimately contain all these types. use app_units::Au; +use smallvec::SmallVec; use std::cmp::max; use values::computed::Angle as ComputedAngle; use values::computed::BorderCornerRadius as ComputedBorderCornerRadius; @@ -71,6 +72,23 @@ where } } +impl<T> ToAnimatedValue for SmallVec<[T; 1]> +where + T: ToAnimatedValue, +{ + type AnimatedValue = SmallVec<[T::AnimatedValue; 1]>; + + #[inline] + fn to_animated_value(self) -> Self::AnimatedValue { + self.into_iter().map(T::to_animated_value).collect() + } + + #[inline] + fn from_animated_value(animated: Self::AnimatedValue) -> Self { + animated.into_iter().map(T::from_animated_value).collect() + } +} + /// Marker trait for computed values with the same representation during animations. pub trait AnimatedValueAsComputed {} diff --git a/components/style/values/computed/background.rs b/components/style/values/computed/background.rs index a1de43c5fe6..d2781ac1891 100644 --- a/components/style/values/computed/background.rs +++ b/components/style/values/computed/background.rs @@ -5,7 +5,8 @@ //! Computed types for CSS values related to backgrounds. use properties::animated_properties::{Animatable, RepeatableListAnimatable}; -use values::animated::ToAnimatedZero; +use properties::longhands::background_size::computed_value::T as BackgroundSizeList; +use values::animated::{ToAnimatedValue, ToAnimatedZero}; use values::computed::length::LengthOrPercentageOrAuto; use values::generics::background::BackgroundSize as GenericBackgroundSize; @@ -56,3 +57,52 @@ impl ToAnimatedZero for BackgroundSize { #[inline] fn to_animated_zero(&self) -> Result<Self, ()> { Err(()) } } + +impl ToAnimatedValue for BackgroundSize { + type AnimatedValue = Self; + + #[inline] + fn to_animated_value(self) -> Self { + self + } + + #[inline] + fn from_animated_value(animated: Self::AnimatedValue) -> Self { + use app_units::Au; + use values::computed::Percentage; + let clamp_animated_value = |value: LengthOrPercentageOrAuto| -> LengthOrPercentageOrAuto { + match value { + LengthOrPercentageOrAuto::Length(len) => { + LengthOrPercentageOrAuto::Length(Au(::std::cmp::max(len.0, 0))) + }, + LengthOrPercentageOrAuto::Percentage(percent) => { + LengthOrPercentageOrAuto::Percentage(Percentage(percent.0.max(0.))) + }, + _ => value + } + }; + match animated { + GenericBackgroundSize::Explicit { width, height } => { + GenericBackgroundSize::Explicit { + width: clamp_animated_value(width), + height: clamp_animated_value(height) + } + }, + _ => animated + } + } +} + +impl ToAnimatedValue for BackgroundSizeList { + type AnimatedValue = Self; + + #[inline] + fn to_animated_value(self) -> Self { + self + } + + #[inline] + fn from_animated_value(animated: Self::AnimatedValue) -> Self { + BackgroundSizeList(ToAnimatedValue::from_animated_value(animated.0)) + } +} |