Bug 1336646 - Apply selector flags during traversal. r=emilio

This commit is contained in:
Bobby Holley 2017-02-04 13:11:02 -08:00
parent 37b8d5231d
commit 9e860df9df
17 changed files with 295 additions and 192 deletions

View file

@ -18,12 +18,12 @@ use properties::{self, CascadeFlags, ComputedValues, INHERIT_ALL};
use properties::PropertyDeclarationBlock;
use restyle_hints::{RestyleHint, DependencySet};
use rule_tree::{CascadeLevel, RuleTree, StrongRuleNode, StyleSource};
use selector_parser::{ElementExt, SelectorImpl, PseudoElement, Snapshot};
use selector_parser::{SelectorImpl, PseudoElement, Snapshot};
use selectors::Element;
use selectors::bloom::BloomFilter;
use selectors::matching::{AFFECTED_BY_ANIMATIONS, AFFECTED_BY_TRANSITIONS};
use selectors::matching::{AFFECTED_BY_STYLE_ATTRIBUTE, AFFECTED_BY_PRESENTATIONAL_HINTS};
use selectors::matching::{MatchingReason, StyleRelations, matches_complex_selector};
use selectors::matching::{ElementSelectorFlags, StyleRelations, matches_complex_selector};
use selectors::parser::{Selector, SimpleSelector, LocalName as LocalNameSelector, ComplexSelector};
use sink::Push;
use smallvec::VecLike;
@ -34,6 +34,7 @@ use std::hash::Hash;
use std::sync::Arc;
use style_traits::viewport::ViewportConstraints;
use stylesheets::{CssRule, Origin, StyleRule, Stylesheet, UserAgentStylesheets};
use thread_state;
use viewport::{self, MaybeNew, ViewportRule};
pub use ::fnv::FnvHashMap;
@ -368,7 +369,7 @@ impl Stylist {
parent: &Arc<ComputedValues>,
default: &Arc<ComputedValues>)
-> Option<ComputedStyle>
where E: ElementExt +
where E: TElement +
fmt::Debug +
PresentationalHintsSynthetizer
{
@ -379,13 +380,14 @@ impl Stylist {
let mut declarations = vec![];
let mut flags = ElementSelectorFlags::empty();
self.push_applicable_declarations(element,
None,
None,
AnimationRules(None, None),
Some(pseudo),
&mut declarations,
MatchingReason::ForStyling);
&mut flags);
let rule_node =
self.rule_tree.insert_ordered_rules(
@ -400,6 +402,28 @@ impl Stylist {
Box::new(StdoutErrorReporter),
CascadeFlags::empty());
// Apply the selector flags. We should be in sequential mode already,
// so we can directly apply the parent flags.
if cfg!(feature = "servo") {
// Servo calls this function from the worker, but only for internal
// pseudos, so we should never generate selector flags here.
debug_assert!(flags.is_empty());
} else {
// Gecko calls this from sequential mode, so we can directly apply
// the flags.
debug_assert!(thread_state::get() == thread_state::LAYOUT);
let self_flags = flags.for_self();
if !self_flags.is_empty() {
unsafe { element.set_selector_flags(self_flags); }
}
let parent_flags = flags.for_parent();
if !parent_flags.is_empty() {
if let Some(p) = element.parent_element() {
unsafe { p.set_selector_flags(parent_flags); }
}
}
}
Some(ComputedStyle::new(rule_node, Arc::new(computed)))
}
@ -495,8 +519,8 @@ impl Stylist {
animation_rules: AnimationRules,
pseudo_element: Option<&PseudoElement>,
applicable_declarations: &mut V,
reason: MatchingReason) -> StyleRelations
where E: ElementExt +
flags: &mut ElementSelectorFlags) -> StyleRelations
where E: TElement +
fmt::Debug +
PresentationalHintsSynthetizer,
V: Push<ApplicableDeclarationBlock> + VecLike<ApplicableDeclarationBlock>
@ -521,7 +545,7 @@ impl Stylist {
parent_bf,
applicable_declarations,
&mut relations,
reason,
flags,
CascadeLevel::UANormal);
debug!("UA normal: {:?}", relations);
@ -545,14 +569,14 @@ impl Stylist {
parent_bf,
applicable_declarations,
&mut relations,
reason,
flags,
CascadeLevel::UserNormal);
debug!("user normal: {:?}", relations);
map.author.get_all_matching_rules(element,
parent_bf,
applicable_declarations,
&mut relations,
reason,
flags,
CascadeLevel::AuthorNormal);
debug!("author normal: {:?}", relations);
@ -586,7 +610,7 @@ impl Stylist {
parent_bf,
applicable_declarations,
&mut relations,
reason,
flags,
CascadeLevel::AuthorImportant);
debug!("author important: {:?}", relations);
@ -609,7 +633,7 @@ impl Stylist {
parent_bf,
applicable_declarations,
&mut relations,
reason,
flags,
CascadeLevel::UserImportant);
debug!("user important: {:?}", relations);
@ -622,7 +646,7 @@ impl Stylist {
parent_bf,
applicable_declarations,
&mut relations,
reason,
flags,
CascadeLevel::UAImportant);
debug!("UA important: {:?}", relations);
@ -663,7 +687,7 @@ impl Stylist {
pub fn match_same_not_common_style_affecting_attributes_rules<E>(&self,
element: &E,
candidate: &E) -> bool
where E: ElementExt,
where E: TElement,
{
use selectors::matching::StyleRelations;
use selectors::matching::matches_complex_selector;
@ -678,11 +702,11 @@ impl Stylist {
let element_matches =
matches_complex_selector(&selector.complex_selector, element,
None, &mut StyleRelations::empty(),
MatchingReason::Other);
&mut ElementSelectorFlags::empty());
let candidate_matches =
matches_complex_selector(&selector.complex_selector, candidate,
None, &mut StyleRelations::empty(),
MatchingReason::Other);
&mut ElementSelectorFlags::empty());
if element_matches != candidate_matches {
return false;
@ -704,7 +728,7 @@ impl Stylist {
pub fn match_same_sibling_affecting_rules<E>(&self,
element: &E,
candidate: &E) -> bool
where E: ElementExt,
where E: TElement,
{
use selectors::matching::StyleRelations;
use selectors::matching::matches_complex_selector;
@ -717,12 +741,12 @@ impl Stylist {
let element_matches =
matches_complex_selector(&selector.complex_selector, element,
None, &mut StyleRelations::empty(),
MatchingReason::Other);
&mut ElementSelectorFlags::empty());
let candidate_matches =
matches_complex_selector(&selector.complex_selector, candidate,
None, &mut StyleRelations::empty(),
MatchingReason::Other);
&mut ElementSelectorFlags::empty());
if element_matches != candidate_matches {
debug!("match_same_sibling_affecting_rules: Failure due to {:?}",
@ -860,7 +884,7 @@ impl SelectorMap {
parent_bf: Option<&BloomFilter>,
matching_rules_list: &mut V,
relations: &mut StyleRelations,
reason: MatchingReason,
flags: &mut ElementSelectorFlags,
cascade_level: CascadeLevel)
where E: Element<Impl=SelectorImpl>,
V: VecLike<ApplicableDeclarationBlock>
@ -878,7 +902,7 @@ impl SelectorMap {
&id,
matching_rules_list,
relations,
reason,
flags,
cascade_level)
}
@ -889,7 +913,7 @@ impl SelectorMap {
class,
matching_rules_list,
relations,
reason,
flags,
cascade_level);
});
@ -904,7 +928,7 @@ impl SelectorMap {
element.get_local_name(),
matching_rules_list,
relations,
reason,
flags,
cascade_level);
SelectorMap::get_matching_rules(element,
@ -912,7 +936,7 @@ impl SelectorMap {
&self.other_rules,
matching_rules_list,
relations,
reason,
flags,
cascade_level);
// Sort only the rules we just added.
@ -963,7 +987,7 @@ impl SelectorMap {
key: &BorrowedStr,
matching_rules: &mut Vector,
relations: &mut StyleRelations,
reason: MatchingReason,
flags: &mut ElementSelectorFlags,
cascade_level: CascadeLevel)
where E: Element<Impl=SelectorImpl>,
Str: Borrow<BorrowedStr> + Eq + Hash,
@ -976,7 +1000,7 @@ impl SelectorMap {
rules,
matching_rules,
relations,
reason,
flags,
cascade_level)
}
}
@ -987,7 +1011,7 @@ impl SelectorMap {
rules: &[Rule],
matching_rules: &mut V,
relations: &mut StyleRelations,
reason: MatchingReason,
flags: &mut ElementSelectorFlags,
cascade_level: CascadeLevel)
where E: Element<Impl=SelectorImpl>,
V: VecLike<ApplicableDeclarationBlock>
@ -1002,7 +1026,7 @@ impl SelectorMap {
};
if any_declaration_for_importance &&
matches_complex_selector(&*rule.selector, element, parent_bf,
relations, reason) {
relations, flags) {
matching_rules.push(
rule.to_applicable_declaration_block(cascade_level));
}