Bug 1341985 - Part 8: Split off animation related process in a function. r?heycam draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Fri, 10 Mar 2017 10:32:37 +0900
changeset 496325 c038533e701a49cb8f2b11ed6f481e65a9ac2881
parent 496324 4c4631a768350e89507481803f4d4d582f7d33f5
child 496326 c8a4acde3ba6e0b8f2de77adb511c97ac8010cf0
push id48568
push userhikezoe@mozilla.com
push dateFri, 10 Mar 2017 01:36:35 +0000
reviewersheycam
bugs1341985
milestone55.0a1
Bug 1341985 - Part 8: Split off animation related process in a function. r?heycam MozReview-Commit-ID: 2OUx5V1SE55
servo/components/style/matching.rs
--- a/servo/components/style/matching.rs
+++ b/servo/components/style/matching.rs
@@ -557,69 +557,92 @@ trait PrivateMatchMethods: TElement {
     /// setting them on the ElementData.
     fn cascade_primary_or_pseudo<'a>(&self,
                                      context: &StyleContext<Self>,
                                      data: &mut ElementData,
                                      pseudo: Option<&PseudoElement>,
                                      possibly_expired_animations: &mut Vec<PropertyAnimation>,
                                      booleans: CascadeBooleans) {
         // Collect some values.
-        let shared_context = context.shared;
         let (mut styles, restyle) = data.styles_and_restyle_mut();
         let mut primary_style = &mut styles.primary;
         let pseudos = &mut styles.pseudos;
         let mut pseudo_style = pseudo.map(|p| (p, pseudos.get_mut(p).unwrap()));
         let mut old_values =
             pseudo_style.as_mut().map_or_else(|| primary_style.values.take(), |p| p.1.values.take());
 
         // Compute the new values.
         let mut new_values = self.cascade_internal(context, primary_style,
                                                    &mut pseudo_style, &booleans);
 
         // Handle animations.
-        if booleans.animate && cfg!(feature = "servo") {
-            if let Some(ref mut old) = old_values {
-                self.update_animations_for_cascade(shared_context, old,
-                                                   possibly_expired_animations);
-            }
-
-            let new_animations_sender = &context.thread_local.new_animations_sender;
-            let this_opaque = self.as_node().opaque();
-            // Trigger any present animations if necessary.
-            animation::maybe_start_animations(&shared_context,
-                                              new_animations_sender,
-                                              this_opaque, &new_values);
-
-            // Trigger transitions if necessary. This will reset `new_values` back
-            // to its old value if it did trigger a transition.
-            if let Some(ref values) = old_values {
-                animation::start_transitions_if_applicable(
-                    new_animations_sender,
-                    this_opaque,
-                    self.as_node().to_unsafe(),
-                    &**values,
-                    &mut new_values,
-                    &shared_context.timer,
-                    &possibly_expired_animations);
-            }
+        if booleans.animate {
+            self.process_animations(&context,
+                                    &mut old_values,
+                                    &mut new_values,
+                                    pseudo,
+                                    possibly_expired_animations);
         }
 
         // Accumulate restyle damage.
         if let Some(old) = old_values {
             self.accumulate_damage(restyle.unwrap(), &old, &new_values, pseudo);
         }
 
         // Set the new computed values.
         if let Some((_, ref mut style)) = pseudo_style {
             style.values = Some(new_values);
         } else {
             primary_style.values = Some(new_values);
         }
     }
 
+    #[cfg(feature = "gecko")]
+    fn process_animations(&self,
+                          _context: &StyleContext<Self>,
+                          _old_values: &mut Option<Arc<ComputedValues>>,
+                          _new_values: &mut Arc<ComputedValues>,
+                          _pseudo: Option<&PseudoElement>,
+                          _possibly_expired_animations: &mut Vec<PropertyAnimation>) {
+    }
+
+    #[cfg(feature = "servo")]
+    fn process_animations(&self,
+                          context: &StyleContext<Self>,
+                          old_values: &mut Option<Arc<ComputedValues>>,
+                          new_values: &mut Arc<ComputedValues>,
+                          _pseudo: Option<&PseudoElement>,
+                          possibly_expired_animations: &mut Vec<PropertyAnimation>) {
+        let shared_context = context.shared;
+        if let Some(ref mut old) = *old_values {
+            self.update_animations_for_cascade(shared_context, old,
+                                               possibly_expired_animations);
+        }
+
+        let new_animations_sender = &context.thread_local.new_animations_sender;
+        let this_opaque = self.as_node().opaque();
+        // Trigger any present animations if necessary.
+        animation::maybe_start_animations(&shared_context,
+                                          new_animations_sender,
+                                          this_opaque, &new_values);
+
+        // Trigger transitions if necessary. This will reset `new_values` back
+        // to its old value if it did trigger a transition.
+        if let Some(ref values) = *old_values {
+            animation::start_transitions_if_applicable(
+                new_animations_sender,
+                this_opaque,
+                self.as_node().to_unsafe(),
+                &**values,
+                new_values,
+                &shared_context.timer,
+                &possibly_expired_animations);
+        }
+    }
+
     /// Computes and applies non-redundant damage.
     #[cfg(feature = "gecko")]
     fn accumulate_damage(&self,
                          restyle: &mut RestyleData,
                          old_values: &Arc<ComputedValues>,
                          new_values: &Arc<ComputedValues>,
                          pseudo: Option<&PseudoElement>) {
         // If an ancestor is already getting reconstructed by Gecko's top-down