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

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

Issue 425223005: Move Node/ContainerNode's traverseToChildAt() to NodeTraversal (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 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
« no previous file with comments | « Source/core/dom/Node.h ('k') | Source/core/dom/Position.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/NodeTraversal.h
diff --git a/Source/core/dom/NodeTraversal.h b/Source/core/dom/NodeTraversal.h
index 652d7025e9dbaed598d867f8173237bebbdd0310..fafabc8e2de7d3fc1872b805ef837d167c8916eb 100644
--- a/Source/core/dom/NodeTraversal.h
+++ b/Source/core/dom/NodeTraversal.h
@@ -70,11 +70,17 @@ public:
static Node* nextAncestorSibling(const Node&, const Node* stayWithin);
static Node& highestAncestorOrSelf(Node&);
+ // Children traversal.
+ static Node* childAt(const Node& parent, unsigned index) { return childAtTemplate(parent, index); }
+ static Node* childAt(const ContainerNode& parent, unsigned index) { return childAtTemplate(parent, index); }
+
private:
template <class NodeType>
static Node* traverseNextTemplate(NodeType&);
template <class NodeType>
static Node* traverseNextTemplate(NodeType&, const Node* stayWithin);
+ template <class NodeType>
+ static Node* childAtTemplate(NodeType&, unsigned);
};
template <class NodeType>
@@ -123,6 +129,15 @@ inline Node& NodeTraversal::highestAncestorOrSelf(Node& current)
return *highest;
}
+template <class NodeType>
+inline Node* NodeTraversal::childAtTemplate(NodeType& parent, unsigned index)
+{
+ Node* child = parent.firstChild();
+ while (child && index--)
+ child = child->nextSibling();
+ return child;
+}
+
} // namespace blink
#endif
« no previous file with comments | « Source/core/dom/Node.h ('k') | Source/core/dom/Position.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698