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

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

Issue 262093006: Oilpan: Make the Node hierarchy RefCountedGarbageCollected instead of TreeShared. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Address more comments. Created 6 years, 7 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 if (!node.isDocumentFragment()) { 65 if (!node.isDocumentFragment()) {
66 nodes.append(&node); 66 nodes.append(&node);
67 if (ContainerNode* oldParent = node.parentNode()) 67 if (ContainerNode* oldParent = node.parentNode())
68 oldParent->removeChild(&node, exceptionState); 68 oldParent->removeChild(&node, exceptionState);
69 return; 69 return;
70 } 70 }
71 getChildNodes(node, nodes); 71 getChildNodes(node, nodes);
72 toContainerNode(node).removeChildren(); 72 toContainerNode(node).removeChildren();
73 } 73 }
74 74
75 #if !ENABLE(OILPAN)
75 void ContainerNode::removeDetachedChildren() 76 void ContainerNode::removeDetachedChildren()
76 { 77 {
77 if (connectedSubframeCount()) { 78 if (connectedSubframeCount()) {
78 for (Node* child = firstChild(); child; child = child->nextSibling()) 79 for (Node* child = firstChild(); child; child = child->nextSibling())
79 child->updateAncestorConnectedSubframeCountForRemoval(); 80 child->updateAncestorConnectedSubframeCountForRemoval();
80 } 81 }
81 ASSERT(needsAttach()); 82 ASSERT(needsAttach());
82 removeDetachedChildrenInContainer<Node, ContainerNode>(*this); 83 removeDetachedChildrenInContainer<Node, ContainerNode>(*this);
83 } 84 }
85 #endif
84 86
85 void ContainerNode::parserTakeAllChildrenFrom(ContainerNode& oldParent) 87 void ContainerNode::parserTakeAllChildrenFrom(ContainerNode& oldParent)
86 { 88 {
87 while (RefPtr<Node> child = oldParent.firstChild()) { 89 while (RefPtr<Node> child = oldParent.firstChild()) {
88 oldParent.parserRemoveChild(*child); 90 oldParent.parserRemoveChild(*child);
89 treeScope().adoptIfNeeded(*child); 91 treeScope().adoptIfNeeded(*child);
90 parserAppendChild(child.get()); 92 parserAppendChild(child.get());
91 } 93 }
92 } 94 }
93 95
94 ContainerNode::~ContainerNode() 96 ContainerNode::~ContainerNode()
95 { 97 {
96 #if !ENABLE(OILPAN) 98 #if !ENABLE(OILPAN)
97 willBeDeletedFromDocument(); 99 willBeDeletedFromDocument();
100 removeDetachedChildren();
98 #endif 101 #endif
haraken 2014/05/06 04:20:16 Shall we add ASSERT(needsAttach()) to oilpan build
Mads Ager (chromium) 2014/05/06 08:26:00 We can probably do that, yes. Done.
99 removeDetachedChildren();
100 } 102 }
101 103
102 bool ContainerNode::isChildTypeAllowed(const Node& child) const 104 bool ContainerNode::isChildTypeAllowed(const Node& child) const
103 { 105 {
104 if (!child.isDocumentFragment()) 106 if (!child.isDocumentFragment())
105 return childTypeAllowed(child.nodeType()); 107 return childTypeAllowed(child.nodeType());
106 108
107 for (Node* node = child.firstChild(); node; node = node->nextSibling()) { 109 for (Node* node = child.firstChild(); node; node = node->nextSibling()) {
108 if (!childTypeAllowed(node->nodeType())) 110 if (!childTypeAllowed(node->nodeType()))
109 return false; 111 return false;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 249
248 ASSERT(!newChild.parentNode()); // Use insertBefore if you need to handle re parenting (and want DOM mutation events). 250 ASSERT(!newChild.parentNode()); // Use insertBefore if you need to handle re parenting (and want DOM mutation events).
249 ASSERT(!newChild.nextSibling()); 251 ASSERT(!newChild.nextSibling());
250 ASSERT(!newChild.previousSibling()); 252 ASSERT(!newChild.previousSibling());
251 ASSERT(!newChild.isShadowRoot()); 253 ASSERT(!newChild.isShadowRoot());
252 254
253 Node* prev = nextChild.previousSibling(); 255 Node* prev = nextChild.previousSibling();
254 ASSERT(m_lastChild != prev); 256 ASSERT(m_lastChild != prev);
255 nextChild.setPreviousSibling(&newChild); 257 nextChild.setPreviousSibling(&newChild);
256 if (prev) { 258 if (prev) {
257 ASSERT(m_firstChild != nextChild); 259 ASSERT(firstChild() != nextChild);
258 ASSERT(prev->nextSibling() == nextChild); 260 ASSERT(prev->nextSibling() == nextChild);
259 prev->setNextSibling(&newChild); 261 prev->setNextSibling(&newChild);
260 } else { 262 } else {
261 ASSERT(m_firstChild == nextChild); 263 ASSERT(firstChild() == nextChild);
262 m_firstChild = &newChild; 264 m_firstChild = &newChild;
263 } 265 }
264 newChild.setParentOrShadowHostNode(this); 266 newChild.setParentOrShadowHostNode(this);
265 newChild.setPreviousSibling(prev); 267 newChild.setPreviousSibling(prev);
266 newChild.setNextSibling(&nextChild); 268 newChild.setNextSibling(&nextChild);
267 } 269 }
268 270
269 void ContainerNode::parserInsertBefore(PassRefPtr<Node> newChild, Node& nextChil d) 271 void ContainerNode::parserInsertBefore(PassRefPtr<Node> newChild, Node& nextChil d)
270 { 272 {
271 ASSERT(newChild); 273 ASSERT(newChild);
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 } 404 }
403 405
404 ChildFrameDisconnector(*this).disconnect(ChildFrameDisconnector::Descendants Only); 406 ChildFrameDisconnector(*this).disconnect(ChildFrameDisconnector::Descendants Only);
405 } 407 }
406 408
407 void ContainerNode::disconnectDescendantFrames() 409 void ContainerNode::disconnectDescendantFrames()
408 { 410 {
409 ChildFrameDisconnector(*this).disconnect(); 411 ChildFrameDisconnector(*this).disconnect();
410 } 412 }
411 413
414 void ContainerNode::trace(Visitor* visitor)
415 {
416 visitor->trace(m_firstChild);
417 visitor->trace(m_lastChild);
418 Node::trace(visitor);
419 }
420
412 void ContainerNode::removeChild(Node* oldChild, ExceptionState& exceptionState) 421 void ContainerNode::removeChild(Node* oldChild, ExceptionState& exceptionState)
413 { 422 {
414 #if !ENABLE(OILPAN) 423 #if !ENABLE(OILPAN)
415 // Check that this node is not "floating". 424 // Check that this node is not "floating".
416 // If it is, it can be deleted as a side effect of sending mutation events. 425 // If it is, it can be deleted as a side effect of sending mutation events.
417 ASSERT(refCount() || parentOrShadowHostNode()); 426 ASSERT(refCount() || parentOrShadowHostNode());
418 #endif 427 #endif
419 428
420 RefPtr<Node> protect(this); 429 RefPtr<Node> protect(this);
421 430
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 477
469 ASSERT(oldChild.parentNode() == this); 478 ASSERT(oldChild.parentNode() == this);
470 479
471 if (!oldChild.needsAttach()) 480 if (!oldChild.needsAttach())
472 oldChild.detach(); 481 oldChild.detach();
473 482
474 if (nextChild) 483 if (nextChild)
475 nextChild->setPreviousSibling(previousChild); 484 nextChild->setPreviousSibling(previousChild);
476 if (previousChild) 485 if (previousChild)
477 previousChild->setNextSibling(nextChild); 486 previousChild->setNextSibling(nextChild);
478 if (m_firstChild == oldChild) 487 if (m_firstChild == &oldChild)
479 m_firstChild = nextChild; 488 m_firstChild = nextChild;
480 if (m_lastChild == oldChild) 489 if (m_lastChild == &oldChild)
481 m_lastChild = previousChild; 490 m_lastChild = previousChild;
482 491
483 oldChild.setPreviousSibling(0); 492 oldChild.setPreviousSibling(0);
484 oldChild.setNextSibling(0); 493 oldChild.setNextSibling(0);
485 oldChild.setParentOrShadowHostNode(0); 494 oldChild.setParentOrShadowHostNode(0);
486 495
487 document().adoptIfNeeded(oldChild); 496 document().adoptIfNeeded(oldChild);
488 } 497 }
489 498
490 void ContainerNode::parserRemoveChild(Node& oldChild) 499 void ContainerNode::parserRemoveChild(Node& oldChild)
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 ChildNodeRemovalNotifier(*this).notify(*removedChildren[i]); 566 ChildNodeRemovalNotifier(*this).notify(*removedChildren[i]);
558 } 567 }
559 568
560 dispatchSubtreeModifiedEvent(); 569 dispatchSubtreeModifiedEvent();
561 } 570 }
562 571
563 void ContainerNode::appendChild(PassRefPtr<Node> newChild, ExceptionState& excep tionState) 572 void ContainerNode::appendChild(PassRefPtr<Node> newChild, ExceptionState& excep tionState)
564 { 573 {
565 RefPtr<ContainerNode> protect(this); 574 RefPtr<ContainerNode> protect(this);
566 575
576 #if !ENABLE(OILPAN)
567 // Check that this node is not "floating". 577 // Check that this node is not "floating".
568 // If it is, it can be deleted as a side effect of sending mutation events. 578 // If it is, it can be deleted as a side effect of sending mutation events.
569 ASSERT(refCount() || parentOrShadowHostNode()); 579 ASSERT(refCount() || parentOrShadowHostNode());
580 #endif
570 581
571 // Make sure adding the new child is ok 582 // Make sure adding the new child is ok
572 if (!checkAcceptChild(newChild.get(), 0, exceptionState)) 583 if (!checkAcceptChild(newChild.get(), 0, exceptionState))
573 return; 584 return;
574 ASSERT(newChild); 585 ASSERT(newChild);
575 586
576 if (newChild == m_lastChild) // nothing to do 587 if (newChild.get() == m_lastChild) // nothing to do
haraken 2014/05/06 04:20:16 Shall we override == so that we can write this as
Mads Ager (chromium) 2014/05/06 08:26:00 Yes, thanks. Added those too. It is much easier to
577 return; 588 return;
578 589
579 NodeVector targets; 590 NodeVector targets;
580 collectChildrenAndRemoveFromOldParent(*newChild, targets, exceptionState); 591 collectChildrenAndRemoveFromOldParent(*newChild, targets, exceptionState);
581 if (exceptionState.hadException()) 592 if (exceptionState.hadException())
582 return; 593 return;
583 594
584 if (targets.isEmpty()) 595 if (targets.isEmpty())
585 return; 596 return;
586 597
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 // dispatch the DOMNodeRemovedFromDocument event to all descendants 999 // dispatch the DOMNodeRemovedFromDocument event to all descendants
989 if (c->inDocument() && document->hasListenerType(Document::DOMNODEREMOVEDFRO MDOCUMENT_LISTENER)) { 1000 if (c->inDocument() && document->hasListenerType(Document::DOMNODEREMOVEDFRO MDOCUMENT_LISTENER)) {
990 NodeChildRemovalTracker scope(child); 1001 NodeChildRemovalTracker scope(child);
991 for (; c; c = NodeTraversal::next(*c, &child)) 1002 for (; c; c = NodeTraversal::next(*c, &child))
992 c->dispatchScopedEvent(MutationEvent::create(EventTypeNames::DOMNode RemovedFromDocument, false)); 1003 c->dispatchScopedEvent(MutationEvent::create(EventTypeNames::DOMNode RemovedFromDocument, false));
993 } 1004 }
994 } 1005 }
995 1006
996 void ContainerNode::updateTreeAfterInsertion(Node& child) 1007 void ContainerNode::updateTreeAfterInsertion(Node& child)
997 { 1008 {
1009 #if !ENABLE(OILPAN)
998 ASSERT(refCount()); 1010 ASSERT(refCount());
999 ASSERT(child.refCount()); 1011 ASSERT(child.refCount());
1012 #endif
1000 1013
1001 ChildListMutationScope(*this).childAdded(child); 1014 ChildListMutationScope(*this).childAdded(child);
1002 1015
1003 childrenChanged(false, child.previousSibling(), child.nextSibling(), 1); 1016 childrenChanged(false, child.previousSibling(), child.nextSibling(), 1);
1004 1017
1005 ChildNodeInsertionNotifier(*this).notify(child); 1018 ChildNodeInsertionNotifier(*this).notify(child);
1006 1019
1007 dispatchChildInsertionEvents(child); 1020 dispatchChildInsertionEvents(child);
1008 } 1021 }
1009 1022
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1197 return true; 1210 return true;
1198 1211
1199 if (node->isElementNode() && toElement(node)->shadow()) 1212 if (node->isElementNode() && toElement(node)->shadow())
1200 return true; 1213 return true;
1201 1214
1202 return false; 1215 return false;
1203 } 1216 }
1204 #endif 1217 #endif
1205 1218
1206 } // namespace WebCore 1219 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698