Bug 1311257 - Make cascade_with_rules() take a boolean representing whether the cascade is for pseudo element or not. r?heycam draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Wed, 05 Apr 2017 08:34:37 +0900
changeset 555842 3665b3a711c6d76048207da61644686c290c55da
parent 555841 0d3d94b4241cc8427275b5d64d51d6e73be8051f
child 555843 da81bb42dcdd0098ba77f62b104928ee8b96d111
push id52367
push userhikezoe@mozilla.com
push dateWed, 05 Apr 2017 02:18:23 +0000
reviewersheycam
bugs1311257
milestone55.0a1
Bug 1311257 - Make cascade_with_rules() take a boolean representing whether the cascade is for pseudo element or not. r?heycam cascade_with_rules() doesn't mutate any already-computed styles. MozReview-Commit-ID: EWzQFGzb4RY
servo/components/style/matching.rs
--- a/servo/components/style/matching.rs
+++ b/servo/components/style/matching.rs
@@ -468,25 +468,25 @@ trait PrivateMatchMethods: TElement {
             }
         }
     }
 
     fn cascade_with_rules(&self,
                           shared_context: &SharedStyleContext,
                           rule_node: &StrongRuleNode,
                           primary_style: &ComputedStyle,
-                          pseudo_style: &Option<(&PseudoElement, &mut ComputedStyle)>,
-                          cascade_flags: CascadeFlags)
+                          cascade_flags: CascadeFlags,
+                          is_pseudo: bool)
                           -> Arc<ComputedValues> {
         let mut cascade_info = CascadeInfo::new();
 
         // Grab the inherited values.
         let parent_el;
         let parent_data;
-        let inherited_values_ = if pseudo_style.is_none() {
+        let inherited_values_ = if !is_pseudo {
             parent_el = self.parent_element();
             parent_data = parent_el.as_ref().and_then(|e| e.borrow_data());
             let parent_values = parent_data.as_ref().map(|d| {
                 // Sometimes Gecko eagerly styles things without processing
                 // pending restyles first. In general we'd like to avoid this,
                 // but there can be good reasons (for example, needing to
                 // construct a frame for some small piece of newly-added
                 // content in order to do something specific with that frame,
@@ -513,17 +513,17 @@ trait PrivateMatchMethods: TElement {
         let inherited_values = inherited_values_.map(|x| &**x);
         let layout_parent_style = layout_parent_style.map(|x| &**x);
 
         // Propagate the "can be fragmented" bit. It would be nice to
         // encapsulate this better.
         //
         // Note that this is not needed for pseudos since we already do that
         // when we resolve the non-pseudo style.
-        if pseudo_style.is_none() {
+        if !is_pseudo {
             if let Some(ref p) = layout_parent_style {
                 let can_be_fragmented =
                     p.is_multicol() ||
                     layout_parent_el.as_ref().unwrap().as_node().can_be_fragmented();
                 unsafe { self.as_node().set_can_be_fragmented(can_be_fragmented); }
             }
         }
 
@@ -553,17 +553,17 @@ trait PrivateMatchMethods: TElement {
             cascade_flags.insert(SHAREABLE)
         }
         if self.skip_root_and_item_based_display_fixup() {
             cascade_flags.insert(SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP)
         }
 
         // Grab the rule node.
         let rule_node = &pseudo_style.as_ref().map_or(primary_style, |p| &*p.1).rules;
-        self.cascade_with_rules(context.shared, rule_node, primary_style, pseudo_style, cascade_flags)
+        self.cascade_with_rules(context.shared, rule_node, primary_style, cascade_flags, pseudo_style.is_some())
     }
 
     /// Computes values and damage for the primary or pseudo style of an element,
     /// setting them on the ElementData.
     fn cascade_primary_or_pseudo<'a>(&self,
                                      context: &mut StyleContext<Self>,
                                      data: &mut ElementData,
                                      pseudo: Option<&PseudoElement>,
@@ -602,17 +602,17 @@ trait PrivateMatchMethods: TElement {
             primary_style.values = Some(new_values);
         }
     }
 
     #[cfg(feature = "gecko")]
     fn get_after_change_style(&self,
                               context: &mut StyleContext<Self>,
                               primary_style: &ComputedStyle,
-                              pseudo_style: &Option<(&PseudoElement, &mut ComputedStyle)>)
+                              pseudo_style: &Option<(&PseudoElement, &ComputedStyle)>)
                               -> 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.
@@ -621,18 +621,18 @@ trait PrivateMatchMethods: TElement {
 
         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)
         }
         self.cascade_with_rules(context.shared,
                                 &without_transition_rules,
                                 primary_style,
-                                &pseudo_style,
-                                cascade_flags)
+                                cascade_flags,
+                                pseudo_style.is_some())
     }
 
     #[cfg(feature = "gecko")]
     fn process_animations(&self,
                           context: &mut StyleContext<Self>,
                           old_values: &mut Option<Arc<ComputedValues>>,
                           new_values: &mut Arc<ComputedValues>,
                           pseudo: Option<&PseudoElement>,