mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
Support #[animation(constant)] when deriving ToAnimatedZero
This commit is contained in:
parent
405e34aa74
commit
8101887d31
4 changed files with 23 additions and 31 deletions
|
@ -152,17 +152,6 @@ impl ComputeSquaredDistance for BoxShadow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToAnimatedZero for BoxShadow {
|
|
||||||
#[inline]
|
|
||||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
|
||||||
Ok(BoxShadow {
|
|
||||||
base: self.base.to_animated_zero()?,
|
|
||||||
spread: self.spread.to_animated_zero()?,
|
|
||||||
inset: self.inset,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToAnimatedValue for ComputedFilterList {
|
impl ToAnimatedValue for ComputedFilterList {
|
||||||
type AnimatedValue = FilterList;
|
type AnimatedValue = FilterList;
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ use style_traits::ToCss;
|
||||||
use style_traits::values::specified::AllowedLengthType;
|
use style_traits::values::specified::AllowedLengthType;
|
||||||
use super::{Number, ToComputedValue, Context, Percentage};
|
use super::{Number, ToComputedValue, Context, Percentage};
|
||||||
use values::{Auto, CSSFloat, Either, ExtremumLength, None_, Normal, specified};
|
use values::{Auto, CSSFloat, Either, ExtremumLength, None_, Normal, specified};
|
||||||
use values::animated::ToAnimatedZero;
|
|
||||||
use values::computed::{NonNegativeAu, NonNegativeNumber};
|
use values::computed::{NonNegativeAu, NonNegativeNumber};
|
||||||
use values::distance::{ComputeSquaredDistance, SquaredDistance};
|
use values::distance::{ComputeSquaredDistance, SquaredDistance};
|
||||||
use values::generics::NonNegative;
|
use values::generics::NonNegative;
|
||||||
|
@ -64,26 +63,16 @@ impl ToComputedValue for specified::Length {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, ToAnimatedZero)]
|
||||||
pub struct CalcLengthOrPercentage {
|
pub struct CalcLengthOrPercentage {
|
||||||
|
#[animation(constant)]
|
||||||
pub clamping_mode: AllowedLengthType,
|
pub clamping_mode: AllowedLengthType,
|
||||||
length: Au,
|
length: Au,
|
||||||
pub percentage: Option<Percentage>,
|
pub percentage: Option<Percentage>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToAnimatedZero for CalcLengthOrPercentage {
|
|
||||||
#[inline]
|
|
||||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
|
||||||
Ok(CalcLengthOrPercentage {
|
|
||||||
clamping_mode: self.clamping_mode,
|
|
||||||
length: self.length.to_animated_zero()?,
|
|
||||||
percentage: self.percentage.to_animated_zero()?,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ComputeSquaredDistance for CalcLengthOrPercentage {
|
impl ComputeSquaredDistance for CalcLengthOrPercentage {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
|
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
|
||||||
|
|
|
@ -11,7 +11,8 @@ use values::specified::url::SpecifiedUrl;
|
||||||
|
|
||||||
/// A generic value for a single `box-shadow`.
|
/// A generic value for a single `box-shadow`.
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
#[derive(Animate, Clone, Debug, HasViewportPercentage, PartialEq, ToAnimatedValue)]
|
#[derive(Animate, Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||||
|
#[derive(ToAnimatedValue, ToAnimatedZero)]
|
||||||
pub struct BoxShadow<Color, SizeLength, BlurShapeLength, ShapeLength> {
|
pub struct BoxShadow<Color, SizeLength, BlurShapeLength, ShapeLength> {
|
||||||
/// The base shadow.
|
/// The base shadow.
|
||||||
pub base: SimpleShadow<Color, SizeLength, BlurShapeLength>,
|
pub base: SimpleShadow<Color, SizeLength, BlurShapeLength>,
|
||||||
|
|
|
@ -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::AnimateAttrs;
|
use animate::{AnimateAttrs, AnimateFieldAttrs};
|
||||||
use cg;
|
use cg;
|
||||||
use quote;
|
use quote;
|
||||||
use syn;
|
use syn;
|
||||||
|
@ -25,11 +25,24 @@ pub fn derive(input: syn::DeriveInput) -> quote::Tokens {
|
||||||
let bindings_pairs = bindings.into_iter().zip(mapped_bindings);
|
let bindings_pairs = bindings.into_iter().zip(mapped_bindings);
|
||||||
let mut computations = quote!();
|
let mut computations = quote!();
|
||||||
computations.append_all(bindings_pairs.map(|(binding, mapped_binding)| {
|
computations.append_all(bindings_pairs.map(|(binding, mapped_binding)| {
|
||||||
|
let field_attrs = cg::parse_field_attrs::<AnimateFieldAttrs>(&binding.field);
|
||||||
|
if field_attrs.constant {
|
||||||
|
if cg::is_parameterized(&binding.field.ty, where_clause.params) {
|
||||||
|
where_clause.inner.predicates.push(cg::where_predicate(
|
||||||
|
binding.field.ty.clone(),
|
||||||
|
&["std", "clone", "Clone"],
|
||||||
|
));
|
||||||
|
}
|
||||||
|
quote! {
|
||||||
|
let #mapped_binding = ::std::clone::Clone::clone(#binding);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
where_clause.add_trait_bound(binding.field.ty.clone());
|
where_clause.add_trait_bound(binding.field.ty.clone());
|
||||||
quote! {
|
quote! {
|
||||||
let #mapped_binding =
|
let #mapped_binding =
|
||||||
::values::animated::ToAnimatedZero::to_animated_zero(#binding)?;
|
::values::animated::ToAnimatedZero::to_animated_zero(#binding)?;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
computations.append(quote! { Ok(#mapped) });
|
computations.append(quote! { Ok(#mapped) });
|
||||||
Some(computations)
|
Some(computations)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue