Introduce #[animation(constant)] for the Animate trait

This allows us to handle fields that should be the same during animations.
This commit is contained in:
Anthony Ramine 2017-08-25 23:51:12 +02:00
parent e49dbc4dfa
commit eaf2f1ec33
5 changed files with 59 additions and 52 deletions

View file

@ -44,11 +44,18 @@ add_impls_for_keyword_enum!(ShapeBox);
/// A shape source, for some reference box.
#[allow(missing_docs)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, Debug, PartialEq, ToComputedValue, ToCss)]
#[derive(Animate, Clone, Debug, PartialEq, ToComputedValue, ToCss)]
pub enum ShapeSource<BasicShape, ReferenceBox, Url> {
#[animation(error)]
Url(Url),
Shape(BasicShape, Option<ReferenceBox>),
Shape(
BasicShape,
#[animation(constant)]
Option<ReferenceBox>,
),
#[animation(error)]
Box(ReferenceBox),
#[animation(error)]
None,
}
@ -126,29 +133,6 @@ define_css_keyword_enum!(FillRule:
);
add_impls_for_keyword_enum!(FillRule);
// FIXME(nox): This should be derivable, but we need to implement Animate
// on the T types.
impl<B, T, U> Animate for ShapeSource<B, T, U>
where
B: Animate,
T: Clone + PartialEq,
{
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
match (self, other) {
(
&ShapeSource::Shape(ref this, ref this_box),
&ShapeSource::Shape(ref other, ref other_box),
) if this_box == other_box => {
Ok(ShapeSource::Shape(
this.animate(other, procedure)?,
this_box.clone(),
))
},
_ => Err(()),
}
}
}
// FIXME(nox): Implement ComputeSquaredDistance for T types and stop
// using PartialEq here, this will let us derive this impl.
impl<B, T, U> ComputeSquaredDistance for ShapeSource<B, T, U>