Bug 1371199 - Add get_zero_value for IntermediateSVGPaint. r?birtles draft
authorMantaroh Yoshinaga <mantaroh@gmail.com>
Thu, 22 Jun 2017 13:26:42 +0900
changeset 598721 d2151daa94af22c59a8917757213ae5cd54e2820
parent 596660 72346a4d6afcc17504f911190dbf470100e879ec
child 598722 b83cc8d4b79a6b6988ce37b2d51ac6e85326b9a7
push id65296
push usermantaroh@gmail.com
push dateThu, 22 Jun 2017 04:33:16 +0000
reviewersbirtles
bugs1371199
milestone56.0a1
Bug 1371199 - Add get_zero_value for IntermediateSVGPaint. r?birtles MozReview-Commit-ID: EJM5EKxeU7i
servo/components/style/properties/helpers/animated_properties.mako.rs
--- 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.