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

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

Issue 313813002: Oilpan: Replace RefPtrs to Node and its subclasses in core/dom/ with Oilpan transtion types. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 6 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv ed. 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv ed.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 void ContainerNode::removeDetachedChildren() 80 void ContainerNode::removeDetachedChildren()
81 { 81 {
82 ASSERT(!connectedSubframeCount()); 82 ASSERT(!connectedSubframeCount());
83 ASSERT(needsAttach()); 83 ASSERT(needsAttach());
84 removeDetachedChildrenInContainer<Node, ContainerNode>(*this); 84 removeDetachedChildrenInContainer<Node, ContainerNode>(*this);
85 } 85 }
86 #endif 86 #endif
87 87
88 void ContainerNode::parserTakeAllChildrenFrom(ContainerNode& oldParent) 88 void ContainerNode::parserTakeAllChildrenFrom(ContainerNode& oldParent)
89 { 89 {
90 while (RefPtr<Node> child = oldParent.firstChild()) { 90 while (RefPtrWillBeRawPtr<Node> child = oldParent.firstChild()) {
91 oldParent.parserRemoveChild(*child); 91 oldParent.parserRemoveChild(*child);
92 treeScope().adoptIfNeeded(*child); 92 treeScope().adoptIfNeeded(*child);
93 parserAppendChild(child.get()); 93 parserAppendChild(child.get());
94 } 94 }
95 } 95 }
96 96
97 ContainerNode::~ContainerNode() 97 ContainerNode::~ContainerNode()
98 { 98 {
99 ASSERT(needsAttach()); 99 ASSERT(needsAttach());
100 #if !ENABLE(OILPAN) 100 #if !ENABLE(OILPAN)
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 bool ContainerNode::checkAcceptChildGuaranteedNodeTypes(const Node& newChild, Ex ceptionState& exceptionState) const 169 bool ContainerNode::checkAcceptChildGuaranteedNodeTypes(const Node& newChild, Ex ceptionState& exceptionState) const
170 { 170 {
171 ASSERT(isChildTypeAllowed(newChild)); 171 ASSERT(isChildTypeAllowed(newChild));
172 if (newChild.contains(this)) { 172 if (newChild.contains(this)) {
173 exceptionState.throwDOMException(HierarchyRequestError, "The new child e lement contains the parent."); 173 exceptionState.throwDOMException(HierarchyRequestError, "The new child e lement contains the parent.");
174 return false; 174 return false;
175 } 175 }
176 return true; 176 return true;
177 } 177 }
178 178
179 void ContainerNode::insertBefore(PassRefPtr<Node> newChild, Node* refChild, Exce ptionState& exceptionState) 179 void ContainerNode::insertBefore(PassRefPtrWillBeRawPtr<Node> newChild, Node* re fChild, ExceptionState& exceptionState)
180 { 180 {
181 #if !ENABLE(OILPAN) 181 #if !ENABLE(OILPAN)
182 // Check that this node is not "floating". 182 // Check that this node is not "floating".
183 // If it is, it can be deleted as a side effect of sending mutation events. 183 // If it is, it can be deleted as a side effect of sending mutation events.
184 ASSERT(refCount() || parentOrShadowHostNode()); 184 ASSERT(refCount() || parentOrShadowHostNode());
185 #endif 185 #endif
186 186
187 RefPtr<Node> protect(this); 187 RefPtrWillBeRawPtr<Node> protect(this);
188 188
189 // insertBefore(node, 0) is equivalent to appendChild(node) 189 // insertBefore(node, 0) is equivalent to appendChild(node)
190 if (!refChild) { 190 if (!refChild) {
191 appendChild(newChild, exceptionState); 191 appendChild(newChild, exceptionState);
192 return; 192 return;
193 } 193 }
194 194
195 // Make sure adding the new child is OK. 195 // Make sure adding the new child is OK.
196 if (!checkAcceptChild(newChild.get(), 0, exceptionState)) 196 if (!checkAcceptChild(newChild.get(), 0, exceptionState))
197 return; 197 return;
198 ASSERT(newChild); 198 ASSERT(newChild);
199 199
200 // NotFoundError: Raised if refChild is not a child of this node 200 // NotFoundError: Raised if refChild is not a child of this node
201 if (refChild->parentNode() != this) { 201 if (refChild->parentNode() != this) {
202 exceptionState.throwDOMException(NotFoundError, "The node before which t he new node is to be inserted is not a child of this node."); 202 exceptionState.throwDOMException(NotFoundError, "The node before which t he new node is to be inserted is not a child of this node.");
203 return; 203 return;
204 } 204 }
205 205
206 if (refChild->previousSibling() == newChild || refChild == newChild) // noth ing to do 206 if (refChild->previousSibling() == newChild || refChild == newChild) // noth ing to do
207 return; 207 return;
208 208
209 RefPtr<Node> next = refChild; 209 RefPtrWillBeRawPtr<Node> next = refChild;
210 210
211 NodeVector targets; 211 NodeVector targets;
212 collectChildrenAndRemoveFromOldParent(*newChild, targets, exceptionState); 212 collectChildrenAndRemoveFromOldParent(*newChild, targets, exceptionState);
213 if (exceptionState.hadException()) 213 if (exceptionState.hadException())
214 return; 214 return;
215 if (targets.isEmpty()) 215 if (targets.isEmpty())
216 return; 216 return;
217 217
218 // We need this extra check because collectChildrenAndRemoveFromOldParent() can fire mutation events. 218 // We need this extra check because collectChildrenAndRemoveFromOldParent() can fire mutation events.
219 if (!checkAcceptChildGuaranteedNodeTypes(*newChild, exceptionState)) 219 if (!checkAcceptChildGuaranteedNodeTypes(*newChild, exceptionState))
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 prev->setNextSibling(&newChild); 264 prev->setNextSibling(&newChild);
265 } else { 265 } else {
266 ASSERT(firstChild() == nextChild); 266 ASSERT(firstChild() == nextChild);
267 m_firstChild = &newChild; 267 m_firstChild = &newChild;
268 } 268 }
269 newChild.setParentOrShadowHostNode(this); 269 newChild.setParentOrShadowHostNode(this);
270 newChild.setPreviousSibling(prev); 270 newChild.setPreviousSibling(prev);
271 newChild.setNextSibling(&nextChild); 271 newChild.setNextSibling(&nextChild);
272 } 272 }
273 273
274 void ContainerNode::parserInsertBefore(PassRefPtr<Node> newChild, Node& nextChil d) 274 void ContainerNode::parserInsertBefore(PassRefPtrWillBeRawPtr<Node> newChild, No de& nextChild)
275 { 275 {
276 ASSERT(newChild); 276 ASSERT(newChild);
277 ASSERT(nextChild.parentNode() == this); 277 ASSERT(nextChild.parentNode() == this);
278 ASSERT(!newChild->isDocumentFragment()); 278 ASSERT(!newChild->isDocumentFragment());
279 ASSERT(!isHTMLTemplateElement(this)); 279 ASSERT(!isHTMLTemplateElement(this));
280 280
281 if (nextChild.previousSibling() == newChild || nextChild == newChild) // not hing to do 281 if (nextChild.previousSibling() == newChild || nextChild == newChild) // not hing to do
282 return; 282 return;
283 283
284 if (document() != newChild->document()) 284 if (document() != newChild->document())
285 document().adoptNode(newChild.get(), ASSERT_NO_EXCEPTION); 285 document().adoptNode(newChild.get(), ASSERT_NO_EXCEPTION);
286 286
287 insertBeforeCommon(nextChild, *newChild); 287 insertBeforeCommon(nextChild, *newChild);
288 288
289 newChild->updateAncestorConnectedSubframeCountForInsertion(); 289 newChild->updateAncestorConnectedSubframeCountForInsertion();
290 290
291 ChildListMutationScope(*this).childAdded(*newChild); 291 ChildListMutationScope(*this).childAdded(*newChild);
292 292
293 childrenChanged(true, newChild->previousSibling(), &nextChild, 1); 293 childrenChanged(true, newChild->previousSibling(), &nextChild, 1);
294 294
295 notifyNodeInserted(*newChild); 295 notifyNodeInserted(*newChild);
296 } 296 }
297 297
298 void ContainerNode::replaceChild(PassRefPtr<Node> newChild, Node* oldChild, Exce ptionState& exceptionState) 298 void ContainerNode::replaceChild(PassRefPtrWillBeRawPtr<Node> newChild, Node* ol dChild, ExceptionState& exceptionState)
299 { 299 {
300 #if !ENABLE(OILPAN) 300 #if !ENABLE(OILPAN)
301 // Check that this node is not "floating". 301 // Check that this node is not "floating".
302 // If it is, it can be deleted as a side effect of sending mutation events. 302 // If it is, it can be deleted as a side effect of sending mutation events.
303 ASSERT(refCount() || parentOrShadowHostNode()); 303 ASSERT(refCount() || parentOrShadowHostNode());
304 #endif 304 #endif
305 305
306 RefPtr<Node> protect(this); 306 RefPtrWillBeRawPtr<Node> protect(this);
307 307
308 if (oldChild == newChild) // nothing to do 308 if (oldChild == newChild) // nothing to do
309 return; 309 return;
310 310
311 if (!oldChild) { 311 if (!oldChild) {
312 exceptionState.throwDOMException(NotFoundError, "The node to be replaced is null."); 312 exceptionState.throwDOMException(NotFoundError, "The node to be replaced is null.");
313 return; 313 return;
314 } 314 }
315 315
316 // Make sure replacing the old child with the new is ok 316 // Make sure replacing the old child with the new is ok
317 if (!checkAcceptChild(newChild.get(), oldChild, exceptionState)) 317 if (!checkAcceptChild(newChild.get(), oldChild, exceptionState))
318 return; 318 return;
319 319
320 // NotFoundError: Raised if oldChild is not a child of this node. 320 // NotFoundError: Raised if oldChild is not a child of this node.
321 if (oldChild->parentNode() != this) { 321 if (oldChild->parentNode() != this) {
322 exceptionState.throwDOMException(NotFoundError, "The node to be replaced is not a child of this node."); 322 exceptionState.throwDOMException(NotFoundError, "The node to be replaced is not a child of this node.");
323 return; 323 return;
324 } 324 }
325 325
326 ChildListMutationScope mutation(*this); 326 ChildListMutationScope mutation(*this);
327 327
328 RefPtr<Node> next = oldChild->nextSibling(); 328 RefPtrWillBeRawPtr<Node> next = oldChild->nextSibling();
329 329
330 // Remove the node we're replacing 330 // Remove the node we're replacing
331 RefPtr<Node> removedChild = oldChild; 331 // FIXME: Oilpan: |removedChild| is unnecessary.
332 RefPtrWillBeRawPtr<Node> removedChild ALLOW_UNUSED = oldChild;
tkent 2014/06/04 08:58:45 This was not buildable without ALLOW_UNUSED.
haraken 2014/06/04 09:04:04 Shall we rename the removeChild to something else?
zerny-chromium 2014/06/04 09:28:18 RefPtrWillBeRawPtr<Node> removedChild(oldChild);
Erik Corry 2014/06/04 09:35:47 I think you are confusing removedChild and removeC
tkent 2014/06/05 00:22:27 I removed this part due to https://codereview.chro
332 removeChild(oldChild, exceptionState); 333 removeChild(oldChild, exceptionState);
333 if (exceptionState.hadException()) 334 if (exceptionState.hadException())
334 return; 335 return;
335 336
336 if (next && (next->previousSibling() == newChild || next == newChild)) // no thing to do 337 if (next && (next->previousSibling() == newChild || next == newChild)) // no thing to do
337 return; 338 return;
338 339
339 // Does this one more time because removeChild() fires a MutationEvent. 340 // Does this one more time because removeChild() fires a MutationEvent.
340 if (!checkAcceptChild(newChild.get(), oldChild, exceptionState)) 341 if (!checkAcceptChild(newChild.get(), oldChild, exceptionState))
341 return; 342 return;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 } 423 }
423 424
424 void ContainerNode::removeChild(Node* oldChild, ExceptionState& exceptionState) 425 void ContainerNode::removeChild(Node* oldChild, ExceptionState& exceptionState)
425 { 426 {
426 #if !ENABLE(OILPAN) 427 #if !ENABLE(OILPAN)
427 // Check that this node is not "floating". 428 // Check that this node is not "floating".
428 // If it is, it can be deleted as a side effect of sending mutation events. 429 // If it is, it can be deleted as a side effect of sending mutation events.
429 ASSERT(refCount() || parentOrShadowHostNode()); 430 ASSERT(refCount() || parentOrShadowHostNode());
430 #endif 431 #endif
431 432
432 RefPtr<Node> protect(this); 433 RefPtrWillBeRawPtr<Node> protect(this);
433 434
434 // NotFoundError: Raised if oldChild is not a child of this node. 435 // NotFoundError: Raised if oldChild is not a child of this node.
435 // FIXME: We should never really get PseudoElements in here, but editing wil l sometimes 436 // FIXME: We should never really get PseudoElements in here, but editing wil l sometimes
436 // attempt to remove them still. We should fix that and enable this ASSERT. 437 // attempt to remove them still. We should fix that and enable this ASSERT.
437 // ASSERT(!oldChild->isPseudoElement()) 438 // ASSERT(!oldChild->isPseudoElement())
438 if (!oldChild || oldChild->parentNode() != this || oldChild->isPseudoElement ()) { 439 if (!oldChild || oldChild->parentNode() != this || oldChild->isPseudoElement ()) {
439 exceptionState.throwDOMException(NotFoundError, "The node to be removed is not a child of this node."); 440 exceptionState.throwDOMException(NotFoundError, "The node to be removed is not a child of this node.");
440 return; 441 return;
441 } 442 }
442 443
443 RefPtr<Node> child = oldChild; 444 RefPtrWillBeRawPtr<Node> child = oldChild;
444 445
445 document().removeFocusedElementOfSubtree(child.get()); 446 document().removeFocusedElementOfSubtree(child.get());
446 447
447 if (FullscreenElementStack* fullscreen = FullscreenElementStack::fromIfExist s(document())) 448 if (FullscreenElementStack* fullscreen = FullscreenElementStack::fromIfExist s(document()))
448 fullscreen->removeFullScreenElementOfSubtree(child.get()); 449 fullscreen->removeFullScreenElementOfSubtree(child.get());
449 450
450 // Events fired when blurring currently focused node might have moved this 451 // Events fired when blurring currently focused node might have moved this
451 // child into a different parent. 452 // child into a different parent.
452 if (child->parentNode() != this) { 453 if (child->parentNode() != this) {
453 exceptionState.throwDOMException(NotFoundError, "The node to be removed is no longer a child of this node. Perhaps it was moved in a 'blur' event handle r?"); 454 exceptionState.throwDOMException(NotFoundError, "The node to be removed is no longer a child of this node. Perhaps it was moved in a 'blur' event handle r?");
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 } 520 }
520 521
521 // this differs from other remove functions because it forcibly removes all the children, 522 // this differs from other remove functions because it forcibly removes all the children,
522 // regardless of read-only status or event exceptions, e.g. 523 // regardless of read-only status or event exceptions, e.g.
523 void ContainerNode::removeChildren() 524 void ContainerNode::removeChildren()
524 { 525 {
525 if (!m_firstChild) 526 if (!m_firstChild)
526 return; 527 return;
527 528
528 // The container node can be removed from event handlers. 529 // The container node can be removed from event handlers.
529 RefPtr<ContainerNode> protect(this); 530 RefPtrWillBeRawPtr<ContainerNode> protect(this);
530 531
531 if (FullscreenElementStack* fullscreen = FullscreenElementStack::fromIfExist s(document())) 532 if (FullscreenElementStack* fullscreen = FullscreenElementStack::fromIfExist s(document()))
532 fullscreen->removeFullScreenElementOfSubtree(this, true); 533 fullscreen->removeFullScreenElementOfSubtree(this, true);
533 534
534 // Do any prep work needed before actually starting to detach 535 // Do any prep work needed before actually starting to detach
535 // and remove... e.g. stop loading frames, fire unload events. 536 // and remove... e.g. stop loading frames, fire unload events.
536 willRemoveChildren(); 537 willRemoveChildren();
537 538
538 { 539 {
539 // Removing focus can cause frames to load, either via events (focusout, blur) 540 // Removing focus can cause frames to load, either via events (focusout, blur)
(...skipping 25 matching lines...) Expand all
565 566
566 childrenChanged(false, 0, 0, -static_cast<int>(removedChildren.size())); 567 childrenChanged(false, 0, 0, -static_cast<int>(removedChildren.size()));
567 568
568 for (size_t i = 0; i < removedChildren.size(); ++i) 569 for (size_t i = 0; i < removedChildren.size(); ++i)
569 notifyNodeRemoved(*removedChildren[i]); 570 notifyNodeRemoved(*removedChildren[i]);
570 } 571 }
571 572
572 dispatchSubtreeModifiedEvent(); 573 dispatchSubtreeModifiedEvent();
573 } 574 }
574 575
575 void ContainerNode::appendChild(PassRefPtr<Node> newChild, ExceptionState& excep tionState) 576 void ContainerNode::appendChild(PassRefPtrWillBeRawPtr<Node> newChild, Exception State& exceptionState)
576 { 577 {
577 RefPtr<ContainerNode> protect(this); 578 RefPtrWillBeRawPtr<ContainerNode> protect(this);
578 579
579 #if !ENABLE(OILPAN) 580 #if !ENABLE(OILPAN)
580 // Check that this node is not "floating". 581 // Check that this node is not "floating".
581 // If it is, it can be deleted as a side effect of sending mutation events. 582 // If it is, it can be deleted as a side effect of sending mutation events.
582 ASSERT(refCount() || parentOrShadowHostNode()); 583 ASSERT(refCount() || parentOrShadowHostNode());
583 #endif 584 #endif
584 585
585 // Make sure adding the new child is ok 586 // Make sure adding the new child is ok
586 if (!checkAcceptChild(newChild.get(), 0, exceptionState)) 587 if (!checkAcceptChild(newChild.get(), 0, exceptionState))
587 return; 588 return;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 treeScope().adoptIfNeeded(child); 624 treeScope().adoptIfNeeded(child);
624 appendChildToContainer(child, *this); 625 appendChildToContainer(child, *this);
625 } 626 }
626 627
627 updateTreeAfterInsertion(child); 628 updateTreeAfterInsertion(child);
628 } 629 }
629 630
630 dispatchSubtreeModifiedEvent(); 631 dispatchSubtreeModifiedEvent();
631 } 632 }
632 633
633 void ContainerNode::parserAppendChild(PassRefPtr<Node> newChild) 634 void ContainerNode::parserAppendChild(PassRefPtrWillBeRawPtr<Node> newChild)
634 { 635 {
635 ASSERT(newChild); 636 ASSERT(newChild);
636 ASSERT(!newChild->parentNode()); // Use appendChild if you need to handle re parenting (and want DOM mutation events). 637 ASSERT(!newChild->parentNode()); // Use appendChild if you need to handle re parenting (and want DOM mutation events).
637 ASSERT(!newChild->isDocumentFragment()); 638 ASSERT(!newChild->isDocumentFragment());
638 ASSERT(!isHTMLTemplateElement(this)); 639 ASSERT(!isHTMLTemplateElement(this));
639 640
640 if (document() != newChild->document()) 641 if (document() != newChild->document())
641 document().adoptNode(newChild.get(), ASSERT_NO_EXCEPTION); 642 document().adoptNode(newChild.get(), ASSERT_NO_EXCEPTION);
642 643
643 Node* last = m_lastChild; 644 Node* last = m_lastChild;
(...skipping 12 matching lines...) Expand all
656 childrenChanged(true, last, 0, 1); 657 childrenChanged(true, last, 0, 1);
657 notifyNodeInserted(*newChild); 658 notifyNodeInserted(*newChild);
658 } 659 }
659 660
660 void ContainerNode::notifyNodeInserted(Node& root) 661 void ContainerNode::notifyNodeInserted(Node& root)
661 { 662 {
662 ASSERT(!NoEventDispatchAssertion::isEventDispatchForbidden()); 663 ASSERT(!NoEventDispatchAssertion::isEventDispatchForbidden());
663 664
664 InspectorInstrumentation::didInsertDOMNode(&root); 665 InspectorInstrumentation::didInsertDOMNode(&root);
665 666
666 RefPtr<Node> protect(this); 667 RefPtrWillBeRawPtr<Node> protect(this);
667 RefPtr<Node> protectNode(root); 668 RefPtrWillBeRawPtr<Node> protectNode(root);
668 669
669 NodeVector postInsertionNotificationTargets; 670 NodeVector postInsertionNotificationTargets;
670 notifyNodeInsertedInternal(root, postInsertionNotificationTargets); 671 notifyNodeInsertedInternal(root, postInsertionNotificationTargets);
671 672
672 for (size_t i = 0; i < postInsertionNotificationTargets.size(); ++i) { 673 for (size_t i = 0; i < postInsertionNotificationTargets.size(); ++i) {
673 Node* targetNode = postInsertionNotificationTargets[i].get(); 674 Node* targetNode = postInsertionNotificationTargets[i].get();
674 if (targetNode->inDocument()) 675 if (targetNode->inDocument())
675 targetNode->didNotifySubtreeInsertionsToDocument(); 676 targetNode->didNotifySubtreeInsertionsToDocument();
676 } 677 }
677 } 678 }
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
1277 return true; 1278 return true;
1278 1279
1279 if (node->isElementNode() && toElement(node)->shadow()) 1280 if (node->isElementNode() && toElement(node)->shadow())
1280 return true; 1281 return true;
1281 1282
1282 return false; 1283 return false;
1283 } 1284 }
1284 #endif 1285 #endif
1285 1286
1286 } // namespace WebCore 1287 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698