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

Unified Diff: Source/core/dom/ElementTraversal.h

Issue 201293002: Add Traversal<*Element>::firstAncestor() API (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Slight clean up Created 6 years, 9 months 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
Index: Source/core/dom/ElementTraversal.h
diff --git a/Source/core/dom/ElementTraversal.h b/Source/core/dom/ElementTraversal.h
index 6705f04efcd20b8bf281258b366a92797c59998a..4c9f2adef8894f48a5ab56d7eaf5b6641f3dc51f 100644
--- a/Source/core/dom/ElementTraversal.h
+++ b/Source/core/dom/ElementTraversal.h
@@ -40,6 +40,9 @@ public:
static ElementType* lastChild(const ContainerNode& current) { return lastChildTemplate(current); }
static ElementType* lastChild(const Node& current) { return lastChildTemplate(current); }
+ // First ElementType ancestor of the node.
esprehn 2014/03/21 07:58:33 The comment doesn't add anything.
Inactive 2014/03/21 14:37:24 Each set of ElementTraversal functions is grouped
+ static ElementType* firstAncestor(const Node& current);
+
// First or last ElementType descendant of the node.
// For Elements firstWithin() is always the same as firstChild().
static ElementType* firstWithin(const ContainerNode& current) { return firstWithinTemplate(current); }
@@ -167,6 +170,15 @@ inline ElementType* Traversal<ElementType>::firstChildTemplate(NodeType& current
}
template <class ElementType>
+inline ElementType* Traversal<ElementType>::firstAncestor(const Node& current)
+{
+ ContainerNode* ancestor = current.parentNode();
Inactive 2014/03/15 23:50:18 One idea that came to mind, we could potentially o
+ while (ancestor && !isElementOfType<const ElementType>(*ancestor))
+ ancestor = ancestor->parentNode();
+ return toElement<ElementType>(ancestor);
+}
+
+template <class ElementType>
template <class NodeType>
inline ElementType* Traversal<ElementType>::lastChildTemplate(NodeType& current)
{

Powered by Google App Engine
This is Rietveld 408576698