Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: Split style resolution and dynamic change computation. #17688

Merged
merged 11 commits into from Jul 12, 2017

style: Make RuleTree::root return a reference instead of a strong poi…

…nter.

There's no reason it wasn't done before.

MozReview-Commit-ID: G0lMLWmfHbS
  • Loading branch information
emilio committed Jul 12, 2017
commit fcf85e46582f9321bc165746ac13acf05413bbab
@@ -150,8 +150,8 @@ impl RuleTree {
}

/// Get the root rule node.
pub fn root(&self) -> StrongRuleNode {
self.root.clone()
pub fn root(&self) -> &StrongRuleNode {
&self.root
}

fn dump<W: Write>(&self, guards: &StylesheetGuards, writer: &mut W) {
@@ -171,11 +171,13 @@ impl RuleTree {
/// !important rules are detected and inserted into the appropriate position
/// in the rule tree. This allows selector matching to ignore importance,
/// while still maintaining the appropriate cascade order in the rule tree.
pub fn insert_ordered_rules_with_important<'a, I>(&self,
iter: I,
guards: &StylesheetGuards)
-> StrongRuleNode
where I: Iterator<Item=(StyleSource, CascadeLevel)>,
pub fn insert_ordered_rules_with_important<'a, I>(
&self,
iter: I,
guards: &StylesheetGuards
) -> StrongRuleNode
where
I: Iterator<Item=(StyleSource, CascadeLevel)>,
{
use self::CascadeLevel::*;
let mut current = self.root.clone();
@@ -257,11 +259,11 @@ impl RuleTree {

/// Given a list of applicable declarations, insert the rules and return the
/// corresponding rule node.
pub fn compute_rule_node(&self,
applicable_declarations: &mut ApplicableDeclarationList,
guards: &StylesheetGuards)
-> StrongRuleNode
{
pub fn compute_rule_node(
&self,
applicable_declarations: &mut ApplicableDeclarationList,
guards: &StylesheetGuards
) -> StrongRuleNode {
let rules = applicable_declarations.drain().map(|d| d.order_and_level());
let rule_node = self.insert_ordered_rules_with_important(rules, guards);
rule_node
@@ -21,7 +21,7 @@ use properties::{self, CascadeFlags, ComputedValues};
use properties::{AnimationRules, PropertyDeclarationBlock};
#[cfg(feature = "servo")]
use properties::INHERIT_ALL;
use rule_tree::{CascadeLevel, RuleTree, StrongRuleNode, StyleSource};
use rule_tree::{CascadeLevel, RuleTree, StyleSource};
use selector_map::{SelectorMap, SelectorMapEntry};
use selector_parser::{SelectorImpl, PseudoElement};
use selectors::attr::NamespaceConstraint;
@@ -607,13 +607,12 @@ impl Stylist {

let rule_node = match self.precomputed_pseudo_element_decls.get(pseudo) {
Some(declarations) => {
// FIXME(emilio): When we've taken rid of the cascade we can just
// use into_iter.
self.rule_tree.insert_ordered_rules_with_important(
declarations.into_iter().map(|a| (a.source.clone(), a.level())),
guards)
guards
)
}
None => self.rule_tree.root(),
None => self.rule_tree.root().clone(),
};

// NOTE(emilio): We skip calculating the proper layout parent style
@@ -757,13 +756,7 @@ impl Stylist {

// We may not have non-visited rules, if we only had visited ones. In
// that case we want to use the root rulenode for our non-visited rules.
let root;
let rules = if let Some(rules) = inputs.get_rules() {
rules
} else {
root = self.rule_tree.root();
&root
};
let rules = inputs.get_rules().unwrap_or(self.rule_tree.root());

// Read the comment on `precomputed_values_for_pseudo` to see why it's
// difficult to assert that display: contents nodes never arrive here
@@ -839,25 +832,25 @@ impl Stylist {
MatchingContext::new(MatchingMode::ForStatelessPseudoElement,
None,
self.quirks_mode);
self.push_applicable_declarations(element,
Some(&pseudo),
None,
None,
AnimationRules(None, None),
rule_inclusion,
&mut declarations,
&mut matching_context,
&mut set_selector_flags);

self.push_applicable_declarations(
element,
Some(&pseudo),
None,
None,
AnimationRules(None, None),
rule_inclusion,
&mut declarations,
&mut matching_context,
&mut set_selector_flags
);

if !declarations.is_empty() {
let rule_node = self.rule_tree.insert_ordered_rules_with_important(
declarations.into_iter().map(|a| a.order_and_level()),
guards);
if rule_node != self.rule_tree.root() {
inputs.set_rules(VisitedHandlingMode::AllLinksUnvisited,
rule_node);
}
};
let rule_node =
self.rule_tree.compute_rule_node(&mut declarations, guards);
debug_assert!(rule_node != *self.rule_tree.root());
inputs.set_rules(VisitedHandlingMode::AllLinksUnvisited, rule_node);
}

if is_probe && !inputs.has_rules() {
// When probing, don't compute visited styles if we have no
@@ -886,7 +879,7 @@ impl Stylist {
self.rule_tree.insert_ordered_rules_with_important(
declarations.into_iter().map(|a| a.order_and_level()),
guards);
if rule_node != self.rule_tree.root() {
if rule_node != *self.rule_tree.root() {
inputs.set_rules(VisitedHandlingMode::RelevantLinkVisited,
rule_node);
}
@@ -1295,12 +1288,6 @@ impl Stylist {
&self.animations
}

/// Returns the rule root node.
#[inline]
pub fn rule_tree_root(&self) -> StrongRuleNode {
self.rule_tree.root()
}

/// Computes the match results of a given element against the set of
/// revalidation selectors.
pub fn match_revalidation_selectors<E, F>(&self,
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.