Support #[animation(constant)] when deriving ToAnimatedZero

This commit is contained in:
Anthony Ramine 2017-08-26 00:07:02 +02:00
parent 405e34aa74
commit 8101887d31
4 changed files with 23 additions and 31 deletions

View file

@ -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 {
type AnimatedValue = FilterList;

View file

@ -11,7 +11,6 @@ use style_traits::ToCss;
use style_traits::values::specified::AllowedLengthType;
use super::{Number, ToComputedValue, Context, Percentage};
use values::{Auto, CSSFloat, Either, ExtremumLength, None_, Normal, specified};
use values::animated::ToAnimatedZero;
use values::computed::{NonNegativeAu, NonNegativeNumber};
use values::distance::{ComputeSquaredDistance, SquaredDistance};
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)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, Copy, Debug, PartialEq, ToAnimatedZero)]
pub struct CalcLengthOrPercentage {
#[animation(constant)]
pub clamping_mode: AllowedLengthType,
length: Au,
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 {
#[inline]
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {

View file

@ -11,7 +11,8 @@ use values::specified::url::SpecifiedUrl;
/// A generic value for a single `box-shadow`.
#[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> {
/// The base shadow.
pub base: SimpleShadow<Color, SizeLength, BlurShapeLength>,

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::AnimateAttrs;
use animate::{AnimateAttrs, AnimateFieldAttrs};
use cg;
use quote;
use syn;
@ -25,11 +25,24 @@ pub fn derive(input: syn::DeriveInput) -> quote::Tokens {
let bindings_pairs = bindings.into_iter().zip(mapped_bindings);
let mut computations = quote!();
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());
quote! {
let #mapped_binding =
::values::animated::ToAnimatedZero::to_animated_zero(#binding)?;
}
}
}));
computations.append(quote! { Ok(#mapped) });
Some(computations)