mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
selectors: Simplify :visited by only using the "is inside link" information.
Right now we go through a lot of hoops to see if we ever see a relevant link. However, that information is not needed: if the element is a link, we'll always need to compute its visited style because its its own relevant link. If the element inherits from a link, we need to also compute the visited style anyway. So the "has a relevant link been found" is pretty useless when we know what are we inheriting from. The branches at the beginning of matches_complex_selector_internal were affecting performance, and there are no good reasons to keep them. I've verified that this passes all the visited tests in mozilla central, and that the test-cases too-flaky to be landed still pass.
This commit is contained in:
parent
e4bb3a102e
commit
3119db724a
10 changed files with 128 additions and 208 deletions
|
@ -11,8 +11,8 @@ use element_state::ElementState;
|
|||
use selector_parser::{NonTSPseudoClass, PseudoElement, SelectorImpl, Snapshot, SnapshotMap, AttrValue};
|
||||
use selectors::{Element, OpaqueElement};
|
||||
use selectors::attr::{AttrSelectorOperation, CaseSensitivity, NamespaceConstraint};
|
||||
use selectors::context::VisitedHandlingMode;
|
||||
use selectors::matching::{ElementSelectorFlags, MatchingContext};
|
||||
use selectors::matching::RelevantLinkStatus;
|
||||
use std::cell::Cell;
|
||||
use std::fmt;
|
||||
|
||||
|
@ -153,7 +153,7 @@ impl<'a, E> Element for ElementWrapper<'a, E>
|
|||
&self,
|
||||
pseudo_class: &NonTSPseudoClass,
|
||||
context: &mut MatchingContext<Self::Impl>,
|
||||
relevant_link: &RelevantLinkStatus,
|
||||
visited_handling: VisitedHandlingMode,
|
||||
_setter: &mut F,
|
||||
) -> bool
|
||||
where
|
||||
|
@ -196,14 +196,16 @@ impl<'a, E> Element for ElementWrapper<'a, E>
|
|||
return state.contains(selector_flag);
|
||||
}
|
||||
|
||||
// For :link and :visited, we don't actually want to test the element
|
||||
// state directly. Instead, we use the `relevant_link` to determine if
|
||||
// they match.
|
||||
// For :link and :visited, we don't actually want to test the
|
||||
// element state directly.
|
||||
//
|
||||
// Instead, we use the `visited_handling` to determine if they
|
||||
// match.
|
||||
NonTSPseudoClass::Link => {
|
||||
return relevant_link.is_unvisited(self, context);
|
||||
return self.is_link() && visited_handling.matches_unvisited()
|
||||
}
|
||||
NonTSPseudoClass::Visited => {
|
||||
return relevant_link.is_visited(self, context);
|
||||
return self.is_link() && visited_handling.matches_visited()
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
|
@ -238,7 +240,7 @@ impl<'a, E> Element for ElementWrapper<'a, E>
|
|||
return self.element.match_non_ts_pseudo_class(
|
||||
pseudo_class,
|
||||
context,
|
||||
relevant_link,
|
||||
visited_handling,
|
||||
&mut |_, _| {},
|
||||
)
|
||||
}
|
||||
|
@ -248,7 +250,7 @@ impl<'a, E> Element for ElementWrapper<'a, E>
|
|||
self.element.match_non_ts_pseudo_class(
|
||||
pseudo_class,
|
||||
context,
|
||||
relevant_link,
|
||||
visited_handling,
|
||||
&mut |_, _| {},
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue