Bug 1309752: Update animations if the logical to physical property changes. r?birtles draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Sun, 08 Jul 2018 16:14:21 +0200
changeset 815644 7b4dd75f61b2d5884f105d4a9b6aa93ec022d00e
parent 815643 f289db27f31ace8a0211611d7bf012e870a815d9
child 815645 4074c169373c04ddd78e39c322b104cf88930746
push id115591
push userbmo:emilio@crisal.io
push dateMon, 09 Jul 2018 16:15:39 +0000
reviewersbirtles
bugs1309752
milestone63.0a1
Bug 1309752: Update animations if the logical to physical property changes. r?birtles MozReview-Commit-ID: 1lbOcniojVO
servo/components/style/matching.rs
--- a/servo/components/style/matching.rs
+++ b/servo/components/style/matching.rs
@@ -228,68 +228,81 @@ trait PrivateMatchMethods: TElement {
 
         Some(style.0)
     }
 
     #[cfg(feature = "gecko")]
     fn needs_animations_update(
         &self,
         context: &mut StyleContext<Self>,
-        old_values: Option<&ComputedValues>,
-        new_values: &ComputedValues,
+        old_style: Option<&ComputedValues>,
+        new_style: &ComputedValues,
     ) -> bool {
-        let new_box_style = new_values.get_box();
-        let has_new_animation_style = new_box_style.specifies_animations();
+        let new_box_style = new_style.get_box();
+        let new_style_specifies_animations = new_box_style.specifies_animations();
 
-        let old = match old_values {
+        let old_style = match old_style {
             Some(old) => old,
-            None => return has_new_animation_style,
+            None => return new_style_specifies_animations,
         };
 
-        let old_box_style = old.get_box();
+        let has_animations = self.has_css_animations();
+        if !new_style_specifies_animations && !has_animations {
+            return false;
+        }
+
+        let old_box_style = old_style.get_box();
 
         let keyframes_could_have_changed = context
             .shared
             .traversal_flags
             .contains(TraversalFlags::ForCSSRuleChanges);
 
         // If the traversal is triggered due to changes in CSS rules changes, we
         // need to try to update all CSS animations on the element if the
         // element has or will have CSS animation style regardless of whether
         // the animation is running or not.
         //
         // TODO: We should check which @keyframes were added/changed/deleted and
         // update only animations corresponding to those @keyframes.
-        if keyframes_could_have_changed && (has_new_animation_style || self.has_css_animations()) {
+        if keyframes_could_have_changed {
             return true;
         }
 
         // If the animations changed, well...
         if !old_box_style.animations_equals(new_box_style) {
             return true;
         }
 
         let old_display = old_box_style.clone_display();
         let new_display = new_box_style.clone_display();
 
         // If we were display: none, we may need to trigger animations.
         if old_display == Display::None && new_display != Display::None {
-            return has_new_animation_style;
+            return new_style_specifies_animations;
         }
 
         // If we are becoming display: none, we may need to stop animations.
         if old_display != Display::None && new_display == Display::None {
-            return self.has_css_animations();
+            return has_animations;
+        }
+
+        // We might need to update animations if writing-mode or direction
+        // changed, and any of the animations contained logical properties.
+        //
+        // We may want to be more granular, but it's probably not worth.
+        if new_style.writing_mode != old_style.writing_mode {
+            return has_animations;
         }
 
         false
     }
 
-    /// Create a SequentialTask for resolving descendants in a SMIL display property
-    /// animation if the display property changed from none.
+    /// Create a SequentialTask for resolving descendants in a SMIL display
+    /// property animation if the display property changed from none.
     #[cfg(feature = "gecko")]
     fn handle_display_change_for_smil_if_needed(
         &self,
         context: &mut StyleContext<Self>,
         old_values: Option<&ComputedValues>,
         new_values: &ComputedValues,
         restyle_hints: RestyleHint,
     ) {