mirror of
https://github.com/servo/servo.git
synced 2025-08-02 20:20:14 +01:00
selectors: Be consistent about how we get next elements for selector-matching.
This fixes bug 1412011. MozReview-Commit-ID: JgLoBNjA3m8
This commit is contained in:
parent
22dc480272
commit
529f33eb6f
1 changed files with 36 additions and 19 deletions
|
@ -486,6 +486,32 @@ enum Rightmost {
|
|||
No,
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn next_element_for_combinator<E>(
|
||||
element: &E,
|
||||
combinator: Combinator,
|
||||
) -> Option<E>
|
||||
where
|
||||
E: Element,
|
||||
{
|
||||
match combinator {
|
||||
Combinator::NextSibling |
|
||||
Combinator::LaterSibling => {
|
||||
element.prev_sibling_element()
|
||||
}
|
||||
Combinator::Child |
|
||||
Combinator::Descendant => {
|
||||
if element.blocks_ancestor_combinators() {
|
||||
return None;
|
||||
}
|
||||
element.parent_element()
|
||||
}
|
||||
Combinator::PseudoElement => {
|
||||
element.pseudo_element_originating_element()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn matches_complex_selector_internal<E, F>(
|
||||
mut selector_iter: SelectorIter<E::Impl>,
|
||||
element: &E,
|
||||
|
@ -538,28 +564,23 @@ where
|
|||
Some(c) => c,
|
||||
};
|
||||
|
||||
let (mut next_element, candidate_not_found) = match combinator {
|
||||
Combinator::NextSibling | Combinator::LaterSibling => {
|
||||
let candidate_not_found = match combinator {
|
||||
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)
|
||||
}
|
||||
SelectorMatchingResult::NotMatchedAndRestartFromClosestDescendant
|
||||
}
|
||||
Combinator::Child |
|
||||
Combinator::Descendant |
|
||||
Combinator::PseudoElement => {
|
||||
(element.pseudo_element_originating_element(),
|
||||
SelectorMatchingResult::NotMatchedGlobally)
|
||||
SelectorMatchingResult::NotMatchedGlobally
|
||||
}
|
||||
};
|
||||
|
||||
let mut next_element = next_element_for_combinator(element, combinator);
|
||||
|
||||
loop {
|
||||
let element = match next_element {
|
||||
None => return candidate_not_found,
|
||||
|
@ -606,11 +627,7 @@ where
|
|||
_ => {},
|
||||
}
|
||||
|
||||
next_element = if siblings {
|
||||
element.prev_sibling_element()
|
||||
} else {
|
||||
element.parent_element()
|
||||
};
|
||||
next_element = next_element_for_combinator(&element, combinator);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue