Bug 1344966 - Introduce a closure to replace rule nodes. r?heycam draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Wed, 22 Mar 2017 09:24:13 +0900
changeset 502531 1f3e99d09e273cdee9782d8e4f9c26f250e50013
parent 502530 716789d03bc76b66077c616034e749eec1f2a4ef
child 502532 c46324f61a1d4c209e474aac104f8ef069d0689f
push id50315
push userhikezoe@mozilla.com
push dateWed, 22 Mar 2017 00:25:31 +0000
reviewersheycam
bugs1344966
milestone55.0a1
Bug 1344966 - Introduce a closure to replace rule nodes. r?heycam We need a scope to restore rule_node_changed that were borrowed by the closure. This closure function will be used for animation-only restyles as well. MozReview-Commit-ID: 4EXotZjfmr6
servo/components/style/matching.rs
--- a/servo/components/style/matching.rs
+++ b/servo/components/style/matching.rs
@@ -872,40 +872,45 @@ pub trait MatchMethods : TElement {
 
     /// Updates the rule nodes without re-running selector matching, using just
     /// the rule tree. Returns true if the rule nodes changed.
     fn cascade_with_replacements(&self,
                                  hint: RestyleHint,
                                  context: &StyleContext<Self>,
                                  data: &mut AtomicRefMut<ElementData>)
                                  -> bool {
+        use properties::PropertyDeclarationBlock;
+        use shared_lock::{Locked, StylesheetGuards};
+
         let primary_rules = &mut data.styles_mut().primary.rules;
         let mut rule_node_changed = false;
 
-        if hint.contains(RESTYLE_STYLE_ATTRIBUTE) {
-            let style_attribute = self.style_attribute();
+        {
+            let mut replace_rule_node = |level: CascadeLevel,
+                                         pdb: Option<&Arc<Locked<PropertyDeclarationBlock>>>,
+                                         path: &mut StrongRuleNode,
+                                         guards: &StylesheetGuards| {
+                let new_node = context.shared.stylist.rule_tree
+                    .update_rule_at_level(level, pdb, path, guards);
+                if let Some(n) = new_node {
+                    *path = n;
+                    rule_node_changed = true;
+                }
+            };
 
-            let new_node = context.shared.stylist.rule_tree
-                .update_rule_at_level(CascadeLevel::StyleAttributeNormal,
-                                      style_attribute,
-                                      primary_rules,
-                                      &context.shared.guards);
-            if let Some(n) = new_node {
-                *primary_rules = n;
-                rule_node_changed = true;
-            }
-
-            let new_node = context.shared.stylist.rule_tree
-                .update_rule_at_level(CascadeLevel::StyleAttributeImportant,
-                                      style_attribute,
-                                      primary_rules,
-                                      &context.shared.guards);
-            if let Some(n) = new_node {
-                *primary_rules = n;
-                rule_node_changed = true;
+            if hint.contains(RESTYLE_STYLE_ATTRIBUTE) {
+                let style_attribute = self.style_attribute();
+                replace_rule_node(CascadeLevel::StyleAttributeNormal,
+                                  style_attribute,
+                                  primary_rules,
+                                  &context.shared.guards);
+                replace_rule_node(CascadeLevel::StyleAttributeImportant,
+                                  style_attribute,
+                                  primary_rules,
+                                  &context.shared.guards);
             }
         }
 
         // The per-pseudo rule nodes never change in this path.
         rule_node_changed
     }
 
     /// Attempts to share a style with another node. This method is unsafe