style: Teach ComputeSquaredDistance derive about #[animation(constant)].

Differential Revision: https://phabricator.services.mozilla.com/D5337
This commit is contained in:
Emilio Cobos Álvarez 2018-09-08 00:43:58 +02:00
parent 0ecd671f52
commit 25db9e3be7
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
5 changed files with 29 additions and 37 deletions

View file

@ -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<Angle, Number, Length, Impossible, Impossible>;
/// An animated value for the `drop-shadow()` filter.
pub type SimpleShadow = GenericSimpleShadow<Color, Length, Length>;
impl ComputeSquaredDistance for BoxShadow {
#[inline]
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
if self.inset != other.inset {
return Err(());
}
Ok(self.base.compute_squared_distance(&other.base)? +
self.spread.compute_squared_distance(&other.spread)?)
}
}

View file

@ -8,6 +8,7 @@
#[derive(
Animate,
Clone,
ComputeSquaredDistance,
Debug,
MallocSizeOf,
PartialEq,

View file

@ -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<Number> {
/// A four-character tag, packed into a u32 (one byte per character).
@ -57,19 +65,6 @@ pub struct VariationValue<Number> {
pub value: Number,
}
impl<Number> ComputeSquaredDistance for VariationValue<Number>
where
Number: ComputeSquaredDistance,
{
#[inline]
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
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)]

View file

@ -538,13 +538,6 @@ impl ToCss for ArcFlag {
}
}
impl ComputeSquaredDistance for ArcFlag {
#[inline]
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
(self.0 as i32).compute_squared_distance(&(other.0 as i32))
}
}
/// SVG Path parser.
struct PathParser<'a> {
chars: Peekable<Cloned<slice::Iter<'a, u8>>>,

View file

@ -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::<AnimationFieldAttrs>(&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