style: Fix relevant-link-visited logic in presence of nested links.
draft
style: Fix relevant-link-visited logic in presence of nested links.
MozReview-Commit-ID: LIjpTAgrPBY
--- a/servo/components/style/properties/properties.mako.rs
+++ b/servo/components/style/properties/properties.mako.rs
@@ -2832,19 +2832,23 @@ bitflags! {
/// Whether to convert display:contents into display:inline. This
/// is used by Gecko to prevent display:contents on generated
/// content.
const PROHIBIT_DISPLAY_CONTENTS = 1 << 4,
/// Whether we're styling the ::-moz-fieldset-content anonymous box.
const IS_FIELDSET_CONTENT = 1 << 5,
+ /// Whether we're computing the style of a link, either visited or
+ /// unvisited.
+ const IS_LINK = 1 << 6,
+
/// Whether we're computing the style of a link element that happens to
/// be visited.
- const IS_VISITED_LINK = 1 << 6,
+ const IS_VISITED_LINK = 1 << 7,
}
}
/// Performs the CSS cascade, computing new styles for an element from its parent style.
///
/// The arguments are:
///
/// * `device`: Used to get the initial viewport and other external state.
--- a/servo/components/style/style_adjuster.rs
+++ b/servo/components/style/style_adjuster.rs
@@ -431,25 +431,30 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
///
/// NOTE(emilio): We don't do this for text styles, which is... dubious, but
/// Gecko doesn't seem to do it either. It's extremely easy to do if needed
/// though.
///
/// FIXME(emilio): This isn't technically a style adjustment thingie, could
/// it move somewhere else?
fn adjust_for_visited(&mut self, flags: CascadeFlags) {
- use properties::IS_VISITED_LINK;
+ use properties::{IS_LINK, IS_VISITED_LINK};
use properties::computed_value_flags::IS_RELEVANT_LINK_VISITED;
if !self.style.has_visited_style() {
return;
}
- if flags.contains(IS_VISITED_LINK) ||
- self.style.inherited_style().flags.contains(IS_RELEVANT_LINK_VISITED) {
+ let relevant_link_visited = if flags.contains(IS_LINK) {
+ flags.contains(IS_VISITED_LINK)
+ } else {
+ self.style.inherited_style().flags.contains(IS_RELEVANT_LINK_VISITED)
+ };
+
+ if relevant_link_visited {
self.style.flags.insert(IS_RELEVANT_LINK_VISITED);
}
}
/// Adjusts the style to account for various fixups that don't fit naturally
/// into the cascade.
///
/// When comparing to Gecko, this is similar to the work done by
--- a/servo/components/style/style_resolver.rs
+++ b/servo/components/style/style_resolver.rs
@@ -7,17 +7,17 @@
use applicable_declarations::ApplicableDeclarationList;
use cascade_info::CascadeInfo;
use context::{CascadeInputs, ElementCascadeInputs, StyleContext};
use data::{ElementStyles, EagerPseudoStyles};
use dom::TElement;
use log::LogLevel::Trace;
use matching::{CascadeVisitedMode, MatchMethods};
use properties::{AnimationRules, CascadeFlags, ComputedValues};
-use properties::{IS_ROOT_ELEMENT, IS_VISITED_LINK, PROHIBIT_DISPLAY_CONTENTS, SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP};
+use properties::{IS_LINK, IS_ROOT_ELEMENT, IS_VISITED_LINK, PROHIBIT_DISPLAY_CONTENTS, SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP};
use properties::{VISITED_DEPENDENT_ONLY, cascade};
use rule_tree::StrongRuleNode;
use selector_parser::{PseudoElement, SelectorImpl};
use selectors::matching::{ElementSelectorFlags, MatchingContext, MatchingMode, VisitedHandlingMode};
use servo_arc::Arc;
use stylist::RuleInclusion;
/// A struct that takes care of resolving the style of a given element.
@@ -469,18 +469,21 @@ where
) -> Arc<ComputedValues> {
let mut cascade_info = CascadeInfo::new();
let mut cascade_flags = CascadeFlags::empty();
if self.element.skip_root_and_item_based_display_fixup() {
cascade_flags.insert(SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP);
}
- if pseudo.is_none() && self.element.is_visited_link() {
- cascade_flags.insert(IS_VISITED_LINK);
+ if pseudo.is_none() && self.element.is_link() {
+ cascade_flags.insert(IS_LINK);
+ if self.element.is_visited_link() {
+ cascade_flags.insert(IS_VISITED_LINK);
+ }
}
if cascade_visited.visited_dependent_only() {
// If this element is a link, we want its visited style to inherit
// from the regular style of its parent, because only the
// visitedness of the relevant link should influence style.
if pseudo.is_some() || !self.element.is_link() {
parent_style = parent_style.map(|s| {