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

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

Issue 1686483002: Oilpan: Remove most WillBe types from the code base (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
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, 2013 Apple Inc. All rights reserved. 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All rights reserved.
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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 void ContainerNode::removeDetachedChildren() 78 void ContainerNode::removeDetachedChildren()
79 { 79 {
80 ASSERT(!connectedSubframeCount()); 80 ASSERT(!connectedSubframeCount());
81 ASSERT(needsAttach()); 81 ASSERT(needsAttach());
82 removeDetachedChildrenInContainer(*this); 82 removeDetachedChildrenInContainer(*this);
83 } 83 }
84 #endif 84 #endif
85 85
86 void ContainerNode::parserTakeAllChildrenFrom(ContainerNode& oldParent) 86 void ContainerNode::parserTakeAllChildrenFrom(ContainerNode& oldParent)
87 { 87 {
88 while (RefPtrWillBeRawPtr<Node> child = oldParent.firstChild()) { 88 while (RawPtr<Node> child = oldParent.firstChild()) {
89 // Explicitly remove since appending can fail, but this loop shouldn't b e infinite. 89 // Explicitly remove since appending can fail, but this loop shouldn't b e infinite.
90 oldParent.parserRemoveChild(*child); 90 oldParent.parserRemoveChild(*child);
91 parserAppendChild(child.get()); 91 parserAppendChild(child.get());
92 } 92 }
93 } 93 }
94 94
95 ContainerNode::~ContainerNode() 95 ContainerNode::~ContainerNode()
96 { 96 {
97 ASSERT(needsAttach()); 97 ASSERT(needsAttach());
98 #if !ENABLE(OILPAN) 98 #if !ENABLE(OILPAN)
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 exceptionState.throwDOMException(HierarchyRequestError, "The new child e lement contains the parent."); 156 exceptionState.throwDOMException(HierarchyRequestError, "The new child e lement contains the parent.");
157 return false; 157 return false;
158 } 158 }
159 if (!isChildTypeAllowed(newChild)) { 159 if (!isChildTypeAllowed(newChild)) {
160 exceptionState.throwDOMException(HierarchyRequestError, "Nodes of type ' " + newChild.nodeName() + "' may not be inserted inside nodes of type '" + nodeN ame() + "'."); 160 exceptionState.throwDOMException(HierarchyRequestError, "Nodes of type ' " + newChild.nodeName() + "' may not be inserted inside nodes of type '" + nodeN ame() + "'.");
161 return false; 161 return false;
162 } 162 }
163 return true; 163 return true;
164 } 164 }
165 165
166 PassRefPtrWillBeRawPtr<Node> ContainerNode::insertBefore(PassRefPtrWillBeRawPtr< Node> newChild, Node* refChild, ExceptionState& exceptionState) 166 RawPtr<Node> ContainerNode::insertBefore(RawPtr<Node> newChild, Node* refChild, ExceptionState& exceptionState)
167 { 167 {
168 #if !ENABLE(OILPAN) 168 #if !ENABLE(OILPAN)
169 // Check that this node is not "floating". 169 // Check that this node is not "floating".
170 // If it is, it can be deleted as a side effect of sending mutation events. 170 // If it is, it can be deleted as a side effect of sending mutation events.
171 ASSERT(refCount() || parentOrShadowHostNode()); 171 ASSERT(refCount() || parentOrShadowHostNode());
172 #endif 172 #endif
173 173
174 RefPtrWillBeRawPtr<Node> protect(this); 174 RawPtr<Node> protect(this);
175 175
176 // insertBefore(node, 0) is equivalent to appendChild(node) 176 // insertBefore(node, 0) is equivalent to appendChild(node)
177 if (!refChild) { 177 if (!refChild) {
178 return appendChild(newChild, exceptionState); 178 return appendChild(newChild, exceptionState);
179 } 179 }
180 180
181 // Make sure adding the new child is OK. 181 // Make sure adding the new child is OK.
182 if (!checkAcceptChild(newChild.get(), 0, exceptionState)) { 182 if (!checkAcceptChild(newChild.get(), 0, exceptionState)) {
183 if (exceptionState.hadException()) 183 if (exceptionState.hadException())
184 return nullptr; 184 return nullptr;
185 return newChild; 185 return newChild;
186 } 186 }
187 ASSERT(newChild); 187 ASSERT(newChild);
188 188
189 // NotFoundError: Raised if refChild is not a child of this node 189 // NotFoundError: Raised if refChild is not a child of this node
190 if (refChild->parentNode() != this) { 190 if (refChild->parentNode() != this) {
191 exceptionState.throwDOMException(NotFoundError, "The node before which t he new node is to be inserted is not a child of this node."); 191 exceptionState.throwDOMException(NotFoundError, "The node before which t he new node is to be inserted is not a child of this node.");
192 return nullptr; 192 return nullptr;
193 } 193 }
194 194
195 // Nothing to do. 195 // Nothing to do.
196 if (refChild->previousSibling() == newChild || refChild == newChild) 196 if (refChild->previousSibling() == newChild || refChild == newChild)
197 return newChild; 197 return newChild;
198 198
199 RefPtrWillBeRawPtr<Node> next = refChild; 199 RawPtr<Node> next = refChild;
200 200
201 NodeVector targets; 201 NodeVector targets;
202 collectChildrenAndRemoveFromOldParent(*newChild, targets, exceptionState); 202 collectChildrenAndRemoveFromOldParent(*newChild, targets, exceptionState);
203 if (exceptionState.hadException()) 203 if (exceptionState.hadException())
204 return nullptr; 204 return nullptr;
205 if (targets.isEmpty()) 205 if (targets.isEmpty())
206 return newChild; 206 return newChild;
207 207
208 // We need this extra check because collectChildrenAndRemoveFromOldParent() can fire mutation events. 208 // We need this extra check because collectChildrenAndRemoveFromOldParent() can fire mutation events.
209 if (!checkAcceptChildGuaranteedNodeTypes(*newChild, nullptr, exceptionState) ) { 209 if (!checkAcceptChildGuaranteedNodeTypes(*newChild, nullptr, exceptionState) ) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 286
287 bool ContainerNode::checkParserAcceptChild(const Node& newChild) const 287 bool ContainerNode::checkParserAcceptChild(const Node& newChild) const
288 { 288 {
289 if (!isDocumentNode()) 289 if (!isDocumentNode())
290 return true; 290 return true;
291 // TODO(esprehn): Are there other conditions where the parser can create 291 // TODO(esprehn): Are there other conditions where the parser can create
292 // invalid trees? 292 // invalid trees?
293 return toDocument(*this).canAcceptChild(newChild, nullptr, IGNORE_EXCEPTION) ; 293 return toDocument(*this).canAcceptChild(newChild, nullptr, IGNORE_EXCEPTION) ;
294 } 294 }
295 295
296 void ContainerNode::parserInsertBefore(PassRefPtrWillBeRawPtr<Node> newChild, No de& nextChild) 296 void ContainerNode::parserInsertBefore(RawPtr<Node> newChild, Node& nextChild)
297 { 297 {
298 ASSERT(newChild); 298 ASSERT(newChild);
299 ASSERT(nextChild.parentNode() == this); 299 ASSERT(nextChild.parentNode() == this);
300 ASSERT(!newChild->isDocumentFragment()); 300 ASSERT(!newChild->isDocumentFragment());
301 ASSERT(!isHTMLTemplateElement(this)); 301 ASSERT(!isHTMLTemplateElement(this));
302 302
303 if (nextChild.previousSibling() == newChild || &nextChild == newChild) // no thing to do 303 if (nextChild.previousSibling() == newChild || &nextChild == newChild) // no thing to do
304 return; 304 return;
305 305
306 if (!checkParserAcceptChild(*newChild)) 306 if (!checkParserAcceptChild(*newChild))
307 return; 307 return;
308 308
309 RefPtrWillBeRawPtr<Node> protect(this); 309 RawPtr<Node> protect(this);
310 310
311 // FIXME: parserRemoveChild can run script which could then insert the 311 // FIXME: parserRemoveChild can run script which could then insert the
312 // newChild back into the page. Loop until the child is actually removed. 312 // newChild back into the page. Loop until the child is actually removed.
313 // See: fast/parser/execute-script-during-adoption-agency-removal.html 313 // See: fast/parser/execute-script-during-adoption-agency-removal.html
314 while (RefPtrWillBeRawPtr<ContainerNode> parent = newChild->parentNode()) 314 while (RawPtr<ContainerNode> parent = newChild->parentNode())
315 parent->parserRemoveChild(*newChild); 315 parent->parserRemoveChild(*newChild);
316 316
317 if (nextChild.parentNode() != this) 317 if (nextChild.parentNode() != this)
318 return; 318 return;
319 319
320 if (document() != newChild->document()) 320 if (document() != newChild->document())
321 document().adoptNode(newChild.get(), ASSERT_NO_EXCEPTION); 321 document().adoptNode(newChild.get(), ASSERT_NO_EXCEPTION);
322 322
323 { 323 {
324 EventDispatchForbiddenScope assertNoEventDispatch; 324 EventDispatchForbiddenScope assertNoEventDispatch;
325 ScriptForbiddenScope forbidScript; 325 ScriptForbiddenScope forbidScript;
326 326
327 treeScope().adoptIfNeeded(*newChild); 327 treeScope().adoptIfNeeded(*newChild);
328 insertBeforeCommon(nextChild, *newChild); 328 insertBeforeCommon(nextChild, *newChild);
329 newChild->updateAncestorConnectedSubframeCountForInsertion(); 329 newChild->updateAncestorConnectedSubframeCountForInsertion();
330 ChildListMutationScope(*this).childAdded(*newChild); 330 ChildListMutationScope(*this).childAdded(*newChild);
331 } 331 }
332 332
333 notifyNodeInserted(*newChild, ChildrenChangeSourceParser); 333 notifyNodeInserted(*newChild, ChildrenChangeSourceParser);
334 } 334 }
335 335
336 PassRefPtrWillBeRawPtr<Node> ContainerNode::replaceChild(PassRefPtrWillBeRawPtr< Node> newChild, PassRefPtrWillBeRawPtr<Node> oldChild, ExceptionState& exception State) 336 RawPtr<Node> ContainerNode::replaceChild(RawPtr<Node> newChild, RawPtr<Node> old Child, ExceptionState& exceptionState)
337 { 337 {
338 #if !ENABLE(OILPAN) 338 #if !ENABLE(OILPAN)
339 // Check that this node is not "floating". 339 // Check that this node is not "floating".
340 // If it is, it can be deleted as a side effect of sending mutation events. 340 // If it is, it can be deleted as a side effect of sending mutation events.
341 ASSERT(refCount() || parentOrShadowHostNode()); 341 ASSERT(refCount() || parentOrShadowHostNode());
342 #endif 342 #endif
343 343
344 RefPtrWillBeRawPtr<Node> protect(this); 344 RawPtr<Node> protect(this);
345 345
346 if (oldChild == newChild) // Nothing to do. 346 if (oldChild == newChild) // Nothing to do.
347 return oldChild; 347 return oldChild;
348 348
349 if (!oldChild) { 349 if (!oldChild) {
350 exceptionState.throwDOMException(NotFoundError, "The node to be replaced is null."); 350 exceptionState.throwDOMException(NotFoundError, "The node to be replaced is null.");
351 return nullptr; 351 return nullptr;
352 } 352 }
353 353
354 RefPtrWillBeRawPtr<Node> child = oldChild; 354 RawPtr<Node> child = oldChild;
355 355
356 // Make sure replacing the old child with the new is OK. 356 // Make sure replacing the old child with the new is OK.
357 if (!checkAcceptChild(newChild.get(), child.get(), exceptionState)) { 357 if (!checkAcceptChild(newChild.get(), child.get(), exceptionState)) {
358 if (exceptionState.hadException()) 358 if (exceptionState.hadException())
359 return nullptr; 359 return nullptr;
360 return child; 360 return child;
361 } 361 }
362 362
363 // NotFoundError: Raised if oldChild is not a child of this node. 363 // NotFoundError: Raised if oldChild is not a child of this node.
364 if (child->parentNode() != this) { 364 if (child->parentNode() != this) {
365 exceptionState.throwDOMException(NotFoundError, "The node to be replaced is not a child of this node."); 365 exceptionState.throwDOMException(NotFoundError, "The node to be replaced is not a child of this node.");
366 return nullptr; 366 return nullptr;
367 } 367 }
368 368
369 ChildListMutationScope mutation(*this); 369 ChildListMutationScope mutation(*this);
370 370
371 RefPtrWillBeRawPtr<Node> next = child->nextSibling(); 371 RawPtr<Node> next = child->nextSibling();
372 372
373 // Remove the node we're replacing. 373 // Remove the node we're replacing.
374 removeChild(child, exceptionState); 374 removeChild(child, exceptionState);
375 if (exceptionState.hadException()) 375 if (exceptionState.hadException())
376 return nullptr; 376 return nullptr;
377 377
378 if (next && (next->previousSibling() == newChild || next == newChild)) // no thing to do 378 if (next && (next->previousSibling() == newChild || next == newChild)) // no thing to do
379 return child; 379 return child;
380 380
381 // Does this one more time because removeChild() fires a MutationEvent. 381 // Does this one more time because removeChild() fires a MutationEvent.
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 #endif 521 #endif
522 // Add the node to the list of nodes to be deleted. 522 // Add the node to the list of nodes to be deleted.
523 // Reuse the nextSibling pointer for this purpose. 523 // Reuse the nextSibling pointer for this purpose.
524 if (tail) 524 if (tail)
525 tail->setNextSibling(n); 525 tail->setNextSibling(n);
526 else 526 else
527 head = n; 527 head = n;
528 528
529 tail = n; 529 tail = n;
530 } else { 530 } else {
531 RefPtrWillBeRawPtr<Node> protect(n); // removedFromDocument may remo ve all references to this node. 531 RawPtr<Node> protect(n); // removedFromDocument may remove all refer ences to this node.
532 container.document().adoptIfNeeded(*n); 532 container.document().adoptIfNeeded(*n);
533 if (n->inDocument()) 533 if (n->inDocument())
534 container.notifyNodeRemoved(*n); 534 container.notifyNodeRemoved(*n);
535 } 535 }
536 } 536 }
537 537
538 container.setLastChild(nullptr); 538 container.setLastChild(nullptr);
539 } 539 }
540 #endif 540 #endif
541 541
542 DEFINE_TRACE(ContainerNode) 542 DEFINE_TRACE(ContainerNode)
543 { 543 {
544 visitor->trace(m_firstChild); 544 visitor->trace(m_firstChild);
545 visitor->trace(m_lastChild); 545 visitor->trace(m_lastChild);
546 Node::trace(visitor); 546 Node::trace(visitor);
547 } 547 }
548 548
549 PassRefPtrWillBeRawPtr<Node> ContainerNode::removeChild(PassRefPtrWillBeRawPtr<N ode> oldChild, ExceptionState& exceptionState) 549 RawPtr<Node> ContainerNode::removeChild(RawPtr<Node> oldChild, ExceptionState& e xceptionState)
550 { 550 {
551 #if !ENABLE(OILPAN) 551 #if !ENABLE(OILPAN)
552 // Check that this node is not "floating". 552 // Check that this node is not "floating".
553 // If it is, it can be deleted as a side effect of sending mutation events. 553 // If it is, it can be deleted as a side effect of sending mutation events.
554 ASSERT(refCount() || parentOrShadowHostNode()); 554 ASSERT(refCount() || parentOrShadowHostNode());
555 #endif 555 #endif
556 556
557 RefPtrWillBeRawPtr<Node> protect(this); 557 RawPtr<Node> protect(this);
558 558
559 // NotFoundError: Raised if oldChild is not a child of this node. 559 // NotFoundError: Raised if oldChild is not a child of this node.
560 // FIXME: We should never really get PseudoElements in here, but editing wil l sometimes 560 // FIXME: We should never really get PseudoElements in here, but editing wil l sometimes
561 // attempt to remove them still. We should fix that and enable this ASSERT. 561 // attempt to remove them still. We should fix that and enable this ASSERT.
562 // ASSERT(!oldChild->isPseudoElement()) 562 // ASSERT(!oldChild->isPseudoElement())
563 if (!oldChild || oldChild->parentNode() != this || oldChild->isPseudoElement ()) { 563 if (!oldChild || oldChild->parentNode() != this || oldChild->isPseudoElement ()) {
564 exceptionState.throwDOMException(NotFoundError, "The node to be removed is not a child of this node."); 564 exceptionState.throwDOMException(NotFoundError, "The node to be removed is not a child of this node.");
565 return nullptr; 565 return nullptr;
566 } 566 }
567 567
568 RefPtrWillBeRawPtr<Node> child = oldChild; 568 RawPtr<Node> child = oldChild;
569 569
570 document().removeFocusedElementOfSubtree(child.get()); 570 document().removeFocusedElementOfSubtree(child.get());
571 571
572 // Events fired when blurring currently focused node might have moved this 572 // Events fired when blurring currently focused node might have moved this
573 // child into a different parent. 573 // child into a different parent.
574 if (child->parentNode() != this) { 574 if (child->parentNode() != this) {
575 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?"); 575 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?");
576 return nullptr; 576 return nullptr;
577 } 577 }
578 578
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 } 652 }
653 653
654 // This differs from other remove functions because it forcibly removes all the children, 654 // This differs from other remove functions because it forcibly removes all the children,
655 // regardless of read-only status or event exceptions, e.g. 655 // regardless of read-only status or event exceptions, e.g.
656 void ContainerNode::removeChildren(SubtreeModificationAction action) 656 void ContainerNode::removeChildren(SubtreeModificationAction action)
657 { 657 {
658 if (!m_firstChild) 658 if (!m_firstChild)
659 return; 659 return;
660 660
661 // The container node can be removed from event handlers. 661 // The container node can be removed from event handlers.
662 RefPtrWillBeRawPtr<ContainerNode> protect(this); 662 RawPtr<ContainerNode> protect(this);
663 663
664 // Do any prep work needed before actually starting to detach 664 // Do any prep work needed before actually starting to detach
665 // and remove... e.g. stop loading frames, fire unload events. 665 // and remove... e.g. stop loading frames, fire unload events.
666 willRemoveChildren(); 666 willRemoveChildren();
667 667
668 { 668 {
669 // Removing focus can cause frames to load, either via events (focusout, blur) 669 // Removing focus can cause frames to load, either via events (focusout, blur)
670 // or widget updates (e.g., for <embed>). 670 // or widget updates (e.g., for <embed>).
671 SubframeLoadingDisabler disabler(*this); 671 SubframeLoadingDisabler disabler(*this);
672 672
(...skipping 18 matching lines...) Expand all
691 { 691 {
692 HTMLFrameOwnerElement::UpdateSuspendScope suspendWidgetHierarchyUpdates; 692 HTMLFrameOwnerElement::UpdateSuspendScope suspendWidgetHierarchyUpdates;
693 DocumentOrderedMap::RemoveScope treeRemoveScope; 693 DocumentOrderedMap::RemoveScope treeRemoveScope;
694 { 694 {
695 EventDispatchForbiddenScope assertNoEventDispatch; 695 EventDispatchForbiddenScope assertNoEventDispatch;
696 ScriptForbiddenScope forbidScript; 696 ScriptForbiddenScope forbidScript;
697 697
698 #if !ENABLE(OILPAN) 698 #if !ENABLE(OILPAN)
699 removedChildren.reserveInitialCapacity(countChildren()); 699 removedChildren.reserveInitialCapacity(countChildren());
700 #endif 700 #endif
701 while (RefPtrWillBeRawPtr<Node> child = m_firstChild) { 701 while (RawPtr<Node> child = m_firstChild) {
702 removeBetween(0, child->nextSibling(), *child); 702 removeBetween(0, child->nextSibling(), *child);
703 #if !ENABLE(OILPAN) 703 #if !ENABLE(OILPAN)
704 removedChildren.append(child.get()); 704 removedChildren.append(child.get());
705 #endif 705 #endif
706 notifyNodeRemoved(*child); 706 notifyNodeRemoved(*child);
707 } 707 }
708 } 708 }
709 709
710 ChildrenChange change = {AllChildrenRemoved, nullptr, nullptr, ChildrenC hangeSourceAPI}; 710 ChildrenChange change = {AllChildrenRemoved, nullptr, nullptr, ChildrenC hangeSourceAPI};
711 childrenChanged(change); 711 childrenChanged(change);
712 } 712 }
713 713
714 if (action == DispatchSubtreeModifiedEvent) 714 if (action == DispatchSubtreeModifiedEvent)
715 dispatchSubtreeModifiedEvent(); 715 dispatchSubtreeModifiedEvent();
716 } 716 }
717 717
718 PassRefPtrWillBeRawPtr<Node> ContainerNode::appendChild(PassRefPtrWillBeRawPtr<N ode> newChild, ExceptionState& exceptionState) 718 RawPtr<Node> ContainerNode::appendChild(RawPtr<Node> newChild, ExceptionState& e xceptionState)
719 { 719 {
720 RefPtrWillBeRawPtr<ContainerNode> protect(this); 720 RawPtr<ContainerNode> protect(this);
721 721
722 #if !ENABLE(OILPAN) 722 #if !ENABLE(OILPAN)
723 // Check that this node is not "floating". 723 // Check that this node is not "floating".
724 // If it is, it can be deleted as a side effect of sending mutation events. 724 // If it is, it can be deleted as a side effect of sending mutation events.
725 ASSERT(refCount() || parentOrShadowHostNode()); 725 ASSERT(refCount() || parentOrShadowHostNode());
726 #endif 726 #endif
727 727
728 // Make sure adding the new child is ok 728 // Make sure adding the new child is ok
729 if (!checkAcceptChild(newChild.get(), 0, exceptionState)) { 729 if (!checkAcceptChild(newChild.get(), 0, exceptionState)) {
730 if (exceptionState.hadException()) 730 if (exceptionState.hadException())
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 appendChildCommon(child); 773 appendChildCommon(child);
774 } 774 }
775 775
776 updateTreeAfterInsertion(child); 776 updateTreeAfterInsertion(child);
777 } 777 }
778 778
779 dispatchSubtreeModifiedEvent(); 779 dispatchSubtreeModifiedEvent();
780 return newChild; 780 return newChild;
781 } 781 }
782 782
783 void ContainerNode::parserAppendChild(PassRefPtrWillBeRawPtr<Node> newChild) 783 void ContainerNode::parserAppendChild(RawPtr<Node> newChild)
784 { 784 {
785 ASSERT(newChild); 785 ASSERT(newChild);
786 ASSERT(!newChild->isDocumentFragment()); 786 ASSERT(!newChild->isDocumentFragment());
787 ASSERT(!isHTMLTemplateElement(this)); 787 ASSERT(!isHTMLTemplateElement(this));
788 788
789 if (!checkParserAcceptChild(*newChild)) 789 if (!checkParserAcceptChild(*newChild))
790 return; 790 return;
791 791
792 RefPtrWillBeRawPtr<Node> protect(this); 792 RawPtr<Node> protect(this);
793 793
794 // FIXME: parserRemoveChild can run script which could then insert the 794 // FIXME: parserRemoveChild can run script which could then insert the
795 // newChild back into the page. Loop until the child is actually removed. 795 // newChild back into the page. Loop until the child is actually removed.
796 // See: fast/parser/execute-script-during-adoption-agency-removal.html 796 // See: fast/parser/execute-script-during-adoption-agency-removal.html
797 while (RefPtrWillBeRawPtr<ContainerNode> parent = newChild->parentNode()) 797 while (RawPtr<ContainerNode> parent = newChild->parentNode())
798 parent->parserRemoveChild(*newChild); 798 parent->parserRemoveChild(*newChild);
799 799
800 if (document() != newChild->document()) 800 if (document() != newChild->document())
801 document().adoptNode(newChild.get(), ASSERT_NO_EXCEPTION); 801 document().adoptNode(newChild.get(), ASSERT_NO_EXCEPTION);
802 802
803 { 803 {
804 EventDispatchForbiddenScope assertNoEventDispatch; 804 EventDispatchForbiddenScope assertNoEventDispatch;
805 ScriptForbiddenScope forbidScript; 805 ScriptForbiddenScope forbidScript;
806 806
807 treeScope().adoptIfNeeded(*newChild); 807 treeScope().adoptIfNeeded(*newChild);
808 appendChildCommon(*newChild); 808 appendChildCommon(*newChild);
809 newChild->updateAncestorConnectedSubframeCountForInsertion(); 809 newChild->updateAncestorConnectedSubframeCountForInsertion();
810 ChildListMutationScope(*this).childAdded(*newChild); 810 ChildListMutationScope(*this).childAdded(*newChild);
811 } 811 }
812 812
813 notifyNodeInserted(*newChild, ChildrenChangeSourceParser); 813 notifyNodeInserted(*newChild, ChildrenChangeSourceParser);
814 } 814 }
815 815
816 void ContainerNode::notifyNodeInserted(Node& root, ChildrenChangeSource source) 816 void ContainerNode::notifyNodeInserted(Node& root, ChildrenChangeSource source)
817 { 817 {
818 ASSERT(!EventDispatchForbiddenScope::isEventDispatchForbidden()); 818 ASSERT(!EventDispatchForbiddenScope::isEventDispatchForbidden());
819 ASSERT(!root.isShadowRoot()); 819 ASSERT(!root.isShadowRoot());
820 820
821 InspectorInstrumentation::didInsertDOMNode(&root); 821 InspectorInstrumentation::didInsertDOMNode(&root);
822 822
823 RefPtrWillBeRawPtr<Node> protect(this); 823 RawPtr<Node> protect(this);
824 RefPtrWillBeRawPtr<Node> protectNode(root); 824 RawPtr<Node> protectNode(root);
825 825
826 NodeVector postInsertionNotificationTargets; 826 NodeVector postInsertionNotificationTargets;
827 notifyNodeInsertedInternal(root, postInsertionNotificationTargets); 827 notifyNodeInsertedInternal(root, postInsertionNotificationTargets);
828 828
829 childrenChanged(ChildrenChange::forInsertion(root, source)); 829 childrenChanged(ChildrenChange::forInsertion(root, source));
830 830
831 for (const auto& targetNode : postInsertionNotificationTargets) { 831 for (const auto& targetNode : postInsertionNotificationTargets) {
832 if (targetNode->inDocument()) 832 if (targetNode->inDocument())
833 targetNode->didNotifySubtreeInsertionsToDocument(); 833 targetNode->didNotifySubtreeInsertionsToDocument();
834 } 834 }
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 if (computedStyle()->affectedByHover()) { 1182 if (computedStyle()->affectedByHover()) {
1183 StyleChangeType changeType = computedStyle()->hasPseudoStyle(FIRST_LETTE R) ? SubtreeStyleChange : LocalStyleChange; 1183 StyleChangeType changeType = computedStyle()->hasPseudoStyle(FIRST_LETTE R) ? SubtreeStyleChange : LocalStyleChange;
1184 setNeedsStyleRecalc(changeType, StyleChangeReasonForTracing::createWithE xtraData(StyleChangeReason::PseudoClass, StyleChangeExtraData::Hover)); 1184 setNeedsStyleRecalc(changeType, StyleChangeReasonForTracing::createWithE xtraData(StyleChangeReason::PseudoClass, StyleChangeExtraData::Hover));
1185 } 1185 }
1186 if (isElementNode() && toElement(this)->childrenOrSiblingsAffectedByHover()) 1186 if (isElementNode() && toElement(this)->childrenOrSiblingsAffectedByHover())
1187 toElement(this)->pseudoStateChanged(CSSSelector::PseudoHover); 1187 toElement(this)->pseudoStateChanged(CSSSelector::PseudoHover);
1188 1188
1189 LayoutTheme::theme().controlStateChanged(*layoutObject(), HoverControlState) ; 1189 LayoutTheme::theme().controlStateChanged(*layoutObject(), HoverControlState) ;
1190 } 1190 }
1191 1191
1192 PassRefPtrWillBeRawPtr<HTMLCollection> ContainerNode::children() 1192 RawPtr<HTMLCollection> ContainerNode::children()
1193 { 1193 {
1194 return ensureCachedCollection<HTMLCollection>(NodeChildren); 1194 return ensureCachedCollection<HTMLCollection>(NodeChildren);
1195 } 1195 }
1196 1196
1197 unsigned ContainerNode::countChildren() const 1197 unsigned ContainerNode::countChildren() const
1198 { 1198 {
1199 unsigned count = 0; 1199 unsigned count = 0;
1200 Node* n; 1200 Node* n;
1201 for (n = firstChild(); n; n = n->nextSibling()) 1201 for (n = firstChild(); n; n = n->nextSibling())
1202 count++; 1202 count++;
1203 return count; 1203 return count;
1204 } 1204 }
1205 1205
1206 PassRefPtrWillBeRawPtr<Element> ContainerNode::querySelector(const AtomicString& selectors, ExceptionState& exceptionState) 1206 RawPtr<Element> ContainerNode::querySelector(const AtomicString& selectors, Exce ptionState& exceptionState)
1207 { 1207 {
1208 if (selectors.isEmpty()) { 1208 if (selectors.isEmpty()) {
1209 exceptionState.throwDOMException(SyntaxError, "The provided selector is empty."); 1209 exceptionState.throwDOMException(SyntaxError, "The provided selector is empty.");
1210 return nullptr; 1210 return nullptr;
1211 } 1211 }
1212 1212
1213 SelectorQuery* selectorQuery = document().selectorQueryCache().add(selectors , document(), exceptionState); 1213 SelectorQuery* selectorQuery = document().selectorQueryCache().add(selectors , document(), exceptionState);
1214 if (!selectorQuery) 1214 if (!selectorQuery)
1215 return nullptr; 1215 return nullptr;
1216 1216
1217 NthIndexCache nthIndexCache(document()); 1217 NthIndexCache nthIndexCache(document());
1218 return selectorQuery->queryFirst(*this); 1218 return selectorQuery->queryFirst(*this);
1219 } 1219 }
1220 1220
1221 PassRefPtrWillBeRawPtr<StaticElementList> ContainerNode::querySelectorAll(const AtomicString& selectors, ExceptionState& exceptionState) 1221 RawPtr<StaticElementList> ContainerNode::querySelectorAll(const AtomicString& se lectors, ExceptionState& exceptionState)
1222 { 1222 {
1223 if (selectors.isEmpty()) { 1223 if (selectors.isEmpty()) {
1224 exceptionState.throwDOMException(SyntaxError, "The provided selector is empty."); 1224 exceptionState.throwDOMException(SyntaxError, "The provided selector is empty.");
1225 return nullptr; 1225 return nullptr;
1226 } 1226 }
1227 1227
1228 SelectorQuery* selectorQuery = document().selectorQueryCache().add(selectors , document(), exceptionState); 1228 SelectorQuery* selectorQuery = document().selectorQueryCache().add(selectors , document(), exceptionState);
1229 if (!selectorQuery) 1229 if (!selectorQuery)
1230 return nullptr; 1230 return nullptr;
1231 1231
1232 NthIndexCache nthIndexCache(document()); 1232 NthIndexCache nthIndexCache(document());
1233 return selectorQuery->queryAll(*this); 1233 return selectorQuery->queryAll(*this);
1234 } 1234 }
1235 1235
1236 static void dispatchChildInsertionEvents(Node& child) 1236 static void dispatchChildInsertionEvents(Node& child)
1237 { 1237 {
1238 if (child.isInShadowTree()) 1238 if (child.isInShadowTree())
1239 return; 1239 return;
1240 1240
1241 ASSERT(!EventDispatchForbiddenScope::isEventDispatchForbidden()); 1241 ASSERT(!EventDispatchForbiddenScope::isEventDispatchForbidden());
1242 1242
1243 RefPtrWillBeRawPtr<Node> c(child); 1243 RawPtr<Node> c(child);
1244 RefPtrWillBeRawPtr<Document> document(child.document()); 1244 RawPtr<Document> document(child.document());
1245 1245
1246 if (c->parentNode() && document->hasListenerType(Document::DOMNODEINSERTED_L ISTENER)) 1246 if (c->parentNode() && document->hasListenerType(Document::DOMNODEINSERTED_L ISTENER))
1247 c->dispatchScopedEvent(MutationEvent::create(EventTypeNames::DOMNodeInse rted, true, c->parentNode())); 1247 c->dispatchScopedEvent(MutationEvent::create(EventTypeNames::DOMNodeInse rted, true, c->parentNode()));
1248 1248
1249 // dispatch the DOMNodeInsertedIntoDocument event to all descendants 1249 // dispatch the DOMNodeInsertedIntoDocument event to all descendants
1250 if (c->inDocument() && document->hasListenerType(Document::DOMNODEINSERTEDIN TODOCUMENT_LISTENER)) { 1250 if (c->inDocument() && document->hasListenerType(Document::DOMNODEINSERTEDIN TODOCUMENT_LISTENER)) {
1251 for (; c; c = NodeTraversal::next(*c, &child)) 1251 for (; c; c = NodeTraversal::next(*c, &child))
1252 c->dispatchScopedEvent(MutationEvent::create(EventTypeNames::DOMNode InsertedIntoDocument, false)); 1252 c->dispatchScopedEvent(MutationEvent::create(EventTypeNames::DOMNode InsertedIntoDocument, false));
1253 } 1253 }
1254 } 1254 }
1255 1255
1256 static void dispatchChildRemovalEvents(Node& child) 1256 static void dispatchChildRemovalEvents(Node& child)
1257 { 1257 {
1258 if (child.isInShadowTree()) { 1258 if (child.isInShadowTree()) {
1259 InspectorInstrumentation::willRemoveDOMNode(&child); 1259 InspectorInstrumentation::willRemoveDOMNode(&child);
1260 return; 1260 return;
1261 } 1261 }
1262 1262
1263 ASSERT(!EventDispatchForbiddenScope::isEventDispatchForbidden()); 1263 ASSERT(!EventDispatchForbiddenScope::isEventDispatchForbidden());
1264 1264
1265 InspectorInstrumentation::willRemoveDOMNode(&child); 1265 InspectorInstrumentation::willRemoveDOMNode(&child);
1266 1266
1267 RefPtrWillBeRawPtr<Node> c(child); 1267 RawPtr<Node> c(child);
1268 RefPtrWillBeRawPtr<Document> document(child.document()); 1268 RawPtr<Document> document(child.document());
1269 1269
1270 // Dispatch pre-removal mutation events. 1270 // Dispatch pre-removal mutation events.
1271 if (c->parentNode() && document->hasListenerType(Document::DOMNODEREMOVED_LI STENER)) { 1271 if (c->parentNode() && document->hasListenerType(Document::DOMNODEREMOVED_LI STENER)) {
1272 NodeChildRemovalTracker scope(child); 1272 NodeChildRemovalTracker scope(child);
1273 c->dispatchScopedEvent(MutationEvent::create(EventTypeNames::DOMNodeRemo ved, true, c->parentNode())); 1273 c->dispatchScopedEvent(MutationEvent::create(EventTypeNames::DOMNodeRemo ved, true, c->parentNode()));
1274 } 1274 }
1275 1275
1276 // Dispatch the DOMNodeRemovedFromDocument event to all descendants. 1276 // Dispatch the DOMNodeRemovedFromDocument event to all descendants.
1277 if (c->inDocument() && document->hasListenerType(Document::DOMNODEREMOVEDFRO MDOCUMENT_LISTENER)) { 1277 if (c->inDocument() && document->hasListenerType(Document::DOMNODEREMOVEDFRO MDOCUMENT_LISTENER)) {
1278 NodeChildRemovalTracker scope(child); 1278 NodeChildRemovalTracker scope(child);
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1427 return; 1427 return;
1428 1428
1429 document().invalidateNodeListCaches(attrName); 1429 document().invalidateNodeListCaches(attrName);
1430 1430
1431 for (ContainerNode* node = this; node; node = node->parentNode()) { 1431 for (ContainerNode* node = this; node; node = node->parentNode()) {
1432 if (NodeListsNodeData* lists = node->nodeLists()) 1432 if (NodeListsNodeData* lists = node->nodeLists())
1433 lists->invalidateCaches(attrName); 1433 lists->invalidateCaches(attrName);
1434 } 1434 }
1435 } 1435 }
1436 1436
1437 PassRefPtrWillBeRawPtr<TagCollection> ContainerNode::getElementsByTagName(const AtomicString& localName) 1437 RawPtr<TagCollection> ContainerNode::getElementsByTagName(const AtomicString& lo calName)
1438 { 1438 {
1439 if (document().isHTMLDocument()) 1439 if (document().isHTMLDocument())
1440 return ensureCachedCollection<HTMLTagCollection>(HTMLTagCollectionType, localName); 1440 return ensureCachedCollection<HTMLTagCollection>(HTMLTagCollectionType, localName);
1441 return ensureCachedCollection<TagCollection>(TagCollectionType, localName); 1441 return ensureCachedCollection<TagCollection>(TagCollectionType, localName);
1442 } 1442 }
1443 1443
1444 PassRefPtrWillBeRawPtr<TagCollection> ContainerNode::getElementsByTagNameNS(cons t AtomicString& namespaceURI, const AtomicString& localName) 1444 RawPtr<TagCollection> ContainerNode::getElementsByTagNameNS(const AtomicString& namespaceURI, const AtomicString& localName)
1445 { 1445 {
1446 if (namespaceURI == starAtom) 1446 if (namespaceURI == starAtom)
1447 return getElementsByTagName(localName); 1447 return getElementsByTagName(localName);
1448 1448
1449 return ensureCachedCollection<TagCollection>(TagCollectionType, namespaceURI .isEmpty() ? nullAtom : namespaceURI, localName); 1449 return ensureCachedCollection<TagCollection>(TagCollectionType, namespaceURI .isEmpty() ? nullAtom : namespaceURI, localName);
1450 } 1450 }
1451 1451
1452 // Takes an AtomicString in argument because it is common for elements to share the same name attribute. 1452 // Takes an AtomicString in argument because it is common for elements to share the same name attribute.
1453 // Therefore, the NameNodeList factory function expects an AtomicString type. 1453 // Therefore, the NameNodeList factory function expects an AtomicString type.
1454 PassRefPtrWillBeRawPtr<NameNodeList> ContainerNode::getElementsByName(const Atom icString& elementName) 1454 RawPtr<NameNodeList> ContainerNode::getElementsByName(const AtomicString& elemen tName)
1455 { 1455 {
1456 return ensureCachedCollection<NameNodeList>(NameNodeListType, elementName); 1456 return ensureCachedCollection<NameNodeList>(NameNodeListType, elementName);
1457 } 1457 }
1458 1458
1459 // Takes an AtomicString in argument because it is common for elements to share the same set of class names. 1459 // Takes an AtomicString in argument because it is common for elements to share the same set of class names.
1460 // Therefore, the ClassNodeList factory function expects an AtomicString type. 1460 // Therefore, the ClassNodeList factory function expects an AtomicString type.
1461 PassRefPtrWillBeRawPtr<ClassCollection> ContainerNode::getElementsByClassName(co nst AtomicString& classNames) 1461 RawPtr<ClassCollection> ContainerNode::getElementsByClassName(const AtomicString & classNames)
1462 { 1462 {
1463 return ensureCachedCollection<ClassCollection>(ClassCollectionType, classNam es); 1463 return ensureCachedCollection<ClassCollection>(ClassCollectionType, classNam es);
1464 } 1464 }
1465 1465
1466 PassRefPtrWillBeRawPtr<RadioNodeList> ContainerNode::radioNodeList(const AtomicS tring& name, bool onlyMatchImgElements) 1466 RawPtr<RadioNodeList> ContainerNode::radioNodeList(const AtomicString& name, boo l onlyMatchImgElements)
1467 { 1467 {
1468 ASSERT(isHTMLFormElement(this) || isHTMLFieldSetElement(this)); 1468 ASSERT(isHTMLFormElement(this) || isHTMLFieldSetElement(this));
1469 CollectionType type = onlyMatchImgElements ? RadioImgNodeListType : RadioNod eListType; 1469 CollectionType type = onlyMatchImgElements ? RadioImgNodeListType : RadioNod eListType;
1470 return ensureCachedCollection<RadioNodeList>(type, name); 1470 return ensureCachedCollection<RadioNodeList>(type, name);
1471 } 1471 }
1472 1472
1473 Element* ContainerNode::getElementById(const AtomicString& id) const 1473 Element* ContainerNode::getElementById(const AtomicString& id) const
1474 { 1474 {
1475 if (isInTreeScope()) { 1475 if (isInTreeScope()) {
1476 // Fast path if we are in a tree scope: call getElementById() on tree sc ope 1476 // Fast path if we are in a tree scope: call getElementById() on tree sc ope
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1508 return true; 1508 return true;
1509 1509
1510 if (node->isElementNode() && toElement(node)->shadow()) 1510 if (node->isElementNode() && toElement(node)->shadow())
1511 return true; 1511 return true;
1512 1512
1513 return false; 1513 return false;
1514 } 1514 }
1515 #endif 1515 #endif
1516 1516
1517 } // namespace blink 1517 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698