Bug 1362897 - Preserve the unit when interpolating/adding angles with matching units. r?birtles draft
authorMantaroh Yoshinaga <mantaroh@gmail.com>
Fri, 09 Jun 2017 13:56:28 +0900
changeset 591569 5c5d25610bd65a8c15c5cd59d4293019543fdc7b
parent 591406 f4262773c4331d4ae139be536ce278ea9aad3436
child 591570 e7639cf1a66941390d3ef27a9ed9495b726c6cd8
push id63091
push usermantaroh@gmail.com
push dateFri, 09 Jun 2017 07:21:29 +0000
reviewersbirtles
bugs1362897
milestone55.0a1
Bug 1362897 - Preserve the unit when interpolating/adding angles with matching units. r?birtles If the units of two angles being interpolated/added matches, we should preserve the original unit; otherwise, we fall back to radians. This matches the behavior of Gecko. MozReview-Commit-ID: 2myDGC7qFLc
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
@@ -894,19 +894,30 @@ impl Animatable for i32 {
         Ok((*self - *other).abs() as f64)
     }
 }
 
 /// https://drafts.csswg.org/css-transitions/#animtype-number
 impl Animatable for Angle {
     #[inline]
     fn add_weighted(&self, other: &Angle, self_portion: f64, other_portion: f64) -> Result<Self, ()> {
-        self.radians()
-            .add_weighted(&other.radians(), self_portion, other_portion)
-            .map(Angle::from_radians)
+        match (*self, *other) {
+            % for angle_type in [ 'Degree', 'Gradian', 'Turn' ]:
+            (Angle::${angle_type}(val1), Angle::${angle_type}(val2)) => {
+                Ok(Angle::${angle_type}(
+                    try!(val1.add_weighted(&val2, self_portion, other_portion))
+                ))
+            }
+            % endfor
+            _ => {
+                self.radians()
+                    .add_weighted(&other.radians(), self_portion, other_portion)
+                    .map(Angle::from_radians)
+            }
+        }
     }
 }
 
 /// https://drafts.csswg.org/css-transitions/#animtype-visibility
 impl Animatable for Visibility {
     #[inline]
     fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> {
         match (*self, *other) {