mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
style: Track the visited-handling-mode on the MatchingContext.
Instead of on the stack. This fixes bugs where we're not passing the value around correctly, like from ::-moz-any. This is a fix for https://bugzilla.mozilla.org/show_bug.cgi?id=1431539.
This commit is contained in:
parent
e4f08ee2bb
commit
8e25c9e674
8 changed files with 50 additions and 52 deletions
|
@ -713,7 +713,6 @@ impl<'le> ::selectors::Element for ServoLayoutElement<'le> {
|
||||||
&self,
|
&self,
|
||||||
pseudo_class: &NonTSPseudoClass,
|
pseudo_class: &NonTSPseudoClass,
|
||||||
_: &mut MatchingContext<Self::Impl>,
|
_: &mut MatchingContext<Self::Impl>,
|
||||||
_: VisitedHandlingMode,
|
|
||||||
_: &mut F,
|
_: &mut F,
|
||||||
) -> bool
|
) -> bool
|
||||||
where
|
where
|
||||||
|
@ -1221,7 +1220,6 @@ impl<'le> ::selectors::Element for ServoThreadSafeLayoutElement<'le> {
|
||||||
&self,
|
&self,
|
||||||
_: &NonTSPseudoClass,
|
_: &NonTSPseudoClass,
|
||||||
_: &mut MatchingContext<Self::Impl>,
|
_: &mut MatchingContext<Self::Impl>,
|
||||||
_: VisitedHandlingMode,
|
|
||||||
_: &mut F,
|
_: &mut F,
|
||||||
) -> bool
|
) -> bool
|
||||||
where
|
where
|
||||||
|
|
|
@ -89,7 +89,6 @@ use script_layout_interface::message::ReflowGoal;
|
||||||
use script_thread::ScriptThread;
|
use script_thread::ScriptThread;
|
||||||
use selectors::Element as SelectorsElement;
|
use selectors::Element as SelectorsElement;
|
||||||
use selectors::attr::{AttrSelectorOperation, NamespaceConstraint, CaseSensitivity};
|
use selectors::attr::{AttrSelectorOperation, NamespaceConstraint, CaseSensitivity};
|
||||||
use selectors::context::VisitedHandlingMode;
|
|
||||||
use selectors::matching::{ElementSelectorFlags, MatchingContext};
|
use selectors::matching::{ElementSelectorFlags, MatchingContext};
|
||||||
use selectors::sink::Push;
|
use selectors::sink::Push;
|
||||||
use servo_arc::Arc;
|
use servo_arc::Arc;
|
||||||
|
@ -2636,7 +2635,6 @@ impl<'a> SelectorsElement for DomRoot<Element> {
|
||||||
&self,
|
&self,
|
||||||
pseudo_class: &NonTSPseudoClass,
|
pseudo_class: &NonTSPseudoClass,
|
||||||
_: &mut MatchingContext<Self::Impl>,
|
_: &mut MatchingContext<Self::Impl>,
|
||||||
_: VisitedHandlingMode,
|
|
||||||
_: &mut F,
|
_: &mut F,
|
||||||
) -> bool
|
) -> bool
|
||||||
where
|
where
|
||||||
|
|
|
@ -105,8 +105,6 @@ where
|
||||||
pub bloom_filter: Option<&'a BloomFilter>,
|
pub bloom_filter: Option<&'a BloomFilter>,
|
||||||
/// An optional cache to speed up nth-index-like selectors.
|
/// An optional cache to speed up nth-index-like selectors.
|
||||||
pub nth_index_cache: Option<&'a mut NthIndexCache>,
|
pub nth_index_cache: Option<&'a mut NthIndexCache>,
|
||||||
/// Input that controls how matching for links is handled.
|
|
||||||
pub visited_handling: VisitedHandlingMode,
|
|
||||||
/// The element which is going to match :scope pseudo-class. It can be
|
/// The element which is going to match :scope pseudo-class. It can be
|
||||||
/// either one :scope element, or the scoping element.
|
/// either one :scope element, or the scoping element.
|
||||||
///
|
///
|
||||||
|
@ -120,10 +118,13 @@ where
|
||||||
/// See https://drafts.csswg.org/selectors-4/#scope-pseudo
|
/// See https://drafts.csswg.org/selectors-4/#scope-pseudo
|
||||||
pub scope_element: Option<OpaqueElement>,
|
pub scope_element: Option<OpaqueElement>,
|
||||||
|
|
||||||
|
/// Controls how matching for links is handled.
|
||||||
|
visited_handling: VisitedHandlingMode,
|
||||||
|
|
||||||
/// The current nesting level of selectors that we're matching.
|
/// The current nesting level of selectors that we're matching.
|
||||||
///
|
///
|
||||||
/// FIXME(emilio): Consider putting the mutable stuff in a Cell.
|
/// FIXME(emilio): Consider putting the mutable stuff in a Cell, then make
|
||||||
/// immutable again.
|
/// MatchingContext immutable again.
|
||||||
nesting_level: usize,
|
nesting_level: usize,
|
||||||
|
|
||||||
/// An optional hook function for checking whether a pseudo-element
|
/// An optional hook function for checking whether a pseudo-element
|
||||||
|
@ -210,4 +211,26 @@ where
|
||||||
self.nesting_level -= 1;
|
self.nesting_level -= 1;
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn visited_handling(&self) -> VisitedHandlingMode {
|
||||||
|
self.visited_handling
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Runs F with a different VisitedHandlingMode.
|
||||||
|
#[inline]
|
||||||
|
pub fn with_visited_handling_mode<F, R>(
|
||||||
|
&mut self,
|
||||||
|
handling_mode: VisitedHandlingMode,
|
||||||
|
f: F,
|
||||||
|
) -> R
|
||||||
|
where
|
||||||
|
F: FnOnce(&mut Self) -> R,
|
||||||
|
{
|
||||||
|
let original_handling_mode = self.visited_handling;
|
||||||
|
self.visited_handling = handling_mode;
|
||||||
|
let result = f(self);
|
||||||
|
self.visited_handling = original_handling_mode;
|
||||||
|
result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,6 @@ impl ElementSelectorFlags {
|
||||||
struct LocalMatchingContext<'a, 'b: 'a, Impl: SelectorImpl> {
|
struct LocalMatchingContext<'a, 'b: 'a, Impl: SelectorImpl> {
|
||||||
shared: &'a mut MatchingContext<'b, Impl>,
|
shared: &'a mut MatchingContext<'b, Impl>,
|
||||||
matches_hover_and_active_quirk: MatchesHoverAndActiveQuirk,
|
matches_hover_and_active_quirk: MatchesHoverAndActiveQuirk,
|
||||||
visited_handling: VisitedHandlingMode,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -245,10 +244,8 @@ where
|
||||||
selector.combinator_at_parse_order(from_offset - 1); // This asserts.
|
selector.combinator_at_parse_order(from_offset - 1); // This asserts.
|
||||||
}
|
}
|
||||||
|
|
||||||
let visited_handling = context.visited_handling;
|
|
||||||
let mut local_context = LocalMatchingContext {
|
let mut local_context = LocalMatchingContext {
|
||||||
shared: context,
|
shared: context,
|
||||||
visited_handling,
|
|
||||||
matches_hover_and_active_quirk: MatchesHoverAndActiveQuirk::No,
|
matches_hover_and_active_quirk: MatchesHoverAndActiveQuirk::No,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -321,12 +318,10 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let visited_handling = context.visited_handling;
|
|
||||||
let result = matches_complex_selector_internal(
|
let result = matches_complex_selector_internal(
|
||||||
iter,
|
iter,
|
||||||
element,
|
element,
|
||||||
context,
|
context,
|
||||||
visited_handling,
|
|
||||||
flags_setter,
|
flags_setter,
|
||||||
Rightmost::Yes,
|
Rightmost::Yes,
|
||||||
);
|
);
|
||||||
|
@ -433,7 +428,6 @@ fn matches_complex_selector_internal<E, F>(
|
||||||
mut selector_iter: SelectorIter<E::Impl>,
|
mut selector_iter: SelectorIter<E::Impl>,
|
||||||
element: &E,
|
element: &E,
|
||||||
context: &mut MatchingContext<E::Impl>,
|
context: &mut MatchingContext<E::Impl>,
|
||||||
visited_handling: VisitedHandlingMode,
|
|
||||||
flags_setter: &mut F,
|
flags_setter: &mut F,
|
||||||
rightmost: Rightmost,
|
rightmost: Rightmost,
|
||||||
) -> SelectorMatchingResult
|
) -> SelectorMatchingResult
|
||||||
|
@ -447,7 +441,6 @@ where
|
||||||
&mut selector_iter,
|
&mut selector_iter,
|
||||||
element,
|
element,
|
||||||
context,
|
context,
|
||||||
visited_handling,
|
|
||||||
flags_setter,
|
flags_setter,
|
||||||
rightmost
|
rightmost
|
||||||
);
|
);
|
||||||
|
@ -483,11 +476,10 @@ where
|
||||||
|
|
||||||
// Stop matching :visited as soon as we find a link, or a combinator for
|
// Stop matching :visited as soon as we find a link, or a combinator for
|
||||||
// something that isn't an ancestor.
|
// something that isn't an ancestor.
|
||||||
let mut visited_handling =
|
let mut visited_handling = if element.is_link() || combinator.is_sibling() {
|
||||||
if element.is_link() || combinator.is_sibling() {
|
|
||||||
VisitedHandlingMode::AllLinksUnvisited
|
VisitedHandlingMode::AllLinksUnvisited
|
||||||
} else {
|
} else {
|
||||||
visited_handling
|
context.visited_handling()
|
||||||
};
|
};
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
@ -496,14 +488,16 @@ where
|
||||||
Some(next_element) => next_element,
|
Some(next_element) => next_element,
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = matches_complex_selector_internal(
|
let result =
|
||||||
|
context.with_visited_handling_mode(visited_handling, |context| {
|
||||||
|
matches_complex_selector_internal(
|
||||||
selector_iter.clone(),
|
selector_iter.clone(),
|
||||||
&element,
|
&element,
|
||||||
context,
|
context,
|
||||||
visited_handling,
|
|
||||||
flags_setter,
|
flags_setter,
|
||||||
Rightmost::No,
|
Rightmost::No,
|
||||||
);
|
)
|
||||||
|
});
|
||||||
|
|
||||||
match (result, combinator) {
|
match (result, combinator) {
|
||||||
// Return the status immediately.
|
// Return the status immediately.
|
||||||
|
@ -537,12 +531,9 @@ where
|
||||||
_ => {},
|
_ => {},
|
||||||
}
|
}
|
||||||
|
|
||||||
visited_handling =
|
|
||||||
if element.is_link() || combinator.is_sibling() {
|
if element.is_link() || combinator.is_sibling() {
|
||||||
VisitedHandlingMode::AllLinksUnvisited
|
visited_handling = VisitedHandlingMode::AllLinksUnvisited;
|
||||||
} else {
|
}
|
||||||
visited_handling
|
|
||||||
};
|
|
||||||
|
|
||||||
next_element = next_element_for_combinator(&element, combinator);
|
next_element = next_element_for_combinator(&element, combinator);
|
||||||
}
|
}
|
||||||
|
@ -570,7 +561,6 @@ fn matches_compound_selector<E, F>(
|
||||||
selector_iter: &mut SelectorIter<E::Impl>,
|
selector_iter: &mut SelectorIter<E::Impl>,
|
||||||
element: &E,
|
element: &E,
|
||||||
context: &mut MatchingContext<E::Impl>,
|
context: &mut MatchingContext<E::Impl>,
|
||||||
visited_handling: VisitedHandlingMode,
|
|
||||||
flags_setter: &mut F,
|
flags_setter: &mut F,
|
||||||
rightmost: Rightmost,
|
rightmost: Rightmost,
|
||||||
) -> bool
|
) -> bool
|
||||||
|
@ -612,7 +602,6 @@ where
|
||||||
let mut local_context =
|
let mut local_context =
|
||||||
LocalMatchingContext {
|
LocalMatchingContext {
|
||||||
shared: context,
|
shared: context,
|
||||||
visited_handling,
|
|
||||||
matches_hover_and_active_quirk,
|
matches_hover_and_active_quirk,
|
||||||
};
|
};
|
||||||
iter::once(selector).chain(selector_iter).all(|simple| {
|
iter::once(selector).chain(selector_iter).all(|simple| {
|
||||||
|
@ -738,7 +727,6 @@ where
|
||||||
element.match_non_ts_pseudo_class(
|
element.match_non_ts_pseudo_class(
|
||||||
pc,
|
pc,
|
||||||
&mut context.shared,
|
&mut context.shared,
|
||||||
context.visited_handling,
|
|
||||||
flags_setter
|
flags_setter
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -788,10 +776,8 @@ where
|
||||||
matches_generic_nth_child(element, context, 0, 1, true, true, flags_setter)
|
matches_generic_nth_child(element, context, 0, 1, true, true, flags_setter)
|
||||||
}
|
}
|
||||||
Component::Negation(ref negated) => {
|
Component::Negation(ref negated) => {
|
||||||
let visited_handling = context.visited_handling;
|
|
||||||
context.shared.nest(|context| {
|
context.shared.nest(|context| {
|
||||||
let mut local_context = LocalMatchingContext {
|
let mut local_context = LocalMatchingContext {
|
||||||
visited_handling,
|
|
||||||
matches_hover_and_active_quirk: MatchesHoverAndActiveQuirk::No,
|
matches_hover_and_active_quirk: MatchesHoverAndActiveQuirk::No,
|
||||||
shared: context,
|
shared: context,
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
//! between layout and style.
|
//! between layout and style.
|
||||||
|
|
||||||
use attr::{AttrSelectorOperation, NamespaceConstraint, CaseSensitivity};
|
use attr::{AttrSelectorOperation, NamespaceConstraint, CaseSensitivity};
|
||||||
use context::VisitedHandlingMode;
|
|
||||||
use matching::{ElementSelectorFlags, MatchingContext};
|
use matching::{ElementSelectorFlags, MatchingContext};
|
||||||
use parser::SelectorImpl;
|
use parser::SelectorImpl;
|
||||||
use servo_arc::NonZeroPtrMut;
|
use servo_arc::NonZeroPtrMut;
|
||||||
|
@ -69,7 +68,6 @@ pub trait Element: Sized + Clone + Debug {
|
||||||
&self,
|
&self,
|
||||||
pc: &<Self::Impl as SelectorImpl>::NonTSPseudoClass,
|
pc: &<Self::Impl as SelectorImpl>::NonTSPseudoClass,
|
||||||
context: &mut MatchingContext<Self::Impl>,
|
context: &mut MatchingContext<Self::Impl>,
|
||||||
visited_handling: VisitedHandlingMode,
|
|
||||||
flags_setter: &mut F,
|
flags_setter: &mut F,
|
||||||
) -> bool
|
) -> bool
|
||||||
where
|
where
|
||||||
|
|
|
@ -1997,7 +1997,6 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
|
||||||
&self,
|
&self,
|
||||||
pseudo_class: &NonTSPseudoClass,
|
pseudo_class: &NonTSPseudoClass,
|
||||||
context: &mut MatchingContext<Self::Impl>,
|
context: &mut MatchingContext<Self::Impl>,
|
||||||
visited_handling: VisitedHandlingMode,
|
|
||||||
flags_setter: &mut F,
|
flags_setter: &mut F,
|
||||||
) -> bool
|
) -> bool
|
||||||
where
|
where
|
||||||
|
@ -2057,10 +2056,10 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
|
||||||
},
|
},
|
||||||
NonTSPseudoClass::AnyLink => self.is_link(),
|
NonTSPseudoClass::AnyLink => self.is_link(),
|
||||||
NonTSPseudoClass::Link => {
|
NonTSPseudoClass::Link => {
|
||||||
self.is_link() && visited_handling.matches_unvisited()
|
self.is_link() && context.visited_handling().matches_unvisited()
|
||||||
}
|
}
|
||||||
NonTSPseudoClass::Visited => {
|
NonTSPseudoClass::Visited => {
|
||||||
self.is_link() && visited_handling.matches_visited()
|
self.is_link() && context.visited_handling().matches_visited()
|
||||||
}
|
}
|
||||||
NonTSPseudoClass::MozFirstNode => {
|
NonTSPseudoClass::MozFirstNode => {
|
||||||
flags_setter(self, ElementSelectorFlags::HAS_EDGE_CHILD_SELECTOR);
|
flags_setter(self, ElementSelectorFlags::HAS_EDGE_CHILD_SELECTOR);
|
||||||
|
|
|
@ -11,7 +11,6 @@ use element_state::ElementState;
|
||||||
use selector_parser::{NonTSPseudoClass, PseudoElement, SelectorImpl, Snapshot, SnapshotMap, AttrValue};
|
use selector_parser::{NonTSPseudoClass, PseudoElement, SelectorImpl, Snapshot, SnapshotMap, AttrValue};
|
||||||
use selectors::{Element, OpaqueElement};
|
use selectors::{Element, OpaqueElement};
|
||||||
use selectors::attr::{AttrSelectorOperation, CaseSensitivity, NamespaceConstraint};
|
use selectors::attr::{AttrSelectorOperation, CaseSensitivity, NamespaceConstraint};
|
||||||
use selectors::context::VisitedHandlingMode;
|
|
||||||
use selectors::matching::{ElementSelectorFlags, MatchingContext};
|
use selectors::matching::{ElementSelectorFlags, MatchingContext};
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -150,7 +149,6 @@ impl<'a, E> Element for ElementWrapper<'a, E>
|
||||||
&self,
|
&self,
|
||||||
pseudo_class: &NonTSPseudoClass,
|
pseudo_class: &NonTSPseudoClass,
|
||||||
context: &mut MatchingContext<Self::Impl>,
|
context: &mut MatchingContext<Self::Impl>,
|
||||||
visited_handling: VisitedHandlingMode,
|
|
||||||
_setter: &mut F,
|
_setter: &mut F,
|
||||||
) -> bool
|
) -> bool
|
||||||
where
|
where
|
||||||
|
@ -198,10 +196,10 @@ impl<'a, E> Element for ElementWrapper<'a, E>
|
||||||
// Instead, we use the `visited_handling` to determine if they
|
// Instead, we use the `visited_handling` to determine if they
|
||||||
// match.
|
// match.
|
||||||
NonTSPseudoClass::Link => {
|
NonTSPseudoClass::Link => {
|
||||||
return self.is_link() && visited_handling.matches_unvisited()
|
return self.is_link() && context.visited_handling().matches_unvisited()
|
||||||
}
|
}
|
||||||
NonTSPseudoClass::Visited => {
|
NonTSPseudoClass::Visited => {
|
||||||
return self.is_link() && visited_handling.matches_visited()
|
return self.is_link() && context.visited_handling().matches_visited()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
|
@ -236,7 +234,6 @@ impl<'a, E> Element for ElementWrapper<'a, E>
|
||||||
return self.element.match_non_ts_pseudo_class(
|
return self.element.match_non_ts_pseudo_class(
|
||||||
pseudo_class,
|
pseudo_class,
|
||||||
context,
|
context,
|
||||||
visited_handling,
|
|
||||||
&mut |_, _| {},
|
&mut |_, _| {},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -246,7 +243,6 @@ impl<'a, E> Element for ElementWrapper<'a, E>
|
||||||
self.element.match_non_ts_pseudo_class(
|
self.element.match_non_ts_pseudo_class(
|
||||||
pseudo_class,
|
pseudo_class,
|
||||||
context,
|
context,
|
||||||
visited_handling,
|
|
||||||
&mut |_, _| {},
|
&mut |_, _| {},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1246,7 +1246,7 @@ impl Stylist {
|
||||||
// Step 2: Presentational hints.
|
// Step 2: Presentational hints.
|
||||||
let length_before_preshints = applicable_declarations.len();
|
let length_before_preshints = applicable_declarations.len();
|
||||||
element.synthesize_presentational_hints_for_legacy_attributes(
|
element.synthesize_presentational_hints_for_legacy_attributes(
|
||||||
context.visited_handling,
|
context.visited_handling(),
|
||||||
applicable_declarations
|
applicable_declarations
|
||||||
);
|
);
|
||||||
if applicable_declarations.len() != length_before_preshints {
|
if applicable_declarations.len() != length_before_preshints {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue