Derive a bunch of animation traits for some SVG types

This commit is contained in:
Anthony Ramine 2017-08-26 00:06:37 +02:00
parent eaf2f1ec33
commit 405e34aa74
2 changed files with 5 additions and 73 deletions

View file

@ -2384,27 +2384,6 @@ pub type IntermediateSVGPaint = SVGPaint<AnimatedRGBA, ComputedUrl>;
/// Animated SVGPaintKind /// Animated SVGPaintKind
pub type IntermediateSVGPaintKind = SVGPaintKind<AnimatedRGBA, ComputedUrl>; pub type IntermediateSVGPaintKind = SVGPaintKind<AnimatedRGBA, ComputedUrl>;
impl Animate for IntermediateSVGPaint {
#[inline]
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
Ok(IntermediateSVGPaint {
kind: self.kind.animate(&other.kind, procedure)?,
fallback: self.fallback.animate(&other.fallback, procedure)?,
})
}
}
impl ComputeSquaredDistance for IntermediateSVGPaint {
#[inline]
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
// FIXME(nox): This should be derived.
Ok(
self.kind.compute_squared_distance(&other.kind)? +
self.fallback.compute_squared_distance(&other.fallback)?,
)
}
}
impl ToAnimatedZero for IntermediateSVGPaint { impl ToAnimatedZero for IntermediateSVGPaint {
#[inline] #[inline]
fn to_animated_zero(&self) -> Result<Self, ()> { fn to_animated_zero(&self) -> Result<Self, ()> {
@ -2415,56 +2394,6 @@ impl ToAnimatedZero for IntermediateSVGPaint {
} }
} }
impl Animate for IntermediateSVGPaintKind {
#[inline]
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
match (self, other) {
(&SVGPaintKind::Color(ref this), &SVGPaintKind::Color(ref other)) => {
Ok(SVGPaintKind::Color(this.animate(other, procedure)?))
},
(&SVGPaintKind::ContextFill, &SVGPaintKind::ContextFill) => Ok(SVGPaintKind::ContextFill),
(&SVGPaintKind::ContextStroke, &SVGPaintKind::ContextStroke) => Ok(SVGPaintKind::ContextStroke),
_ => {
// FIXME: Context values should be interpolable with colors,
// Gecko doesn't implement this behavior either.
Err(())
}
}
}
}
impl ComputeSquaredDistance for IntermediateSVGPaintKind {
#[inline]
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
match (self, other) {
(&SVGPaintKind::Color(ref this), &SVGPaintKind::Color(ref other)) => {
this.compute_squared_distance(other)
}
(&SVGPaintKind::None, &SVGPaintKind::None) |
(&SVGPaintKind::ContextFill, &SVGPaintKind::ContextFill) |
(&SVGPaintKind::ContextStroke, &SVGPaintKind::ContextStroke) => {
Ok(SquaredDistance::Value(0.))
},
_ => Err(())
}
}
}
impl ToAnimatedZero for IntermediateSVGPaintKind {
#[inline]
fn to_animated_zero(&self) -> Result<Self, ()> {
match *self {
SVGPaintKind::Color(ref color) => {
Ok(SVGPaintKind::Color(color.to_animated_zero()?))
},
SVGPaintKind::None |
SVGPaintKind::ContextFill |
SVGPaintKind::ContextStroke => Ok(self.clone()),
_ => Err(()),
}
}
}
impl From<NonNegativeLengthOrPercentage> for NumberOrPercentage { impl From<NonNegativeLengthOrPercentage> for NumberOrPercentage {
fn from(lop: NonNegativeLengthOrPercentage) -> NumberOrPercentage { fn from(lop: NonNegativeLengthOrPercentage) -> NumberOrPercentage {
lop.0.into() lop.0.into()

View file

@ -16,7 +16,8 @@ use values::distance::{ComputeSquaredDistance, SquaredDistance};
/// ///
/// https://www.w3.org/TR/SVG2/painting.html#SpecifyingPaint /// https://www.w3.org/TR/SVG2/painting.html#SpecifyingPaint
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, Debug, PartialEq, ToAnimatedValue, ToComputedValue, ToCss)] #[derive(Animate, Clone, ComputeSquaredDistance, Debug, PartialEq)]
#[derive(ToAnimatedValue, ToComputedValue, ToCss)]
pub struct SVGPaint<ColorType, UrlPaintServer> { pub struct SVGPaint<ColorType, UrlPaintServer> {
/// The paint source /// The paint source
pub kind: SVGPaintKind<ColorType, UrlPaintServer>, pub kind: SVGPaintKind<ColorType, UrlPaintServer>,
@ -30,13 +31,15 @@ pub struct SVGPaint<ColorType, UrlPaintServer> {
/// to have a fallback, Gecko lets the context /// to have a fallback, Gecko lets the context
/// properties have a fallback as well. /// properties have a fallback as well.
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, Debug, PartialEq, ToAnimatedValue, ToComputedValue, ToCss)] #[derive(Animate, Clone, ComputeSquaredDistance, Debug, PartialEq)]
#[derive(ToAnimatedValue, ToAnimatedZero, ToComputedValue, ToCss)]
pub enum SVGPaintKind<ColorType, UrlPaintServer> { pub enum SVGPaintKind<ColorType, UrlPaintServer> {
/// `none` /// `none`
None, None,
/// `<color>` /// `<color>`
Color(ColorType), Color(ColorType),
/// `url(...)` /// `url(...)`
#[animation(error)]
PaintServer(UrlPaintServer), PaintServer(UrlPaintServer),
/// `context-fill` /// `context-fill`
ContextFill, ContextFill,