| 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 14 matching lines...) Expand all Loading... |
| 25 #include "core/dom/TreeWalker.h" | 25 #include "core/dom/TreeWalker.h" |
| 26 | 26 |
| 27 #include "bindings/core/v8/ExceptionMessages.h" | 27 #include "bindings/core/v8/ExceptionMessages.h" |
| 28 #include "bindings/core/v8/ExceptionState.h" | 28 #include "bindings/core/v8/ExceptionState.h" |
| 29 #include "core/dom/ContainerNode.h" | 29 #include "core/dom/ContainerNode.h" |
| 30 #include "core/dom/ExceptionCode.h" | 30 #include "core/dom/ExceptionCode.h" |
| 31 #include "core/dom/NodeTraversal.h" | 31 #include "core/dom/NodeTraversal.h" |
| 32 | 32 |
| 33 namespace blink { | 33 namespace blink { |
| 34 | 34 |
| 35 TreeWalker::TreeWalker(PassRefPtrWillBeRawPtr<Node> rootNode, unsigned whatToSho
w, PassRefPtrWillBeRawPtr<NodeFilter> filter) | 35 TreeWalker::TreeWalker(RawPtr<Node> rootNode, unsigned whatToShow, RawPtr<NodeFi
lter> filter) |
| 36 : NodeIteratorBase(rootNode, whatToShow, filter) | 36 : NodeIteratorBase(rootNode, whatToShow, filter) |
| 37 , m_current(root()) | 37 , m_current(root()) |
| 38 { | 38 { |
| 39 } | 39 } |
| 40 | 40 |
| 41 void TreeWalker::setCurrentNode(PassRefPtrWillBeRawPtr<Node> node) | 41 void TreeWalker::setCurrentNode(RawPtr<Node> node) |
| 42 { | 42 { |
| 43 ASSERT(node); | 43 ASSERT(node); |
| 44 m_current = node; | 44 m_current = node; |
| 45 } | 45 } |
| 46 | 46 |
| 47 inline Node* TreeWalker::setCurrent(PassRefPtrWillBeRawPtr<Node> node) | 47 inline Node* TreeWalker::setCurrent(RawPtr<Node> node) |
| 48 { | 48 { |
| 49 m_current = node; | 49 m_current = node; |
| 50 return m_current.get(); | 50 return m_current.get(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 Node* TreeWalker::parentNode(ExceptionState& exceptionState) | 53 Node* TreeWalker::parentNode(ExceptionState& exceptionState) |
| 54 { | 54 { |
| 55 RefPtrWillBeRawPtr<Node> node = m_current; | 55 RawPtr<Node> node = m_current; |
| 56 while (node != root()) { | 56 while (node != root()) { |
| 57 node = node->parentNode(); | 57 node = node->parentNode(); |
| 58 if (!node) | 58 if (!node) |
| 59 return 0; | 59 return 0; |
| 60 unsigned acceptNodeResult = acceptNode(node.get(), exceptionState); | 60 unsigned acceptNodeResult = acceptNode(node.get(), exceptionState); |
| 61 if (exceptionState.hadException()) | 61 if (exceptionState.hadException()) |
| 62 return 0; | 62 return 0; |
| 63 if (acceptNodeResult == NodeFilter::FILTER_ACCEPT) | 63 if (acceptNodeResult == NodeFilter::FILTER_ACCEPT) |
| 64 return setCurrent(node.release()); | 64 return setCurrent(node.release()); |
| 65 } | 65 } |
| 66 return 0; | 66 return 0; |
| 67 } | 67 } |
| 68 | 68 |
| 69 Node* TreeWalker::firstChild(ExceptionState& exceptionState) | 69 Node* TreeWalker::firstChild(ExceptionState& exceptionState) |
| 70 { | 70 { |
| 71 for (RefPtrWillBeRawPtr<Node> node = m_current->firstChild(); node; ) { | 71 for (RawPtr<Node> node = m_current->firstChild(); node; ) { |
| 72 unsigned acceptNodeResult = acceptNode(node.get(), exceptionState); | 72 unsigned acceptNodeResult = acceptNode(node.get(), exceptionState); |
| 73 if (exceptionState.hadException()) | 73 if (exceptionState.hadException()) |
| 74 return 0; | 74 return 0; |
| 75 switch (acceptNodeResult) { | 75 switch (acceptNodeResult) { |
| 76 case NodeFilter::FILTER_ACCEPT: | 76 case NodeFilter::FILTER_ACCEPT: |
| 77 m_current = node.release(); | 77 m_current = node.release(); |
| 78 return m_current.get(); | 78 return m_current.get(); |
| 79 case NodeFilter::FILTER_SKIP: | 79 case NodeFilter::FILTER_SKIP: |
| 80 if (node->hasChildren()) { | 80 if (node->hasChildren()) { |
| 81 node = node->firstChild(); | 81 node = node->firstChild(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 94 if (!parent || parent == root() || parent == m_current) | 94 if (!parent || parent == root() || parent == m_current) |
| 95 return 0; | 95 return 0; |
| 96 node = parent; | 96 node = parent; |
| 97 } while (node); | 97 } while (node); |
| 98 } | 98 } |
| 99 return 0; | 99 return 0; |
| 100 } | 100 } |
| 101 | 101 |
| 102 Node* TreeWalker::lastChild(ExceptionState& exceptionState) | 102 Node* TreeWalker::lastChild(ExceptionState& exceptionState) |
| 103 { | 103 { |
| 104 for (RefPtrWillBeRawPtr<Node> node = m_current->lastChild(); node; ) { | 104 for (RawPtr<Node> node = m_current->lastChild(); node; ) { |
| 105 unsigned acceptNodeResult = acceptNode(node.get(), exceptionState); | 105 unsigned acceptNodeResult = acceptNode(node.get(), exceptionState); |
| 106 if (exceptionState.hadException()) | 106 if (exceptionState.hadException()) |
| 107 return 0; | 107 return 0; |
| 108 switch (acceptNodeResult) { | 108 switch (acceptNodeResult) { |
| 109 case NodeFilter::FILTER_ACCEPT: | 109 case NodeFilter::FILTER_ACCEPT: |
| 110 m_current = node.release(); | 110 m_current = node.release(); |
| 111 return m_current.get(); | 111 return m_current.get(); |
| 112 case NodeFilter::FILTER_SKIP: | 112 case NodeFilter::FILTER_SKIP: |
| 113 if (node->lastChild()) { | 113 if (node->lastChild()) { |
| 114 node = node->lastChild(); | 114 node = node->lastChild(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 127 if (!parent || parent == root() || parent == m_current) | 127 if (!parent || parent == root() || parent == m_current) |
| 128 return 0; | 128 return 0; |
| 129 node = parent; | 129 node = parent; |
| 130 } while (node); | 130 } while (node); |
| 131 } | 131 } |
| 132 return 0; | 132 return 0; |
| 133 } | 133 } |
| 134 | 134 |
| 135 Node* TreeWalker::previousSibling(ExceptionState& exceptionState) | 135 Node* TreeWalker::previousSibling(ExceptionState& exceptionState) |
| 136 { | 136 { |
| 137 RefPtrWillBeRawPtr<Node> node = m_current; | 137 RawPtr<Node> node = m_current; |
| 138 if (node == root()) | 138 if (node == root()) |
| 139 return 0; | 139 return 0; |
| 140 while (1) { | 140 while (1) { |
| 141 for (RefPtrWillBeRawPtr<Node> sibling = node->previousSibling(); sibling
; ) { | 141 for (RawPtr<Node> sibling = node->previousSibling(); sibling; ) { |
| 142 unsigned acceptNodeResult = acceptNode(sibling.get(), exceptionState
); | 142 unsigned acceptNodeResult = acceptNode(sibling.get(), exceptionState
); |
| 143 if (exceptionState.hadException()) | 143 if (exceptionState.hadException()) |
| 144 return 0; | 144 return 0; |
| 145 switch (acceptNodeResult) { | 145 switch (acceptNodeResult) { |
| 146 case NodeFilter::FILTER_ACCEPT: | 146 case NodeFilter::FILTER_ACCEPT: |
| 147 m_current = sibling.release(); | 147 m_current = sibling.release(); |
| 148 return m_current.get(); | 148 return m_current.get(); |
| 149 case NodeFilter::FILTER_SKIP: | 149 case NodeFilter::FILTER_SKIP: |
| 150 if (sibling->lastChild()) { | 150 if (sibling->lastChild()) { |
| 151 sibling = sibling->lastChild(); | 151 sibling = sibling->lastChild(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 164 unsigned acceptNodeResult = acceptNode(node.get(), exceptionState); | 164 unsigned acceptNodeResult = acceptNode(node.get(), exceptionState); |
| 165 if (exceptionState.hadException()) | 165 if (exceptionState.hadException()) |
| 166 return 0; | 166 return 0; |
| 167 if (acceptNodeResult == NodeFilter::FILTER_ACCEPT) | 167 if (acceptNodeResult == NodeFilter::FILTER_ACCEPT) |
| 168 return 0; | 168 return 0; |
| 169 } | 169 } |
| 170 } | 170 } |
| 171 | 171 |
| 172 Node* TreeWalker::nextSibling(ExceptionState& exceptionState) | 172 Node* TreeWalker::nextSibling(ExceptionState& exceptionState) |
| 173 { | 173 { |
| 174 RefPtrWillBeRawPtr<Node> node = m_current; | 174 RawPtr<Node> node = m_current; |
| 175 if (node == root()) | 175 if (node == root()) |
| 176 return 0; | 176 return 0; |
| 177 while (1) { | 177 while (1) { |
| 178 for (RefPtrWillBeRawPtr<Node> sibling = node->nextSibling(); sibling; )
{ | 178 for (RawPtr<Node> sibling = node->nextSibling(); sibling; ) { |
| 179 unsigned acceptNodeResult = acceptNode(sibling.get(), exceptionState
); | 179 unsigned acceptNodeResult = acceptNode(sibling.get(), exceptionState
); |
| 180 if (exceptionState.hadException()) | 180 if (exceptionState.hadException()) |
| 181 return 0; | 181 return 0; |
| 182 switch (acceptNodeResult) { | 182 switch (acceptNodeResult) { |
| 183 case NodeFilter::FILTER_ACCEPT: | 183 case NodeFilter::FILTER_ACCEPT: |
| 184 m_current = sibling.release(); | 184 m_current = sibling.release(); |
| 185 return m_current.get(); | 185 return m_current.get(); |
| 186 case NodeFilter::FILTER_SKIP: | 186 case NodeFilter::FILTER_SKIP: |
| 187 if (sibling->hasChildren()) { | 187 if (sibling->hasChildren()) { |
| 188 sibling = sibling->firstChild(); | 188 sibling = sibling->firstChild(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 201 unsigned acceptNodeResult = acceptNode(node.get(), exceptionState); | 201 unsigned acceptNodeResult = acceptNode(node.get(), exceptionState); |
| 202 if (exceptionState.hadException()) | 202 if (exceptionState.hadException()) |
| 203 return 0; | 203 return 0; |
| 204 if (acceptNodeResult == NodeFilter::FILTER_ACCEPT) | 204 if (acceptNodeResult == NodeFilter::FILTER_ACCEPT) |
| 205 return 0; | 205 return 0; |
| 206 } | 206 } |
| 207 } | 207 } |
| 208 | 208 |
| 209 Node* TreeWalker::previousNode(ExceptionState& exceptionState) | 209 Node* TreeWalker::previousNode(ExceptionState& exceptionState) |
| 210 { | 210 { |
| 211 RefPtrWillBeRawPtr<Node> node = m_current; | 211 RawPtr<Node> node = m_current; |
| 212 while (node != root()) { | 212 while (node != root()) { |
| 213 while (Node* previousSibling = node->previousSibling()) { | 213 while (Node* previousSibling = node->previousSibling()) { |
| 214 node = previousSibling; | 214 node = previousSibling; |
| 215 unsigned acceptNodeResult = acceptNode(node.get(), exceptionState); | 215 unsigned acceptNodeResult = acceptNode(node.get(), exceptionState); |
| 216 if (exceptionState.hadException()) | 216 if (exceptionState.hadException()) |
| 217 return 0; | 217 return 0; |
| 218 if (acceptNodeResult == NodeFilter::FILTER_REJECT) | 218 if (acceptNodeResult == NodeFilter::FILTER_REJECT) |
| 219 continue; | 219 continue; |
| 220 while (Node* lastChild = node->lastChild()) { | 220 while (Node* lastChild = node->lastChild()) { |
| 221 node = lastChild; | 221 node = lastChild; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 240 if (exceptionState.hadException()) | 240 if (exceptionState.hadException()) |
| 241 return 0; | 241 return 0; |
| 242 if (acceptNodeResult == NodeFilter::FILTER_ACCEPT) | 242 if (acceptNodeResult == NodeFilter::FILTER_ACCEPT) |
| 243 return setCurrent(node.release()); | 243 return setCurrent(node.release()); |
| 244 } | 244 } |
| 245 return 0; | 245 return 0; |
| 246 } | 246 } |
| 247 | 247 |
| 248 Node* TreeWalker::nextNode(ExceptionState& exceptionState) | 248 Node* TreeWalker::nextNode(ExceptionState& exceptionState) |
| 249 { | 249 { |
| 250 RefPtrWillBeRawPtr<Node> node = m_current; | 250 RawPtr<Node> node = m_current; |
| 251 Children: | 251 Children: |
| 252 while (Node* firstChild = node->firstChild()) { | 252 while (Node* firstChild = node->firstChild()) { |
| 253 node = firstChild; | 253 node = firstChild; |
| 254 unsigned acceptNodeResult = acceptNode(node.get(), exceptionState); | 254 unsigned acceptNodeResult = acceptNode(node.get(), exceptionState); |
| 255 if (exceptionState.hadException()) | 255 if (exceptionState.hadException()) |
| 256 return 0; | 256 return 0; |
| 257 if (acceptNodeResult == NodeFilter::FILTER_ACCEPT) | 257 if (acceptNodeResult == NodeFilter::FILTER_ACCEPT) |
| 258 return setCurrent(node.release()); | 258 return setCurrent(node.release()); |
| 259 if (acceptNodeResult == NodeFilter::FILTER_REJECT) | 259 if (acceptNodeResult == NodeFilter::FILTER_REJECT) |
| 260 break; | 260 break; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 272 return 0; | 272 return 0; |
| 273 } | 273 } |
| 274 | 274 |
| 275 DEFINE_TRACE(TreeWalker) | 275 DEFINE_TRACE(TreeWalker) |
| 276 { | 276 { |
| 277 visitor->trace(m_current); | 277 visitor->trace(m_current); |
| 278 NodeIteratorBase::trace(visitor); | 278 NodeIteratorBase::trace(visitor); |
| 279 } | 279 } |
| 280 | 280 |
| 281 } // namespace blink | 281 } // namespace blink |
| OLD | NEW |