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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/DocumentOrderedMap.cpp ('k') | Source/core/dom/Node.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Appl e Inc. All rights reserved. 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Appl e Inc. All rights reserved.
6 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 6 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
7 * Copyright (C) 2014 Samsung Electronics. All rights reserved. 7 * Copyright (C) 2014 Samsung Electronics. All rights reserved.
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 16 matching lines...) Expand all
27 #define ElementTraversal_h 27 #define ElementTraversal_h
28 28
29 #include "core/dom/Element.h" 29 #include "core/dom/Element.h"
30 #include "core/dom/NodeTraversal.h" 30 #include "core/dom/NodeTraversal.h"
31 31
32 namespace blink { 32 namespace blink {
33 33
34 template <class ElementType> 34 template <class ElementType>
35 class Traversal { 35 class Traversal {
36 public: 36 public:
37 using TraversalNodeType = ElementType;
37 // First or last ElementType child of the node. 38 // First or last ElementType child of the node.
38 static ElementType* firstChild(const ContainerNode& current) { return firstC hildTemplate(current); } 39 static ElementType* firstChild(const ContainerNode& current) { return firstC hildTemplate(current); }
39 static ElementType* firstChild(const Node& current) { return firstChildTempl ate(current); } 40 static ElementType* firstChild(const Node& current) { return firstChildTempl ate(current); }
40 template <class MatchFunc> 41 template <class MatchFunc>
41 static ElementType* firstChild(const ContainerNode&, MatchFunc); 42 static ElementType* firstChild(const ContainerNode&, MatchFunc);
42 static ElementType* lastChild(const ContainerNode& current) { return lastChi ldTemplate(current); } 43 static ElementType* lastChild(const ContainerNode& current) { return lastChi ldTemplate(current); }
43 static ElementType* lastChild(const Node& current) { return lastChildTemplat e(current); } 44 static ElementType* lastChild(const Node& current) { return lastChildTemplat e(current); }
44 template <class MatchFunc> 45 template <class MatchFunc>
45 static ElementType* lastChild(const ContainerNode&, MatchFunc); 46 static ElementType* lastChild(const ContainerNode&, MatchFunc);
46 47
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 static ElementType* pseudoAwarePreviousSibling(const Node&); 88 static ElementType* pseudoAwarePreviousSibling(const Node&);
88 89
89 // Previous / Next sibling. 90 // Previous / Next sibling.
90 static ElementType* previousSibling(const Node&); 91 static ElementType* previousSibling(const Node&);
91 template <class MatchFunc> 92 template <class MatchFunc>
92 static ElementType* previousSibling(const Node&, MatchFunc); 93 static ElementType* previousSibling(const Node&, MatchFunc);
93 static ElementType* nextSibling(const Node&); 94 static ElementType* nextSibling(const Node&);
94 template <class MatchFunc> 95 template <class MatchFunc>
95 static ElementType* nextSibling(const Node&, MatchFunc); 96 static ElementType* nextSibling(const Node&, MatchFunc);
96 97
98 static TraversalRange<TraversalChildrenIterator<Traversal<ElementType>>> chi ldrenOf(const Node&);
99 static TraversalRange<TraversalDescendantIterator<Traversal<ElementType>>> d escendantsOf(const Node&);
100 static TraversalRange<TraversalInclusiveDescendantIterator<Traversal<Element Type>>> inclusiveDescendantsOf(const ElementType&);
101 static TraversalRange<TraversalNextIterator<Traversal<ElementType>>> fromNex t(const Node&);
102
97 private: 103 private:
98 template <class NodeType> 104 template <class NodeType>
99 static ElementType* firstChildTemplate(NodeType&); 105 static ElementType* firstChildTemplate(NodeType&);
100 template <class NodeType> 106 template <class NodeType>
101 static ElementType* lastChildTemplate(NodeType&); 107 static ElementType* lastChildTemplate(NodeType&);
102 template <class NodeType> 108 template <class NodeType>
103 static ElementType* firstAncestorOrSelfTemplate(NodeType&); 109 static ElementType* firstAncestorOrSelfTemplate(NodeType&);
104 template <class NodeType> 110 template <class NodeType>
105 static ElementType* firstWithinTemplate(NodeType&); 111 static ElementType* firstWithinTemplate(NodeType&);
106 template <class NodeType> 112 template <class NodeType>
107 static ElementType* lastWithinTemplate(NodeType&); 113 static ElementType* lastWithinTemplate(NodeType&);
108 template <class NodeType> 114 template <class NodeType>
109 static ElementType* nextTemplate(NodeType&); 115 static ElementType* nextTemplate(NodeType&);
110 template <class NodeType> 116 template <class NodeType>
111 static ElementType* nextTemplate(NodeType&, const Node* stayWithin); 117 static ElementType* nextTemplate(NodeType&, const Node* stayWithin);
112 }; 118 };
113 119
114 typedef Traversal<Element> ElementTraversal; 120 typedef Traversal<Element> ElementTraversal;
115 121
122 template <class ElementType>
123 inline TraversalRange<TraversalChildrenIterator<Traversal<ElementType>>> Travers al<ElementType>::childrenOf(const Node& start)
124 {
125 return TraversalRange<TraversalChildrenIterator<Traversal<ElementType>>>(sta rt);
126 };
127
128 template <class ElementType>
129 inline TraversalRange<TraversalDescendantIterator<Traversal<ElementType>>> Trave rsal<ElementType>::descendantsOf(const Node& root)
130 {
131 return TraversalRange<TraversalDescendantIterator<Traversal<ElementType>>>(r oot);
132 };
133
134 template <class ElementType>
135 inline TraversalRange<TraversalInclusiveDescendantIterator<Traversal<ElementType >>> Traversal<ElementType>::inclusiveDescendantsOf(const ElementType& root)
136 {
137 return TraversalRange<TraversalInclusiveDescendantIterator<Traversal<Element Type>>>(root);
138 };
139
140 template <class ElementType>
141 inline TraversalRange<TraversalNextIterator<Traversal<ElementType>>> Traversal<E lementType>::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
142 {
143 return TraversalRange<TraversalNextIterator<Traversal<ElementType>>>(start);
144 };
145
116 // Specialized for pure Element to exploit the fact that Elements parent is alwa ys either another Element or the root. 146 // Specialized for pure Element to exploit the fact that Elements parent is alwa ys either another Element or the root.
117 template <> 147 template <>
118 template <class NodeType> 148 template <class NodeType>
119 inline Element* Traversal<Element>::firstWithinTemplate(NodeType& current) 149 inline Element* Traversal<Element>::firstWithinTemplate(NodeType& current)
120 { 150 {
121 return firstChildTemplate(current); 151 return firstChildTemplate(current);
122 } 152 }
123 153
124 template <> 154 template <>
125 template <class NodeType> 155 template <class NodeType>
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 { 416 {
387 ElementType* element = Traversal<ElementType>::nextSibling(current); 417 ElementType* element = Traversal<ElementType>::nextSibling(current);
388 while (element && !isMatch(*element)) 418 while (element && !isMatch(*element))
389 element = Traversal<ElementType>::nextSibling(*element); 419 element = Traversal<ElementType>::nextSibling(*element);
390 return element; 420 return element;
391 } 421 }
392 422
393 } // namespace blink 423 } // namespace blink
394 424
395 #endif 425 #endif
OLDNEW
« 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