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

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

Issue 642973003: Introduce typed Node/Element iterators for range-based for loops of C++11. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rename `from` to `fromNext`. Make some parameters const references. Created 6 years, 2 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/DocumentOrderedMap.cpp ('k') | Source/core/dom/Node.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/ElementTraversal.h
diff --git a/Source/core/dom/ElementTraversal.h b/Source/core/dom/ElementTraversal.h
index c5a39068ce5c6abc6801fbee57fdc919c7cd1865..3d24b383ad877ab32524b92c96a2615be8e11081 100644
--- a/Source/core/dom/ElementTraversal.h
+++ b/Source/core/dom/ElementTraversal.h
@@ -34,6 +34,7 @@ namespace blink {
template <class ElementType>
class Traversal {
public:
+ using TraversalNodeType = ElementType;
// First or last ElementType child of the node.
static ElementType* firstChild(const ContainerNode& current) { return firstChildTemplate(current); }
static ElementType* firstChild(const Node& current) { return firstChildTemplate(current); }
@@ -94,6 +95,11 @@ public:
template <class MatchFunc>
static ElementType* nextSibling(const Node&, MatchFunc);
+ static TraversalRange<TraversalChildrenIterator<Traversal<ElementType>>> childrenOf(const Node&);
+ static TraversalRange<TraversalDescendantIterator<Traversal<ElementType>>> descendantsOf(const Node&);
+ static TraversalRange<TraversalInclusiveDescendantIterator<Traversal<ElementType>>> inclusiveDescendantsOf(const ElementType&);
+ static TraversalRange<TraversalNextIterator<Traversal<ElementType>>> fromNext(const Node&);
+
private:
template <class NodeType>
static ElementType* firstChildTemplate(NodeType&);
@@ -113,6 +119,30 @@ private:
typedef Traversal<Element> ElementTraversal;
+template <class ElementType>
+inline TraversalRange<TraversalChildrenIterator<Traversal<ElementType>>> Traversal<ElementType>::childrenOf(const Node& start)
+{
+ return TraversalRange<TraversalChildrenIterator<Traversal<ElementType>>>(start);
+};
+
+template <class ElementType>
+inline TraversalRange<TraversalDescendantIterator<Traversal<ElementType>>> Traversal<ElementType>::descendantsOf(const Node& root)
+{
+ return TraversalRange<TraversalDescendantIterator<Traversal<ElementType>>>(root);
+};
+
+template <class ElementType>
+inline TraversalRange<TraversalInclusiveDescendantIterator<Traversal<ElementType>>> Traversal<ElementType>::inclusiveDescendantsOf(const ElementType& root)
+{
+ return TraversalRange<TraversalInclusiveDescendantIterator<Traversal<ElementType>>>(root);
+};
+
+template <class ElementType>
+inline TraversalRange<TraversalNextIterator<Traversal<ElementType>>> Traversal<ElementType>::fromNext(const Node& start)
dglazkov 2014/10/21 16:03:11 This name had stumped me a little bit. What does i
hayato 2014/10/22 05:15:18 NodeTraversal::startsFromNext might be better? An
+{
+ return TraversalRange<TraversalNextIterator<Traversal<ElementType>>>(start);
+};
+
// Specialized for pure Element to exploit the fact that Elements parent is always either another Element or the root.
template <>
template <class NodeType>
« no previous file with comments | « Source/core/dom/DocumentOrderedMap.cpp ('k') | Source/core/dom/Node.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698