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
This commit is contained in:
J. Ryan Stinnett 2017-06-06 17:04:03 -05:00
parent 6b1b8bbee8
commit 2c8866e919

View file

@ -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)
}