Bug 1390352 - Skip adding/accumulating the values which corresponding rect offset is auto. r?manishearth,birtles draft
authorMantaroh Yoshinaga <mantaroh@gmail.com>
Wed, 23 Aug 2017 09:51:17 +0900
changeset 650880 4db702232be90496c0048d6ab18221072c782ef0
parent 650865 ec808fe61a74599e89ca63bb680cc9a5489b5ee8
child 727527 fb45dcfed301286c016960b47d4564abdd3ec86a
push id75527
push userbmo:mantaroh@gmail.com
push dateWed, 23 Aug 2017 00:51:55 +0000
reviewersmanishearth, birtles
bugs1390352
milestone57.0a1
Bug 1390352 - Skip adding/accumulating the values which corresponding rect offset is auto. r?manishearth,birtles This patch will skip add_weighted() when self_portion + other_portion not equal to zero. (i.e. adding or accumulating). Gecko does same behavior since we can't add two auto value. MozReview-Commit-ID: 7vzF548nQuD
servo/components/style/properties/helpers/animated_properties.mako.rs
servo/components/style/values/computed/mod.rs
--- a/servo/components/style/properties/helpers/animated_properties.mako.rs
+++ b/servo/components/style/properties/helpers/animated_properties.mako.rs
@@ -1150,16 +1150,20 @@ where
 
 impl<H, V> RepeatableListAnimatable for generic_position::Position<H, V>
     where H: RepeatableListAnimatable, V: RepeatableListAnimatable {}
 
 /// https://drafts.csswg.org/css-transitions/#animtype-rect
 impl Animate for ClipRect {
     #[inline]
     fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
+        if !self.can_animate_with(other, procedure) {
+            return Err(());
+        }
+
         Ok(ClipRect {
             top: self.top.animate(&other.top, procedure)?,
             right: self.right.animate(&other.right, procedure)?,
             bottom: self.bottom.animate(&other.bottom, procedure)?,
             left: self.left.animate(&other.left, procedure)?,
         })
     }
 }
--- a/servo/components/style/values/computed/mod.rs
+++ b/servo/components/style/values/computed/mod.rs
@@ -15,16 +15,17 @@ use properties::{ComputedValues, StyleBu
 #[cfg(feature = "servo")]
 use servo_url::ServoUrl;
 use std::f32;
 use std::fmt;
 #[cfg(feature = "servo")]
 use std::sync::Arc;
 use style_traits::ToCss;
 use super::{CSSFloat, CSSInteger};
+use super::animated::Procedure;
 use super::generics::{GreaterThanOrEqualToOne, NonNegative};
 use super::generics::grid::{TrackBreadth as GenericTrackBreadth, TrackSize as GenericTrackSize};
 use super::generics::grid::GridTemplateComponent as GenericGridTemplateComponent;
 use super::generics::grid::TrackList as GenericTrackList;
 use super::specified;
 
 pub use app_units::Au;
 pub use properties::animated_properties::TransitionProperty;
@@ -476,16 +477,46 @@ impl ToCss for ClipRect {
             left.to_css(dest)?;
         } else {
             dest.write_str("auto")?;
         }
         dest.write_str(")")
     }
 }
 
+impl ClipRect {
+    /// Returns true if both values can be interpolated/added together using the
+    /// specified interpolation procedure.
+    fn can_animate_component(a: Option<Au>,
+                             b: Option<Au>,
+                             procedure: Procedure) -> bool {
+        match (a, b) {
+            (Some(_), Some(_)) => true,
+            (None, None) => {
+                match procedure {
+                    // We allow interpolating 'auto' with 'auto' but not adding them.
+                    Procedure::Interpolate { .. } => true,
+                    _ => false,
+                }
+            },
+            _ => false,
+        }
+    }
+
+    /// Return true if all corresponding components in this and |other| can be
+    /// interpolated/added together.
+    pub fn can_animate_with(&self, other: &Self, procedure: Procedure)
+        -> bool {
+        return ClipRect::can_animate_component(self.top, other.top, procedure) &&
+            ClipRect::can_animate_component(self.right, other.right, procedure) &&
+            ClipRect::can_animate_component(self.bottom, other.bottom, procedure) &&
+            ClipRect::can_animate_component(self.left, other.left, procedure);
+    }
+}
+
 /// rect(...) | auto
 pub type ClipRectOrAuto = Either<ClipRect, Auto>;
 
 /// The computed value of a grid `<track-breadth>`
 pub type TrackBreadth = GenericTrackBreadth<LengthOrPercentage>;
 
 /// The computed value of a grid `<track-size>`
 pub type TrackSize = GenericTrackSize<LengthOrPercentage>;