Bug 1371199 - Add get_zero_value for IntermediateSVGPaint. r?birtles
MozReview-Commit-ID: EJM5EKxeU7i
--- a/servo/components/style/properties/helpers/animated_properties.mako.rs
+++ b/servo/components/style/properties/helpers/animated_properties.mako.rs
@@ -2761,17 +2761,17 @@ impl Animatable for IntermediateRGBA {
&(other.blue * other.alpha), self_portion, other_portion
)? * 1. / alpha;
Ok(IntermediateRGBA::new(red, green, blue, alpha))
}
}
#[inline]
fn get_zero_value(&self) -> Option<Self> {
- Some(IntermediateRGBA::new(0., 0., 0., 1.))
+ Some(IntermediateRGBA::transparent())
}
#[inline]
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
self.compute_squared_distance(other).map(|sq| sq.sqrt())
}
#[inline]
@@ -2978,16 +2978,24 @@ impl Animatable for IntermediateSVGPaint
self.compute_squared_distance(other).map(|sq| sq.sqrt())
}
#[inline]
fn compute_squared_distance(&self, other: &Self) -> Result<f64, ()> {
Ok(self.kind.compute_squared_distance(&other.kind)? +
self.fallback.compute_squared_distance(&other.fallback)?)
}
+
+ #[inline]
+ fn get_zero_value(&self) -> Option<Self> {
+ Some(IntermediateSVGPaint {
+ kind: option_try!(self.kind.get_zero_value()),
+ fallback: self.fallback.map(|v| v.get_zero_value().unwrap()),
+ })
+ }
}
impl Animatable for IntermediateSVGPaintKind {
#[inline]
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> {
match (self, other) {
(&SVGPaintKind::Color(ref self_color), &SVGPaintKind::Color(ref other_color)) => {
Ok(SVGPaintKind::Color(self_color.add_weighted(other_color, self_portion, other_portion)?))
@@ -3008,16 +3016,29 @@ impl Animatable for IntermediateSVGPaint
self_color.compute_distance(other_color)
}
(&SVGPaintKind::None, &SVGPaintKind::None) |
(&SVGPaintKind::ContextFill, &SVGPaintKind::ContextFill) |
(&SVGPaintKind::ContextStroke, &SVGPaintKind::ContextStroke)=> Ok(0.0),
_ => Err(())
}
}
+
+ #[inline]
+ fn get_zero_value(&self) -> Option<Self> {
+ match self {
+ &SVGPaintKind::Color(_) => {
+ Some(SVGPaintKind::Color(IntermediateRGBA::transparent()))
+ },
+ &SVGPaintKind::None |
+ &SVGPaintKind::ContextFill |
+ &SVGPaintKind::ContextStroke => Some(self.clone()),
+ _ => None,
+ }
+ }
}
#[derive(Copy, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[allow(missing_docs)]
/// Intermediate type for box-shadow and text-shadow.
/// The difference from normal shadow type is that this type uses
/// IntermediateColor instead of ParserColor.