Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(773)

Unified Diff: Source/core/dom/SelectorQuery.cpp

Issue 704733002: Adding Element.closest() API (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/dom/SelectorQuery.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
« no previous file with comments | « Source/core/dom/SelectorQuery.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698