mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-10 15:33:23 +00:00
Bug 1407952: Use stylo for Element::Closest. r=heycam
MozReview-Commit-ID: 3H2piFT2CfF
This commit is contained in:
parent
1f743b9139
commit
5fe1768dec
@ -3467,27 +3467,38 @@ Element::GetTokenList(nsAtom* aAtom,
|
||||
Element*
|
||||
Element::Closest(const nsAString& aSelector, ErrorResult& aResult)
|
||||
{
|
||||
nsCSSSelectorList* selectorList = ParseSelectorList(aSelector, aResult);
|
||||
if (!selectorList) {
|
||||
// Either we failed (and aResult already has the exception), or this
|
||||
// is a pseudo-element-only selector that matches nothing.
|
||||
return nullptr;
|
||||
}
|
||||
TreeMatchContext matchingContext(false,
|
||||
nsRuleWalker::eRelevantLinkUnvisited,
|
||||
OwnerDoc(),
|
||||
TreeMatchContext::eNeverMatchVisited);
|
||||
matchingContext.SetHasSpecifiedScope();
|
||||
matchingContext.AddScopeElement(this);
|
||||
for (nsINode* node = this; node; node = node->GetParentNode()) {
|
||||
if (node->IsElement() &&
|
||||
nsCSSRuleProcessor::SelectorListMatches(node->AsElement(),
|
||||
matchingContext,
|
||||
selectorList)) {
|
||||
return node->AsElement();
|
||||
return WithSelectorList<Element*>(
|
||||
aSelector,
|
||||
aResult,
|
||||
[&](const RawServoSelectorList* aList) -> Element* {
|
||||
if (!aList) {
|
||||
return nullptr;
|
||||
}
|
||||
return const_cast<Element*>(Servo_SelectorList_Closest(this, aList));
|
||||
},
|
||||
[&](nsCSSSelectorList* aList) -> Element* {
|
||||
if (!aList) {
|
||||
// Either we failed (and aError already has the exception), or this
|
||||
// is a pseudo-element-only selector that matches nothing.
|
||||
return nullptr;
|
||||
}
|
||||
TreeMatchContext matchingContext(false,
|
||||
nsRuleWalker::eRelevantLinkUnvisited,
|
||||
OwnerDoc(),
|
||||
TreeMatchContext::eNeverMatchVisited);
|
||||
matchingContext.SetHasSpecifiedScope();
|
||||
matchingContext.AddScopeElement(this);
|
||||
for (nsINode* node = this; node; node = node->GetParentNode()) {
|
||||
if (node->IsElement() &&
|
||||
nsCSSRuleProcessor::SelectorListMatches(node->AsElement(),
|
||||
matchingContext,
|
||||
aList)) {
|
||||
return node->AsElement();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
);
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -136,6 +136,8 @@ SERVO_BINDING_FUNC(Servo_SelectorList_Parse,
|
||||
const nsACString* selector_list)
|
||||
SERVO_BINDING_FUNC(Servo_SelectorList_Matches, bool,
|
||||
RawGeckoElementBorrowed, RawServoSelectorListBorrowed)
|
||||
SERVO_BINDING_FUNC(Servo_SelectorList_Closest, RawGeckoElementBorrowedOrNull,
|
||||
RawGeckoElementBorrowed, RawServoSelectorListBorrowed)
|
||||
SERVO_BINDING_FUNC(Servo_StyleSet_AddSizeOfExcludingThis, void,
|
||||
mozilla::MallocSizeOf malloc_size_of,
|
||||
mozilla::MallocSizeOf malloc_enclosing_size_of,
|
||||
|
Loading…
Reference in New Issue
Block a user