| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 Node* TreeWalker::parentNode(ExceptionState& exceptionState) | 52 Node* TreeWalker::parentNode(ExceptionState& exceptionState) |
| 53 { | 53 { |
| 54 Node* node = m_current; | 54 Node* node = m_current; |
| 55 while (node != root()) { | 55 while (node != root()) { |
| 56 node = node->parentNode(); | 56 node = node->parentNode(); |
| 57 if (!node) | 57 if (!node) |
| 58 return 0; | 58 return 0; |
| 59 unsigned acceptNodeResult = acceptNode(node, exceptionState); | 59 unsigned acceptNodeResult = acceptNode(node, exceptionState); |
| 60 if (exceptionState.hadException()) | 60 if (exceptionState.hadException()) |
| 61 return 0; | 61 return 0; |
| 62 if (acceptNodeResult == NodeFilter::FILTER_ACCEPT) | 62 if (acceptNodeResult == NodeFilter::kFilterAccept) |
| 63 return setCurrent(node); | 63 return setCurrent(node); |
| 64 } | 64 } |
| 65 return 0; | 65 return 0; |
| 66 } | 66 } |
| 67 | 67 |
| 68 Node* TreeWalker::firstChild(ExceptionState& exceptionState) | 68 Node* TreeWalker::firstChild(ExceptionState& exceptionState) |
| 69 { | 69 { |
| 70 for (Node* node = m_current->firstChild(); node; ) { | 70 for (Node* node = m_current->firstChild(); node; ) { |
| 71 unsigned acceptNodeResult = acceptNode(node, exceptionState); | 71 unsigned acceptNodeResult = acceptNode(node, exceptionState); |
| 72 if (exceptionState.hadException()) | 72 if (exceptionState.hadException()) |
| 73 return 0; | 73 return 0; |
| 74 switch (acceptNodeResult) { | 74 switch (acceptNodeResult) { |
| 75 case NodeFilter::FILTER_ACCEPT: | 75 case NodeFilter::kFilterAccept: |
| 76 m_current = node; | 76 m_current = node; |
| 77 return m_current.get(); | 77 return m_current.get(); |
| 78 case NodeFilter::FILTER_SKIP: | 78 case NodeFilter::kFilterSkip: |
| 79 if (node->hasChildren()) { | 79 if (node->hasChildren()) { |
| 80 node = node->firstChild(); | 80 node = node->firstChild(); |
| 81 continue; | 81 continue; |
| 82 } | 82 } |
| 83 break; | 83 break; |
| 84 case NodeFilter::FILTER_REJECT: | 84 case NodeFilter::kFilterReject: |
| 85 break; | 85 break; |
| 86 } | 86 } |
| 87 do { | 87 do { |
| 88 if (node->nextSibling()) { | 88 if (node->nextSibling()) { |
| 89 node = node->nextSibling(); | 89 node = node->nextSibling(); |
| 90 break; | 90 break; |
| 91 } | 91 } |
| 92 ContainerNode* parent = node->parentNode(); | 92 ContainerNode* parent = node->parentNode(); |
| 93 if (!parent || parent == root() || parent == m_current) | 93 if (!parent || parent == root() || parent == m_current) |
| 94 return 0; | 94 return 0; |
| 95 node = parent; | 95 node = parent; |
| 96 } while (node); | 96 } while (node); |
| 97 } | 97 } |
| 98 return 0; | 98 return 0; |
| 99 } | 99 } |
| 100 | 100 |
| 101 Node* TreeWalker::lastChild(ExceptionState& exceptionState) | 101 Node* TreeWalker::lastChild(ExceptionState& exceptionState) |
| 102 { | 102 { |
| 103 for (Node* node = m_current->lastChild(); node; ) { | 103 for (Node* node = m_current->lastChild(); node; ) { |
| 104 unsigned acceptNodeResult = acceptNode(node, exceptionState); | 104 unsigned acceptNodeResult = acceptNode(node, exceptionState); |
| 105 if (exceptionState.hadException()) | 105 if (exceptionState.hadException()) |
| 106 return 0; | 106 return 0; |
| 107 switch (acceptNodeResult) { | 107 switch (acceptNodeResult) { |
| 108 case NodeFilter::FILTER_ACCEPT: | 108 case NodeFilter::kFilterAccept: |
| 109 m_current = node; | 109 m_current = node; |
| 110 return m_current.get(); | 110 return m_current.get(); |
| 111 case NodeFilter::FILTER_SKIP: | 111 case NodeFilter::kFilterSkip: |
| 112 if (node->lastChild()) { | 112 if (node->lastChild()) { |
| 113 node = node->lastChild(); | 113 node = node->lastChild(); |
| 114 continue; | 114 continue; |
| 115 } | 115 } |
| 116 break; | 116 break; |
| 117 case NodeFilter::FILTER_REJECT: | 117 case NodeFilter::kFilterReject: |
| 118 break; | 118 break; |
| 119 } | 119 } |
| 120 do { | 120 do { |
| 121 if (node->previousSibling()) { | 121 if (node->previousSibling()) { |
| 122 node = node->previousSibling(); | 122 node = node->previousSibling(); |
| 123 break; | 123 break; |
| 124 } | 124 } |
| 125 ContainerNode* parent = node->parentNode(); | 125 ContainerNode* parent = node->parentNode(); |
| 126 if (!parent || parent == root() || parent == m_current) | 126 if (!parent || parent == root() || parent == m_current) |
| 127 return 0; | 127 return 0; |
| 128 node = parent; | 128 node = parent; |
| 129 } while (node); | 129 } while (node); |
| 130 } | 130 } |
| 131 return 0; | 131 return 0; |
| 132 } | 132 } |
| 133 | 133 |
| 134 Node* TreeWalker::previousSibling(ExceptionState& exceptionState) | 134 Node* TreeWalker::previousSibling(ExceptionState& exceptionState) |
| 135 { | 135 { |
| 136 Node* node = m_current; | 136 Node* node = m_current; |
| 137 if (node == root()) | 137 if (node == root()) |
| 138 return 0; | 138 return 0; |
| 139 while (1) { | 139 while (1) { |
| 140 for (Node* sibling = node->previousSibling(); sibling; ) { | 140 for (Node* sibling = node->previousSibling(); sibling; ) { |
| 141 unsigned acceptNodeResult = acceptNode(sibling, exceptionState); | 141 unsigned acceptNodeResult = acceptNode(sibling, exceptionState); |
| 142 if (exceptionState.hadException()) | 142 if (exceptionState.hadException()) |
| 143 return 0; | 143 return 0; |
| 144 switch (acceptNodeResult) { | 144 switch (acceptNodeResult) { |
| 145 case NodeFilter::FILTER_ACCEPT: | 145 case NodeFilter::kFilterAccept: |
| 146 m_current = sibling; | 146 m_current = sibling; |
| 147 return m_current.get(); | 147 return m_current.get(); |
| 148 case NodeFilter::FILTER_SKIP: | 148 case NodeFilter::kFilterSkip: |
| 149 if (sibling->lastChild()) { | 149 if (sibling->lastChild()) { |
| 150 sibling = sibling->lastChild(); | 150 sibling = sibling->lastChild(); |
| 151 node = sibling; | 151 node = sibling; |
| 152 continue; | 152 continue; |
| 153 } | 153 } |
| 154 break; | 154 break; |
| 155 case NodeFilter::FILTER_REJECT: | 155 case NodeFilter::kFilterReject: |
| 156 break; | 156 break; |
| 157 } | 157 } |
| 158 sibling = sibling->previousSibling(); | 158 sibling = sibling->previousSibling(); |
| 159 } | 159 } |
| 160 node = node->parentNode(); | 160 node = node->parentNode(); |
| 161 if (!node || node == root()) | 161 if (!node || node == root()) |
| 162 return 0; | 162 return 0; |
| 163 unsigned acceptNodeResult = acceptNode(node, exceptionState); | 163 unsigned acceptNodeResult = acceptNode(node, exceptionState); |
| 164 if (exceptionState.hadException()) | 164 if (exceptionState.hadException()) |
| 165 return 0; | 165 return 0; |
| 166 if (acceptNodeResult == NodeFilter::FILTER_ACCEPT) | 166 if (acceptNodeResult == NodeFilter::kFilterAccept) |
| 167 return 0; | 167 return 0; |
| 168 } | 168 } |
| 169 } | 169 } |
| 170 | 170 |
| 171 Node* TreeWalker::nextSibling(ExceptionState& exceptionState) | 171 Node* TreeWalker::nextSibling(ExceptionState& exceptionState) |
| 172 { | 172 { |
| 173 Node* node = m_current; | 173 Node* node = m_current; |
| 174 if (node == root()) | 174 if (node == root()) |
| 175 return 0; | 175 return 0; |
| 176 while (1) { | 176 while (1) { |
| 177 for (Node* sibling = node->nextSibling(); sibling; ) { | 177 for (Node* sibling = node->nextSibling(); sibling; ) { |
| 178 unsigned acceptNodeResult = acceptNode(sibling, exceptionState); | 178 unsigned acceptNodeResult = acceptNode(sibling, exceptionState); |
| 179 if (exceptionState.hadException()) | 179 if (exceptionState.hadException()) |
| 180 return 0; | 180 return 0; |
| 181 switch (acceptNodeResult) { | 181 switch (acceptNodeResult) { |
| 182 case NodeFilter::FILTER_ACCEPT: | 182 case NodeFilter::kFilterAccept: |
| 183 m_current = sibling; | 183 m_current = sibling; |
| 184 return m_current.get(); | 184 return m_current.get(); |
| 185 case NodeFilter::FILTER_SKIP: | 185 case NodeFilter::kFilterSkip: |
| 186 if (sibling->hasChildren()) { | 186 if (sibling->hasChildren()) { |
| 187 sibling = sibling->firstChild(); | 187 sibling = sibling->firstChild(); |
| 188 node = sibling; | 188 node = sibling; |
| 189 continue; | 189 continue; |
| 190 } | 190 } |
| 191 break; | 191 break; |
| 192 case NodeFilter::FILTER_REJECT: | 192 case NodeFilter::kFilterReject: |
| 193 break; | 193 break; |
| 194 } | 194 } |
| 195 sibling = sibling->nextSibling(); | 195 sibling = sibling->nextSibling(); |
| 196 } | 196 } |
| 197 node = node->parentNode(); | 197 node = node->parentNode(); |
| 198 if (!node || node == root()) | 198 if (!node || node == root()) |
| 199 return 0; | 199 return 0; |
| 200 unsigned acceptNodeResult = acceptNode(node, exceptionState); | 200 unsigned acceptNodeResult = acceptNode(node, exceptionState); |
| 201 if (exceptionState.hadException()) | 201 if (exceptionState.hadException()) |
| 202 return 0; | 202 return 0; |
| 203 if (acceptNodeResult == NodeFilter::FILTER_ACCEPT) | 203 if (acceptNodeResult == NodeFilter::kFilterAccept) |
| 204 return 0; | 204 return 0; |
| 205 } | 205 } |
| 206 } | 206 } |
| 207 | 207 |
| 208 Node* TreeWalker::previousNode(ExceptionState& exceptionState) | 208 Node* TreeWalker::previousNode(ExceptionState& exceptionState) |
| 209 { | 209 { |
| 210 Node* node = m_current; | 210 Node* node = m_current; |
| 211 while (node != root()) { | 211 while (node != root()) { |
| 212 while (Node* previousSibling = node->previousSibling()) { | 212 while (Node* previousSibling = node->previousSibling()) { |
| 213 node = previousSibling; | 213 node = previousSibling; |
| 214 unsigned acceptNodeResult = acceptNode(node, exceptionState); | 214 unsigned acceptNodeResult = acceptNode(node, exceptionState); |
| 215 if (exceptionState.hadException()) | 215 if (exceptionState.hadException()) |
| 216 return 0; | 216 return 0; |
| 217 if (acceptNodeResult == NodeFilter::FILTER_REJECT) | 217 if (acceptNodeResult == NodeFilter::kFilterReject) |
| 218 continue; | 218 continue; |
| 219 while (Node* lastChild = node->lastChild()) { | 219 while (Node* lastChild = node->lastChild()) { |
| 220 node = lastChild; | 220 node = lastChild; |
| 221 acceptNodeResult = acceptNode(node, exceptionState); | 221 acceptNodeResult = acceptNode(node, exceptionState); |
| 222 if (exceptionState.hadException()) | 222 if (exceptionState.hadException()) |
| 223 return 0; | 223 return 0; |
| 224 if (acceptNodeResult == NodeFilter::FILTER_REJECT) | 224 if (acceptNodeResult == NodeFilter::kFilterReject) |
| 225 break; | 225 break; |
| 226 } | 226 } |
| 227 if (acceptNodeResult == NodeFilter::FILTER_ACCEPT) { | 227 if (acceptNodeResult == NodeFilter::kFilterAccept) { |
| 228 m_current = node; | 228 m_current = node; |
| 229 return m_current.get(); | 229 return m_current.get(); |
| 230 } | 230 } |
| 231 } | 231 } |
| 232 if (node == root()) | 232 if (node == root()) |
| 233 return 0; | 233 return 0; |
| 234 ContainerNode* parent = node->parentNode(); | 234 ContainerNode* parent = node->parentNode(); |
| 235 if (!parent) | 235 if (!parent) |
| 236 return 0; | 236 return 0; |
| 237 node = parent; | 237 node = parent; |
| 238 unsigned acceptNodeResult = acceptNode(node, exceptionState); | 238 unsigned acceptNodeResult = acceptNode(node, exceptionState); |
| 239 if (exceptionState.hadException()) | 239 if (exceptionState.hadException()) |
| 240 return 0; | 240 return 0; |
| 241 if (acceptNodeResult == NodeFilter::FILTER_ACCEPT) | 241 if (acceptNodeResult == NodeFilter::kFilterAccept) |
| 242 return setCurrent(node); | 242 return setCurrent(node); |
| 243 } | 243 } |
| 244 return 0; | 244 return 0; |
| 245 } | 245 } |
| 246 | 246 |
| 247 Node* TreeWalker::nextNode(ExceptionState& exceptionState) | 247 Node* TreeWalker::nextNode(ExceptionState& exceptionState) |
| 248 { | 248 { |
| 249 Node* node = m_current; | 249 Node* node = m_current; |
| 250 Children: | 250 Children: |
| 251 while (Node* firstChild = node->firstChild()) { | 251 while (Node* firstChild = node->firstChild()) { |
| 252 node = firstChild; | 252 node = firstChild; |
| 253 unsigned acceptNodeResult = acceptNode(node, exceptionState); | 253 unsigned acceptNodeResult = acceptNode(node, exceptionState); |
| 254 if (exceptionState.hadException()) | 254 if (exceptionState.hadException()) |
| 255 return 0; | 255 return 0; |
| 256 if (acceptNodeResult == NodeFilter::FILTER_ACCEPT) | 256 if (acceptNodeResult == NodeFilter::kFilterAccept) |
| 257 return setCurrent(node); | 257 return setCurrent(node); |
| 258 if (acceptNodeResult == NodeFilter::FILTER_REJECT) | 258 if (acceptNodeResult == NodeFilter::kFilterReject) |
| 259 break; | 259 break; |
| 260 } | 260 } |
| 261 while (Node* nextSibling = NodeTraversal::nextSkippingChildren(*node, root()
)) { | 261 while (Node* nextSibling = NodeTraversal::nextSkippingChildren(*node, root()
)) { |
| 262 node = nextSibling; | 262 node = nextSibling; |
| 263 unsigned acceptNodeResult = acceptNode(node, exceptionState); | 263 unsigned acceptNodeResult = acceptNode(node, exceptionState); |
| 264 if (exceptionState.hadException()) | 264 if (exceptionState.hadException()) |
| 265 return 0; | 265 return 0; |
| 266 if (acceptNodeResult == NodeFilter::FILTER_ACCEPT) | 266 if (acceptNodeResult == NodeFilter::kFilterAccept) |
| 267 return setCurrent(node); | 267 return setCurrent(node); |
| 268 if (acceptNodeResult == NodeFilter::FILTER_SKIP) | 268 if (acceptNodeResult == NodeFilter::kFilterSkip) |
| 269 goto Children; | 269 goto Children; |
| 270 } | 270 } |
| 271 return 0; | 271 return 0; |
| 272 } | 272 } |
| 273 | 273 |
| 274 DEFINE_TRACE(TreeWalker) | 274 DEFINE_TRACE(TreeWalker) |
| 275 { | 275 { |
| 276 visitor->trace(m_current); | 276 visitor->trace(m_current); |
| 277 NodeIteratorBase::trace(visitor); | 277 NodeIteratorBase::trace(visitor); |
| 278 } | 278 } |
| 279 | 279 |
| 280 DEFINE_TRACE_WRAPPERS(TreeWalker) | 280 DEFINE_TRACE_WRAPPERS(TreeWalker) |
| 281 { | 281 { |
| 282 NodeIteratorBase::traceWrappers(visitor); | 282 NodeIteratorBase::traceWrappers(visitor); |
| 283 } | 283 } |
| 284 | 284 |
| 285 } // namespace blink | 285 } // namespace blink |
| OLD | NEW |