Bug 1341372 - Part 4: Let get_after_change_style return Option. draft
authorBoris Chiou <boris.chiou@gmail.com>
Tue, 04 Apr 2017 18:45:11 +0800
changeset 562568 d4d944d551ff6f41da27284ca7630b0a62a23f45
parent 562567 0de7e1a8c0a00fd418f31347879f9ade365182ce
child 562569 2265ab5cf7a12b7836f1e3f1feb14653d296068e
child 563240 fc5e7ff70ba599718002f1a09c5fba567b20953b
push id54048
push userbmo:boris.chiou@gmail.com
push dateFri, 14 Apr 2017 02:45:56 +0000
bugs1341372
milestone55.0a1
Bug 1341372 - Part 4: Let get_after_change_style return Option. It is possible to call get_after_change_style if there is no transition rule. In order to avoid cloning the token computed values, we just return None. The caller can use this Option to know which computed values should be used. MozReview-Commit-ID: 7fcgSVEtXWh
servo/components/style/matching.rs
--- a/servo/components/style/matching.rs
+++ b/servo/components/style/matching.rs
@@ -491,42 +491,44 @@ trait PrivateMatchMethods: TElement {
         // 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);
         }
     }
 
+    /// get_after_change_style removes the transition rules from the ComputedValues.
+    /// If there is no transition rule in the ComputedValues, it returns None.
     #[cfg(feature = "gecko")]
     fn get_after_change_style(&self,
                               context: &mut StyleContext<Self>,
                               primary_style: &ComputedStyle,
                               pseudo_style: &Option<(&PseudoElement, &ComputedStyle)>)
-                              -> Arc<ComputedValues> {
+                              -> Option<Arc<ComputedValues>> {
         let style = &pseudo_style.as_ref().map_or(primary_style, |p| &*p.1);
         let rule_node = &style.rules;
         let without_transition_rules =
             context.shared.stylist.rule_tree.remove_transition_rule_if_applicable(rule_node);
         if without_transition_rules == *rule_node {
-            // Note that unwrapping here is fine, because the style is
-            // only incomplete during the styling process.
-            return style.values.as_ref().unwrap().clone();
+            // We don't have transition rule in this case, so return None to let the caller
+            // use the original ComputedValues.
+            return None;
         }
 
         let mut cascade_flags = CascadeFlags::empty();
         if self.skip_root_and_item_based_display_fixup() {
-            cascade_flags.insert(SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP)
+            cascade_flags.insert(SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP);
         }
-        self.cascade_with_rules(context.shared,
-                                &context.thread_local.font_metrics_provider,
-                                &without_transition_rules,
-                                primary_style,
-                                cascade_flags,
-                                pseudo_style.is_some())
+        Some(self.cascade_with_rules(context.shared,
+                                     &context.thread_local.font_metrics_provider,
+                                     &without_transition_rules,
+                                     primary_style,
+                                     cascade_flags,
+                                     pseudo_style.is_some()))
     }
 
     #[cfg(feature = "gecko")]
     fn needs_update_animations(&self,
                                old_values: &Option<Arc<ComputedValues>>,
                                new_values: &Arc<ComputedValues>,
                                pseudo: Option<&PseudoElement>) -> bool {
         let ref new_box_style = new_values.get_box();