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 "NodeIterator.h" | 26 #include "NodeIterator.h" |
27 | 27 |
28 #include <kjs/ExecState.h> | |
29 #include "Document.h" | 28 #include "Document.h" |
30 #include "ExceptionCode.h" | 29 #include "ExceptionCode.h" |
| 30 #include "ExceptionContext.h" |
31 #include "NodeFilter.h" | 31 #include "NodeFilter.h" |
32 | 32 |
33 using namespace KJS; | |
34 | |
35 namespace WebCore { | 33 namespace WebCore { |
36 | 34 |
37 NodeIterator::NodePointer::NodePointer() | 35 NodeIterator::NodePointer::NodePointer() |
38 { | 36 { |
39 } | 37 } |
40 | 38 |
41 NodeIterator::NodePointer::NodePointer(PassRefPtr<Node> n, bool b) | 39 NodeIterator::NodePointer::NodePointer(PassRefPtr<Node> n, bool b) |
42 : node(n) | 40 : node(n) |
43 , isPointerBeforeNode(b) | 41 , isPointerBeforeNode(b) |
44 { | 42 { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 , m_detached(false) | 77 , m_detached(false) |
80 { | 78 { |
81 root()->document()->attachNodeIterator(this); | 79 root()->document()->attachNodeIterator(this); |
82 } | 80 } |
83 | 81 |
84 NodeIterator::~NodeIterator() | 82 NodeIterator::~NodeIterator() |
85 { | 83 { |
86 root()->document()->detachNodeIterator(this); | 84 root()->document()->detachNodeIterator(this); |
87 } | 85 } |
88 | 86 |
89 #if USE(JSC) | 87 PassRefPtr<Node> NodeIterator::nextNode(ExceptionContext* exec, ExceptionCode& e
c) |
90 PassRefPtr<Node> NodeIterator::nextNode(ExecState* exec, ExceptionCode& ec) | |
91 { | 88 { |
92 if (m_detached) { | 89 if (m_detached) { |
93 ec = INVALID_STATE_ERR; | 90 ec = INVALID_STATE_ERR; |
94 return 0; | 91 return 0; |
95 } | 92 } |
96 | 93 |
97 RefPtr<Node> result; | 94 RefPtr<Node> result; |
98 | 95 |
99 m_candidateNode = m_referenceNode; | 96 m_candidateNode = m_referenceNode; |
100 while (m_candidateNode.moveToNext(root())) { | 97 while (m_candidateNode.moveToNext(root())) { |
101 // NodeIterators treat the DOM tree as a flat list of nodes. | 98 // NodeIterators treat the DOM tree as a flat list of nodes. |
102 // In other words, FILTER_REJECT does not pass over descendants | 99 // In other words, FILTER_REJECT does not pass over descendants |
103 // of the rejected node. Hence, FILTER_REJECT is the same as FILTER_SKIP
. | 100 // of the rejected node. Hence, FILTER_REJECT is the same as FILTER_SKIP
. |
104 RefPtr<Node> provisionalResult = m_candidateNode.node; | 101 RefPtr<Node> provisionalResult = m_candidateNode.node; |
105 bool nodeWasAccepted = acceptNode(exec, provisionalResult.get()) == Node
Filter::FILTER_ACCEPT; | 102 bool nodeWasAccepted = acceptNode(exec, provisionalResult.get()) == Node
Filter::FILTER_ACCEPT; |
106 if (exec && exec->hadException()) | 103 if (exec && exec->hadException()) |
107 break; | 104 break; |
108 if (nodeWasAccepted) { | 105 if (nodeWasAccepted) { |
109 m_referenceNode = m_candidateNode; | 106 m_referenceNode = m_candidateNode; |
110 result = provisionalResult.release(); | 107 result = provisionalResult.release(); |
111 break; | 108 break; |
112 } | 109 } |
113 } | 110 } |
114 | 111 |
115 m_candidateNode.clear(); | 112 m_candidateNode.clear(); |
116 return result.release(); | 113 return result.release(); |
117 } | 114 } |
118 | 115 |
119 PassRefPtr<Node> NodeIterator::previousNode(ExecState* exec, ExceptionCode& ec) | 116 PassRefPtr<Node> NodeIterator::previousNode(ExceptionContext* exec, ExceptionCod
e& ec) |
120 { | 117 { |
121 if (m_detached) { | 118 if (m_detached) { |
122 ec = INVALID_STATE_ERR; | 119 ec = INVALID_STATE_ERR; |
123 return 0; | 120 return 0; |
124 } | 121 } |
125 | 122 |
126 RefPtr<Node> result; | 123 RefPtr<Node> result; |
127 | 124 |
128 m_candidateNode = m_referenceNode; | 125 m_candidateNode = m_referenceNode; |
129 while (m_candidateNode.moveToPrevious(root())) { | 126 while (m_candidateNode.moveToPrevious(root())) { |
130 // NodeIterators treat the DOM tree as a flat list of nodes. | 127 // NodeIterators treat the DOM tree as a flat list of nodes. |
131 // In other words, FILTER_REJECT does not pass over descendants | 128 // In other words, FILTER_REJECT does not pass over descendants |
132 // of the rejected node. Hence, FILTER_REJECT is the same as FILTER_SKIP
. | 129 // of the rejected node. Hence, FILTER_REJECT is the same as FILTER_SKIP
. |
133 RefPtr<Node> provisionalResult = m_candidateNode.node; | 130 RefPtr<Node> provisionalResult = m_candidateNode.node; |
134 bool nodeWasAccepted = acceptNode(exec, provisionalResult.get()) == Node
Filter::FILTER_ACCEPT; | 131 bool nodeWasAccepted = acceptNode(exec, provisionalResult.get()) == Node
Filter::FILTER_ACCEPT; |
135 if (exec && exec->hadException()) | 132 if (exec && exec->hadException()) |
136 break; | 133 break; |
137 if (nodeWasAccepted) { | 134 if (nodeWasAccepted) { |
138 m_referenceNode = m_candidateNode; | 135 m_referenceNode = m_candidateNode; |
139 result = provisionalResult.release(); | 136 result = provisionalResult.release(); |
140 break; | 137 break; |
141 } | 138 } |
142 } | 139 } |
143 | 140 |
144 m_candidateNode.clear(); | 141 m_candidateNode.clear(); |
145 return result.release(); | 142 return result.release(); |
146 } | 143 } |
147 #endif | |
148 | 144 |
149 void NodeIterator::detach() | 145 void NodeIterator::detach() |
150 { | 146 { |
151 root()->document()->detachNodeIterator(this); | 147 root()->document()->detachNodeIterator(this); |
152 m_detached = true; | 148 m_detached = true; |
153 m_referenceNode.node.clear(); | 149 m_referenceNode.node.clear(); |
154 } | 150 } |
155 | 151 |
156 void NodeIterator::nodeWillBeRemoved(Node* removedNode) | 152 void NodeIterator::nodeWillBeRemoved(Node* removedNode) |
157 { | 153 { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 if (willRemoveReferenceNodeAncestor) { | 217 if (willRemoveReferenceNodeAncestor) { |
222 while (node && node->isDescendantOf(removedNode)) | 218 while (node && node->isDescendantOf(removedNode)) |
223 node = node->traversePreviousNode(root()); | 219 node = node->traversePreviousNode(root()); |
224 } | 220 } |
225 if (node) | 221 if (node) |
226 referenceNode.node = node; | 222 referenceNode.node = node; |
227 } | 223 } |
228 } | 224 } |
229 } | 225 } |
230 | 226 |
| 227 PassRefPtr<Node> NodeIterator::nextNode(ExceptionCode& ec) |
| 228 { |
| 229 return nextNode(ExceptionContext::createFromNode(referenceNode()), ec); |
| 230 } |
| 231 |
| 232 PassRefPtr<Node> NodeIterator::previousNode(ExceptionCode& ec) |
| 233 { |
| 234 return previousNode(ExceptionContext::createFromNode(referenceNode()), ec); |
| 235 } |
231 | 236 |
232 } // namespace WebCore | 237 } // namespace WebCore |
OLD | NEW |