Skip to content

Commit

Permalink
Stop looking for relevant links once found
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jryans committed Jun 7, 2017
1 parent 6b1b8bb commit 2c8866e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions components/selectors/matching.rs
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
}
Expand Down

0 comments on commit 2c8866e

Please sign in to comment.