From 04e855c38db66315b9458a0a809d44e8715a398f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 23 Jul 2017 15:05:36 +0200 Subject: [PATCH] style: Fix relevant-link-visited logic in presence of nested links. MozReview-Commit-ID: LIjpTAgrPBY --- components/style/properties/properties.mako.rs | 6 +++++- components/style/style_adjuster.rs | 11 ++++++++--- components/style/style_resolver.rs | 9 ++++++--- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 33d59ad4105..b2445f53dfb 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -2837,9 +2837,13 @@ bitflags! { /// 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, } } diff --git a/components/style/style_adjuster.rs b/components/style/style_adjuster.rs index 5ddcd42a095..8222634317e 100644 --- a/components/style/style_adjuster.rs +++ b/components/style/style_adjuster.rs @@ -436,15 +436,20 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { /// 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); } } diff --git a/components/style/style_resolver.rs b/components/style/style_resolver.rs index dcb7134cf50..d2c6c545cf9 100644 --- a/components/style/style_resolver.rs +++ b/components/style/style_resolver.rs @@ -12,7 +12,7 @@ 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}; @@ -474,8 +474,11 @@ where 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() {