diff options
author | J. Ryan Stinnett <jryans@gmail.com> | 2017-06-06 17:04:03 -0500 |
---|---|---|
committer | J. Ryan Stinnett <jryans@gmail.com> | 2017-06-07 14:24:06 -0500 |
commit | 2c8866e919f864e989eeacf73b515fbb4325111d (patch) | |
tree | 51f747eb39c09e9e9a32c568cb507383bbe22d9e | |
parent | 6b1b8bbee83a090b67dbccb83ac527052559a5a6 (diff) | |
download | servo-2c8866e919f864e989eeacf73b515fbb4325111d.tar.gz servo-2c8866e919f864e989eeacf73b515fbb4325111d.zip |
Stop looking for relevant links once found
Once we've encountered a relevant link, stop looking for potential relevant
link. A relevant link is only the nearest ancestor link, so it is incorrect to
keep looking once one is found. This only matters for the somewhat unusual case
of nested links.
MozReview-Commit-ID: LiXsUGWfxg3
-rw-r--r-- | components/selectors/matching.rs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/components/selectors/matching.rs b/components/selectors/matching.rs index 84ddde2b261..0ab6c7e29e0 100644 --- a/components/selectors/matching.rs +++ b/components/selectors/matching.rs @@ -225,8 +225,10 @@ impl RelevantLinkStatus { -> RelevantLinkStatus where E: Element, { + // If a relevant link was previously found, we no longer want to look + // for links. Only the nearest ancestor link is considered relevant. if *self != RelevantLinkStatus::Looking { - return *self + return RelevantLinkStatus::NotLooking } if !element.is_link() { @@ -407,7 +409,7 @@ pub fn matches_complex_selector<E, F>(complex_selector: &Selector<E::Impl>, match matches_complex_selector_internal(iter, element, context, - RelevantLinkStatus::Looking, + &mut RelevantLinkStatus::Looking, flags_setter) { SelectorMatchingResult::Matched => true, _ => false @@ -417,13 +419,13 @@ pub fn matches_complex_selector<E, F>(complex_selector: &Selector<E::Impl>, fn matches_complex_selector_internal<E, F>(mut selector_iter: SelectorIter<E::Impl>, element: &E, context: &mut MatchingContext, - relevant_link: RelevantLinkStatus, + relevant_link: &mut RelevantLinkStatus, flags_setter: &mut F) -> SelectorMatchingResult where E: Element, F: FnMut(&E, ElementSelectorFlags), { - let mut relevant_link = relevant_link.examine_potential_link(element, context); + *relevant_link = relevant_link.examine_potential_link(element, context); let matches_all_simple_selectors = selector_iter.all(|simple| { matches_simple_selector(simple, element, context, &relevant_link, flags_setter) @@ -449,7 +451,7 @@ fn matches_complex_selector_internal<E, F>(mut selector_iter: SelectorIter<E::Im Combinator::NextSibling | Combinator::LaterSibling => { // Only ancestor combinators are allowed while looking for // relevant links, so switch to not looking. - relevant_link = RelevantLinkStatus::NotLooking; + *relevant_link = RelevantLinkStatus::NotLooking; (element.prev_sibling_element(), SelectorMatchingResult::NotMatchedAndRestartFromClosestDescendant) } |