OLD | NEW |
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 Loading... |
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 Loading... |
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(Node&); |
| 99 static TraversalRange<TraversalDescendantIterator<Traversal<ElementType>>> d
escendantsOf(Node&); |
| 100 static TraversalRange<TraversalNextIterator<Traversal<ElementType>>> from(No
de&); |
| 101 |
97 private: | 102 private: |
98 template <class NodeType> | 103 template <class NodeType> |
99 static ElementType* firstChildTemplate(NodeType&); | 104 static ElementType* firstChildTemplate(NodeType&); |
100 template <class NodeType> | 105 template <class NodeType> |
101 static ElementType* lastChildTemplate(NodeType&); | 106 static ElementType* lastChildTemplate(NodeType&); |
102 template <class NodeType> | 107 template <class NodeType> |
103 static ElementType* firstAncestorOrSelfTemplate(NodeType&); | 108 static ElementType* firstAncestorOrSelfTemplate(NodeType&); |
104 template <class NodeType> | 109 template <class NodeType> |
105 static ElementType* firstWithinTemplate(NodeType&); | 110 static ElementType* firstWithinTemplate(NodeType&); |
106 template <class NodeType> | 111 template <class NodeType> |
107 static ElementType* lastWithinTemplate(NodeType&); | 112 static ElementType* lastWithinTemplate(NodeType&); |
108 template <class NodeType> | 113 template <class NodeType> |
109 static ElementType* nextTemplate(NodeType&); | 114 static ElementType* nextTemplate(NodeType&); |
110 template <class NodeType> | 115 template <class NodeType> |
111 static ElementType* nextTemplate(NodeType&, const Node* stayWithin); | 116 static ElementType* nextTemplate(NodeType&, const Node* stayWithin); |
112 }; | 117 }; |
113 | 118 |
114 typedef Traversal<Element> ElementTraversal; | 119 typedef Traversal<Element> ElementTraversal; |
115 | 120 |
| 121 template <class ElementType> |
| 122 inline TraversalRange<TraversalChildrenIterator<Traversal<ElementType>>> Travers
al<ElementType>::childrenOf(Node& start) |
| 123 { |
| 124 return TraversalRange<TraversalChildrenIterator<Traversal<ElementType>>>(sta
rt); |
| 125 }; |
| 126 |
| 127 template <class ElementType> |
| 128 inline TraversalRange<TraversalDescendantIterator<Traversal<ElementType>>> Trave
rsal<ElementType>::descendantsOf(Node& root) |
| 129 { |
| 130 return TraversalRange<TraversalDescendantIterator<Traversal<ElementType>>>(r
oot); |
| 131 }; |
| 132 |
| 133 template <class ElementType> |
| 134 inline TraversalRange<TraversalNextIterator<Traversal<ElementType>>> Traversal<E
lementType>::from(Node& start) |
| 135 { |
| 136 return TraversalRange<TraversalNextIterator<Traversal<ElementType>>>(start); |
| 137 }; |
| 138 |
116 // Specialized for pure Element to exploit the fact that Elements parent is alwa
ys either another Element or the root. | 139 // Specialized for pure Element to exploit the fact that Elements parent is alwa
ys either another Element or the root. |
117 template <> | 140 template <> |
118 template <class NodeType> | 141 template <class NodeType> |
119 inline Element* Traversal<Element>::firstWithinTemplate(NodeType& current) | 142 inline Element* Traversal<Element>::firstWithinTemplate(NodeType& current) |
120 { | 143 { |
121 return firstChildTemplate(current); | 144 return firstChildTemplate(current); |
122 } | 145 } |
123 | 146 |
124 template <> | 147 template <> |
125 template <class NodeType> | 148 template <class NodeType> |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 { | 409 { |
387 ElementType* element = Traversal<ElementType>::nextSibling(current); | 410 ElementType* element = Traversal<ElementType>::nextSibling(current); |
388 while (element && !isMatch(*element)) | 411 while (element && !isMatch(*element)) |
389 element = Traversal<ElementType>::nextSibling(*element); | 412 element = Traversal<ElementType>::nextSibling(*element); |
390 return element; | 413 return element; |
391 } | 414 } |
392 | 415 |
393 } // namespace blink | 416 } // namespace blink |
394 | 417 |
395 #endif | 418 #endif |
OLD | NEW |