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

@ -568,6 +568,7 @@ impl Stylist {
parent.map(|p| &**p),
parent.map(|p| &**p),
None,
None,
&RustLogReporter,
font_metrics,
cascade_flags,
@ -639,6 +640,7 @@ impl Stylist {
// difficult to assert that display: contents nodes never arrive here
// (tl;dr: It doesn't apply for replaced elements and such, but the
// computed value is still "contents").
// Bug 1364242: We need to add visited support for lazy pseudos
let computed =
properties::cascade(&self.device,
&rule_node,
@ -646,6 +648,7 @@ impl Stylist {
Some(parent_style),
Some(parent_style),
None,
None,
&RustLogReporter,
font_metrics,
CascadeFlags::empty(),
@ -695,6 +698,7 @@ impl Stylist {
}
};
// Bug 1364242: We need to add visited support for lazy pseudos
let mut declarations = ApplicableDeclarationList::new();
let mut matching_context =
MatchingContext::new(MatchingMode::ForStatelessPseudoElement, None);
@ -1048,6 +1052,9 @@ impl Stylist {
let rule_node =
self.rule_tree.insert_ordered_rules(v.into_iter().map(|a| (a.source, a.level)));
// This currently ignores visited styles. It appears to be used for
// font styles in <canvas> via Servo_StyleSet_ResolveForDeclarations.
// It is unclear if visited styles are meaningful for this case.
let metrics = get_metrics_provider_for_product();
Arc::new(properties::cascade(&self.device,
&rule_node,
@ -1055,6 +1062,7 @@ impl Stylist {
Some(parent_style),
Some(parent_style),
None,
None,
&RustLogReporter,
&metrics,
CascadeFlags::empty(),