Derive the most trivial Animate impls

This commit is contained in:
Anthony Ramine 2017-08-22 18:45:30 +02:00
parent faaf31411a
commit 7ee124b1ed
20 changed files with 168 additions and 314 deletions

View file

@ -439,7 +439,7 @@ pub type NonNegativeLengthOrPercentageOrNumber = Either<NonNegativeNumber, NonNe
#[allow(missing_docs)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, Eq, PartialEq)]
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, Eq, PartialEq)]
/// A computed cliprect for clip and image-region
pub struct ClipRect {
pub top: Option<Au>,

View file

@ -7,11 +7,10 @@
use std::fmt;
use style_traits::ToCss;
use values::{CSSFloat, serialize_percentage};
use values::animated::{Animate, Procedure};
/// A computed percentage.
#[cfg_attr(feature = "servo", derive(Deserialize, HeapSizeOf, Serialize))]
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, Default)]
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, Default)]
#[derive(HasViewportPercentage, PartialEq, PartialOrd, ToAnimatedZero)]
pub struct Percentage(pub CSSFloat);
@ -35,14 +34,6 @@ impl Percentage {
}
}
/// https://drafts.csswg.org/css-transitions/#animtype-percentage
impl Animate for Percentage {
#[inline]
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
Ok(Percentage(self.0.animate(&other.0, procedure)?))
}
}
impl ToCss for Percentage {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
where

View file

@ -5,7 +5,7 @@
//! Computed types for text properties.
use values::{CSSInteger, CSSFloat};
use values::animated::{Animate, Procedure, ToAnimatedZero};
use values::animated::ToAnimatedZero;
use values::computed::{NonNegativeAu, NonNegativeNumber};
use values::computed::length::{Length, LengthOrPercentage};
use values::generics::text::InitialLetter as GenericInitialLetter;
@ -24,28 +24,6 @@ pub type WordSpacing = Spacing<LengthOrPercentage>;
/// A computed value for the `line-height` property.
pub type LineHeight = GenericLineHeight<NonNegativeNumber, NonNegativeAu>;
impl Animate for LineHeight {
#[inline]
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
match (self, other) {
(&GenericLineHeight::Length(ref this), &GenericLineHeight::Length(ref other)) => {
Ok(GenericLineHeight::Length(this.animate(other, procedure)?))
},
(&GenericLineHeight::Number(ref this), &GenericLineHeight::Number(ref other)) => {
Ok(GenericLineHeight::Number(this.animate(other, procedure)?))
},
(&GenericLineHeight::Normal, &GenericLineHeight::Normal) => {
Ok(GenericLineHeight::Normal)
},
#[cfg(feature = "gecko")]
(&GenericLineHeight::MozBlockHeight, &GenericLineHeight::MozBlockHeight) => {
Ok(GenericLineHeight::MozBlockHeight)
},
_ => Err(()),
}
}
}
impl ToAnimatedZero for LineHeight {
#[inline]
fn to_animated_zero(&self) -> Result<Self, ()> { Err(()) }

View file

@ -4,7 +4,6 @@
//! Computed types for CSS values that are related to transformations.
use values::animated::{Animate, Procedure};
use values::computed::{Length, LengthOrPercentage, Number, Percentage};
use values::generics::transform::TimingFunction as GenericTimingFunction;
use values::generics::transform::TransformOrigin as GenericTransformOrigin;
@ -26,14 +25,3 @@ impl TransformOrigin {
)
}
}
impl Animate for TransformOrigin {
#[inline]
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
Ok(Self::new(
self.horizontal.animate(&other.horizontal, procedure)?,
self.vertical.animate(&other.vertical, procedure)?,
self.depth.animate(&other.depth, procedure)?,
))
}
}