mirror of
https://github.com/servo/servo.git
synced 2025-08-12 08:55:32 +01:00
Derive the most trivial ToAnimatedZero impls
This commit is contained in:
parent
8ca9542de6
commit
faaf31411a
15 changed files with 112 additions and 174 deletions
|
@ -12,7 +12,7 @@ use values::distance::{ComputeSquaredDistance, SquaredDistance};
|
|||
/// Unlike in computed values, each component value may exceed the
|
||||
/// range `[0.0, 1.0]`.
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, ToAnimatedZero)]
|
||||
pub struct RGBA {
|
||||
/// The red component.
|
||||
pub red: f32,
|
||||
|
@ -69,13 +69,6 @@ impl ComputeSquaredDistance for RGBA {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for RGBA {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||
Ok(RGBA::transparent())
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
|
|
|
@ -223,15 +223,3 @@ impl Animate for SimpleShadow {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for SimpleShadow {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||
Ok(SimpleShadow {
|
||||
color: self.color.to_animated_zero()?,
|
||||
horizontal: self.horizontal.to_animated_zero()?,
|
||||
vertical: self.vertical.to_animated_zero()?,
|
||||
blur: self.blur.to_animated_zero()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,12 +8,12 @@ use std::{f32, f64, fmt};
|
|||
use std::f64::consts::PI;
|
||||
use style_traits::ToCss;
|
||||
use values::CSSFloat;
|
||||
use values::animated::{Animate, Procedure, ToAnimatedZero};
|
||||
use values::animated::{Animate, Procedure};
|
||||
use values::distance::{ComputeSquaredDistance, SquaredDistance};
|
||||
|
||||
/// A computed angle.
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf, Deserialize, Serialize))]
|
||||
#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, PartialOrd)]
|
||||
#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, PartialOrd, ToAnimatedZero)]
|
||||
pub enum Angle {
|
||||
/// An angle with degree unit.
|
||||
Degree(CSSFloat),
|
||||
|
@ -85,18 +85,6 @@ impl Animate for Angle {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for Angle {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Angle, ()> {
|
||||
match *self {
|
||||
Angle::Degree(ref this) => Ok(Angle::Degree(this.to_animated_zero()?)),
|
||||
Angle::Gradian(ref this) => Ok(Angle::Gradian(this.to_animated_zero()?)),
|
||||
Angle::Radian(ref this) => Ok(Angle::Radian(this.to_animated_zero()?)),
|
||||
Angle::Turn(ref this) => Ok(Angle::Turn(this.to_animated_zero()?)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ComputeSquaredDistance for Angle {
|
||||
#[inline]
|
||||
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
|
||||
|
|
|
@ -286,7 +286,7 @@ impl ToComputedValue for specified::CalcLengthOrPercentage {
|
|||
|
||||
#[allow(missing_docs)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Copy, PartialEq, ToCss)]
|
||||
#[derive(Clone, Copy, PartialEq, ToAnimatedZero, ToCss)]
|
||||
pub enum LengthOrPercentage {
|
||||
Length(Au),
|
||||
Percentage(Percentage),
|
||||
|
|
|
@ -7,11 +7,12 @@
|
|||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use values::{CSSFloat, serialize_percentage};
|
||||
use values::animated::{Animate, Procedure, ToAnimatedZero};
|
||||
use values::animated::{Animate, Procedure};
|
||||
|
||||
/// A computed percentage.
|
||||
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, Default, HasViewportPercentage, PartialEq, PartialOrd)]
|
||||
#[cfg_attr(feature = "servo", derive(Deserialize, HeapSizeOf, Serialize))]
|
||||
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, Default)]
|
||||
#[derive(HasViewportPercentage, PartialEq, PartialOrd, ToAnimatedZero)]
|
||||
pub struct Percentage(pub CSSFloat);
|
||||
|
||||
impl Percentage {
|
||||
|
@ -42,13 +43,6 @@ impl Animate for Percentage {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for Percentage {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||
Ok(Percentage(0.))
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for Percentage {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||
where
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
//! Computed types for CSS values that are related to transformations.
|
||||
|
||||
use values::animated::{Animate, Procedure, ToAnimatedZero};
|
||||
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;
|
||||
|
@ -37,14 +37,3 @@ impl Animate for TransformOrigin {
|
|||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for TransformOrigin {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||
Ok(Self::new(
|
||||
self.horizontal.to_animated_zero()?,
|
||||
self.vertical.to_animated_zero()?,
|
||||
self.depth.to_animated_zero()?,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,7 +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, ToAnimatedValue, ToCss)]
|
||||
#[derive(Clone, ComputeSquaredDistance, Debug, HasViewportPercentage, PartialEq)]
|
||||
#[derive(ToAnimatedValue, ToAnimatedZero, ToCss)]
|
||||
pub struct SimpleShadow<Color, SizeLength, ShapeLength> {
|
||||
/// Color.
|
||||
pub color: Color,
|
||||
|
|
|
@ -269,11 +269,11 @@ 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(PartialEq, PartialOrd, ToComputedValue, ToCss)]
|
||||
#[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(PartialEq, PartialOrd, ToComputedValue, ToCss)]
|
||||
#[derive(PartialEq, PartialOrd, ToAnimatedZero, ToComputedValue, ToCss)]
|
||||
pub struct GreaterThanOrEqualToOne<T>(pub T);
|
||||
|
|
|
@ -7,7 +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, PartialEq, ToComputedValue)]
|
||||
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, HasViewportPercentage)]
|
||||
#[derive(PartialEq, ToAnimatedZero, ToComputedValue)]
|
||||
pub struct Position<H, V> {
|
||||
/// The horizontal component of position.
|
||||
pub horizontal: H,
|
||||
|
|
|
@ -102,12 +102,12 @@ impl<ColorType: Parse, UrlPaintServer: Parse> Parse for SVGPaint<ColorType, UrlP
|
|||
/// https://www.w3.org/TR/SVG11/painting.html#StrokeProperties
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToAnimatedValue)]
|
||||
#[derive(ToCss, ToComputedValue)]
|
||||
pub enum SvgLengthOrPercentageOrNumber<LengthOrPercentageType, NumberType> {
|
||||
#[derive(ToAnimatedZero, ToCss, ToComputedValue)]
|
||||
pub enum SvgLengthOrPercentageOrNumber<LengthOrPercentage, Number> {
|
||||
/// <length> | <percentage>
|
||||
LengthOrPercentage(LengthOrPercentageType),
|
||||
LengthOrPercentage(LengthOrPercentage),
|
||||
/// <number>
|
||||
Number(NumberType),
|
||||
Number(Number),
|
||||
}
|
||||
|
||||
impl<L, N> ComputeSquaredDistance for SvgLengthOrPercentageOrNumber<L, N>
|
||||
|
@ -184,7 +184,8 @@ impl <LengthOrPercentageType: Parse, NumberType: Parse> Parse for
|
|||
/// An SVG length value supports `context-value` in addition to length.
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, PartialEq)]
|
||||
#[derive(HasViewportPercentage, ToAnimatedValue, ToComputedValue, ToCss)]
|
||||
#[derive(HasViewportPercentage, ToAnimatedValue, ToAnimatedZero)]
|
||||
#[derive(ToComputedValue, ToCss)]
|
||||
pub enum SVGLength<LengthType> {
|
||||
/// `<length> | <percentage> | <number>`
|
||||
Length(LengthType),
|
||||
|
@ -228,7 +229,8 @@ impl<LengthType> ToCss for SVGStrokeDashArray<LengthType> where LengthType: ToCs
|
|||
/// An SVG opacity value accepts `context-{fill,stroke}-opacity` in
|
||||
/// addition to opacity value.
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, PartialEq, HasViewportPercentage, ToComputedValue, ToCss)]
|
||||
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, HasViewportPercentage)]
|
||||
#[derive(PartialEq, ToAnimatedZero, ToComputedValue, ToCss)]
|
||||
pub enum SVGOpacity<OpacityType> {
|
||||
/// `<opacity-value>`
|
||||
Opacity(OpacityType),
|
||||
|
|
|
@ -24,7 +24,8 @@ pub struct Matrix<T, U = T> {
|
|||
|
||||
/// A generic transform origin.
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue, ToCss)]
|
||||
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, HasViewportPercentage)]
|
||||
#[derive(PartialEq, ToAnimatedZero, ToComputedValue, ToCss)]
|
||||
pub struct TransformOrigin<H, V, Depth> {
|
||||
/// The horizontal origin.
|
||||
pub horizontal: H,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue