Bug 1404897: Implement Element.matches using stylo. r=heycam

MozReview-Commit-ID: 7nxYVcweu0W
This commit is contained in:
Emilio Cobos Álvarez
2017-10-02 18:14:15 +02:00
parent 76cb832917
commit 7233693b2d
4 changed files with 111 additions and 17 deletions

View File

@@ -3496,21 +3496,31 @@ Element::Closest(const nsAString& aSelector, ErrorResult& aResult)
bool
Element::Matches(const nsAString& aSelector, ErrorResult& aError)
{
nsCSSSelectorList* selectorList = ParseSelectorList(aSelector, aError);
if (!selectorList) {
// Either we failed (and aError already has the exception), or this
// is a pseudo-element-only selector that matches nothing.
return false;
}
TreeMatchContext matchingContext(false,
nsRuleWalker::eRelevantLinkUnvisited,
OwnerDoc(),
TreeMatchContext::eNeverMatchVisited);
matchingContext.SetHasSpecifiedScope();
matchingContext.AddScopeElement(this);
return nsCSSRuleProcessor::SelectorListMatches(this, matchingContext,
selectorList);
return WithSelectorList<bool>(
aSelector,
aError,
[&](const RawServoSelectorList* aList) {
if (!aList) {
return false;
}
return Servo_SelectorList_Matches(this, aList);
},
[&](nsCSSSelectorList* aList) {
if (!aList) {
// Either we failed (and aError already has the exception), or this
// is a pseudo-element-only selector that matches nothing.
return false;
}
TreeMatchContext matchingContext(false,
nsRuleWalker::eRelevantLinkUnvisited,
OwnerDoc(),
TreeMatchContext::eNeverMatchVisited);
matchingContext.SetHasSpecifiedScope();
matchingContext.AddScopeElement(this);
return nsCSSRuleProcessor::SelectorListMatches(this, matchingContext,
aList);
}
);
}
static const nsAttrValue::EnumTable kCORSAttributeTable[] = {