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

@ -122,7 +122,7 @@
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, Debug, PartialEq)]
% if need_animatable or animation_value_type == "ComputedValue":
#[derive(ComputeSquaredDistance)]
#[derive(Animate, ComputeSquaredDistance)]
% endif
pub struct T(
% if allow_empty and allow_empty != "NotInitial":
@ -133,14 +133,7 @@
);
% if need_animatable or animation_value_type == "ComputedValue":
use values::animated::{Animate, Procedure, ToAnimatedZero};
impl Animate for T {
#[inline]
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
Ok(T(self.0.animate(&other.0, procedure)?))
}
}
use values::animated::{ToAnimatedZero};
impl ToAnimatedZero for T {
#[inline]

View file

@ -54,7 +54,7 @@ use values::computed::{PositiveIntegerOrAuto, ToComputedValue};
use values::computed::length::{NonNegativeLengthOrAuto, NonNegativeLengthOrNormal};
use values::computed::length::NonNegativeLengthOrPercentage;
use values::distance::{ComputeSquaredDistance, SquaredDistance};
use values::generics::{GreaterThanOrEqualToOne, NonNegative};
use values::generics::NonNegative;
use values::generics::effects::Filter;
use values::generics::position as generic_position;
use values::generics::svg::{SVGLength, SvgLengthOrPercentageOrNumber, SVGPaint};
@ -1103,36 +1103,9 @@ impl Into<FontStretch> for f64 {
}
}
impl<H, V> Animate for generic_position::Position<H, V>
where
H: Animate,
V: Animate,
{
#[inline]
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
Ok(generic_position::Position {
horizontal: self.horizontal.animate(&other.horizontal, procedure)?,
vertical: self.vertical.animate(&other.vertical, procedure)?,
})
}
}
impl<H, V> RepeatableListAnimatable for generic_position::Position<H, V>
where H: RepeatableListAnimatable, V: RepeatableListAnimatable {}
/// https://drafts.csswg.org/css-transitions/#animtype-rect
impl Animate for ClipRect {
#[inline]
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
Ok(ClipRect {
top: self.top.animate(&other.top, procedure)?,
right: self.right.animate(&other.right, procedure)?,
bottom: self.bottom.animate(&other.bottom, procedure)?,
left: self.left.animate(&other.left, procedure)?,
})
}
}
impl ToAnimatedZero for ClipRect {
#[inline]
fn to_animated_zero(&self) -> Result<Self, ()> { Err(()) }
@ -1322,8 +1295,8 @@ pub struct InnerMatrix2D {
}
/// A 2d translation function.
#[derive(Clone, ComputeSquaredDistance, Copy, Debug)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug)]
pub struct Translate2D(f32, f32);
/// A 2d scale function.
@ -1356,15 +1329,6 @@ impl Animate for InnerMatrix2D {
}
}
impl Animate for Translate2D {
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
Ok(Translate2D(
self.0.animate(&other.0, procedure)?,
self.1.animate(&other.1, procedure)?,
))
}
}
impl Animate for Scale2D {
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
Ok(Scale2D(
@ -1596,8 +1560,8 @@ impl From<ComputedMatrix> for RawGeckoGfxMatrix4x4 {
}
/// A 3d translation.
#[derive(Clone, ComputeSquaredDistance, Copy, Debug)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug)]
pub struct Translate3D(f32, f32, f32);
/// A 3d scale function.
@ -1606,8 +1570,8 @@ pub struct Translate3D(f32, f32, f32);
pub struct Scale3D(f32, f32, f32);
/// A 3d skew function.
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Animate, Clone, Copy, Debug)]
pub struct Skew(f32, f32, f32);
/// A 3d perspective transformation.
@ -1889,16 +1853,6 @@ fn cross(row1: [f32; 3], row2: [f32; 3]) -> [f32; 3] {
]
}
impl Animate for Translate3D {
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
Ok(Translate3D(
self.0.animate(&other.0, procedure)?,
self.1.animate(&other.1, procedure)?,
self.2.animate(&other.2, procedure)?,
))
}
}
impl Animate for Scale3D {
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
Ok(Scale3D(
@ -1909,16 +1863,6 @@ impl Animate for Scale3D {
}
}
impl Animate for Skew {
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
Ok(Skew(
self.0.animate(&other.0, procedure)?,
self.1.animate(&other.1, procedure)?,
self.2.animate(&other.2, procedure)?,
))
}
}
impl ComputeSquaredDistance for Skew {
// We have to use atan() to convert the skew factors into skew angles, so implement
// ComputeSquaredDistance manually.
@ -2433,25 +2377,6 @@ impl ToAnimatedZero for TransformList {
}
}
impl<T, U> Animate for Either<T, U>
where
T: Animate,
U: Animate,
{
#[inline]
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
match (self, other) {
(&Either::First(ref this), &Either::First(ref other)) => {
Ok(Either::First(this.animate(other, procedure)?))
},
(&Either::Second(ref this), &Either::Second(ref other)) => {
Ok(Either::Second(this.animate(other, procedure)?))
},
_ => Err(()),
}
}
}
impl<A, B> ToAnimatedZero for Either<A, B>
where
A: ToAnimatedZero,
@ -2911,23 +2836,3 @@ sorted_shorthands = [(p, position) for position, p in enumerate(sorted_shorthand
% endfor
}
}
impl<T> Animate for NonNegative<T>
where
T: Animate,
{
#[inline]
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
Ok(NonNegative(self.0.animate(&other.0, procedure)?))
}
}
impl<T> Animate for GreaterThanOrEqualToOne<T>
where
T: Animate,
{
#[inline]
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
Ok(GreaterThanOrEqualToOne(self.0.animate(&other.0, procedure)?))
}
}

View file

@ -26,27 +26,16 @@ ${helpers.single_keyword("caption-side", "top bottom",
use values::specified::length::NonNegativeLength;
pub mod computed_value {
use values::animated::{Animate, Procedure, ToAnimatedValue, ToAnimatedZero};
use values::animated::{ToAnimatedValue, ToAnimatedZero};
use values::computed::NonNegativeAu;
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, PartialEq, ToCss)]
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, PartialEq, ToCss)]
pub struct T {
pub horizontal: NonNegativeAu,
pub vertical: NonNegativeAu,
}
/// https://drafts.csswg.org/css-transitions/#animtype-simple-list
impl Animate for T {
#[inline]
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
Ok(T {
horizontal: self.horizontal.animate(&other.horizontal, procedure)?,
vertical: self.vertical.animate(&other.vertical, procedure)?,
})
}
}
impl ToAnimatedZero for T {
#[inline]
fn to_animated_zero(&self) -> Result<Self, ()> { Err(()) }