diff --git a/components/style/macros.rs b/components/style/macros.rs index 5f20e3c8d0c..b2cce740002 100644 --- a/components/style/macros.rs +++ b/components/style/macros.rs @@ -68,8 +68,8 @@ macro_rules! try_match_ident_ignore_ascii_case { macro_rules! define_keyword_type { ($name: ident, $css: expr) => { #[allow(missing_docs)] - #[derive(Animate, Clone, ComputeSquaredDistance, Copy, MallocSizeOf, PartialEq)] - #[derive(ToAnimatedZero, ToComputedValue, ToCss)] + #[derive(Animate, Clone, ComputeSquaredDistance, Copy, MallocSizeOf)] + #[derive(PartialEq, ToAnimatedValue, ToAnimatedZero, ToComputedValue, ToCss)] pub struct $name; impl fmt::Debug for $name { @@ -86,8 +86,6 @@ macro_rules! define_keyword_type { input.expect_ident_matching($css).map(|_| $name).map_err(|e| e.into()) } } - - impl $crate::values::animated::AnimatedValueAsComputed for $name {} }; } diff --git a/components/style/values/animated/mod.rs b/components/style/values/animated/mod.rs index f7100bf77c8..17151a51d17 100644 --- a/components/style/values/animated/mod.rs +++ b/components/style/values/animated/mod.rs @@ -76,9 +76,6 @@ pub trait ToAnimatedValue { fn from_animated_value(animated: Self::AnimatedValue) -> Self; } -/// Marker trait for computed values with the same representation during animations. -pub trait AnimatedValueAsComputed {} - /// Returns a value similar to `self` that represents zero. /// /// This trait is derivable with `#[derive(ToAnimatedValue)]`. If a field is @@ -243,31 +240,32 @@ where } } -impl AnimatedValueAsComputed for Au {} -impl AnimatedValueAsComputed for ComputedAngle {} -impl AnimatedValueAsComputed for SpecifiedUrl {} -#[cfg(feature = "servo")] -impl AnimatedValueAsComputed for ComputedUrl {} -impl AnimatedValueAsComputed for bool {} -impl AnimatedValueAsComputed for f32 {} +macro_rules! trivial_to_animated_value { + ($ty:ty) => { + impl $crate::values::animated::ToAnimatedValue for $ty { + type AnimatedValue = Self; -impl ToAnimatedValue for T -where - T: AnimatedValueAsComputed, -{ - type AnimatedValue = Self; + #[inline] + fn to_animated_value(self) -> Self { + self + } - #[inline] - fn to_animated_value(self) -> Self { - self - } - - #[inline] - fn from_animated_value(animated: Self::AnimatedValue) -> Self { - animated + #[inline] + fn from_animated_value(animated: Self::AnimatedValue) -> Self { + animated + } + } } } +trivial_to_animated_value!(Au); +trivial_to_animated_value!(ComputedAngle); +trivial_to_animated_value!(SpecifiedUrl); +#[cfg(feature = "servo")] +trivial_to_animated_value!(ComputedUrl); +trivial_to_animated_value!(bool); +trivial_to_animated_value!(f32); + impl ToAnimatedValue for ComputedNonNegativeNumber { type AnimatedValue = Self;