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 |
11 * version 2 of the License, or (at your option) any later version. | 11 * version 2 of the License, or (at your option) any later version. |
12 * | 12 * |
13 * This library is distributed in the hope that it will be useful, | 13 * This library is distributed in the hope that it will be useful, |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 * Library General Public License for more details. | 16 * Library General Public License for more details. |
17 * | 17 * |
18 * You should have received a copy of the GNU Library General Public License | 18 * You should have received a copy of the GNU Library General Public License |
19 * along with this library; see the file COPYING.LIB. If not, write to | 19 * along with this library; see the file COPYING.LIB. If not, write to |
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
21 * Boston, MA 02110-1301, USA. | 21 * Boston, MA 02110-1301, USA. |
22 * | 22 * |
23 */ | 23 */ |
24 | 24 |
25 #include "config.h" | 25 #include "config.h" |
26 #include "core/dom/NodeIterator.h" | 26 #include "core/dom/NodeIterator.h" |
27 | 27 |
28 #include "bindings/v8/ExceptionMessages.h" | |
29 #include "bindings/v8/ExceptionState.h" | 28 #include "bindings/v8/ExceptionState.h" |
30 #include "bindings/v8/ScriptState.h" | 29 #include "bindings/v8/ScriptState.h" |
31 #include "core/dom/Document.h" | 30 #include "core/dom/Document.h" |
32 #include "core/dom/ExceptionCode.h" | 31 #include "core/dom/ExceptionCode.h" |
33 #include "core/dom/NodeTraversal.h" | 32 #include "core/dom/NodeTraversal.h" |
34 | 33 |
35 namespace WebCore { | 34 namespace WebCore { |
36 | 35 |
37 NodeIterator::NodePointer::NodePointer() | 36 NodeIterator::NodePointer::NodePointer() |
38 { | 37 { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 } | 82 } |
84 | 83 |
85 NodeIterator::~NodeIterator() | 84 NodeIterator::~NodeIterator() |
86 { | 85 { |
87 root()->document().detachNodeIterator(this); | 86 root()->document().detachNodeIterator(this); |
88 } | 87 } |
89 | 88 |
90 PassRefPtr<Node> NodeIterator::nextNode(ScriptState* state, ExceptionState& exce
ptionState) | 89 PassRefPtr<Node> NodeIterator::nextNode(ScriptState* state, ExceptionState& exce
ptionState) |
91 { | 90 { |
92 if (m_detached) { | 91 if (m_detached) { |
93 exceptionState.throwDOMException(InvalidStateError, ExceptionMessages::f
ailedToExecute("nextNode", "NodeIterator", "The iterator is detached.")); | 92 exceptionState.throwDOMException(InvalidStateError, "The iterator is det
ached."); |
94 return 0; | 93 return 0; |
95 } | 94 } |
96 | 95 |
97 RefPtr<Node> result; | 96 RefPtr<Node> result; |
98 | 97 |
99 m_candidateNode = m_referenceNode; | 98 m_candidateNode = m_referenceNode; |
100 while (m_candidateNode.moveToNext(root())) { | 99 while (m_candidateNode.moveToNext(root())) { |
101 // NodeIterators treat the DOM tree as a flat list of nodes. | 100 // NodeIterators treat the DOM tree as a flat list of nodes. |
102 // In other words, FILTER_REJECT does not pass over descendants | 101 // In other words, FILTER_REJECT does not pass over descendants |
103 // of the rejected node. Hence, FILTER_REJECT is the same as FILTER_SKIP
. | 102 // of the rejected node. Hence, FILTER_REJECT is the same as FILTER_SKIP
. |
104 RefPtr<Node> provisionalResult = m_candidateNode.node; | 103 RefPtr<Node> provisionalResult = m_candidateNode.node; |
105 bool nodeWasAccepted = acceptNode(state, provisionalResult.get()) == Nod
eFilter::FILTER_ACCEPT; | 104 bool nodeWasAccepted = acceptNode(state, provisionalResult.get()) == Nod
eFilter::FILTER_ACCEPT; |
106 if (state && state->hadException()) | 105 if (state && state->hadException()) |
107 break; | 106 break; |
108 if (nodeWasAccepted) { | 107 if (nodeWasAccepted) { |
109 m_referenceNode = m_candidateNode; | 108 m_referenceNode = m_candidateNode; |
110 result = provisionalResult.release(); | 109 result = provisionalResult.release(); |
111 break; | 110 break; |
112 } | 111 } |
113 } | 112 } |
114 | 113 |
115 m_candidateNode.clear(); | 114 m_candidateNode.clear(); |
116 return result.release(); | 115 return result.release(); |
117 } | 116 } |
118 | 117 |
119 PassRefPtr<Node> NodeIterator::previousNode(ScriptState* state, ExceptionState&
exceptionState) | 118 PassRefPtr<Node> NodeIterator::previousNode(ScriptState* state, ExceptionState&
exceptionState) |
120 { | 119 { |
121 if (m_detached) { | 120 if (m_detached) { |
122 exceptionState.throwDOMException(InvalidStateError, ExceptionMessages::f
ailedToExecute("previousNode", "NodeIterator", "The iterator is detached.")); | 121 exceptionState.throwDOMException(InvalidStateError, "The iterator is det
ached."); |
123 return 0; | 122 return 0; |
124 } | 123 } |
125 | 124 |
126 RefPtr<Node> result; | 125 RefPtr<Node> result; |
127 | 126 |
128 m_candidateNode = m_referenceNode; | 127 m_candidateNode = m_referenceNode; |
129 while (m_candidateNode.moveToPrevious(root())) { | 128 while (m_candidateNode.moveToPrevious(root())) { |
130 // NodeIterators treat the DOM tree as a flat list of nodes. | 129 // NodeIterators treat the DOM tree as a flat list of nodes. |
131 // In other words, FILTER_REJECT does not pass over descendants | 130 // In other words, FILTER_REJECT does not pass over descendants |
132 // of the rejected node. Hence, FILTER_REJECT is the same as FILTER_SKIP
. | 131 // of the rejected node. Hence, FILTER_REJECT is the same as FILTER_SKIP
. |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 node = NodeTraversal::previous(*node, root()); | 219 node = NodeTraversal::previous(*node, root()); |
221 } | 220 } |
222 if (node) | 221 if (node) |
223 referenceNode.node = node; | 222 referenceNode.node = node; |
224 } | 223 } |
225 } | 224 } |
226 } | 225 } |
227 | 226 |
228 | 227 |
229 } // namespace WebCore | 228 } // namespace WebCore |
OLD | NEW |