selectors: Deindent some selector-matching code.

MozReview-Commit-ID: B0ixSTcRS4S
This commit is contained in:
Emilio Cobos Álvarez 2017-10-26 17:21:06 +02:00
parent dd5cd29a61
commit 22dc480272
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C

View file

@ -533,78 +533,84 @@ where
return SelectorMatchingResult::NotMatchedAndRestartFromClosestLaterSibling; return SelectorMatchingResult::NotMatchedAndRestartFromClosestLaterSibling;
} }
match combinator { let combinator = match combinator {
None => SelectorMatchingResult::Matched, None => return SelectorMatchingResult::Matched,
Some(c) => { Some(c) => c,
let (mut next_element, candidate_not_found) = match c { };
Combinator::NextSibling | Combinator::LaterSibling => {
// Only ancestor combinators are allowed while looking for
// relevant links, so switch to not looking.
*relevant_link = RelevantLinkStatus::NotLooking;
(element.prev_sibling_element(),
SelectorMatchingResult::NotMatchedAndRestartFromClosestDescendant)
}
Combinator::Child | Combinator::Descendant => {
if element.blocks_ancestor_combinators() {
(None, SelectorMatchingResult::NotMatchedGlobally)
} else {
(element.parent_element(),
SelectorMatchingResult::NotMatchedGlobally)
}
}
Combinator::PseudoElement => {
(element.pseudo_element_originating_element(),
SelectorMatchingResult::NotMatchedGlobally)
}
};
loop { let (mut next_element, candidate_not_found) = match combinator {
let element = match next_element { Combinator::NextSibling | Combinator::LaterSibling => {
None => return candidate_not_found, // Only ancestor combinators are allowed while looking for
Some(next_element) => next_element, // relevant links, so switch to not looking.
}; *relevant_link = RelevantLinkStatus::NotLooking;
let result = matches_complex_selector_internal( (element.prev_sibling_element(),
selector_iter.clone(), SelectorMatchingResult::NotMatchedAndRestartFromClosestDescendant)
&element, }
context, Combinator::Child | Combinator::Descendant => {
relevant_link, if element.blocks_ancestor_combinators() {
flags_setter, (None, SelectorMatchingResult::NotMatchedGlobally)
Rightmost::No, } else {
); (element.parent_element(),
match (result, c) { SelectorMatchingResult::NotMatchedGlobally)
// Return the status immediately.
(SelectorMatchingResult::Matched, _) => return result,
(SelectorMatchingResult::NotMatchedGlobally, _) => return result,
// Upgrade the failure status to
// NotMatchedAndRestartFromClosestDescendant.
(_, Combinator::PseudoElement) |
(_, Combinator::Child) => return SelectorMatchingResult::NotMatchedAndRestartFromClosestDescendant,
// Return the status directly.
(_, Combinator::NextSibling) => return result,
// If the failure status is NotMatchedAndRestartFromClosestDescendant
// and combinator is Combinator::LaterSibling, give up this Combinator::LaterSibling matching
// and restart from the closest descendant combinator.
(SelectorMatchingResult::NotMatchedAndRestartFromClosestDescendant, Combinator::LaterSibling)
=> return result,
// The Combinator::Descendant combinator and the status is
// NotMatchedAndRestartFromClosestLaterSibling or
// NotMatchedAndRestartFromClosestDescendant,
// or the Combinator::LaterSibling combinator and the status is
// NotMatchedAndRestartFromClosestDescendant
// can continue to matching on the next candidate element.
_ => {},
}
next_element = if siblings {
element.prev_sibling_element()
} else {
element.parent_element()
};
} }
} }
Combinator::PseudoElement => {
(element.pseudo_element_originating_element(),
SelectorMatchingResult::NotMatchedGlobally)
}
};
loop {
let element = match next_element {
None => return candidate_not_found,
Some(next_element) => next_element,
};
let result = matches_complex_selector_internal(
selector_iter.clone(),
&element,
context,
relevant_link,
flags_setter,
Rightmost::No,
);
match (result, combinator) {
// Return the status immediately.
(SelectorMatchingResult::Matched, _) |
(SelectorMatchingResult::NotMatchedGlobally, _) |
(_, Combinator::NextSibling) => {
return result;
}
// Upgrade the failure status to
// NotMatchedAndRestartFromClosestDescendant.
(_, Combinator::PseudoElement) |
(_, Combinator::Child) => {
return SelectorMatchingResult::NotMatchedAndRestartFromClosestDescendant;
}
// If the failure status is
// NotMatchedAndRestartFromClosestDescendant and combinator is
// Combinator::LaterSibling, give up this Combinator::LaterSibling
// matching and restart from the closest descendant combinator.
(SelectorMatchingResult::NotMatchedAndRestartFromClosestDescendant, Combinator::LaterSibling) => {
return result;
}
// The Combinator::Descendant combinator and the status is
// NotMatchedAndRestartFromClosestLaterSibling or
// NotMatchedAndRestartFromClosestDescendant, or the
// Combinator::LaterSibling combinator and the status is
// NotMatchedAndRestartFromClosestDescendant, we can continue to
// matching on the next candidate element.
_ => {},
}
next_element = if siblings {
element.prev_sibling_element()
} else {
element.parent_element()
};
} }
} }