From 98bf8321693645c8eb14aa39989b8e97ef438f0d Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Tue, 18 Jul 2017 15:48:29 +0200 Subject: [PATCH] Move Animatable::get_zero_value to ToAnimatedZero::to_animated_zero --- components/style/macros.rs | 5 + components/style/properties/helpers.mako.rs | 7 + .../helpers/animated_properties.mako.rs | 263 +++++++++++------- .../style/properties/longhand/font.mako.rs | 6 + .../longhand/inherited_table.mako.rs | 6 + components/style/values/animated/effects.rs | 64 +++-- components/style/values/animated/mod.rs | 31 +++ .../style/values/computed/background.rs | 6 + components/style/values/computed/text.rs | 6 + components/style/values/computed/transform.rs | 12 + components/style/values/generics/text.rs | 9 + ports/geckolib/glue.rs | 3 +- tests/unit/style/animated_properties.rs | 2 +- 13 files changed, 293 insertions(+), 127 deletions(-) diff --git a/components/style/macros.rs b/components/style/macros.rs index 569d5e7d54c..af4e0b74684 100644 --- a/components/style/macros.rs +++ b/components/style/macros.rs @@ -112,5 +112,10 @@ macro_rules! define_keyword_type { impl $crate::values::computed::ComputedValueAsSpecified for $name {} impl $crate::values::animated::AnimatedValueAsComputed for $name {} no_viewport_percentage!($name); + + impl $crate::values::animated::ToAnimatedZero for $name { + #[inline] + fn to_animated_zero(&self) -> Result { Ok($name) } + } }; } diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index 580e2fd6329..4574bc708ab 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -129,6 +129,8 @@ % if animation_value_type == "ComputedValue": use properties::animated_properties::Animatable; + use values::animated::ToAnimatedZero; + impl Animatable for T { fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result { @@ -149,6 +151,11 @@ self.0.compute_squared_distance(&other.0) } } + + impl ToAnimatedZero for T { + #[inline] + fn to_animated_zero(&self) -> Result { Err(()) } + } % endif pub type Iter<'a, 'cx, 'cx_a> = ComputedVecIter<'a, 'cx, 'cx_a, super::single_value::SpecifiedValue>; diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index e2a8233383f..0c485ef57fd 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -33,7 +33,7 @@ use super::ComputedValuesInner; #[cfg(any(feature = "gecko", feature = "testing"))] use values::Auto; use values::{CSSFloat, CustomIdent, Either}; -use values::animated::ToAnimatedValue; +use values::animated::{ToAnimatedValue, ToAnimatedZero}; use values::animated::effects::BoxShadowList as AnimatedBoxShadowList; use values::animated::effects::Filter as AnimatedFilter; use values::animated::effects::FilterList as AnimatedFilterList; @@ -77,16 +77,6 @@ pub trait Animatable: Sized { self.add_weighted(other, count as f64, 1.0) } - /// Returns a value that, when added with an underlying value, will produce the underlying - /// value. This is used for SMIL animation's "by-animation" where SMIL first interpolates from - /// the zero value to the 'by' value, and then adds the result to the underlying value. - /// - /// This is not the necessarily the same as the initial value of a property. For example, the - /// initial value of 'stroke-width' is 1, but the zero value is 0, since adding 1 to the - /// underlying value will not produce the underlying value. - #[inline] - fn get_zero_value(&self) -> Result { Err(()) } - /// Compute distance between a value and another for a given property. fn compute_distance(&self, _other: &Self) -> Result { Err(()) } @@ -745,19 +735,6 @@ impl Animatable for AnimationValue { } } - fn get_zero_value(&self) -> Result { - match *self { - % for prop in data.longhands: - % if prop.animatable and prop.animation_value_type != "discrete": - AnimationValue::${prop.camel_case}(ref base) => { - Ok(AnimationValue::${prop.camel_case}(base.get_zero_value()?)) - }, - % endif - % endfor - _ => Err(()), - } - } - fn compute_distance(&self, other: &Self) -> Result { match (self, other) { % for prop in data.longhands: @@ -783,6 +760,22 @@ impl Animatable for AnimationValue { } } +impl ToAnimatedZero for AnimationValue { + #[inline] + fn to_animated_zero(&self) -> Result { + match *self { + % for prop in data.longhands: + % if prop.animatable and prop.animation_value_type != "discrete": + AnimationValue::${prop.camel_case}(ref base) => { + Ok(AnimationValue::${prop.camel_case}(base.to_animated_zero()?)) + }, + % endif + % endfor + _ => Err(()), + } + } +} + impl RepeatableListAnimatable for LengthOrPercentage {} impl RepeatableListAnimatable for Either {} @@ -832,9 +825,6 @@ impl Animatable for Au { Ok(Au((self.0 as f64 * self_portion + other.0 as f64 * other_portion).round() as i32)) } - #[inline] - fn get_zero_value(&self) -> Result { Ok(Au(0)) } - #[inline] fn compute_distance(&self, other: &Self) -> Result { self.0.compute_distance(&other.0) @@ -885,9 +875,6 @@ impl Animatable for f32 { Ok((*self as f64 * self_portion + *other as f64 * other_portion) as f32) } - #[inline] - fn get_zero_value(&self) -> Result { Ok(0.) } - #[inline] fn compute_distance(&self, other: &Self) -> Result { Ok((*self - *other).abs() as f64) @@ -901,9 +888,6 @@ impl Animatable for f64 { Ok(*self * self_portion + *other * other_portion) } - #[inline] - fn get_zero_value(&self) -> Result { Ok(0.) } - #[inline] fn compute_distance(&self, other: &Self) -> Result { Ok((*self - *other).abs()) @@ -917,9 +901,6 @@ impl Animatable for i32 { Ok((*self as f64 * self_portion + *other as f64 * other_portion).round() as i32) } - #[inline] - fn get_zero_value(&self) -> Result { Ok(0) } - #[inline] fn compute_distance(&self, other: &Self) -> Result { Ok((*self - *other).abs() as f64) @@ -954,15 +935,19 @@ impl Animatable for Percentage { Ok(Percentage((self.0 as f64 * self_portion + other.0 as f64 * other_portion) as f32)) } - #[inline] - fn get_zero_value(&self) -> Result { Ok(Percentage(0.)) } - #[inline] fn compute_distance(&self, other: &Self) -> Result { Ok((self.0 as f64 - other.0 as f64).abs()) } } +impl ToAnimatedZero for Percentage { + #[inline] + fn to_animated_zero(&self) -> Result { + Ok(Percentage(0.)) + } +} + /// https://drafts.csswg.org/css-transitions/#animtype-visibility impl Animatable for Visibility { #[inline] @@ -988,6 +973,13 @@ impl Animatable for Visibility { } } +impl ToAnimatedZero for Visibility { + #[inline] + fn to_animated_zero(&self) -> Result { + Err(()) + } +} + impl Animatable for Size2D { #[inline] fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result { @@ -1026,6 +1018,11 @@ impl Animatable for BorderCornerRadius { } } +impl ToAnimatedZero for BorderCornerRadius { + #[inline] + fn to_animated_zero(&self) -> Result { Err(()) } +} + /// https://drafts.csswg.org/css-transitions/#animtype-length impl Animatable for VerticalAlign { #[inline] @@ -1053,6 +1050,11 @@ impl Animatable for VerticalAlign { } } +impl ToAnimatedZero for VerticalAlign { + #[inline] + fn to_animated_zero(&self) -> Result { Err(()) } +} + /// https://drafts.csswg.org/css-transitions/#animtype-lpcalc impl Animatable for CalcLengthOrPercentage { #[inline] @@ -1123,11 +1125,6 @@ impl Animatable for LengthOrPercentage { } } - #[inline] - fn get_zero_value(&self) -> Result { - Ok(LengthOrPercentage::zero()) - } - #[inline] fn compute_distance(&self, other: &Self) -> Result { match (*self, *other) { @@ -1171,6 +1168,13 @@ impl Animatable for LengthOrPercentage { } } +impl ToAnimatedZero for LengthOrPercentage { + #[inline] + fn to_animated_zero(&self) -> Result { + Ok(LengthOrPercentage::zero()) + } +} + /// https://drafts.csswg.org/css-transitions/#animtype-lpcalc impl Animatable for LengthOrPercentageOrAuto { #[inline] @@ -1200,18 +1204,6 @@ impl Animatable for LengthOrPercentageOrAuto { } } - #[inline] - fn get_zero_value(&self) -> Result { - match *self { - LengthOrPercentageOrAuto::Length(_) | - LengthOrPercentageOrAuto::Percentage(_) | - LengthOrPercentageOrAuto::Calc(_) => { - Ok(LengthOrPercentageOrAuto::Length(Au(0))) - }, - LengthOrPercentageOrAuto::Auto => Err(()), - } - } - #[inline] fn compute_distance(&self, other: &Self) -> Result { match (*self, *other) { @@ -1260,6 +1252,20 @@ impl Animatable for LengthOrPercentageOrAuto { } } +impl ToAnimatedZero for LengthOrPercentageOrAuto { + #[inline] + fn to_animated_zero(&self) -> Result { + match *self { + LengthOrPercentageOrAuto::Length(_) | + LengthOrPercentageOrAuto::Percentage(_) | + LengthOrPercentageOrAuto::Calc(_) => { + Ok(LengthOrPercentageOrAuto::Length(Au(0))) + }, + LengthOrPercentageOrAuto::Auto => Err(()), + } + } +} + /// https://drafts.csswg.org/css-transitions/#animtype-lpcalc impl Animatable for LengthOrPercentageOrNone { #[inline] @@ -1289,18 +1295,6 @@ impl Animatable for LengthOrPercentageOrNone { } } - #[inline] - fn get_zero_value(&self) -> Result { - match *self { - LengthOrPercentageOrNone::Length(_) | - LengthOrPercentageOrNone::Percentage(_) | - LengthOrPercentageOrNone::Calc(_) => { - Ok(LengthOrPercentageOrNone::Length(Au(0))) - }, - LengthOrPercentageOrNone::None => Err(()), - } - } - #[inline] fn compute_distance(&self, other: &Self) -> Result { match (*self, *other) { @@ -1322,6 +1316,20 @@ impl Animatable for LengthOrPercentageOrNone { } } +impl ToAnimatedZero for LengthOrPercentageOrNone { + #[inline] + fn to_animated_zero(&self) -> Result { + match *self { + LengthOrPercentageOrNone::Length(_) | + LengthOrPercentageOrNone::Percentage(_) | + LengthOrPercentageOrNone::Calc(_) => { + Ok(LengthOrPercentageOrNone::Length(Au(0))) + }, + LengthOrPercentageOrNone::None => Err(()), + } + } +} + /// https://drafts.csswg.org/css-transitions/#animtype-lpcalc impl Animatable for MozLength { #[inline] @@ -1348,6 +1356,11 @@ impl Animatable for MozLength { } } +impl ToAnimatedZero for MozLength { + #[inline] + fn to_animated_zero(&self) -> Result { Err(()) } +} + /// https://drafts.csswg.org/css-transitions/#animtype-lpcalc impl Animatable for MaxLength { #[inline] @@ -1374,6 +1387,11 @@ impl Animatable for MaxLength { } } +impl ToAnimatedZero for MaxLength { + #[inline] + fn to_animated_zero(&self) -> Result { Err(()) } +} + /// http://dev.w3.org/csswg/css-transitions/#animtype-font-weight impl Animatable for FontWeight { #[inline] @@ -1386,9 +1404,6 @@ impl Animatable for FontWeight { Ok(FontWeight(weight as u16)) } - #[inline] - fn get_zero_value(&self) -> Result { Ok(FontWeight::normal()) } - #[inline] fn compute_distance(&self, other: &Self) -> Result { let a = self.0 as f64; @@ -1397,6 +1412,13 @@ impl Animatable for FontWeight { } } +impl ToAnimatedZero for FontWeight { + #[inline] + fn to_animated_zero(&self) -> Result { + Ok(FontWeight::normal()) + } +} + /// https://drafts.csswg.org/css-fonts/#font-stretch-prop impl Animatable for FontStretch { #[inline] @@ -1420,6 +1442,11 @@ impl Animatable for FontStretch { } } +impl ToAnimatedZero for FontStretch { + #[inline] + fn to_animated_zero(&self) -> Result { Err(()) } +} + /// We should treat font stretch as real number in order to interpolate this property. /// https://drafts.csswg.org/css-fonts-3/#font-stretch-animation impl From for f64 { @@ -1460,14 +1487,6 @@ impl Animatable for generic_position::Position Result { - Ok(generic_position::Position { - horizontal: self.horizontal.get_zero_value()?, - vertical: self.vertical.get_zero_value()?, - }) - } - #[inline] fn compute_distance(&self, other: &Self) -> Result { self.compute_squared_distance(other).map(|sd| sd.sqrt()) @@ -1480,6 +1499,20 @@ impl Animatable for generic_position::Position ToAnimatedZero for generic_position::Position +where + H: ToAnimatedZero, + V: ToAnimatedZero, +{ + #[inline] + fn to_animated_zero(&self) -> Result { + Ok(generic_position::Position { + horizontal: self.horizontal.to_animated_zero()?, + vertical: self.vertical.to_animated_zero()?, + }) + } +} + impl RepeatableListAnimatable for generic_position::Position where H: RepeatableListAnimatable, V: RepeatableListAnimatable {} @@ -1513,6 +1546,11 @@ impl Animatable for ClipRect { } } +impl ToAnimatedZero for ClipRect { + #[inline] + fn to_animated_zero(&self) -> Result { Err(()) } +} + /// Check if it's possible to do a direct numerical interpolation /// between these two transform lists. /// http://dev.w3.org/csswg/css-transforms/#transform-transform-animation @@ -2587,9 +2625,13 @@ impl Animatable for TransformList { } } } +} +impl ToAnimatedZero for TransformList { #[inline] - fn get_zero_value(&self) -> Result { Ok(TransformList(None)) } + fn to_animated_zero(&self) -> Result { + Ok(TransformList(None)) + } } impl Animatable for Either @@ -2611,18 +2653,6 @@ impl Animatable for Either } } - #[inline] - fn get_zero_value(&self) -> Result { - match *self { - Either::First(ref this) => { - Ok(Either::First(this.get_zero_value()?)) - }, - Either::Second(ref this) => { - Ok(Either::Second(this.get_zero_value()?)) - }, - } - } - #[inline] fn compute_distance(&self, other: &Self) -> Result { match (self, other) { @@ -2650,6 +2680,24 @@ impl Animatable for Either } } +impl ToAnimatedZero for Either +where + A: ToAnimatedZero, + B: ToAnimatedZero, +{ + #[inline] + fn to_animated_zero(&self) -> Result { + match *self { + Either::First(ref first) => { + Ok(Either::First(first.to_animated_zero()?)) + }, + Either::Second(ref second) => { + Ok(Either::Second(second.to_animated_zero()?)) + }, + } + } +} + #[derive(Copy, Clone, Debug, PartialEq)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] /// Unlike RGBA, each component value may exceed the range [0.0, 1.0]. @@ -2728,11 +2776,6 @@ impl Animatable for IntermediateRGBA { } } - #[inline] - fn get_zero_value(&self) -> Result { - Ok(IntermediateRGBA::transparent()) - } - #[inline] fn compute_distance(&self, other: &Self) -> Result { self.compute_squared_distance(other).map(|sq| sq.sqrt()) @@ -2757,6 +2800,13 @@ impl Animatable for IntermediateRGBA { } } +impl ToAnimatedZero for IntermediateRGBA { + #[inline] + fn to_animated_zero(&self) -> Result { + Ok(IntermediateRGBA::transparent()) + } +} + #[derive(Copy, Clone, Debug, PartialEq)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[allow(missing_docs)] @@ -2895,6 +2945,11 @@ impl Animatable for IntermediateColor { } } +impl ToAnimatedZero for IntermediateColor { + #[inline] + fn to_animated_zero(&self) -> Result { Err(()) } +} + /// Animatable SVGPaint pub type IntermediateSVGPaint = SVGPaint; @@ -2920,12 +2975,14 @@ impl Animatable for IntermediateSVGPaint { Ok(self.kind.compute_squared_distance(&other.kind)? + self.fallback.compute_squared_distance(&other.fallback)?) } +} +impl ToAnimatedZero for IntermediateSVGPaint { #[inline] - fn get_zero_value(&self) -> Result { + fn to_animated_zero(&self) -> Result { Ok(IntermediateSVGPaint { - kind: self.kind.get_zero_value()?, - fallback: self.fallback.and_then(|v| v.get_zero_value().ok()), + kind: self.kind.to_animated_zero()?, + fallback: self.fallback.and_then(|v| v.to_animated_zero().ok()), }) } } @@ -2958,12 +3015,14 @@ impl Animatable for IntermediateSVGPaintKind { _ => Err(()) } } +} +impl ToAnimatedZero for IntermediateSVGPaintKind { #[inline] - fn get_zero_value(&self) -> Result { + fn to_animated_zero(&self) -> Result { match *self { SVGPaintKind::Color(ref color) => { - Ok(SVGPaintKind::Color(color.get_zero_value()?)) + Ok(SVGPaintKind::Color(color.to_animated_zero()?)) }, SVGPaintKind::None | SVGPaintKind::ContextFill | diff --git a/components/style/properties/longhand/font.mako.rs b/components/style/properties/longhand/font.mako.rs index f4c0332b3eb..d5a0180208e 100644 --- a/components/style/properties/longhand/font.mako.rs +++ b/components/style/properties/longhand/font.mako.rs @@ -1044,6 +1044,7 @@ ${helpers.single_keyword_system("font-variant-caps", pub mod computed_value { use properties::animated_properties::Animatable; use values::CSSFloat; + use values::animated::ToAnimatedZero; #[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[derive(Copy, Clone, Debug, PartialEq, ToCss)] @@ -1081,6 +1082,11 @@ ${helpers.single_keyword_system("font-variant-caps", } } } + + impl ToAnimatedZero for T { + #[inline] + fn to_animated_zero(&self) -> Result { Err(()) } + } } #[inline] diff --git a/components/style/properties/longhand/inherited_table.mako.rs b/components/style/properties/longhand/inherited_table.mako.rs index 44ddc1881c9..d524833304c 100644 --- a/components/style/properties/longhand/inherited_table.mako.rs +++ b/components/style/properties/longhand/inherited_table.mako.rs @@ -28,6 +28,7 @@ ${helpers.single_keyword("caption-side", "top bottom", pub mod computed_value { use app_units::Au; use properties::animated_properties::Animatable; + use values::animated::ToAnimatedZero; #[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[derive(Clone, Copy, Debug, PartialEq, ToCss)] @@ -60,6 +61,11 @@ ${helpers.single_keyword("caption-side", "top bottom", self.vertical.compute_squared_distance(&other.vertical)?) } } + + impl ToAnimatedZero for T { + #[inline] + fn to_animated_zero(&self) -> Result { Err(()) } + } } #[cfg_attr(feature = "servo", derive(HeapSizeOf))] diff --git a/components/style/values/animated/effects.rs b/components/style/values/animated/effects.rs index 0d5204275a3..cb0fc8799d4 100644 --- a/components/style/values/animated/effects.rs +++ b/components/style/values/animated/effects.rs @@ -11,7 +11,7 @@ use properties::longhands::text_shadow::computed_value::T as ComputedTextShadowL use std::cmp; #[cfg(not(feature = "gecko"))] use values::Impossible; -use values::animated::ToAnimatedValue; +use values::animated::{ToAnimatedValue, ToAnimatedZero}; use values::computed::{Angle, Number}; use values::computed::length::Length; use values::generics::effects::BoxShadow as GenericBoxShadow; @@ -66,7 +66,7 @@ impl ToAnimatedValue for ComputedBoxShadowList { impl Animatable for ShadowList where - S: Animatable + Clone, + S: Animatable + Clone + ToAnimatedZero, { #[inline] fn add_weighted( @@ -83,10 +83,10 @@ where shadow.add_weighted(other, self_portion, other_portion)? }, (Some(shadow), None) => { - shadow.add_weighted(&shadow.get_zero_value()?, self_portion, other_portion)? + shadow.add_weighted(&shadow.to_animated_zero()?, self_portion, other_portion)? }, (None, Some(shadow)) => { - shadow.get_zero_value()?.add_weighted(&shadow, self_portion, other_portion)? + shadow.to_animated_zero()?.add_weighted(&shadow, self_portion, other_portion)? }, (None, None) => unreachable!(), }); @@ -102,6 +102,13 @@ where } } +impl ToAnimatedZero for ShadowList { + #[inline] + fn to_animated_zero(&self) -> Result { + Ok(ShadowList(vec![])) + } +} + impl ToAnimatedValue for ComputedTextShadowList { type AnimatedValue = TextShadowList; @@ -134,15 +141,6 @@ impl Animatable for BoxShadow { }) } - #[inline] - fn get_zero_value(&self) -> Result { - Ok(BoxShadow { - base: self.base.get_zero_value()?, - spread: self.spread.get_zero_value()?, - inset: self.inset, - }) - } - #[inline] fn compute_distance(&self, other: &Self) -> Result { self.compute_squared_distance(other).map(|sd| sd.sqrt()) @@ -160,6 +158,17 @@ impl Animatable for BoxShadow { } } +impl ToAnimatedZero for BoxShadow { + #[inline] + fn to_animated_zero(&self) -> Result { + Ok(BoxShadow { + base: self.base.to_animated_zero()?, + spread: self.spread.to_animated_zero()?, + inset: self.inset, + }) + } +} + impl ToAnimatedValue for ComputedFilterList { type AnimatedValue = FilterList; @@ -188,6 +197,13 @@ impl ToAnimatedValue for ComputedFilterList { } } +impl ToAnimatedZero for FilterList { + #[inline] + fn to_animated_zero(&self) -> Result { + Ok(FilterList(vec![])) + } +} + impl Animatable for SimpleShadow { #[inline] fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result { @@ -204,16 +220,6 @@ impl Animatable for SimpleShadow { }) } - #[inline] - fn get_zero_value(&self) -> Result { - Ok(SimpleShadow { - color: IntermediateColor::transparent(), - horizontal: self.horizontal.get_zero_value()?, - vertical: self.vertical.get_zero_value()?, - blur: self.blur.get_zero_value()?, - }) - } - #[inline] fn compute_distance(&self, other: &Self) -> Result { self.compute_squared_distance(other).map(|sd| sd.sqrt()) @@ -229,3 +235,15 @@ impl Animatable for SimpleShadow { ) } } + +impl ToAnimatedZero for SimpleShadow { + #[inline] + fn to_animated_zero(&self) -> Result { + Ok(SimpleShadow { + color: IntermediateColor::transparent(), + horizontal: self.horizontal.to_animated_zero()?, + vertical: self.vertical.to_animated_zero()?, + blur: self.blur.to_animated_zero()?, + }) + } +} diff --git a/components/style/values/animated/mod.rs b/components/style/values/animated/mod.rs index f671d1e207f..63d85254598 100644 --- a/components/style/values/animated/mod.rs +++ b/components/style/values/animated/mod.rs @@ -88,3 +88,34 @@ where } } +/// 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 + /// value. This is used for SMIL animation's "by-animation" where SMIL first interpolates from + /// the zero value to the 'by' value, and then adds the result to the underlying value. + /// + /// This is not the necessarily the same as the initial value of a property. For example, the + /// initial value of 'stroke-width' is 1, but the zero value is 0, since adding 1 to the + /// underlying value will not produce the underlying value. + fn to_animated_zero(&self) -> Result; +} + +impl ToAnimatedZero for Au { + #[inline] + fn to_animated_zero(&self) -> Result { Ok(Au(0)) } +} + +impl ToAnimatedZero for f32 { + #[inline] + fn to_animated_zero(&self) -> Result { Ok(0.) } +} + +impl ToAnimatedZero for f64 { + #[inline] + fn to_animated_zero(&self) -> Result { Ok(0.) } +} + +impl ToAnimatedZero for i32 { + #[inline] + fn to_animated_zero(&self) -> Result { Ok(0) } +} diff --git a/components/style/values/computed/background.rs b/components/style/values/computed/background.rs index cdcab051405..a1de43c5fe6 100644 --- a/components/style/values/computed/background.rs +++ b/components/style/values/computed/background.rs @@ -5,6 +5,7 @@ //! Computed types for CSS values related to backgrounds. use properties::animated_properties::{Animatable, RepeatableListAnimatable}; +use values::animated::ToAnimatedZero; use values::computed::length::LengthOrPercentageOrAuto; use values::generics::background::BackgroundSize as GenericBackgroundSize; @@ -50,3 +51,8 @@ impl Animatable for BackgroundSize { } } } + +impl ToAnimatedZero for BackgroundSize { + #[inline] + fn to_animated_zero(&self) -> Result { Err(()) } +} diff --git a/components/style/values/computed/text.rs b/components/style/values/computed/text.rs index 857a985d851..c6902515c2a 100644 --- a/components/style/values/computed/text.rs +++ b/components/style/values/computed/text.rs @@ -7,6 +7,7 @@ use app_units::Au; use properties::animated_properties::Animatable; use values::{CSSInteger, CSSFloat}; +use values::animated::ToAnimatedZero; use values::computed::length::{Length, LengthOrPercentage}; use values::generics::text::InitialLetter as GenericInitialLetter; use values::generics::text::LineHeight as GenericLineHeight; @@ -61,3 +62,8 @@ impl Animatable for LineHeight { } } } + +impl ToAnimatedZero for LineHeight { + #[inline] + fn to_animated_zero(&self) -> Result { Err(()) } +} diff --git a/components/style/values/computed/transform.rs b/components/style/values/computed/transform.rs index a4f35215560..5bf953d46be 100644 --- a/components/style/values/computed/transform.rs +++ b/components/style/values/computed/transform.rs @@ -5,6 +5,7 @@ //! Computed types for CSS values that are related to transformations. use properties::animated_properties::Animatable; +use values::animated::ToAnimatedZero; use values::computed::{Length, LengthOrPercentage, Number, Percentage}; use values::generics::transform::TimingFunction as GenericTimingFunction; use values::generics::transform::TransformOrigin as GenericTransformOrigin; @@ -51,3 +52,14 @@ impl Animatable for TransformOrigin { ) } } + +impl ToAnimatedZero for TransformOrigin { + #[inline] + fn to_animated_zero(&self) -> Result { + Ok(Self::new( + self.horizontal.to_animated_zero()?, + self.vertical.to_animated_zero()?, + self.depth.to_animated_zero()?, + )) + } +} diff --git a/components/style/values/generics/text.rs b/components/style/values/generics/text.rs index 64b2e4c9c10..995752ce70f 100644 --- a/components/style/values/generics/text.rs +++ b/components/style/values/generics/text.rs @@ -9,6 +9,7 @@ use cssparser::Parser; use parser::ParserContext; use properties::animated_properties::Animatable; use style_traits::ParseError; +use values::animated::ToAnimatedZero; /// A generic value for the `initial-letter` property. #[cfg_attr(feature = "servo", derive(HeapSizeOf))] @@ -93,6 +94,14 @@ impl Animatable for Spacing } } +impl ToAnimatedZero for Spacing +where + V: From, +{ + #[inline] + fn to_animated_zero(&self) -> Result { Err(()) } +} + /// A generic value for the `line-height` property. #[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToCss)] diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index f69f77898b2..f0526b3ce1a 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -119,6 +119,7 @@ use style::traversal::{ANIMATION_ONLY, DomTraversal, FOR_CSS_RULE_CHANGES, FOR_R use style::traversal::{TraversalDriver, TraversalFlags, UNSTYLED_CHILDREN_ONLY}; use style::traversal::resolve_style; use style::values::{CustomIdent, KeyframesName}; +use style::values::animated::ToAnimatedZero; use style::values::computed::Context; use style_traits::{PARSING_MODE_DEFAULT, ToCss}; use super::error_reporter::ErrorReporter; @@ -377,7 +378,7 @@ pub extern "C" fn Servo_AnimationValues_GetZeroValue( -> RawServoAnimationValueStrong { let value_to_match = AnimationValue::as_arc(&value_to_match); - if let Ok(zero_value) = value_to_match.get_zero_value() { + if let Ok(zero_value) = value_to_match.to_animated_zero() { Arc::new(zero_value).into_strong() } else { RawServoAnimationValueStrong::null() diff --git a/tests/unit/style/animated_properties.rs b/tests/unit/style/animated_properties.rs index b1c33c65dc6..ba387422262 100644 --- a/tests/unit/style/animated_properties.rs +++ b/tests/unit/style/animated_properties.rs @@ -4,7 +4,7 @@ use app_units::Au; use cssparser::RGBA; -use style::properties::animated_properties::{Animatable, IntermediateRGBA}; +use style::properties::animated_properties::Animatable; use style::properties::longhands::transform::computed_value::ComputedOperation as TransformOperation; use style::properties::longhands::transform::computed_value::T as TransformList; use style::values::animated::ToAnimatedValue;