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

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

Issue 674553002: Move parts of core/dom to C++11 (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Make Windows shut up when I just try following the style guide Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/ContainerNode.h ('k') | Source/core/dom/ContextLifecycleNotifier.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 return newChild; 198 return newChild;
199 } 199 }
200 ASSERT(newChild); 200 ASSERT(newChild);
201 201
202 // NotFoundError: Raised if refChild is not a child of this node 202 // NotFoundError: Raised if refChild is not a child of this node
203 if (refChild->parentNode() != this) { 203 if (refChild->parentNode() != this) {
204 exceptionState.throwDOMException(NotFoundError, "The node before which t he new node is to be inserted is not a child of this node."); 204 exceptionState.throwDOMException(NotFoundError, "The node before which t he new node is to be inserted is not a child of this node.");
205 return nullptr; 205 return nullptr;
206 } 206 }
207 207
208 // nothing to do 208 // Nothing to do.
209 if (refChild->previousSibling() == newChild || refChild == newChild) 209 if (refChild->previousSibling() == newChild || refChild == newChild)
210 return newChild; 210 return newChild;
211 211
212 RefPtrWillBeRawPtr<Node> next = refChild; 212 RefPtrWillBeRawPtr<Node> next = refChild;
213 213
214 NodeVector targets; 214 NodeVector targets;
215 collectChildrenAndRemoveFromOldParent(*newChild, targets, exceptionState); 215 collectChildrenAndRemoveFromOldParent(*newChild, targets, exceptionState);
216 if (exceptionState.hadException()) 216 if (exceptionState.hadException())
217 return nullptr; 217 return nullptr;
218 if (targets.isEmpty()) 218 if (targets.isEmpty())
219 return newChild; 219 return newChild;
220 220
221 // We need this extra check because collectChildrenAndRemoveFromOldParent() can fire mutation events. 221 // We need this extra check because collectChildrenAndRemoveFromOldParent() can fire mutation events.
222 if (!checkAcceptChildGuaranteedNodeTypes(*newChild, exceptionState)) { 222 if (!checkAcceptChildGuaranteedNodeTypes(*newChild, exceptionState)) {
223 if (exceptionState.hadException()) 223 if (exceptionState.hadException())
224 return nullptr; 224 return nullptr;
225 return newChild; 225 return newChild;
226 } 226 }
227 227
228 InspectorInstrumentation::willInsertDOMNode(this); 228 InspectorInstrumentation::willInsertDOMNode(this);
229 229
230 ChildListMutationScope mutation(*this); 230 ChildListMutationScope mutation(*this);
231 for (NodeVector::const_iterator it = targets.begin(); it != targets.end(); + +it) { 231 for (const auto& targetNode : targets) {
232 ASSERT(*it); 232 ASSERT(targetNode);
233 Node& child = **it; 233 Node& child = *targetNode;
234 234
235 // Due to arbitrary code running in response to a DOM mutation event it' s 235 // Due to arbitrary code running in response to a DOM mutation event it' s
236 // possible that "next" is no longer a child of "this". 236 // possible that "next" is no longer a child of "this".
237 // It's also possible that "child" has been inserted elsewhere. 237 // It's also possible that "child" has been inserted elsewhere.
238 // In either of those cases, we'll just stop. 238 // In either of those cases, we'll just stop.
239 if (next->parentNode() != this) 239 if (next->parentNode() != this)
240 break; 240 break;
241 if (child.parentNode()) 241 if (child.parentNode())
242 break; 242 break;
243 243
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 PassRefPtrWillBeRawPtr<Node> ContainerNode::replaceChild(PassRefPtrWillBeRawPtr< Node> newChild, PassRefPtrWillBeRawPtr<Node> oldChild, ExceptionState& exception State) 320 PassRefPtrWillBeRawPtr<Node> ContainerNode::replaceChild(PassRefPtrWillBeRawPtr< Node> newChild, PassRefPtrWillBeRawPtr<Node> oldChild, ExceptionState& exception State)
321 { 321 {
322 #if !ENABLE(OILPAN) 322 #if !ENABLE(OILPAN)
323 // Check that this node is not "floating". 323 // Check that this node is not "floating".
324 // If it is, it can be deleted as a side effect of sending mutation events. 324 // If it is, it can be deleted as a side effect of sending mutation events.
325 ASSERT(refCount() || parentOrShadowHostNode()); 325 ASSERT(refCount() || parentOrShadowHostNode());
326 #endif 326 #endif
327 327
328 RefPtrWillBeRawPtr<Node> protect(this); 328 RefPtrWillBeRawPtr<Node> protect(this);
329 329
330 if (oldChild == newChild) // nothing to do 330 if (oldChild == newChild) // Nothing to do.
331 return oldChild; 331 return oldChild;
332 332
333 if (!oldChild) { 333 if (!oldChild) {
334 exceptionState.throwDOMException(NotFoundError, "The node to be replaced is null."); 334 exceptionState.throwDOMException(NotFoundError, "The node to be replaced is null.");
335 return nullptr; 335 return nullptr;
336 } 336 }
337 337
338 RefPtrWillBeRawPtr<Node> child = oldChild; 338 RefPtrWillBeRawPtr<Node> child = oldChild;
339 339
340 // Make sure replacing the old child with the new is ok 340 // Make sure replacing the old child with the new is OK.
341 if (!checkAcceptChild(newChild.get(), child.get(), exceptionState)) { 341 if (!checkAcceptChild(newChild.get(), child.get(), exceptionState)) {
342 if (exceptionState.hadException()) 342 if (exceptionState.hadException())
343 return nullptr; 343 return nullptr;
344 return child; 344 return child;
345 } 345 }
346 346
347 // NotFoundError: Raised if oldChild is not a child of this node. 347 // NotFoundError: Raised if oldChild is not a child of this node.
348 if (child->parentNode() != this) { 348 if (child->parentNode() != this) {
349 exceptionState.throwDOMException(NotFoundError, "The node to be replaced is not a child of this node."); 349 exceptionState.throwDOMException(NotFoundError, "The node to be replaced is not a child of this node.");
350 return nullptr; 350 return nullptr;
351 } 351 }
352 352
353 ChildListMutationScope mutation(*this); 353 ChildListMutationScope mutation(*this);
354 354
355 RefPtrWillBeRawPtr<Node> next = child->nextSibling(); 355 RefPtrWillBeRawPtr<Node> next = child->nextSibling();
356 356
357 // Remove the node we're replacing 357 // Remove the node we're replacing.
358 removeChild(child, exceptionState); 358 removeChild(child, exceptionState);
359 if (exceptionState.hadException()) 359 if (exceptionState.hadException())
360 return nullptr; 360 return nullptr;
361 361
362 if (next && (next->previousSibling() == newChild || next == newChild)) // no thing to do 362 if (next && (next->previousSibling() == newChild || next == newChild)) // no thing to do
363 return child; 363 return child;
364 364
365 // Does this one more time because removeChild() fires a MutationEvent. 365 // Does this one more time because removeChild() fires a MutationEvent.
366 if (!checkAcceptChild(newChild.get(), child.get(), exceptionState)) { 366 if (!checkAcceptChild(newChild.get(), child.get(), exceptionState)) {
367 if (exceptionState.hadException()) 367 if (exceptionState.hadException())
368 return nullptr; 368 return nullptr;
369 return child; 369 return child;
370 } 370 }
371 371
372 NodeVector targets; 372 NodeVector targets;
373 collectChildrenAndRemoveFromOldParent(*newChild, targets, exceptionState); 373 collectChildrenAndRemoveFromOldParent(*newChild, targets, exceptionState);
374 if (exceptionState.hadException()) 374 if (exceptionState.hadException())
375 return nullptr; 375 return nullptr;
376 376
377 // Does this yet another check because collectChildrenAndRemoveFromOldParent () fires a MutationEvent. 377 // Does this yet another check because collectChildrenAndRemoveFromOldParent () fires a MutationEvent.
378 if (!checkAcceptChild(newChild.get(), child.get(), exceptionState)) { 378 if (!checkAcceptChild(newChild.get(), child.get(), exceptionState)) {
379 if (exceptionState.hadException()) 379 if (exceptionState.hadException())
380 return nullptr; 380 return nullptr;
381 return child; 381 return child;
382 } 382 }
383 383
384 InspectorInstrumentation::willInsertDOMNode(this); 384 InspectorInstrumentation::willInsertDOMNode(this);
385 385
386 // Add the new child(ren) 386 // Add the new child(ren).
387 for (NodeVector::const_iterator it = targets.begin(); it != targets.end(); + +it) { 387 for (const auto& targetNode : targets) {
388 ASSERT(*it); 388 ASSERT(targetNode);
389 Node& child = **it; 389 Node& child = *targetNode;
390 390
391 // Due to arbitrary code running in response to a DOM mutation event it' s 391 // Due to arbitrary code running in response to a DOM mutation event it' s
392 // possible that "next" is no longer a child of "this". 392 // possible that "next" is no longer a child of "this".
393 // It's also possible that "child" has been inserted elsewhere. 393 // It's also possible that "child" has been inserted elsewhere.
394 // In either of those cases, we'll just stop. 394 // In either of those cases, we'll just stop.
395 if (next && next->parentNode() != this) 395 if (next && next->parentNode() != this)
396 break; 396 break;
397 if (child.parentNode()) 397 if (child.parentNode())
398 break; 398 break;
399 399
(...skipping 24 matching lines...) Expand all
424 document().nodeWillBeRemoved(child); // e.g. mutation event listener can cre ate a new range. 424 document().nodeWillBeRemoved(child); // e.g. mutation event listener can cre ate a new range.
425 ChildFrameDisconnector(child).disconnect(); 425 ChildFrameDisconnector(child).disconnect();
426 } 426 }
427 427
428 void ContainerNode::willRemoveChildren() 428 void ContainerNode::willRemoveChildren()
429 { 429 {
430 NodeVector children; 430 NodeVector children;
431 getChildNodes(*this, children); 431 getChildNodes(*this, children);
432 432
433 ChildListMutationScope mutation(*this); 433 ChildListMutationScope mutation(*this);
434 for (NodeVector::const_iterator it = children.begin(); it != children.end(); ++it) { 434 for (const auto& node : children) {
435 ASSERT(*it); 435 ASSERT(node);
436 Node& child = **it; 436 Node& child = *node;
437 mutation.willRemoveChild(child); 437 mutation.willRemoveChild(child);
438 child.notifyMutationObserversNodeWillDetach(); 438 child.notifyMutationObserversNodeWillDetach();
439 dispatchChildRemovalEvents(child); 439 dispatchChildRemovalEvents(child);
440 } 440 }
441 441
442 ChildFrameDisconnector(*this).disconnect(ChildFrameDisconnector::Descendants Only); 442 ChildFrameDisconnector(*this).disconnect(ChildFrameDisconnector::Descendants Only);
443 } 443 }
444 444
445 #if !ENABLE(OILPAN) 445 #if !ENABLE(OILPAN)
446 void ContainerNode::removeDetachedChildrenInContainer(ContainerNode& container) 446 void ContainerNode::removeDetachedChildrenInContainer(ContainerNode& container)
447 { 447 {
448 // List of nodes to be deleted. 448 // List of nodes to be deleted.
449 Node* head = 0; 449 Node* head = nullptr;
450 Node* tail = 0; 450 Node* tail = nullptr;
451 451
452 addChildNodesToDeletionQueue(head, tail, container); 452 addChildNodesToDeletionQueue(head, tail, container);
453 453
454 Node* n; 454 Node* n;
455 Node* next; 455 Node* next;
456 while ((n = head) != 0) { 456 while (head) {
457 n = head;
457 ASSERT_WITH_SECURITY_IMPLICATION(n->m_deletionHasBegun); 458 ASSERT_WITH_SECURITY_IMPLICATION(n->m_deletionHasBegun);
458 459
459 next = n->nextSibling(); 460 next = n->nextSibling();
460 n->setNextSibling(0); 461 n->setNextSibling(nullptr);
461 462
462 head = next; 463 head = next;
463 if (next == 0) 464 if (!next)
464 tail = 0; 465 tail = nullptr;
465 466
466 if (n->hasChildren()) 467 if (n->hasChildren())
467 addChildNodesToDeletionQueue(head, tail, toContainerNode(*n)); 468 addChildNodesToDeletionQueue(head, tail, toContainerNode(*n));
468 469
469 delete n; 470 delete n;
470 } 471 }
471 } 472 }
472 473
473 void ContainerNode::addChildNodesToDeletionQueue(Node*& head, Node*& tail, Conta inerNode& container) 474 void ContainerNode::addChildNodesToDeletionQueue(Node*& head, Node*& tail, Conta inerNode& container)
474 { 475 {
475 // We have to tell all children that their parent has died. 476 // We have to tell all children that their parent has died.
476 Node* next = 0; 477 Node* next = nullptr;
477 for (Node* n = container.firstChild(); n; n = next) { 478 for (Node* n = container.firstChild(); n; n = next) {
478 ASSERT_WITH_SECURITY_IMPLICATION(!n->m_deletionHasBegun); 479 ASSERT_WITH_SECURITY_IMPLICATION(!n->m_deletionHasBegun);
479 480
480 next = n->nextSibling(); 481 next = n->nextSibling();
481 n->setNextSibling(0); 482 n->setNextSibling(nullptr);
482 n->setParentOrShadowHostNode(0); 483 n->setParentOrShadowHostNode(nullptr);
483 container.setFirstChild(next); 484 container.setFirstChild(next);
484 if (next) 485 if (next)
485 next->setPreviousSibling(0); 486 next->setPreviousSibling(nullptr);
486 487
487 if (!n->refCount()) { 488 if (!n->refCount()) {
488 #if ENABLE(SECURITY_ASSERT) 489 #if ENABLE(SECURITY_ASSERT)
489 n->m_deletionHasBegun = true; 490 n->m_deletionHasBegun = true;
490 #endif 491 #endif
491 // Add the node to the list of nodes to be deleted. 492 // Add the node to the list of nodes to be deleted.
492 // Reuse the nextSibling pointer for this purpose. 493 // Reuse the nextSibling pointer for this purpose.
493 if (tail) 494 if (tail)
494 tail->setNextSibling(n); 495 tail->setNextSibling(n);
495 else 496 else
496 head = n; 497 head = n;
497 498
498 tail = n; 499 tail = n;
499 } else { 500 } else {
500 RefPtrWillBeRawPtr<Node> protect(n); // removedFromDocument may remo ve all references to this node. 501 RefPtrWillBeRawPtr<Node> protect(n); // removedFromDocument may remo ve all references to this node.
501 container.document().adoptIfNeeded(*n); 502 container.document().adoptIfNeeded(*n);
502 if (n->inDocument()) 503 if (n->inDocument())
503 container.notifyNodeRemoved(*n); 504 container.notifyNodeRemoved(*n);
504 } 505 }
505 } 506 }
506 507
507 container.setLastChild(0); 508 container.setLastChild(nullptr);
508 } 509 }
509 #endif 510 #endif
510 511
511 void ContainerNode::disconnectDescendantFrames() 512 void ContainerNode::disconnectDescendantFrames()
512 { 513 {
513 ChildFrameDisconnector(*this).disconnect(); 514 ChildFrameDisconnector(*this).disconnect();
514 } 515 }
515 516
516 void ContainerNode::trace(Visitor* visitor) 517 void ContainerNode::trace(Visitor* visitor)
517 { 518 {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 583
583 if (nextChild) 584 if (nextChild)
584 nextChild->setPreviousSibling(previousChild); 585 nextChild->setPreviousSibling(previousChild);
585 if (previousChild) 586 if (previousChild)
586 previousChild->setNextSibling(nextChild); 587 previousChild->setNextSibling(nextChild);
587 if (m_firstChild == &oldChild) 588 if (m_firstChild == &oldChild)
588 m_firstChild = nextChild; 589 m_firstChild = nextChild;
589 if (m_lastChild == &oldChild) 590 if (m_lastChild == &oldChild)
590 m_lastChild = previousChild; 591 m_lastChild = previousChild;
591 592
592 oldChild.setPreviousSibling(0); 593 oldChild.setPreviousSibling(nullptr);
593 oldChild.setNextSibling(0); 594 oldChild.setNextSibling(nullptr);
594 oldChild.setParentOrShadowHostNode(0); 595 oldChild.setParentOrShadowHostNode(nullptr);
595 596
596 document().adoptIfNeeded(oldChild); 597 document().adoptIfNeeded(oldChild);
597 } 598 }
598 599
599 void ContainerNode::parserRemoveChild(Node& oldChild) 600 void ContainerNode::parserRemoveChild(Node& oldChild)
600 { 601 {
601 ASSERT(oldChild.parentNode() == this); 602 ASSERT(oldChild.parentNode() == this);
602 ASSERT(!oldChild.isDocumentFragment()); 603 ASSERT(!oldChild.isDocumentFragment());
603 604
604 Node* prev = oldChild.previousSibling(); 605 Node* prev = oldChild.previousSibling();
605 Node* next = oldChild.nextSibling(); 606 Node* next = oldChild.nextSibling();
606 607
607 oldChild.updateAncestorConnectedSubframeCountForRemoval(); 608 oldChild.updateAncestorConnectedSubframeCountForRemoval();
608 609
609 ChildListMutationScope(*this).willRemoveChild(oldChild); 610 ChildListMutationScope(*this).willRemoveChild(oldChild);
610 oldChild.notifyMutationObserversNodeWillDetach(); 611 oldChild.notifyMutationObserversNodeWillDetach();
611 612
612 removeBetween(prev, next, oldChild); 613 removeBetween(prev, next, oldChild);
613 614
614 notifyNodeRemoved(oldChild); 615 notifyNodeRemoved(oldChild);
615 childrenChanged(ChildrenChange::forRemoval(oldChild, prev, next, ChildrenCha ngeSourceParser)); 616 childrenChanged(ChildrenChange::forRemoval(oldChild, prev, next, ChildrenCha ngeSourceParser));
616 } 617 }
617 618
618 // this differs from other remove functions because it forcibly removes all the children, 619 // This differs from other remove functions because it forcibly removes all the children,
619 // regardless of read-only status or event exceptions, e.g. 620 // regardless of read-only status or event exceptions, e.g.
620 void ContainerNode::removeChildren() 621 void ContainerNode::removeChildren()
621 { 622 {
622 if (!m_firstChild) 623 if (!m_firstChild)
623 return; 624 return;
624 625
625 // The container node can be removed from event handlers. 626 // The container node can be removed from event handlers.
626 RefPtrWillBeRawPtr<ContainerNode> protect(this); 627 RefPtrWillBeRawPtr<ContainerNode> protect(this);
627 628
628 // Do any prep work needed before actually starting to detach 629 // Do any prep work needed before actually starting to detach
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 709
709 // We need this extra check because collectChildrenAndRemoveFromOldParent() can fire mutation events. 710 // We need this extra check because collectChildrenAndRemoveFromOldParent() can fire mutation events.
710 if (!checkAcceptChildGuaranteedNodeTypes(*newChild, exceptionState)) { 711 if (!checkAcceptChildGuaranteedNodeTypes(*newChild, exceptionState)) {
711 if (exceptionState.hadException()) 712 if (exceptionState.hadException())
712 return nullptr; 713 return nullptr;
713 return newChild; 714 return newChild;
714 } 715 }
715 716
716 InspectorInstrumentation::willInsertDOMNode(this); 717 InspectorInstrumentation::willInsertDOMNode(this);
717 718
718 // Now actually add the child(ren) 719 // Now actually add the child(ren).
719 ChildListMutationScope mutation(*this); 720 ChildListMutationScope mutation(*this);
720 for (NodeVector::const_iterator it = targets.begin(); it != targets.end(); + +it) { 721 for (const auto& targetNode : targets) {
721 ASSERT(*it); 722 ASSERT(targetNode);
722 Node& child = **it; 723 Node& child = *targetNode;
723 724
724 // If the child has a parent again, just stop what we're doing, because 725 // If the child has a parent again, just stop what we're doing, because
725 // that means someone is doing something with DOM mutation -- can't re-p arent 726 // that means someone is doing something with DOM mutation -- can't re-p arent
726 // a child that already has a parent. 727 // a child that already has a parent.
727 if (child.parentNode()) 728 if (child.parentNode())
728 break; 729 break;
729 730
730 { 731 {
731 EventDispatchForbiddenScope assertNoEventDispatch; 732 EventDispatchForbiddenScope assertNoEventDispatch;
732 ScriptForbiddenScope forbidScript; 733 ScriptForbiddenScope forbidScript;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 InspectorInstrumentation::didInsertDOMNode(&root); 776 InspectorInstrumentation::didInsertDOMNode(&root);
776 777
777 RefPtrWillBeRawPtr<Node> protect(this); 778 RefPtrWillBeRawPtr<Node> protect(this);
778 RefPtrWillBeRawPtr<Node> protectNode(root); 779 RefPtrWillBeRawPtr<Node> protectNode(root);
779 780
780 NodeVector postInsertionNotificationTargets; 781 NodeVector postInsertionNotificationTargets;
781 notifyNodeInsertedInternal(root, postInsertionNotificationTargets); 782 notifyNodeInsertedInternal(root, postInsertionNotificationTargets);
782 783
783 childrenChanged(ChildrenChange::forInsertion(root, source)); 784 childrenChanged(ChildrenChange::forInsertion(root, source));
784 785
785 for (size_t i = 0; i < postInsertionNotificationTargets.size(); ++i) { 786 for (const auto& targetNode : postInsertionNotificationTargets) {
786 Node* targetNode = postInsertionNotificationTargets[i].get();
787 if (targetNode->inDocument()) 787 if (targetNode->inDocument())
788 targetNode->didNotifySubtreeInsertionsToDocument(); 788 targetNode->didNotifySubtreeInsertionsToDocument();
789 } 789 }
790 } 790 }
791 791
792 void ContainerNode::notifyNodeInsertedInternal(Node& root, NodeVector& postInser tionNotificationTargets) 792 void ContainerNode::notifyNodeInsertedInternal(Node& root, NodeVector& postInser tionNotificationTargets)
793 { 793 {
794 EventDispatchForbiddenScope assertNoEventDispatch; 794 EventDispatchForbiddenScope assertNoEventDispatch;
795 ScriptForbiddenScope forbidScript; 795 ScriptForbiddenScope forbidScript;
796 796
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 TrackExceptionState exceptionState; 857 TrackExceptionState exceptionState;
858 for (Node* n = firstChild(); n && !exceptionState.hadException(); n = n->nex tSibling()) 858 for (Node* n = firstChild(); n && !exceptionState.hadException(); n = n->nex tSibling())
859 clone->appendChild(n->cloneNode(true), exceptionState); 859 clone->appendChild(n->cloneNode(true), exceptionState);
860 } 860 }
861 861
862 862
863 bool ContainerNode::getUpperLeftCorner(FloatPoint& point) const 863 bool ContainerNode::getUpperLeftCorner(FloatPoint& point) const
864 { 864 {
865 if (!renderer()) 865 if (!renderer())
866 return false; 866 return false;
867 // What is this code really trying to do? 867
868 // FIXME: What is this code really trying to do?
868 RenderObject* o = renderer(); 869 RenderObject* o = renderer();
869
870 if (!o->isInline() || o->isReplaced()) { 870 if (!o->isInline() || o->isReplaced()) {
871 point = o->localToAbsolute(FloatPoint(), UseTransforms); 871 point = o->localToAbsolute(FloatPoint(), UseTransforms);
872 return true; 872 return true;
873 } 873 }
874 874
875 // find the next text/image child, to get a position 875 // Find the next text/image child, to get a position.
876 while (o) { 876 while (o) {
877 RenderObject* p = o; 877 RenderObject* p = o;
878 if (RenderObject* oFirstChild = o->slowFirstChild()) { 878 if (RenderObject* oFirstChild = o->slowFirstChild()) {
879 o = oFirstChild; 879 o = oFirstChild;
880 } else if (o->nextSibling()) { 880 } else if (o->nextSibling()) {
881 o = o->nextSibling(); 881 o = o->nextSibling();
882 } else { 882 } else {
883 RenderObject* next = 0; 883 RenderObject* next = nullptr;
884 while (!next && o->parent()) { 884 while (!next && o->parent()) {
885 o = o->parent(); 885 o = o->parent();
886 next = o->nextSibling(); 886 next = o->nextSibling();
887 } 887 }
888 o = next; 888 o = next;
889 889
890 if (!o) 890 if (!o)
891 break; 891 break;
892 } 892 }
893 ASSERT(o); 893 ASSERT(o);
894 894
895 if (!o->isInline() || o->isReplaced()) { 895 if (!o->isInline() || o->isReplaced()) {
896 point = o->localToAbsolute(FloatPoint(), UseTransforms); 896 point = o->localToAbsolute(FloatPoint(), UseTransforms);
897 return true; 897 return true;
898 } 898 }
899 899
900 if (p->node() && p->node() == this && o->isText() && !o->isBR() && !toRe nderText(o)->firstTextBox()) { 900 if (p->node() && p->node() == this && o->isText() && !o->isBR() && !toRe nderText(o)->firstTextBox()) {
901 // do nothing - skip unrendered whitespace that is a child or next s ibling of the anchor 901 // Do nothing - skip unrendered whitespace that is a child or next s ibling of the anchor.
902 } else if ((o->isText() && !o->isBR()) || o->isReplaced()) { 902 } else if ((o->isText() && !o->isBR()) || o->isReplaced()) {
903 point = FloatPoint(); 903 point = FloatPoint();
904 if (o->isText() && toRenderText(o)->firstTextBox()) { 904 if (o->isText() && toRenderText(o)->firstTextBox()) {
905 point.move(toRenderText(o)->linesBoundingBox().x(), toRenderText (o)->firstTextBox()->root().lineTop().toFloat()); 905 point.move(toRenderText(o)->linesBoundingBox().x(), toRenderText (o)->firstTextBox()->root().lineTop().toFloat());
906 } else if (o->isBox()) { 906 } else if (o->isBox()) {
907 RenderBox* box = toRenderBox(o); 907 RenderBox* box = toRenderBox(o);
908 point.moveBy(box->location()); 908 point.moveBy(box->location());
909 } 909 }
910 point = o->container()->localToAbsolute(point, UseTransforms); 910 point = o->container()->localToAbsolute(point, UseTransforms);
911 return true; 911 return true;
(...skipping 14 matching lines...) Expand all
926 if (!renderer()) 926 if (!renderer())
927 return false; 927 return false;
928 928
929 RenderObject* o = renderer(); 929 RenderObject* o = renderer();
930 if (!o->isInline() || o->isReplaced()) { 930 if (!o->isInline() || o->isReplaced()) {
931 RenderBox* box = toRenderBox(o); 931 RenderBox* box = toRenderBox(o);
932 point = o->localToAbsolute(LayoutPoint(box->size()), UseTransforms); 932 point = o->localToAbsolute(LayoutPoint(box->size()), UseTransforms);
933 return true; 933 return true;
934 } 934 }
935 935
936 // find the last text/image child, to get a position 936 // Find the last text/image child, to get a position.
937 while (o) { 937 while (o) {
938 if (RenderObject* oLastChild = o->slowLastChild()) { 938 if (RenderObject* oLastChild = o->slowLastChild()) {
939 o = oLastChild; 939 o = oLastChild;
940 } else if (o->previousSibling()) { 940 } else if (o->previousSibling()) {
941 o = o->previousSibling(); 941 o = o->previousSibling();
942 } else { 942 } else {
943 RenderObject* prev = 0; 943 RenderObject* prev = nullptr;
944 while (!prev) { 944 while (!prev) {
945 o = o->parent(); 945 o = o->parent();
946 if (!o) 946 if (!o)
947 return false; 947 return false;
948 prev = o->previousSibling(); 948 prev = o->previousSibling();
949 } 949 }
950 o = prev; 950 o = prev;
951 } 951 }
952 ASSERT(o); 952 ASSERT(o);
953 if (o->isText() || o->isReplaced()) { 953 if (o->isText() || o->isReplaced()) {
954 point = FloatPoint(); 954 point = FloatPoint();
955 if (o->isText()) { 955 if (o->isText()) {
956 RenderText* text = toRenderText(o); 956 RenderText* text = toRenderText(o);
957 IntRect linesBox = text->linesBoundingBox(); 957 IntRect linesBox = text->linesBoundingBox();
958 if (!linesBox.maxX() && !linesBox.maxY()) 958 if (!linesBox.maxX() && !linesBox.maxY())
959 continue; 959 continue;
960 point.moveBy(linesBox.maxXMaxYCorner()); 960 point.moveBy(linesBox.maxXMaxYCorner());
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1154 return; 1154 return;
1155 } 1155 }
1156 1156
1157 ASSERT(!EventDispatchForbiddenScope::isEventDispatchForbidden()); 1157 ASSERT(!EventDispatchForbiddenScope::isEventDispatchForbidden());
1158 1158
1159 InspectorInstrumentation::willRemoveDOMNode(&child); 1159 InspectorInstrumentation::willRemoveDOMNode(&child);
1160 1160
1161 RefPtrWillBeRawPtr<Node> c(child); 1161 RefPtrWillBeRawPtr<Node> c(child);
1162 RefPtrWillBeRawPtr<Document> document(child.document()); 1162 RefPtrWillBeRawPtr<Document> document(child.document());
1163 1163
1164 // dispatch pre-removal mutation events 1164 // Dispatch pre-removal mutation events.
1165 if (c->parentNode() && document->hasListenerType(Document::DOMNODEREMOVED_LI STENER)) { 1165 if (c->parentNode() && document->hasListenerType(Document::DOMNODEREMOVED_LI STENER)) {
1166 NodeChildRemovalTracker scope(child); 1166 NodeChildRemovalTracker scope(child);
1167 c->dispatchScopedEvent(MutationEvent::create(EventTypeNames::DOMNodeRemo ved, true, c->parentNode())); 1167 c->dispatchScopedEvent(MutationEvent::create(EventTypeNames::DOMNodeRemo ved, true, c->parentNode()));
1168 } 1168 }
1169 1169
1170 // dispatch the DOMNodeRemovedFromDocument event to all descendants 1170 // Dispatch the DOMNodeRemovedFromDocument event to all descendants.
1171 if (c->inDocument() && document->hasListenerType(Document::DOMNODEREMOVEDFRO MDOCUMENT_LISTENER)) { 1171 if (c->inDocument() && document->hasListenerType(Document::DOMNODEREMOVEDFRO MDOCUMENT_LISTENER)) {
1172 NodeChildRemovalTracker scope(child); 1172 NodeChildRemovalTracker scope(child);
1173 for (; c; c = NodeTraversal::next(*c, &child)) 1173 for (; c; c = NodeTraversal::next(*c, &child))
1174 c->dispatchScopedEvent(MutationEvent::create(EventTypeNames::DOMNode RemovedFromDocument, false)); 1174 c->dispatchScopedEvent(MutationEvent::create(EventTypeNames::DOMNode RemovedFromDocument, false));
1175 } 1175 }
1176 } 1176 }
1177 1177
1178 void ContainerNode::updateTreeAfterInsertion(Node& child) 1178 void ContainerNode::updateTreeAfterInsertion(Node& child)
1179 { 1179 {
1180 #if !ENABLE(OILPAN) 1180 #if !ENABLE(OILPAN)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 ASSERT(!needsStyleRecalc()); 1212 ASSERT(!needsStyleRecalc());
1213 1213
1214 if (change < Force && hasRareData() && childNeedsStyleRecalc()) 1214 if (change < Force && hasRareData() && childNeedsStyleRecalc())
1215 checkForChildrenAdjacentRuleChanges(); 1215 checkForChildrenAdjacentRuleChanges();
1216 1216
1217 // This loop is deliberately backwards because we use insertBefore in the re ndering tree, and want to avoid 1217 // This loop is deliberately backwards because we use insertBefore in the re ndering tree, and want to avoid
1218 // a potentially n^2 loop to find the insertion point while resolving style. Having us start from the last 1218 // a potentially n^2 loop to find the insertion point while resolving style. Having us start from the last
1219 // child and work our way back means in the common case, we'll find the inse rtion point in O(1) time. 1219 // child and work our way back means in the common case, we'll find the inse rtion point in O(1) time.
1220 // See crbug.com/288225 1220 // See crbug.com/288225
1221 StyleResolver& styleResolver = document().ensureStyleResolver(); 1221 StyleResolver& styleResolver = document().ensureStyleResolver();
1222 Text* lastTextNode = 0; 1222 Text* lastTextNode = nullptr;
1223 for (Node* child = lastChild(); child; child = child->previousSibling()) { 1223 for (Node* child = lastChild(); child; child = child->previousSibling()) {
1224 if (child->isTextNode()) { 1224 if (child->isTextNode()) {
1225 toText(child)->recalcTextStyle(change, lastTextNode); 1225 toText(child)->recalcTextStyle(change, lastTextNode);
1226 lastTextNode = toText(child); 1226 lastTextNode = toText(child);
1227 } else if (child->isElementNode()) { 1227 } else if (child->isElementNode()) {
1228 Element* element = toElement(child); 1228 Element* element = toElement(child);
1229 if (element->shouldCallRecalcStyle(change)) 1229 if (element->shouldCallRecalcStyle(change))
1230 element->recalcStyle(change, lastTextNode); 1230 element->recalcStyle(change, lastTextNode);
1231 else if (element->supportsStyleSharing()) 1231 else if (element->supportsStyleSharing())
1232 styleResolver.addToStyleSharingList(*element); 1232 styleResolver.addToStyleSharingList(*element);
1233 if (element->renderer()) 1233 if (element->renderer())
1234 lastTextNode = 0; 1234 lastTextNode = nullptr;
1235 } 1235 }
1236 } 1236 }
1237 } 1237 }
1238 1238
1239 void ContainerNode::checkForChildrenAdjacentRuleChanges() 1239 void ContainerNode::checkForChildrenAdjacentRuleChanges()
1240 { 1240 {
1241 bool hasDirectAdjacentRules = childrenAffectedByDirectAdjacentRules(); 1241 bool hasDirectAdjacentRules = childrenAffectedByDirectAdjacentRules();
1242 bool hasIndirectAdjacentRules = childrenAffectedByIndirectAdjacentRules(); 1242 bool hasIndirectAdjacentRules = childrenAffectedByIndirectAdjacentRules();
1243 1243
1244 if (!hasDirectAdjacentRules && !hasIndirectAdjacentRules) 1244 if (!hasDirectAdjacentRules && !hasIndirectAdjacentRules)
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 return; 1285 return;
1286 } 1286 }
1287 1287
1288 // :first-child. In the parser callback case, we don't have to check anythin g, since we were right the first time. 1288 // :first-child. In the parser callback case, we don't have to check anythin g, since we were right the first time.
1289 // In the DOM case, we only need to do something if |afterChange| is not 0. 1289 // In the DOM case, we only need to do something if |afterChange| is not 0.
1290 // |afterChange| is 0 in the parser case, so it works out that we'll skip th is block. 1290 // |afterChange| is 0 in the parser case, so it works out that we'll skip th is block.
1291 if (childrenAffectedByFirstChildRules() && nodeAfterChange) { 1291 if (childrenAffectedByFirstChildRules() && nodeAfterChange) {
1292 ASSERT(changeType != FinishedParsingChildren); 1292 ASSERT(changeType != FinishedParsingChildren);
1293 // Find our new first child element. 1293 // Find our new first child element.
1294 Element* firstChildElement = ElementTraversal::firstChild(*this); 1294 Element* firstChildElement = ElementTraversal::firstChild(*this);
1295 RenderStyle* firstChildElementStyle = firstChildElement ? firstChildElem ent->renderStyle() : 0; 1295 RenderStyle* firstChildElementStyle = firstChildElement ? firstChildElem ent->renderStyle() : nullptr;
1296 1296
1297 // Find the first element after the change. 1297 // Find the first element after the change.
1298 Element* elementAfterChange = nodeAfterChange->isElementNode() ? toEleme nt(nodeAfterChange) : ElementTraversal::nextSibling(*nodeAfterChange); 1298 Element* elementAfterChange = nodeAfterChange->isElementNode() ? toEleme nt(nodeAfterChange) : ElementTraversal::nextSibling(*nodeAfterChange);
1299 RenderStyle* elementAfterChangeStyle = elementAfterChange ? elementAfter Change->renderStyle() : 0; 1299 RenderStyle* elementAfterChangeStyle = elementAfterChange ? elementAfter Change->renderStyle() : nullptr;
1300 1300
1301 // This is the element insertion as first child element case. 1301 // This is the element insertion as first child element case.
1302 if (firstChildElement != elementAfterChange && elementAfterChangeStyle & & elementAfterChangeStyle->firstChildState()) { 1302 if (firstChildElement != elementAfterChange && elementAfterChangeStyle & & elementAfterChangeStyle->firstChildState()) {
1303 ASSERT(changeType == SiblingElementInserted); 1303 ASSERT(changeType == SiblingElementInserted);
1304 elementAfterChange->setNeedsStyleRecalc(SubtreeStyleChange, StyleCha ngeReasonForTracing::create(StyleChangeReason::SiblingSelector)); 1304 elementAfterChange->setNeedsStyleRecalc(SubtreeStyleChange, StyleCha ngeReasonForTracing::create(StyleChangeReason::SiblingSelector));
1305 } 1305 }
1306 1306
1307 // This is the first child element removal case. 1307 // This is the first child element removal case.
1308 if (changeType == SiblingElementRemoved && firstChildElement == elementA fterChange && firstChildElement && (!firstChildElementStyle || !firstChildElemen tStyle->firstChildState())) 1308 if (changeType == SiblingElementRemoved && firstChildElement == elementA fterChange && firstChildElement && (!firstChildElementStyle || !firstChildElemen tStyle->firstChildState()))
1309 firstChildElement->setNeedsStyleRecalc(SubtreeStyleChange, StyleChan geReasonForTracing::create(StyleChangeReason::SiblingSelector)); 1309 firstChildElement->setNeedsStyleRecalc(SubtreeStyleChange, StyleChan geReasonForTracing::create(StyleChangeReason::SiblingSelector));
1310 } 1310 }
1311 1311
1312 // :last-child. In the parser callback case, we don't have to check anything , since we were right the first time. 1312 // :last-child. In the parser callback case, we don't have to check anything , since we were right the first time.
1313 // In the DOM case, we only need to do something if |afterChange| is not 0. 1313 // In the DOM case, we only need to do something if |afterChange| is not 0.
1314 if (childrenAffectedByLastChildRules() && nodeBeforeChange) { 1314 if (childrenAffectedByLastChildRules() && nodeBeforeChange) {
1315 // Find our new last child element. 1315 // Find our new last child element.
1316 Element* lastChildElement = ElementTraversal::lastChild(*this); 1316 Element* lastChildElement = ElementTraversal::lastChild(*this);
1317 RenderStyle* lastChildElementStyle = lastChildElement ? lastChildElement ->renderStyle() : 0; 1317 RenderStyle* lastChildElementStyle = lastChildElement ? lastChildElement ->renderStyle() : nullptr;
1318 1318
1319 // Find the last element before the change. 1319 // Find the last element before the change.
1320 Element* elementBeforeChange = nodeBeforeChange->isElementNode() ? toEle ment(nodeBeforeChange) : ElementTraversal::previousSibling(*nodeBeforeChange); 1320 Element* elementBeforeChange = nodeBeforeChange->isElementNode() ? toEle ment(nodeBeforeChange) : ElementTraversal::previousSibling(*nodeBeforeChange);
1321 RenderStyle* elementBeforeChangeStyle = elementBeforeChange ? elementBef oreChange->renderStyle() : 0; 1321 RenderStyle* elementBeforeChangeStyle = elementBeforeChange ? elementBef oreChange->renderStyle() : nullptr;
1322 1322
1323 // This is the element insertion as last child element case. 1323 // This is the element insertion as last child element case.
1324 if (lastChildElement != elementBeforeChange && elementBeforeChangeStyle && elementBeforeChangeStyle->lastChildState()) { 1324 if (lastChildElement != elementBeforeChange && elementBeforeChangeStyle && elementBeforeChangeStyle->lastChildState()) {
1325 ASSERT(SiblingElementInserted); 1325 ASSERT(SiblingElementInserted);
1326 elementBeforeChange->setNeedsStyleRecalc(SubtreeStyleChange, StyleCh angeReasonForTracing::create(StyleChangeReason::SiblingSelector)); 1326 elementBeforeChange->setNeedsStyleRecalc(SubtreeStyleChange, StyleCh angeReasonForTracing::create(StyleChangeReason::SiblingSelector));
1327 } 1327 }
1328 1328
1329 // This is the last child element removal case. The parser callback case is similar to node removal as well in that we need to change the last child 1329 // This is the last child element removal case. The parser callback case is similar to node removal as well in that we need to change the last child
1330 // to match now. 1330 // to match now.
1331 if ((changeType == SiblingElementRemoved || changeType == FinishedParsin gChildren) && lastChildElement == elementBeforeChange && lastChildElement && (!l astChildElementStyle || !lastChildElementStyle->lastChildState())) 1331 if ((changeType == SiblingElementRemoved || changeType == FinishedParsin gChildren) && lastChildElement == elementBeforeChange && lastChildElement && (!l astChildElementStyle || !lastChildElementStyle->lastChildState()))
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1406 return ensureCachedCollection<RadioNodeList>(type, name); 1406 return ensureCachedCollection<RadioNodeList>(type, name);
1407 } 1407 }
1408 1408
1409 Element* ContainerNode::getElementById(const AtomicString& id) const 1409 Element* ContainerNode::getElementById(const AtomicString& id) const
1410 { 1410 {
1411 if (isInTreeScope()) { 1411 if (isInTreeScope()) {
1412 // Fast path if we are in a tree scope: call getElementById() on tree sc ope 1412 // Fast path if we are in a tree scope: call getElementById() on tree sc ope
1413 // and check if the matching element is in our subtree. 1413 // and check if the matching element is in our subtree.
1414 Element* element = treeScope().getElementById(id); 1414 Element* element = treeScope().getElementById(id);
1415 if (!element) 1415 if (!element)
1416 return 0; 1416 return nullptr;
1417 if (element->isDescendantOf(this)) 1417 if (element->isDescendantOf(this))
1418 return element; 1418 return element;
1419 } 1419 }
1420 1420
1421 // Fall back to traversing our subtree. In case of duplicate ids, the first element found will be returned. 1421 // Fall back to traversing our subtree. In case of duplicate ids, the first element found will be returned.
1422 for (Element& element : ElementTraversal::descendantsOf(*this)) { 1422 for (Element& element : ElementTraversal::descendantsOf(*this)) {
1423 if (element.getIdAttribute() == id) 1423 if (element.getIdAttribute() == id)
1424 return &element; 1424 return &element;
1425 } 1425 }
1426 return 0; 1426 return nullptr;
1427 } 1427 }
1428 1428
1429 NodeListsNodeData& ContainerNode::ensureNodeLists() 1429 NodeListsNodeData& ContainerNode::ensureNodeLists()
1430 { 1430 {
1431 return ensureRareData().ensureNodeLists(); 1431 return ensureRareData().ensureNodeLists();
1432 } 1432 }
1433 1433
1434 #if ENABLE(ASSERT) 1434 #if ENABLE(ASSERT)
1435 bool childAttachedAllowedWhenAttachingChildren(ContainerNode* node) 1435 bool childAttachedAllowedWhenAttachingChildren(ContainerNode* node)
1436 { 1436 {
1437 if (node->isShadowRoot()) 1437 if (node->isShadowRoot())
1438 return true; 1438 return true;
1439 1439
1440 if (node->isInsertionPoint()) 1440 if (node->isInsertionPoint())
1441 return true; 1441 return true;
1442 1442
1443 if (node->isElementNode() && toElement(node)->shadow()) 1443 if (node->isElementNode() && toElement(node)->shadow())
1444 return true; 1444 return true;
1445 1445
1446 return false; 1446 return false;
1447 } 1447 }
1448 #endif 1448 #endif
1449 1449
1450 } // namespace blink 1450 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/dom/ContainerNode.h ('k') | Source/core/dom/ContextLifecycleNotifier.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698