Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: Source/core/dom/NodeIterator.cpp

Issue 23819007: Have Node::document() return a reference instead of a pointer (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase on master Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/Node.cpp ('k') | Source/core/dom/NodeRenderingContext.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 node = NodeTraversal::previous(node.get(), root); 72 node = NodeTraversal::previous(node.get(), root);
73 return node; 73 return node;
74 } 74 }
75 75
76 NodeIterator::NodeIterator(PassRefPtr<Node> rootNode, unsigned whatToShow, PassR efPtr<NodeFilter> filter) 76 NodeIterator::NodeIterator(PassRefPtr<Node> rootNode, unsigned whatToShow, PassR efPtr<NodeFilter> filter)
77 : Traversal(rootNode, whatToShow, filter) 77 : Traversal(rootNode, whatToShow, filter)
78 , m_referenceNode(root(), true) 78 , m_referenceNode(root(), true)
79 , m_detached(false) 79 , m_detached(false)
80 { 80 {
81 ScriptWrappable::init(this); 81 ScriptWrappable::init(this);
82 root()->document()->attachNodeIterator(this); 82 root()->document().attachNodeIterator(this);
83 } 83 }
84 84
85 NodeIterator::~NodeIterator() 85 NodeIterator::~NodeIterator()
86 { 86 {
87 root()->document()->detachNodeIterator(this); 87 root()->document().detachNodeIterator(this);
88 } 88 }
89 89
90 PassRefPtr<Node> NodeIterator::nextNode(ScriptState* state, ExceptionState& es) 90 PassRefPtr<Node> NodeIterator::nextNode(ScriptState* state, ExceptionState& es)
91 { 91 {
92 if (m_detached) { 92 if (m_detached) {
93 es.throwDOMException(InvalidStateError); 93 es.throwDOMException(InvalidStateError);
94 return 0; 94 return 0;
95 } 95 }
96 96
97 RefPtr<Node> result; 97 RefPtr<Node> result;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 break; 140 break;
141 } 141 }
142 } 142 }
143 143
144 m_candidateNode.clear(); 144 m_candidateNode.clear();
145 return result.release(); 145 return result.release();
146 } 146 }
147 147
148 void NodeIterator::detach() 148 void NodeIterator::detach()
149 { 149 {
150 root()->document()->detachNodeIterator(this); 150 root()->document().detachNodeIterator(this);
151 m_detached = true; 151 m_detached = true;
152 m_referenceNode.node.clear(); 152 m_referenceNode.node.clear();
153 } 153 }
154 154
155 void NodeIterator::nodeWillBeRemoved(Node* removedNode) 155 void NodeIterator::nodeWillBeRemoved(Node* removedNode)
156 { 156 {
157 updateForNodeRemoval(removedNode, m_candidateNode); 157 updateForNodeRemoval(removedNode, m_candidateNode);
158 updateForNodeRemoval(removedNode, m_referenceNode); 158 updateForNodeRemoval(removedNode, m_referenceNode);
159 } 159 }
160 160
161 void NodeIterator::updateForNodeRemoval(Node* removedNode, NodePointer& referenc eNode) const 161 void NodeIterator::updateForNodeRemoval(Node* removedNode, NodePointer& referenc eNode) const
162 { 162 {
163 ASSERT(!m_detached); 163 ASSERT(!m_detached);
164 ASSERT(removedNode); 164 ASSERT(removedNode);
165 ASSERT(root()->document()); 165 ASSERT(&root()->document() == &removedNode->document());
166 ASSERT(root()->document() == removedNode->document());
167 166
168 // Iterator is not affected if the removed node is the reference node and is the root. 167 // Iterator is not affected if the removed node is the reference node and is the root.
169 // or if removed node is not the reference node, or the ancestor of the refe rence node. 168 // or if removed node is not the reference node, or the ancestor of the refe rence node.
170 if (!removedNode->isDescendantOf(root())) 169 if (!removedNode->isDescendantOf(root()))
171 return; 170 return;
172 bool willRemoveReferenceNode = removedNode == referenceNode.node; 171 bool willRemoveReferenceNode = removedNode == referenceNode.node;
173 bool willRemoveReferenceNodeAncestor = referenceNode.node && referenceNode.n ode->isDescendantOf(removedNode); 172 bool willRemoveReferenceNodeAncestor = referenceNode.node && referenceNode.n ode->isDescendantOf(removedNode);
174 if (!willRemoveReferenceNode && !willRemoveReferenceNodeAncestor) 173 if (!willRemoveReferenceNode && !willRemoveReferenceNodeAncestor)
175 return; 174 return;
176 175
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 node = NodeTraversal::previous(node, root()); 221 node = NodeTraversal::previous(node, root());
223 } 222 }
224 if (node) 223 if (node)
225 referenceNode.node = node; 224 referenceNode.node = node;
226 } 225 }
227 } 226 }
228 } 227 }
229 228
230 229
231 } // namespace WebCore 230 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/Node.cpp ('k') | Source/core/dom/NodeRenderingContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698