diff options
-rw-r--r-- | components/layout/css/matching.rs | 37 | ||||
-rw-r--r-- | components/layout/traversal.rs | 12 |
2 files changed, 26 insertions, 23 deletions
diff --git a/components/layout/css/matching.rs b/components/layout/css/matching.rs index ddb6cbe06ab..2e05046b089 100644 --- a/components/layout/css/matching.rs +++ b/components/layout/css/matching.rs @@ -371,6 +371,14 @@ pub enum StyleSharingResult { StyleWasShared(usize, RestyleDamage), } +pub trait ElementMatchMethods { + fn match_element(&self, + stylist: &Stylist, + parent_bf: Option<&BloomFilter>, + applicable_declarations: &mut ApplicableDeclarations, + shareable: &mut bool); +} + pub trait MatchMethods { /// Inserts and removes the matching `Descendant` selectors from a bloom /// filter. This is used to speed up CSS selector matching to remove @@ -385,12 +393,6 @@ pub trait MatchMethods { /// called to reset the bloom filter after an `insert`. fn remove_from_bloom_filter(&self, bf: &mut BloomFilter); - fn match_node(&self, - stylist: &Stylist, - parent_bf: Option<&BloomFilter>, - applicable_declarations: &mut ApplicableDeclarations, - shareable: &mut bool); - /// Attempts to share a style with another node. This method is unsafe because it depends on /// the `style_sharing_candidate_cache` having only live nodes in it, and we have no way to /// guarantee that at the type system level yet. @@ -543,27 +545,26 @@ impl<'ln> PrivateElementMatchMethods for LayoutElement<'ln> { } } -impl<'ln> MatchMethods for LayoutNode<'ln> { - fn match_node(&self, - stylist: &Stylist, - parent_bf: Option<&BloomFilter>, - applicable_declarations: &mut ApplicableDeclarations, - shareable: &mut bool) { - let element = self.as_element().unwrap(); - let style_attribute = element.style_attribute().as_ref(); +impl<'ln> ElementMatchMethods for LayoutElement<'ln> { + fn match_element(&self, + stylist: &Stylist, + parent_bf: Option<&BloomFilter>, + applicable_declarations: &mut ApplicableDeclarations, + shareable: &mut bool) { + let style_attribute = self.style_attribute().as_ref(); applicable_declarations.normal_shareable = - stylist.push_applicable_declarations(&element, + stylist.push_applicable_declarations(self, parent_bf, style_attribute, None, &mut applicable_declarations.normal); - stylist.push_applicable_declarations(&element, + stylist.push_applicable_declarations(self, parent_bf, None, Some(PseudoElement::Before), &mut applicable_declarations.before); - stylist.push_applicable_declarations(&element, + stylist.push_applicable_declarations(self, parent_bf, None, Some(PseudoElement::After), @@ -573,7 +574,9 @@ impl<'ln> MatchMethods for LayoutNode<'ln> { applicable_declarations.before.is_empty() && applicable_declarations.after.is_empty() } +} +impl<'ln> MatchMethods for LayoutNode<'ln> { unsafe fn share_style_if_possible(&self, style_sharing_candidate_cache: &mut StyleSharingCandidateCache, diff --git a/components/layout/traversal.rs b/components/layout/traversal.rs index cee485d62ce..1b0c3782e75 100644 --- a/components/layout/traversal.rs +++ b/components/layout/traversal.rs @@ -6,7 +6,7 @@ use construct::FlowConstructor; use context::LayoutContext; -use css::matching::{ApplicableDeclarations, MatchMethods, StyleSharingResult}; +use css::matching::{ApplicableDeclarations, ElementMatchMethods, MatchMethods, StyleSharingResult}; use flow::{MutableFlowUtils, PostorderFlowTraversal, PreorderFlowTraversal}; use flow::{self, Flow}; use incremental::{self, BUBBLE_ISIZES, REFLOW, REFLOW_OUT_OF_FLOW, RestyleDamage}; @@ -174,13 +174,13 @@ impl<'a> PreorderDomTraversal for RecalcStyleForNode<'a> { StyleSharingResult::CannotShare(mut shareable) => { let mut applicable_declarations = ApplicableDeclarations::new(); - if node.as_element().is_some() { + if let Some(element) = node.as_element() { // Perform the CSS selector matching. let stylist = unsafe { &*self.layout_context.shared.stylist }; - node.match_node(stylist, - Some(&*bf), - &mut applicable_declarations, - &mut shareable); + element.match_element(stylist, + Some(&*bf), + &mut applicable_declarations, + &mut shareable); } else if node.has_changed() { ThreadSafeLayoutNode::new(&node).set_restyle_damage( incremental::rebuild_and_reflow()) |