Match and cascade visited styles

To support visited styles, we match and cascade a separate set of styles any
time we notice that an element has a relevant link.

The visited rules and values are held in `ComputedStyle` alongside the
regular rules and values, which simplifies supporting various APIs like
`cascade_primary_and_pseudos` which expect easy access to previously matched
rules.

To simplify passing the additional values around, an additional reference to the
visited `ComputedValues` is placed inside the regular `ComputedValues`.

MozReview-Commit-ID: 2ebbjcfkfWf
This commit is contained in:
J. Ryan Stinnett 2017-05-04 18:54:20 -05:00
parent e3a256803d
commit a7882cfeb9
9 changed files with 621 additions and 141 deletions

View file

@ -16,6 +16,7 @@ use std::ptr;
use std::sync::atomic::{AtomicPtr, AtomicUsize, Ordering};
use stylearc::Arc;
use stylesheets::StyleRule;
use stylist::ApplicableDeclarationList;
use thread_state;
/// The rule tree, the structure servo uses to preserve the results of selector
@ -215,6 +216,18 @@ impl RuleTree {
current
}
/// 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
{
let rules = applicable_declarations.drain().map(|d| (d.source, d.level));
let rule_node = self.insert_ordered_rules_with_important(rules, guards);
rule_node
}
/// Insert the given rules, that must be in proper order by specifity, and
/// return the corresponding rule node representing the last inserted one.
pub fn insert_ordered_rules<'a, I>(&self, iter: I) -> StrongRuleNode
@ -632,6 +645,8 @@ struct WeakRuleNode {
/// A strong reference to a rule node.
#[derive(Debug, PartialEq)]
pub struct StrongRuleNode {
// TODO: Mark this as NonZero once stable to save space inside Option.
// https://github.com/rust-lang/rust/issues/27730
ptr: *mut RuleNode,
}