servo: Merge #12768 - Fix interpolation of CalcLengthOrPercentage (fixes #12765) (from nox:fix-transition); r=SimonSapin
authorAnthony Ramine <n.oxyde@gmail.com>
Tue, 09 Aug 2016 09:03:10 -0500
changeset 339458 3113bc024ae00c102f48b4b49e4c15574dcbb1da
parent 339457 8ec8c863e0c22356984bf559a52dcc6cfc859021
child 339459 703c3bfa19f8a99a2d91e6bfedc0676c2beb7406
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersSimonSapin
servo: Merge #12768 - Fix interpolation of CalcLengthOrPercentage (fixes #12765) (from nox:fix-transition); r=SimonSapin Source-Repo: https://github.com/servo/servo Source-Revision: 44ebbfc20de186f66eb39f6c076b369ed4e3c8ed
servo/components/style/properties/helpers/animated_properties.mako.rs
servo/components/style/values/specified/basic_shape.rs
--- a/servo/components/style/properties/helpers/animated_properties.mako.rs
+++ b/servo/components/style/properties/helpers/animated_properties.mako.rs
@@ -321,19 +321,35 @@ impl Interpolate for CSSParserColor {
         }
     }
 }
 
 /// https://drafts.csswg.org/css-transitions/#animtype-lpcalc
 impl Interpolate for CalcLengthOrPercentage {
     #[inline]
     fn interpolate(&self, other: &Self, time: f64) -> Result<Self, ()> {
+        fn interpolate_half<T>(this: Option<T>,
+                               other: Option<T>,
+                               time: f64)
+                               -> Result<Option<T>, ()>
+            where T: Default + Interpolate
+        {
+            match (this, other) {
+                (None, None) => Ok(None),
+                (this, other) => {
+                    let this = this.unwrap_or(T::default());
+                    let other = other.unwrap_or(T::default());
+                    this.interpolate(&other, time).map(Some)
+                }
+            }
+        }
+
         Ok(CalcLengthOrPercentage {
-            length: self.length.interpolate(&other.length, time).ok().and_then(|x|x),
-            percentage: self.percentage.interpolate(&other.percentage, time).ok().and_then(|x|x),
+            length: try!(interpolate_half(self.length, other.length, time)),
+            percentage: try!(interpolate_half(self.percentage, other.percentage, time)),
         })
     }
 }
 
 /// https://drafts.csswg.org/css-transitions/#animtype-lpcalc
 impl Interpolate for LengthOrPercentage {
     #[inline]
     fn interpolate(&self, other: &Self, time: f64) -> Result<Self, ()> {
--- a/servo/components/style/values/specified/basic_shape.rs
+++ b/servo/components/style/values/specified/basic_shape.rs
@@ -2,24 +2,23 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 //! CSS handling for the specified value of
 //! [`basic-shape`][basic-shape]s
 //!
 //! [basic-shape]: https://drafts.csswg.org/css-shapes/#typedef-basic-shape
 
-use app_units::Au;
 use cssparser::{Parser, ToCss};
 use properties::shorthands::{parse_four_sides, serialize_four_sides};
 use std::fmt;
 use values::computed::basic_shape as computed_basic_shape;
 use values::computed::{Context, ToComputedValue, ComputedValueAsSpecified};
-use values::specified::position::{Position, PositionComponent};
-use values::specified::{BorderRadiusSize, Length, LengthOrPercentage, Percentage};
+use values::specified::position::Position;
+use values::specified::{BorderRadiusSize, LengthOrPercentage, Percentage};
 
 #[derive(Clone, PartialEq, Debug)]
 #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
 pub enum BasicShape {
     Inset(InsetRect),
     Circle(Circle),
     Ellipse(Ellipse),
     Polygon(Polygon),