mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
style: Teach ComputeSquaredDistance derive about #[animation(constant)].
Differential Revision: https://phabricator.services.mozilla.com/D5337
This commit is contained in:
parent
0ecd671f52
commit
25db9e3be7
5 changed files with 29 additions and 37 deletions
|
@ -11,7 +11,6 @@ use values::computed::{Angle, Number};
|
||||||
use values::computed::length::Length;
|
use values::computed::length::Length;
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
use values::computed::url::ComputedUrl;
|
use values::computed::url::ComputedUrl;
|
||||||
use values::distance::{ComputeSquaredDistance, SquaredDistance};
|
|
||||||
use values::generics::effects::BoxShadow as GenericBoxShadow;
|
use values::generics::effects::BoxShadow as GenericBoxShadow;
|
||||||
use values::generics::effects::Filter as GenericFilter;
|
use values::generics::effects::Filter as GenericFilter;
|
||||||
use values::generics::effects::SimpleShadow as GenericSimpleShadow;
|
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.
|
/// An animated value for the `drop-shadow()` filter.
|
||||||
pub type SimpleShadow = GenericSimpleShadow<Color, Length, Length>;
|
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)?)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#[derive(
|
#[derive(
|
||||||
Animate,
|
Animate,
|
||||||
Clone,
|
Clone,
|
||||||
|
ComputeSquaredDistance,
|
||||||
Debug,
|
Debug,
|
||||||
MallocSizeOf,
|
MallocSizeOf,
|
||||||
PartialEq,
|
PartialEq,
|
||||||
|
|
|
@ -13,7 +13,6 @@ use std::fmt::{self, Write};
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
use style_traits::{CssWriter, KeywordsCollectFn, ParseError};
|
use style_traits::{CssWriter, KeywordsCollectFn, ParseError};
|
||||||
use style_traits::{SpecifiedValueInfo, StyleParseErrorKind, ToCss};
|
use style_traits::{SpecifiedValueInfo, StyleParseErrorKind, ToCss};
|
||||||
use values::distance::{ComputeSquaredDistance, SquaredDistance};
|
|
||||||
|
|
||||||
/// https://drafts.csswg.org/css-fonts-4/#feature-tag-value
|
/// https://drafts.csswg.org/css-fonts-4/#feature-tag-value
|
||||||
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue)]
|
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue)]
|
||||||
|
@ -47,7 +46,16 @@ where
|
||||||
///
|
///
|
||||||
/// https://drafts.csswg.org/css-fonts-4/#font-variation-settings-def
|
/// https://drafts.csswg.org/css-fonts-4/#font-variation-settings-def
|
||||||
#[derive(
|
#[derive(
|
||||||
Animate, Clone, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss,
|
Animate,
|
||||||
|
Clone,
|
||||||
|
ComputeSquaredDistance,
|
||||||
|
Debug,
|
||||||
|
Eq,
|
||||||
|
MallocSizeOf,
|
||||||
|
PartialEq,
|
||||||
|
SpecifiedValueInfo,
|
||||||
|
ToComputedValue,
|
||||||
|
ToCss,
|
||||||
)]
|
)]
|
||||||
pub struct VariationValue<Number> {
|
pub struct VariationValue<Number> {
|
||||||
/// A four-character tag, packed into a u32 (one byte per character).
|
/// A four-character tag, packed into a u32 (one byte per character).
|
||||||
|
@ -57,19 +65,6 @@ pub struct VariationValue<Number> {
|
||||||
pub value: 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.
|
/// A value both for font-variation-settings and font-feature-settings.
|
||||||
#[css(comma)]
|
#[css(comma)]
|
||||||
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss)]
|
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss)]
|
||||||
|
|
|
@ -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.
|
/// SVG Path parser.
|
||||||
struct PathParser<'a> {
|
struct PathParser<'a> {
|
||||||
chars: Peekable<Cloned<slice::Iter<'a, u8>>>,
|
chars: Peekable<Cloned<slice::Iter<'a, u8>>>,
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use animate::{AnimationInputAttrs, AnimationVariantAttrs};
|
use animate::{AnimationInputAttrs, AnimationVariantAttrs, AnimationFieldAttrs};
|
||||||
use cg;
|
use cg;
|
||||||
use quote::Tokens;
|
use quote::Tokens;
|
||||||
use syn::{DeriveInput, Path};
|
use syn::{DeriveInput, Path};
|
||||||
|
@ -47,8 +47,23 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
|
||||||
parse_quote!(#ty: ::values::distance::ComputeSquaredDistance),
|
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!(+));
|
}), quote!(+));
|
||||||
sum
|
sum
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue