Index: Source/core/dom/SelectorQuery.cpp |
diff --git a/Source/core/dom/SelectorQuery.cpp b/Source/core/dom/SelectorQuery.cpp |
index b097dd0c653e290ee34defe00a34f24e10d14443..455b1731cf28f8c74f7c78ed1b4cb3d7ae58b85f 100644 |
--- a/Source/core/dom/SelectorQuery.cpp |
+++ b/Source/core/dom/SelectorQuery.cpp |
@@ -136,6 +136,18 @@ bool SelectorDataList::matches(Element& targetElement) const |
return false; |
} |
+Element* SelectorDataList::closest(Element& targetElement) const |
+{ |
+ unsigned selectorCount = m_selectors.size(); |
+ for (Element* currentElement = &targetElement; currentElement; currentElement = currentElement->parentElement()) { |
+ for (unsigned i = 0; i < selectorCount; ++i) { |
+ if (selectorMatches(*m_selectors[i], *currentElement, targetElement)) |
+ return currentElement; |
+ } |
+ } |
+ return nullptr; |
+} |
+ |
PassRefPtrWillBeRawPtr<StaticElementList> SelectorDataList::queryAll(ContainerNode& rootNode) const |
{ |
WillBeHeapVector<RefPtrWillBeMember<Element> > result; |
@@ -481,6 +493,11 @@ bool SelectorQuery::matches(Element& element) const |
return m_selectors.matches(element); |
} |
+Element* SelectorQuery::closest(Element& element) const |
+{ |
+ return m_selectors.closest(element); |
+} |
+ |
PassRefPtrWillBeRawPtr<StaticElementList> SelectorQuery::queryAll(ContainerNode& rootNode) const |
{ |
return m_selectors.queryAll(rootNode); |