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

@ -54,7 +54,8 @@ pub enum ShapeSource<BasicShape, ReferenceBox, Url> {
#[allow(missing_docs)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, ComputeSquaredDistance, Debug, PartialEq, ToComputedValue, ToCss)]
#[derive(Animate, Clone, ComputeSquaredDistance, Debug, PartialEq)]
#[derive(ToComputedValue, ToCss)]
pub enum BasicShape<H, V, LengthOrPercentage> {
Inset(InsetRect<LengthOrPercentage>),
Circle(Circle<H, V, LengthOrPercentage>),
@ -65,7 +66,7 @@ pub enum BasicShape<H, V, LengthOrPercentage> {
/// https://drafts.csswg.org/css-shapes/#funcdef-inset
#[allow(missing_docs)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, ComputeSquaredDistance, Debug, PartialEq, ToComputedValue)]
#[derive(Animate, Clone, ComputeSquaredDistance, Debug, PartialEq, ToComputedValue)]
pub struct InsetRect<LengthOrPercentage> {
pub rect: Rect<LengthOrPercentage>,
pub round: Option<BorderRadius<LengthOrPercentage>>,
@ -74,7 +75,7 @@ pub struct InsetRect<LengthOrPercentage> {
/// https://drafts.csswg.org/css-shapes/#funcdef-circle
#[allow(missing_docs)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, PartialEq, ToComputedValue)]
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, PartialEq, ToComputedValue)]
pub struct Circle<H, V, LengthOrPercentage> {
pub position: Position<H, V>,
pub radius: ShapeRadius<LengthOrPercentage>,
@ -83,7 +84,7 @@ pub struct Circle<H, V, LengthOrPercentage> {
/// https://drafts.csswg.org/css-shapes/#funcdef-ellipse
#[allow(missing_docs)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, PartialEq, ToComputedValue)]
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, PartialEq, ToComputedValue)]
pub struct Ellipse<H, V, LengthOrPercentage> {
pub position: Position<H, V>,
pub semiaxis_x: ShapeRadius<LengthOrPercentage>,
@ -122,6 +123,8 @@ 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,
@ -174,43 +177,6 @@ impl<B, T, U> HasViewportPercentage for ShapeSource<B, T, U> {
fn has_viewport_percentage(&self) -> bool { false }
}
impl<H, V, L> Animate for BasicShape<H, V, L>
where
H: Animate,
V: Animate,
L: Animate + Copy,
{
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
match (self, other) {
(&BasicShape::Circle(ref this), &BasicShape::Circle(ref other)) => {
Ok(BasicShape::Circle(this.animate(other, procedure)?))
},
(&BasicShape::Ellipse(ref this), &BasicShape::Ellipse(ref other)) => {
Ok(BasicShape::Ellipse(this.animate(other, procedure)?))
},
(&BasicShape::Inset(ref this), &BasicShape::Inset(ref other)) => {
Ok(BasicShape::Inset(this.animate(other, procedure)?))
},
(&BasicShape::Polygon(ref this), &BasicShape::Polygon(ref other)) => {
Ok(BasicShape::Polygon(this.animate(other, procedure)?))
},
_ => Err(()),
}
}
}
impl<L> Animate for InsetRect<L>
where
L: Animate + Copy,
{
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
Ok(InsetRect {
rect: self.rect.animate(&other.rect, procedure)?,
round: self.round.animate(&other.round, procedure)?,
})
}
}
impl<L> ToCss for InsetRect<L>
where L: ToCss + PartialEq
{
@ -225,35 +191,6 @@ impl<L> ToCss for InsetRect<L>
}
}
impl<H, V, L> Animate for Circle<H, V, L>
where
H: Animate,
V: Animate,
L: Animate,
{
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
Ok(Circle {
position: self.position.animate(&other.position, procedure)?,
radius: self.radius.animate(&other.radius, procedure)?,
})
}
}
impl<H, V, L> Animate for Ellipse<H, V, L>
where
H: Animate,
V: Animate,
L: Animate,
{
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
Ok(Ellipse {
position: self.position.animate(&other.position, procedure)?,
semiaxis_x: self.semiaxis_x.animate(&other.semiaxis_x, procedure)?,
semiaxis_y: self.semiaxis_y.animate(&other.semiaxis_y, procedure)?,
})
}
}
impl<L> Animate for ShapeRadius<L>
where
L: Animate,

View file

@ -7,7 +7,6 @@
use euclid::Size2D;
use std::fmt;
use style_traits::ToCss;
use values::animated::{Animate, Procedure};
use values::generics::rect::Rect;
/// A generic value for a single side of a `border-image-width` property.
@ -36,7 +35,8 @@ pub struct BorderImageSlice<NumberOrPercentage> {
///
/// https://drafts.csswg.org/css-backgrounds-3/#border-radius
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue)]
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, HasViewportPercentage)]
#[derive(PartialEq, ToComputedValue)]
pub struct BorderRadius<LengthOrPercentage> {
/// The top left radius.
pub top_left: BorderCornerRadius<LengthOrPercentage>,
@ -50,7 +50,8 @@ pub struct BorderRadius<LengthOrPercentage> {
/// A generic value for `border-*-radius` longhand properties.
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue)]
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, HasViewportPercentage)]
#[derive(PartialEq, ToComputedValue)]
pub struct BorderCornerRadius<L>(pub Size2D<L>);
impl<N> From<N> for BorderImageSlice<N>
@ -113,20 +114,6 @@ impl<L> BorderRadius<L>
}
}
impl<L> Animate for BorderRadius<L>
where
L: Animate + Copy,
{
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
Ok(BorderRadius::new(
self.top_left.animate(&other.top_left, procedure)?,
self.top_right.animate(&other.top_right, procedure)?,
self.bottom_right.animate(&other.bottom_right, procedure)?,
self.bottom_left.animate(&other.bottom_left, procedure)?,
))
}
}
impl<L> ToCss for BorderRadius<L>
where L: PartialEq + ToCss
{
@ -159,16 +146,6 @@ impl<L: Clone> From<L> for BorderCornerRadius<L> {
}
}
impl<L> Animate for BorderCornerRadius<L>
where
L: Animate + Copy,
{
#[inline]
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
Ok(BorderCornerRadius(self.0.animate(&other.0, procedure)?))
}
}
impl<L> ToCss for BorderCornerRadius<L>
where L: ToCss,
{

View file

@ -65,8 +65,8 @@ pub enum Filter<Angle, Factor, Length, DropShadow> {
/// Contrary to the canonical order from the spec, the color is serialised
/// first, like in Gecko and Webkit.
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, ComputeSquaredDistance, Debug, HasViewportPercentage, PartialEq)]
#[derive(ToAnimatedValue, ToAnimatedZero, ToCss)]
#[derive(Animate, Clone, ComputeSquaredDistance, Debug, HasViewportPercentage)]
#[derive(PartialEq, ToAnimatedValue, ToAnimatedZero, ToCss)]
pub struct SimpleShadow<Color, SizeLength, ShapeLength> {
/// Color.
pub color: Color,

View file

@ -268,12 +268,12 @@ impl ToCss for FontSettingTagFloat {
/// A wrapper of Non-negative values.
#[cfg_attr(feature = "servo", derive(Deserialize, HeapSizeOf, Serialize))]
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, HasViewportPercentage)]
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, HasViewportPercentage)]
#[derive(PartialEq, PartialOrd, ToAnimatedZero, ToComputedValue, ToCss)]
pub struct NonNegative<T>(pub T);
/// A wrapper of greater-than-or-equal-to-one values.
#[cfg_attr(feature = "servo", derive(Deserialize, HeapSizeOf, Serialize))]
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, HasViewportPercentage)]
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, HasViewportPercentage)]
#[derive(PartialEq, PartialOrd, ToAnimatedZero, ToComputedValue, ToCss)]
pub struct GreaterThanOrEqualToOne<T>(pub T);

View file

@ -7,8 +7,8 @@
/// A generic type for representing a CSS [position](https://drafts.csswg.org/css-values/#position).
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, HasViewportPercentage)]
#[derive(PartialEq, ToAnimatedZero, ToComputedValue)]
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug)]
#[derive(HasViewportPercentage, PartialEq, ToAnimatedZero, ToComputedValue)]
pub struct Position<H, V> {
/// The horizontal component of position.
pub horizontal: H,

View file

@ -8,12 +8,12 @@ use cssparser::Parser;
use parser::{Parse, ParserContext};
use std::fmt;
use style_traits::{ToCss, ParseError};
use values::animated::{Animate, Procedure};
/// A CSS value made of four components, where its `ToCss` impl will try to
/// serialize as few components as possible, like for example in `border-width`.
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug)]
#[derive(HasViewportPercentage, PartialEq, ToComputedValue)]
pub struct Rect<T>(pub T, pub T, pub T, pub T);
impl<T> Rect<T> {
@ -52,20 +52,6 @@ impl<T> Rect<T>
}
}
impl<L> Animate for Rect<L>
where
L: Animate,
{
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
Ok(Rect(
self.0.animate(&other.0, procedure)?,
self.1.animate(&other.1, procedure)?,
self.2.animate(&other.2, procedure)?,
self.3.animate(&other.3, procedure)?,
))
}
}
impl<T> From<T> for Rect<T>
where T: Clone
{

View file

@ -110,7 +110,8 @@ where
/// A generic value for the `line-height` property.
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, HasViewportPercentage, PartialEq, ToAnimatedValue, ToCss)]
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug)]
#[derive(HasViewportPercentage, PartialEq, ToAnimatedValue, ToCss)]
pub enum LineHeight<Number, LengthOrPercentage> {
/// `normal`
Normal,

View file

@ -24,7 +24,7 @@ pub struct Matrix<T, U = T> {
/// A generic transform origin.
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, HasViewportPercentage)]
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, HasViewportPercentage)]
#[derive(PartialEq, ToAnimatedZero, ToComputedValue, ToCss)]
pub struct TransformOrigin<H, V, Depth> {
/// The horizontal origin.