mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
style: Make RuleTree::root return a reference instead of a strong pointer.
There's no reason it wasn't done before. MozReview-Commit-ID: G0lMLWmfHbS
This commit is contained in:
parent
cc94a8b7cb
commit
fcf85e4658
2 changed files with 37 additions and 48 deletions
|
@ -150,8 +150,8 @@ impl RuleTree {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the root rule node.
|
/// Get the root rule node.
|
||||||
pub fn root(&self) -> StrongRuleNode {
|
pub fn root(&self) -> &StrongRuleNode {
|
||||||
self.root.clone()
|
&self.root
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dump<W: Write>(&self, guards: &StylesheetGuards, writer: &mut W) {
|
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
|
/// !important rules are detected and inserted into the appropriate position
|
||||||
/// in the rule tree. This allows selector matching to ignore importance,
|
/// in the rule tree. This allows selector matching to ignore importance,
|
||||||
/// while still maintaining the appropriate cascade order in the rule tree.
|
/// while still maintaining the appropriate cascade order in the rule tree.
|
||||||
pub fn insert_ordered_rules_with_important<'a, I>(&self,
|
pub fn insert_ordered_rules_with_important<'a, I>(
|
||||||
iter: I,
|
&self,
|
||||||
guards: &StylesheetGuards)
|
iter: I,
|
||||||
-> StrongRuleNode
|
guards: &StylesheetGuards
|
||||||
where I: Iterator<Item=(StyleSource, CascadeLevel)>,
|
) -> StrongRuleNode
|
||||||
|
where
|
||||||
|
I: Iterator<Item=(StyleSource, CascadeLevel)>,
|
||||||
{
|
{
|
||||||
use self::CascadeLevel::*;
|
use self::CascadeLevel::*;
|
||||||
let mut current = self.root.clone();
|
let mut current = self.root.clone();
|
||||||
|
@ -257,11 +259,11 @@ impl RuleTree {
|
||||||
|
|
||||||
/// Given a list of applicable declarations, insert the rules and return the
|
/// Given a list of applicable declarations, insert the rules and return the
|
||||||
/// corresponding rule node.
|
/// corresponding rule node.
|
||||||
pub fn compute_rule_node(&self,
|
pub fn compute_rule_node(
|
||||||
applicable_declarations: &mut ApplicableDeclarationList,
|
&self,
|
||||||
guards: &StylesheetGuards)
|
applicable_declarations: &mut ApplicableDeclarationList,
|
||||||
-> StrongRuleNode
|
guards: &StylesheetGuards
|
||||||
{
|
) -> StrongRuleNode {
|
||||||
let rules = applicable_declarations.drain().map(|d| d.order_and_level());
|
let rules = applicable_declarations.drain().map(|d| d.order_and_level());
|
||||||
let rule_node = self.insert_ordered_rules_with_important(rules, guards);
|
let rule_node = self.insert_ordered_rules_with_important(rules, guards);
|
||||||
rule_node
|
rule_node
|
||||||
|
|
|
@ -21,7 +21,7 @@ use properties::{self, CascadeFlags, ComputedValues};
|
||||||
use properties::{AnimationRules, PropertyDeclarationBlock};
|
use properties::{AnimationRules, PropertyDeclarationBlock};
|
||||||
#[cfg(feature = "servo")]
|
#[cfg(feature = "servo")]
|
||||||
use properties::INHERIT_ALL;
|
use properties::INHERIT_ALL;
|
||||||
use rule_tree::{CascadeLevel, RuleTree, StrongRuleNode, StyleSource};
|
use rule_tree::{CascadeLevel, RuleTree, StyleSource};
|
||||||
use selector_map::{SelectorMap, SelectorMapEntry};
|
use selector_map::{SelectorMap, SelectorMapEntry};
|
||||||
use selector_parser::{SelectorImpl, PseudoElement};
|
use selector_parser::{SelectorImpl, PseudoElement};
|
||||||
use selectors::attr::NamespaceConstraint;
|
use selectors::attr::NamespaceConstraint;
|
||||||
|
@ -607,13 +607,12 @@ impl Stylist {
|
||||||
|
|
||||||
let rule_node = match self.precomputed_pseudo_element_decls.get(pseudo) {
|
let rule_node = match self.precomputed_pseudo_element_decls.get(pseudo) {
|
||||||
Some(declarations) => {
|
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(
|
self.rule_tree.insert_ordered_rules_with_important(
|
||||||
declarations.into_iter().map(|a| (a.source.clone(), a.level())),
|
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
|
// 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
|
// 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.
|
// that case we want to use the root rulenode for our non-visited rules.
|
||||||
let root;
|
let rules = inputs.get_rules().unwrap_or(self.rule_tree.root());
|
||||||
let rules = if let Some(rules) = inputs.get_rules() {
|
|
||||||
rules
|
|
||||||
} else {
|
|
||||||
root = self.rule_tree.root();
|
|
||||||
&root
|
|
||||||
};
|
|
||||||
|
|
||||||
// Read the comment on `precomputed_values_for_pseudo` to see why it's
|
// Read the comment on `precomputed_values_for_pseudo` to see why it's
|
||||||
// difficult to assert that display: contents nodes never arrive here
|
// difficult to assert that display: contents nodes never arrive here
|
||||||
|
@ -839,25 +832,25 @@ impl Stylist {
|
||||||
MatchingContext::new(MatchingMode::ForStatelessPseudoElement,
|
MatchingContext::new(MatchingMode::ForStatelessPseudoElement,
|
||||||
None,
|
None,
|
||||||
self.quirks_mode);
|
self.quirks_mode);
|
||||||
self.push_applicable_declarations(element,
|
|
||||||
Some(&pseudo),
|
self.push_applicable_declarations(
|
||||||
None,
|
element,
|
||||||
None,
|
Some(&pseudo),
|
||||||
AnimationRules(None, None),
|
None,
|
||||||
rule_inclusion,
|
None,
|
||||||
&mut declarations,
|
AnimationRules(None, None),
|
||||||
&mut matching_context,
|
rule_inclusion,
|
||||||
&mut set_selector_flags);
|
&mut declarations,
|
||||||
|
&mut matching_context,
|
||||||
|
&mut set_selector_flags
|
||||||
|
);
|
||||||
|
|
||||||
if !declarations.is_empty() {
|
if !declarations.is_empty() {
|
||||||
let rule_node = self.rule_tree.insert_ordered_rules_with_important(
|
let rule_node =
|
||||||
declarations.into_iter().map(|a| a.order_and_level()),
|
self.rule_tree.compute_rule_node(&mut declarations, guards);
|
||||||
guards);
|
debug_assert!(rule_node != *self.rule_tree.root());
|
||||||
if rule_node != self.rule_tree.root() {
|
inputs.set_rules(VisitedHandlingMode::AllLinksUnvisited, rule_node);
|
||||||
inputs.set_rules(VisitedHandlingMode::AllLinksUnvisited,
|
}
|
||||||
rule_node);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if is_probe && !inputs.has_rules() {
|
if is_probe && !inputs.has_rules() {
|
||||||
// When probing, don't compute visited styles if we have no
|
// 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(
|
self.rule_tree.insert_ordered_rules_with_important(
|
||||||
declarations.into_iter().map(|a| a.order_and_level()),
|
declarations.into_iter().map(|a| a.order_and_level()),
|
||||||
guards);
|
guards);
|
||||||
if rule_node != self.rule_tree.root() {
|
if rule_node != *self.rule_tree.root() {
|
||||||
inputs.set_rules(VisitedHandlingMode::RelevantLinkVisited,
|
inputs.set_rules(VisitedHandlingMode::RelevantLinkVisited,
|
||||||
rule_node);
|
rule_node);
|
||||||
}
|
}
|
||||||
|
@ -1295,12 +1288,6 @@ impl Stylist {
|
||||||
&self.animations
|
&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
|
/// Computes the match results of a given element against the set of
|
||||||
/// revalidation selectors.
|
/// revalidation selectors.
|
||||||
pub fn match_revalidation_selectors<E, F>(&self,
|
pub fn match_revalidation_selectors<E, F>(&self,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue