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

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

Powered by Google App Engine
This is Rietveld 408576698