OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * Copyright (C) 2000 Frederik Holljen (frederik.holljen@hig.no) | 3 * Copyright (C) 2000 Frederik Holljen (frederik.holljen@hig.no) |
4 * Copyright (C) 2001 Peter Kelly (pmk@post.com) | 4 * Copyright (C) 2001 Peter Kelly (pmk@post.com) |
5 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) | 5 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
6 * Copyright (C) 2004, 2008 Apple Inc. All rights reserved. | 6 * Copyright (C) 2004, 2008 Apple Inc. All rights reserved. |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "core/dom/TreeWalker.h" | 26 #include "core/dom/TreeWalker.h" |
27 | 27 |
28 #include "bindings/v8/ExceptionMessages.h" | 28 #include "bindings/v8/ExceptionMessages.h" |
29 #include "bindings/v8/ExceptionState.h" | 29 #include "bindings/v8/ExceptionState.h" |
30 #include "core/dom/ContainerNode.h" | 30 #include "core/dom/ContainerNode.h" |
31 #include "core/dom/ExceptionCode.h" | 31 #include "core/dom/ExceptionCode.h" |
32 #include "core/dom/NodeTraversal.h" | 32 #include "core/dom/NodeTraversal.h" |
33 | 33 |
34 namespace WebCore { | 34 namespace WebCore { |
35 | 35 |
36 TreeWalker::TreeWalker(PassRefPtr<Node> rootNode, unsigned whatToShow, PassRefPt
r<NodeFilter> filter) | 36 TreeWalker::TreeWalker(PassRefPtrWillBeRawPtr<Node> rootNode, unsigned whatToSho
w, PassRefPtrWillBeRawPtr<NodeFilter> filter) |
37 : NodeIteratorBase(rootNode, whatToShow, filter) | 37 : NodeIteratorBase(rootNode, whatToShow, filter) |
38 , m_current(root()) | 38 , m_current(root()) |
39 { | 39 { |
40 ScriptWrappable::init(this); | 40 ScriptWrappable::init(this); |
41 } | 41 } |
42 | 42 |
43 void TreeWalker::setCurrentNode(PassRefPtr<Node> node, ExceptionState& exception
State) | 43 void TreeWalker::setCurrentNode(PassRefPtrWillBeRawPtr<Node> node, ExceptionStat
e& exceptionState) |
44 { | 44 { |
45 if (!node) { | 45 if (!node) { |
46 exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::a
rgumentNullOrIncorrectType(1, "Node")); | 46 exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::a
rgumentNullOrIncorrectType(1, "Node")); |
47 return; | 47 return; |
48 } | 48 } |
49 m_current = node; | 49 m_current = node; |
50 } | 50 } |
51 | 51 |
52 inline Node* TreeWalker::setCurrent(PassRefPtr<Node> node) | 52 inline Node* TreeWalker::setCurrent(PassRefPtrWillBeRawPtr<Node> node) |
53 { | 53 { |
54 m_current = node; | 54 m_current = node; |
55 return m_current.get(); | 55 return m_current.get(); |
56 } | 56 } |
57 | 57 |
58 Node* TreeWalker::parentNode(ExceptionState& exceptionState) | 58 Node* TreeWalker::parentNode(ExceptionState& exceptionState) |
59 { | 59 { |
60 RefPtr<Node> node = m_current; | 60 RefPtrWillBeRawPtr<Node> node = m_current; |
61 while (node != root()) { | 61 while (node != root()) { |
62 node = node->parentNode(); | 62 node = node->parentNode(); |
63 if (!node) | 63 if (!node) |
64 return 0; | 64 return 0; |
65 short acceptNodeResult = acceptNode(node.get(), exceptionState); | 65 short acceptNodeResult = acceptNode(node.get(), exceptionState); |
66 if (exceptionState.hadException()) | 66 if (exceptionState.hadException()) |
67 return 0; | 67 return 0; |
68 if (acceptNodeResult == NodeFilter::FILTER_ACCEPT) | 68 if (acceptNodeResult == NodeFilter::FILTER_ACCEPT) |
69 return setCurrent(node.release()); | 69 return setCurrent(node.release()); |
70 } | 70 } |
71 return 0; | 71 return 0; |
72 } | 72 } |
73 | 73 |
74 Node* TreeWalker::firstChild(ExceptionState& exceptionState) | 74 Node* TreeWalker::firstChild(ExceptionState& exceptionState) |
75 { | 75 { |
76 for (RefPtr<Node> node = m_current->firstChild(); node; ) { | 76 for (RefPtrWillBeRawPtr<Node> node = m_current->firstChild(); node; ) { |
77 short acceptNodeResult = acceptNode(node.get(), exceptionState); | 77 short acceptNodeResult = acceptNode(node.get(), exceptionState); |
78 if (exceptionState.hadException()) | 78 if (exceptionState.hadException()) |
79 return 0; | 79 return 0; |
80 switch (acceptNodeResult) { | 80 switch (acceptNodeResult) { |
81 case NodeFilter::FILTER_ACCEPT: | 81 case NodeFilter::FILTER_ACCEPT: |
82 m_current = node.release(); | 82 m_current = node.release(); |
83 return m_current.get(); | 83 return m_current.get(); |
84 case NodeFilter::FILTER_SKIP: | 84 case NodeFilter::FILTER_SKIP: |
85 if (node->firstChild()) { | 85 if (node->firstChild()) { |
86 node = node->firstChild(); | 86 node = node->firstChild(); |
(...skipping 12 matching lines...) Expand all Loading... |
99 if (!parent || parent == root() || parent == m_current) | 99 if (!parent || parent == root() || parent == m_current) |
100 return 0; | 100 return 0; |
101 node = parent; | 101 node = parent; |
102 } while (node); | 102 } while (node); |
103 } | 103 } |
104 return 0; | 104 return 0; |
105 } | 105 } |
106 | 106 |
107 Node* TreeWalker::lastChild(ExceptionState& exceptionState) | 107 Node* TreeWalker::lastChild(ExceptionState& exceptionState) |
108 { | 108 { |
109 for (RefPtr<Node> node = m_current->lastChild(); node; ) { | 109 for (RefPtrWillBeRawPtr<Node> node = m_current->lastChild(); node; ) { |
110 short acceptNodeResult = acceptNode(node.get(), exceptionState); | 110 short acceptNodeResult = acceptNode(node.get(), exceptionState); |
111 if (exceptionState.hadException()) | 111 if (exceptionState.hadException()) |
112 return 0; | 112 return 0; |
113 switch (acceptNodeResult) { | 113 switch (acceptNodeResult) { |
114 case NodeFilter::FILTER_ACCEPT: | 114 case NodeFilter::FILTER_ACCEPT: |
115 m_current = node.release(); | 115 m_current = node.release(); |
116 return m_current.get(); | 116 return m_current.get(); |
117 case NodeFilter::FILTER_SKIP: | 117 case NodeFilter::FILTER_SKIP: |
118 if (node->lastChild()) { | 118 if (node->lastChild()) { |
119 node = node->lastChild(); | 119 node = node->lastChild(); |
(...skipping 12 matching lines...) Expand all Loading... |
132 if (!parent || parent == root() || parent == m_current) | 132 if (!parent || parent == root() || parent == m_current) |
133 return 0; | 133 return 0; |
134 node = parent; | 134 node = parent; |
135 } while (node); | 135 } while (node); |
136 } | 136 } |
137 return 0; | 137 return 0; |
138 } | 138 } |
139 | 139 |
140 Node* TreeWalker::previousSibling(ExceptionState& exceptionState) | 140 Node* TreeWalker::previousSibling(ExceptionState& exceptionState) |
141 { | 141 { |
142 RefPtr<Node> node = m_current; | 142 RefPtrWillBeRawPtr<Node> node = m_current; |
143 if (node == root()) | 143 if (node == root()) |
144 return 0; | 144 return 0; |
145 while (1) { | 145 while (1) { |
146 for (RefPtr<Node> sibling = node->previousSibling(); sibling; ) { | 146 for (RefPtrWillBeRawPtr<Node> sibling = node->previousSibling(); sibling
; ) { |
147 short acceptNodeResult = acceptNode(sibling.get(), exceptionState); | 147 short acceptNodeResult = acceptNode(sibling.get(), exceptionState); |
148 if (exceptionState.hadException()) | 148 if (exceptionState.hadException()) |
149 return 0; | 149 return 0; |
150 switch (acceptNodeResult) { | 150 switch (acceptNodeResult) { |
151 case NodeFilter::FILTER_ACCEPT: | 151 case NodeFilter::FILTER_ACCEPT: |
152 m_current = sibling.release(); | 152 m_current = sibling.release(); |
153 return m_current.get(); | 153 return m_current.get(); |
154 case NodeFilter::FILTER_SKIP: | 154 case NodeFilter::FILTER_SKIP: |
155 if (sibling->lastChild()) { | 155 if (sibling->lastChild()) { |
156 sibling = sibling->lastChild(); | 156 sibling = sibling->lastChild(); |
(...skipping 12 matching lines...) Expand all Loading... |
169 short acceptNodeResult = acceptNode(node.get(), exceptionState); | 169 short acceptNodeResult = acceptNode(node.get(), exceptionState); |
170 if (exceptionState.hadException()) | 170 if (exceptionState.hadException()) |
171 return 0; | 171 return 0; |
172 if (acceptNodeResult == NodeFilter::FILTER_ACCEPT) | 172 if (acceptNodeResult == NodeFilter::FILTER_ACCEPT) |
173 return 0; | 173 return 0; |
174 } | 174 } |
175 } | 175 } |
176 | 176 |
177 Node* TreeWalker::nextSibling(ExceptionState& exceptionState) | 177 Node* TreeWalker::nextSibling(ExceptionState& exceptionState) |
178 { | 178 { |
179 RefPtr<Node> node = m_current; | 179 RefPtrWillBeRawPtr<Node> node = m_current; |
180 if (node == root()) | 180 if (node == root()) |
181 return 0; | 181 return 0; |
182 while (1) { | 182 while (1) { |
183 for (RefPtr<Node> sibling = node->nextSibling(); sibling; ) { | 183 for (RefPtrWillBeRawPtr<Node> sibling = node->nextSibling(); sibling; )
{ |
184 short acceptNodeResult = acceptNode(sibling.get(), exceptionState); | 184 short acceptNodeResult = acceptNode(sibling.get(), exceptionState); |
185 if (exceptionState.hadException()) | 185 if (exceptionState.hadException()) |
186 return 0; | 186 return 0; |
187 switch (acceptNodeResult) { | 187 switch (acceptNodeResult) { |
188 case NodeFilter::FILTER_ACCEPT: | 188 case NodeFilter::FILTER_ACCEPT: |
189 m_current = sibling.release(); | 189 m_current = sibling.release(); |
190 return m_current.get(); | 190 return m_current.get(); |
191 case NodeFilter::FILTER_SKIP: | 191 case NodeFilter::FILTER_SKIP: |
192 if (sibling->firstChild()) { | 192 if (sibling->firstChild()) { |
193 sibling = sibling->firstChild(); | 193 sibling = sibling->firstChild(); |
(...skipping 12 matching lines...) Expand all Loading... |
206 short acceptNodeResult = acceptNode(node.get(), exceptionState); | 206 short acceptNodeResult = acceptNode(node.get(), exceptionState); |
207 if (exceptionState.hadException()) | 207 if (exceptionState.hadException()) |
208 return 0; | 208 return 0; |
209 if (acceptNodeResult == NodeFilter::FILTER_ACCEPT) | 209 if (acceptNodeResult == NodeFilter::FILTER_ACCEPT) |
210 return 0; | 210 return 0; |
211 } | 211 } |
212 } | 212 } |
213 | 213 |
214 Node* TreeWalker::previousNode(ExceptionState& exceptionState) | 214 Node* TreeWalker::previousNode(ExceptionState& exceptionState) |
215 { | 215 { |
216 RefPtr<Node> node = m_current; | 216 RefPtrWillBeRawPtr<Node> node = m_current; |
217 while (node != root()) { | 217 while (node != root()) { |
218 while (Node* previousSibling = node->previousSibling()) { | 218 while (Node* previousSibling = node->previousSibling()) { |
219 node = previousSibling; | 219 node = previousSibling; |
220 short acceptNodeResult = acceptNode(node.get(), exceptionState); | 220 short acceptNodeResult = acceptNode(node.get(), exceptionState); |
221 if (exceptionState.hadException()) | 221 if (exceptionState.hadException()) |
222 return 0; | 222 return 0; |
223 if (acceptNodeResult == NodeFilter::FILTER_REJECT) | 223 if (acceptNodeResult == NodeFilter::FILTER_REJECT) |
224 continue; | 224 continue; |
225 while (Node* lastChild = node->lastChild()) { | 225 while (Node* lastChild = node->lastChild()) { |
226 node = lastChild; | 226 node = lastChild; |
(...skipping 18 matching lines...) Expand all Loading... |
245 if (exceptionState.hadException()) | 245 if (exceptionState.hadException()) |
246 return 0; | 246 return 0; |
247 if (acceptNodeResult == NodeFilter::FILTER_ACCEPT) | 247 if (acceptNodeResult == NodeFilter::FILTER_ACCEPT) |
248 return setCurrent(node.release()); | 248 return setCurrent(node.release()); |
249 } | 249 } |
250 return 0; | 250 return 0; |
251 } | 251 } |
252 | 252 |
253 Node* TreeWalker::nextNode(ExceptionState& exceptionState) | 253 Node* TreeWalker::nextNode(ExceptionState& exceptionState) |
254 { | 254 { |
255 RefPtr<Node> node = m_current; | 255 RefPtrWillBeRawPtr<Node> node = m_current; |
256 Children: | 256 Children: |
257 while (Node* firstChild = node->firstChild()) { | 257 while (Node* firstChild = node->firstChild()) { |
258 node = firstChild; | 258 node = firstChild; |
259 short acceptNodeResult = acceptNode(node.get(), exceptionState); | 259 short acceptNodeResult = acceptNode(node.get(), exceptionState); |
260 if (exceptionState.hadException()) | 260 if (exceptionState.hadException()) |
261 return 0; | 261 return 0; |
262 if (acceptNodeResult == NodeFilter::FILTER_ACCEPT) | 262 if (acceptNodeResult == NodeFilter::FILTER_ACCEPT) |
263 return setCurrent(node.release()); | 263 return setCurrent(node.release()); |
264 if (acceptNodeResult == NodeFilter::FILTER_REJECT) | 264 if (acceptNodeResult == NodeFilter::FILTER_REJECT) |
265 break; | 265 break; |
266 } | 266 } |
267 while (Node* nextSibling = NodeTraversal::nextSkippingChildren(*node, root()
)) { | 267 while (Node* nextSibling = NodeTraversal::nextSkippingChildren(*node, root()
)) { |
268 node = nextSibling; | 268 node = nextSibling; |
269 short acceptNodeResult = acceptNode(node.get(), exceptionState); | 269 short acceptNodeResult = acceptNode(node.get(), exceptionState); |
270 if (exceptionState.hadException()) | 270 if (exceptionState.hadException()) |
271 return 0; | 271 return 0; |
272 if (acceptNodeResult == NodeFilter::FILTER_ACCEPT) | 272 if (acceptNodeResult == NodeFilter::FILTER_ACCEPT) |
273 return setCurrent(node.release()); | 273 return setCurrent(node.release()); |
274 if (acceptNodeResult == NodeFilter::FILTER_SKIP) | 274 if (acceptNodeResult == NodeFilter::FILTER_SKIP) |
275 goto Children; | 275 goto Children; |
276 } | 276 } |
277 return 0; | 277 return 0; |
278 } | 278 } |
279 | 279 |
| 280 void TreeWalker::trace(Visitor* visitor) |
| 281 { |
| 282 visitor->trace(m_current); |
| 283 NodeIteratorBase::trace(visitor); |
| 284 } |
| 285 |
280 } // namespace WebCore | 286 } // namespace WebCore |
OLD | NEW |