diff --git a/components/style/values/animated/effects.rs b/components/style/values/animated/effects.rs index a201ec0549e..a86396506df 100644 --- a/components/style/values/animated/effects.rs +++ b/components/style/values/animated/effects.rs @@ -11,7 +11,6 @@ use values::computed::{Angle, Number}; use values::computed::length::Length; #[cfg(feature = "gecko")] use values::computed::url::ComputedUrl; -use values::distance::{ComputeSquaredDistance, SquaredDistance}; use values::generics::effects::BoxShadow as GenericBoxShadow; use values::generics::effects::Filter as GenericFilter; use values::generics::effects::SimpleShadow as GenericSimpleShadow; @@ -29,14 +28,3 @@ pub type Filter = GenericFilter; /// An animated value for the `drop-shadow()` filter. pub type SimpleShadow = GenericSimpleShadow; - -impl ComputeSquaredDistance for BoxShadow { - #[inline] - fn compute_squared_distance(&self, other: &Self) -> Result { - if self.inset != other.inset { - return Err(()); - } - Ok(self.base.compute_squared_distance(&other.base)? + - self.spread.compute_squared_distance(&other.spread)?) - } -} diff --git a/components/style/values/generics/effects.rs b/components/style/values/generics/effects.rs index 7c7e3f4bef3..7b8e64f90bf 100644 --- a/components/style/values/generics/effects.rs +++ b/components/style/values/generics/effects.rs @@ -8,6 +8,7 @@ #[derive( Animate, Clone, + ComputeSquaredDistance, Debug, MallocSizeOf, PartialEq, diff --git a/components/style/values/generics/font.rs b/components/style/values/generics/font.rs index 03a76c5a32d..fa1e160273c 100644 --- a/components/style/values/generics/font.rs +++ b/components/style/values/generics/font.rs @@ -13,7 +13,6 @@ use std::fmt::{self, Write}; use std::io::Cursor; use style_traits::{CssWriter, KeywordsCollectFn, ParseError}; use style_traits::{SpecifiedValueInfo, StyleParseErrorKind, ToCss}; -use values::distance::{ComputeSquaredDistance, SquaredDistance}; /// https://drafts.csswg.org/css-fonts-4/#feature-tag-value #[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue)] @@ -47,7 +46,16 @@ where /// /// https://drafts.csswg.org/css-fonts-4/#font-variation-settings-def #[derive( - Animate, Clone, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss, + Animate, + Clone, + ComputeSquaredDistance, + Debug, + Eq, + MallocSizeOf, + PartialEq, + SpecifiedValueInfo, + ToComputedValue, + ToCss, )] pub struct VariationValue { /// A four-character tag, packed into a u32 (one byte per character). @@ -57,19 +65,6 @@ pub struct VariationValue { pub value: Number, } -impl ComputeSquaredDistance for VariationValue -where - Number: ComputeSquaredDistance, -{ - #[inline] - fn compute_squared_distance(&self, other: &Self) -> Result { - if self.tag != other.tag { - return Err(()); - } - self.value.compute_squared_distance(&other.value) - } -} - /// A value both for font-variation-settings and font-feature-settings. #[css(comma)] #[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss)] diff --git a/components/style/values/specified/svg_path.rs b/components/style/values/specified/svg_path.rs index f0973b545a5..5d397558d25 100644 --- a/components/style/values/specified/svg_path.rs +++ b/components/style/values/specified/svg_path.rs @@ -538,13 +538,6 @@ impl ToCss for ArcFlag { } } -impl ComputeSquaredDistance for ArcFlag { - #[inline] - fn compute_squared_distance(&self, other: &Self) -> Result { - (self.0 as i32).compute_squared_distance(&(other.0 as i32)) - } -} - /// SVG Path parser. struct PathParser<'a> { chars: Peekable>>, diff --git a/components/style_derive/compute_squared_distance.rs b/components/style_derive/compute_squared_distance.rs index 5b414206cda..f7e50c6bb00 100644 --- a/components/style_derive/compute_squared_distance.rs +++ b/components/style_derive/compute_squared_distance.rs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use animate::{AnimationInputAttrs, AnimationVariantAttrs}; +use animate::{AnimationInputAttrs, AnimationVariantAttrs, AnimationFieldAttrs}; use cg; use quote::Tokens; use syn::{DeriveInput, Path}; @@ -47,8 +47,23 @@ pub fn derive(mut input: DeriveInput) -> Tokens { parse_quote!(#ty: ::values::distance::ComputeSquaredDistance), ); } - quote! { - ::values::distance::ComputeSquaredDistance::compute_squared_distance(#this, #other)? + + let animation_field_attrs = + cg::parse_field_attrs::(&this.ast()); + + if animation_field_attrs.constant { + quote! { + { + if #this != #other { + return Err(()); + } + ::values::distance::SquaredDistance::from_sqrt(0.) + } + } + } else { + quote! { + ::values::distance::ComputeSquaredDistance::compute_squared_distance(#this, #other)? + } } }), quote!(+)); sum