| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 return 0; | 70 return 0; |
| 71 } | 71 } |
| 72 | 72 |
| 73 Node* TreeWalker::firstChild(ExceptionState& exceptionState) | 73 Node* TreeWalker::firstChild(ExceptionState& exceptionState) |
| 74 { | 74 { |
| 75 for (RefPtrWillBeRawPtr<Node> node = m_current->firstChild(); node; ) { | 75 for (RefPtrWillBeRawPtr<Node> node = m_current->firstChild(); node; ) { |
| 76 unsigned acceptNodeResult = acceptNode(node.get(), exceptionState); | 76 unsigned acceptNodeResult = acceptNode(node.get(), exceptionState); |
| 77 if (exceptionState.hadException()) | 77 if (exceptionState.hadException()) |
| 78 return 0; | 78 return 0; |
| 79 switch (acceptNodeResult) { | 79 switch (acceptNodeResult) { |
| 80 case NodeFilter::FILTER_ACCEPT: | 80 case NodeFilter::FILTER_ACCEPT: |
| 81 m_current = node.release(); | 81 m_current = node.release(); |
| 82 return m_current.get(); | 82 return m_current.get(); |
| 83 case NodeFilter::FILTER_SKIP: | 83 case NodeFilter::FILTER_SKIP: |
| 84 if (node->hasChildren()) { | 84 if (node->hasChildren()) { |
| 85 node = node->firstChild(); | 85 node = node->firstChild(); |
| 86 continue; | 86 continue; |
| 87 } | 87 } |
| 88 break; | 88 break; |
| 89 case NodeFilter::FILTER_REJECT: | 89 case NodeFilter::FILTER_REJECT: |
| 90 break; | 90 break; |
| 91 } | 91 } |
| 92 do { | 92 do { |
| 93 if (node->nextSibling()) { | 93 if (node->nextSibling()) { |
| 94 node = node->nextSibling(); | 94 node = node->nextSibling(); |
| 95 break; | 95 break; |
| 96 } | 96 } |
| 97 ContainerNode* parent = node->parentNode(); | 97 ContainerNode* parent = node->parentNode(); |
| 98 if (!parent || parent == root() || parent == m_current) | 98 if (!parent || parent == root() || parent == m_current) |
| 99 return 0; | 99 return 0; |
| 100 node = parent; | 100 node = parent; |
| 101 } while (node); | 101 } while (node); |
| 102 } | 102 } |
| 103 return 0; | 103 return 0; |
| 104 } | 104 } |
| 105 | 105 |
| 106 Node* TreeWalker::lastChild(ExceptionState& exceptionState) | 106 Node* TreeWalker::lastChild(ExceptionState& exceptionState) |
| 107 { | 107 { |
| 108 for (RefPtrWillBeRawPtr<Node> node = m_current->lastChild(); node; ) { | 108 for (RefPtrWillBeRawPtr<Node> node = m_current->lastChild(); node; ) { |
| 109 unsigned acceptNodeResult = acceptNode(node.get(), exceptionState); | 109 unsigned acceptNodeResult = acceptNode(node.get(), exceptionState); |
| 110 if (exceptionState.hadException()) | 110 if (exceptionState.hadException()) |
| 111 return 0; | 111 return 0; |
| 112 switch (acceptNodeResult) { | 112 switch (acceptNodeResult) { |
| 113 case NodeFilter::FILTER_ACCEPT: | 113 case NodeFilter::FILTER_ACCEPT: |
| 114 m_current = node.release(); | 114 m_current = node.release(); |
| 115 return m_current.get(); | 115 return m_current.get(); |
| 116 case NodeFilter::FILTER_SKIP: | 116 case NodeFilter::FILTER_SKIP: |
| 117 if (node->lastChild()) { | 117 if (node->lastChild()) { |
| 118 node = node->lastChild(); | 118 node = node->lastChild(); |
| 119 continue; | 119 continue; |
| 120 } | 120 } |
| 121 break; | 121 break; |
| 122 case NodeFilter::FILTER_REJECT: | 122 case NodeFilter::FILTER_REJECT: |
| 123 break; | 123 break; |
| 124 } | 124 } |
| 125 do { | 125 do { |
| 126 if (node->previousSibling()) { | 126 if (node->previousSibling()) { |
| 127 node = node->previousSibling(); | 127 node = node->previousSibling(); |
| 128 break; | 128 break; |
| 129 } | 129 } |
| 130 ContainerNode* parent = node->parentNode(); | 130 ContainerNode* parent = node->parentNode(); |
| 131 if (!parent || parent == root() || parent == m_current) | 131 if (!parent || parent == root() || parent == m_current) |
| 132 return 0; | 132 return 0; |
| 133 node = parent; | 133 node = parent; |
| 134 } while (node); | 134 } while (node); |
| 135 } | 135 } |
| 136 return 0; | 136 return 0; |
| 137 } | 137 } |
| 138 | 138 |
| 139 Node* TreeWalker::previousSibling(ExceptionState& exceptionState) | 139 Node* TreeWalker::previousSibling(ExceptionState& exceptionState) |
| 140 { | 140 { |
| 141 RefPtrWillBeRawPtr<Node> node = m_current; | 141 RefPtrWillBeRawPtr<Node> node = m_current; |
| 142 if (node == root()) | 142 if (node == root()) |
| 143 return 0; | 143 return 0; |
| 144 while (1) { | 144 while (1) { |
| 145 for (RefPtrWillBeRawPtr<Node> sibling = node->previousSibling(); sibling
; ) { | 145 for (RefPtrWillBeRawPtr<Node> sibling = node->previousSibling(); sibling
; ) { |
| 146 unsigned acceptNodeResult = acceptNode(sibling.get(), exceptionState
); | 146 unsigned acceptNodeResult = acceptNode(sibling.get(), exceptionState
); |
| 147 if (exceptionState.hadException()) | 147 if (exceptionState.hadException()) |
| 148 return 0; | 148 return 0; |
| 149 switch (acceptNodeResult) { | 149 switch (acceptNodeResult) { |
| 150 case NodeFilter::FILTER_ACCEPT: | 150 case NodeFilter::FILTER_ACCEPT: |
| 151 m_current = sibling.release(); | 151 m_current = sibling.release(); |
| 152 return m_current.get(); | 152 return m_current.get(); |
| 153 case NodeFilter::FILTER_SKIP: | 153 case NodeFilter::FILTER_SKIP: |
| 154 if (sibling->lastChild()) { | 154 if (sibling->lastChild()) { |
| 155 sibling = sibling->lastChild(); | 155 sibling = sibling->lastChild(); |
| 156 node = sibling; | 156 node = sibling; |
| 157 continue; | 157 continue; |
| 158 } | 158 } |
| 159 break; | 159 break; |
| 160 case NodeFilter::FILTER_REJECT: | 160 case NodeFilter::FILTER_REJECT: |
| 161 break; | 161 break; |
| 162 } | 162 } |
| 163 sibling = sibling->previousSibling(); | 163 sibling = sibling->previousSibling(); |
| 164 } | 164 } |
| 165 node = node->parentNode(); | 165 node = node->parentNode(); |
| 166 if (!node || node == root()) | 166 if (!node || node == root()) |
| 167 return 0; | 167 return 0; |
| 168 unsigned acceptNodeResult = acceptNode(node.get(), exceptionState); | 168 unsigned acceptNodeResult = acceptNode(node.get(), exceptionState); |
| 169 if (exceptionState.hadException()) | 169 if (exceptionState.hadException()) |
| 170 return 0; | 170 return 0; |
| 171 if (acceptNodeResult == NodeFilter::FILTER_ACCEPT) | 171 if (acceptNodeResult == NodeFilter::FILTER_ACCEPT) |
| 172 return 0; | 172 return 0; |
| 173 } | 173 } |
| 174 } | 174 } |
| 175 | 175 |
| 176 Node* TreeWalker::nextSibling(ExceptionState& exceptionState) | 176 Node* TreeWalker::nextSibling(ExceptionState& exceptionState) |
| 177 { | 177 { |
| 178 RefPtrWillBeRawPtr<Node> node = m_current; | 178 RefPtrWillBeRawPtr<Node> node = m_current; |
| 179 if (node == root()) | 179 if (node == root()) |
| 180 return 0; | 180 return 0; |
| 181 while (1) { | 181 while (1) { |
| 182 for (RefPtrWillBeRawPtr<Node> sibling = node->nextSibling(); sibling; )
{ | 182 for (RefPtrWillBeRawPtr<Node> sibling = node->nextSibling(); sibling; )
{ |
| 183 unsigned acceptNodeResult = acceptNode(sibling.get(), exceptionState
); | 183 unsigned acceptNodeResult = acceptNode(sibling.get(), exceptionState
); |
| 184 if (exceptionState.hadException()) | 184 if (exceptionState.hadException()) |
| 185 return 0; | 185 return 0; |
| 186 switch (acceptNodeResult) { | 186 switch (acceptNodeResult) { |
| 187 case NodeFilter::FILTER_ACCEPT: | 187 case NodeFilter::FILTER_ACCEPT: |
| 188 m_current = sibling.release(); | 188 m_current = sibling.release(); |
| 189 return m_current.get(); | 189 return m_current.get(); |
| 190 case NodeFilter::FILTER_SKIP: | 190 case NodeFilter::FILTER_SKIP: |
| 191 if (sibling->hasChildren()) { | 191 if (sibling->hasChildren()) { |
| 192 sibling = sibling->firstChild(); | 192 sibling = sibling->firstChild(); |
| 193 node = sibling; | 193 node = sibling; |
| 194 continue; | 194 continue; |
| 195 } | 195 } |
| 196 break; | 196 break; |
| 197 case NodeFilter::FILTER_REJECT: | 197 case NodeFilter::FILTER_REJECT: |
| 198 break; | 198 break; |
| 199 } | 199 } |
| 200 sibling = sibling->nextSibling(); | 200 sibling = sibling->nextSibling(); |
| 201 } | 201 } |
| 202 node = node->parentNode(); | 202 node = node->parentNode(); |
| 203 if (!node || node == root()) | 203 if (!node || node == root()) |
| 204 return 0; | 204 return 0; |
| 205 unsigned acceptNodeResult = acceptNode(node.get(), exceptionState); | 205 unsigned acceptNodeResult = acceptNode(node.get(), exceptionState); |
| 206 if (exceptionState.hadException()) | 206 if (exceptionState.hadException()) |
| 207 return 0; | 207 return 0; |
| 208 if (acceptNodeResult == NodeFilter::FILTER_ACCEPT) | 208 if (acceptNodeResult == NodeFilter::FILTER_ACCEPT) |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 return 0; | 276 return 0; |
| 277 } | 277 } |
| 278 | 278 |
| 279 DEFINE_TRACE(TreeWalker) | 279 DEFINE_TRACE(TreeWalker) |
| 280 { | 280 { |
| 281 visitor->trace(m_current); | 281 visitor->trace(m_current); |
| 282 NodeIteratorBase::trace(visitor); | 282 NodeIteratorBase::trace(visitor); |
| 283 } | 283 } |
| 284 | 284 |
| 285 } // namespace blink | 285 } // namespace blink |
| OLD | NEW |