| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
| 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. | 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. |
| 6 * | 6 * |
| 7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
| 9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
| 10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "core/dom/ClassCollection.h" | 29 #include "core/dom/ClassCollection.h" |
| 30 #include "core/dom/ContainerNodeAlgorithms.h" | 30 #include "core/dom/ContainerNodeAlgorithms.h" |
| 31 #include "core/dom/ElementTraversal.h" | 31 #include "core/dom/ElementTraversal.h" |
| 32 #include "core/dom/ExceptionCode.h" | 32 #include "core/dom/ExceptionCode.h" |
| 33 #include "core/dom/FullscreenElementStack.h" | 33 #include "core/dom/FullscreenElementStack.h" |
| 34 #include "core/dom/NameNodeList.h" | 34 #include "core/dom/NameNodeList.h" |
| 35 #include "core/dom/NodeChildRemovalTracker.h" | 35 #include "core/dom/NodeChildRemovalTracker.h" |
| 36 #include "core/dom/NodeRareData.h" | 36 #include "core/dom/NodeRareData.h" |
| 37 #include "core/dom/NodeRenderStyle.h" | 37 #include "core/dom/NodeRenderStyle.h" |
| 38 #include "core/dom/NodeTraversal.h" | 38 #include "core/dom/NodeTraversal.h" |
| 39 #include "core/dom/ScriptForbiddenScope.h" |
| 39 #include "core/dom/SelectorQuery.h" | 40 #include "core/dom/SelectorQuery.h" |
| 41 #include "core/dom/shadow/ElementShadow.h" |
| 42 #include "core/dom/shadow/ShadowRoot.h" |
| 40 #include "core/events/MutationEvent.h" | 43 #include "core/events/MutationEvent.h" |
| 41 #include "core/html/HTMLCollection.h" | 44 #include "core/html/HTMLCollection.h" |
| 42 #include "core/html/HTMLFrameOwnerElement.h" | 45 #include "core/html/HTMLFrameOwnerElement.h" |
| 43 #include "core/html/RadioNodeList.h" | 46 #include "core/html/RadioNodeList.h" |
| 47 #include "core/inspector/InspectorInstrumentation.h" |
| 44 #include "core/rendering/InlineTextBox.h" | 48 #include "core/rendering/InlineTextBox.h" |
| 45 #include "core/rendering/RenderText.h" | 49 #include "core/rendering/RenderText.h" |
| 46 #include "core/rendering/RenderTheme.h" | 50 #include "core/rendering/RenderTheme.h" |
| 47 #include "core/rendering/RenderView.h" | 51 #include "core/rendering/RenderView.h" |
| 48 | 52 |
| 49 using namespace std; | 53 using namespace std; |
| 50 | 54 |
| 51 namespace WebCore { | 55 namespace WebCore { |
| 52 | 56 |
| 53 using namespace HTMLNames; | 57 using namespace HTMLNames; |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 document().adoptNode(newChild.get(), ASSERT_NO_EXCEPTION); | 286 document().adoptNode(newChild.get(), ASSERT_NO_EXCEPTION); |
| 283 | 287 |
| 284 insertBeforeCommon(nextChild, *newChild); | 288 insertBeforeCommon(nextChild, *newChild); |
| 285 | 289 |
| 286 newChild->updateAncestorConnectedSubframeCountForInsertion(); | 290 newChild->updateAncestorConnectedSubframeCountForInsertion(); |
| 287 | 291 |
| 288 ChildListMutationScope(*this).childAdded(*newChild); | 292 ChildListMutationScope(*this).childAdded(*newChild); |
| 289 | 293 |
| 290 childrenChanged(true, newChild->previousSibling(), &nextChild, 1); | 294 childrenChanged(true, newChild->previousSibling(), &nextChild, 1); |
| 291 | 295 |
| 292 ChildNodeInsertionNotifier(*this).notify(*newChild); | 296 notifyNodeInserted(*newChild); |
| 293 } | 297 } |
| 294 | 298 |
| 295 void ContainerNode::replaceChild(PassRefPtr<Node> newChild, Node* oldChild, Exce
ptionState& exceptionState) | 299 void ContainerNode::replaceChild(PassRefPtr<Node> newChild, Node* oldChild, Exce
ptionState& exceptionState) |
| 296 { | 300 { |
| 297 #if !ENABLE(OILPAN) | 301 #if !ENABLE(OILPAN) |
| 298 // Check that this node is not "floating". | 302 // Check that this node is not "floating". |
| 299 // If it is, it can be deleted as a side effect of sending mutation events. | 303 // If it is, it can be deleted as a side effect of sending mutation events. |
| 300 ASSERT(refCount() || parentOrShadowHostNode()); | 304 ASSERT(refCount() || parentOrShadowHostNode()); |
| 301 #endif | 305 #endif |
| 302 | 306 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 return; | 463 return; |
| 460 } | 464 } |
| 461 | 465 |
| 462 { | 466 { |
| 463 HTMLFrameOwnerElement::UpdateSuspendScope suspendWidgetHierarchyUpdates; | 467 HTMLFrameOwnerElement::UpdateSuspendScope suspendWidgetHierarchyUpdates; |
| 464 | 468 |
| 465 Node* prev = child->previousSibling(); | 469 Node* prev = child->previousSibling(); |
| 466 Node* next = child->nextSibling(); | 470 Node* next = child->nextSibling(); |
| 467 removeBetween(prev, next, *child); | 471 removeBetween(prev, next, *child); |
| 468 childrenChanged(false, prev, next, -1); | 472 childrenChanged(false, prev, next, -1); |
| 469 ChildNodeRemovalNotifier(*this).notify(*child); | 473 notifyNodeRemoved(*child); |
| 470 } | 474 } |
| 471 dispatchSubtreeModifiedEvent(); | 475 dispatchSubtreeModifiedEvent(); |
| 472 } | 476 } |
| 473 | 477 |
| 474 void ContainerNode::removeBetween(Node* previousChild, Node* nextChild, Node& ol
dChild) | 478 void ContainerNode::removeBetween(Node* previousChild, Node* nextChild, Node& ol
dChild) |
| 475 { | 479 { |
| 476 NoEventDispatchAssertion assertNoEventDispatch; | 480 NoEventDispatchAssertion assertNoEventDispatch; |
| 477 | 481 |
| 478 ASSERT(oldChild.parentNode() == this); | 482 ASSERT(oldChild.parentNode() == this); |
| 479 | 483 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 505 Node* next = oldChild.nextSibling(); | 509 Node* next = oldChild.nextSibling(); |
| 506 | 510 |
| 507 oldChild.updateAncestorConnectedSubframeCountForRemoval(); | 511 oldChild.updateAncestorConnectedSubframeCountForRemoval(); |
| 508 | 512 |
| 509 ChildListMutationScope(*this).willRemoveChild(oldChild); | 513 ChildListMutationScope(*this).willRemoveChild(oldChild); |
| 510 oldChild.notifyMutationObserversNodeWillDetach(); | 514 oldChild.notifyMutationObserversNodeWillDetach(); |
| 511 | 515 |
| 512 removeBetween(prev, next, oldChild); | 516 removeBetween(prev, next, oldChild); |
| 513 | 517 |
| 514 childrenChanged(true, prev, next, -1); | 518 childrenChanged(true, prev, next, -1); |
| 515 ChildNodeRemovalNotifier(*this).notify(oldChild); | 519 notifyNodeRemoved(oldChild); |
| 516 } | 520 } |
| 517 | 521 |
| 518 // this differs from other remove functions because it forcibly removes all the
children, | 522 // this differs from other remove functions because it forcibly removes all the
children, |
| 519 // regardless of read-only status or event exceptions, e.g. | 523 // regardless of read-only status or event exceptions, e.g. |
| 520 void ContainerNode::removeChildren() | 524 void ContainerNode::removeChildren() |
| 521 { | 525 { |
| 522 if (!m_firstChild) | 526 if (!m_firstChild) |
| 523 return; | 527 return; |
| 524 | 528 |
| 525 // The container node can be removed from event handlers. | 529 // The container node can be removed from event handlers. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 556 removedChildren.reserveInitialCapacity(countChildren()); | 560 removedChildren.reserveInitialCapacity(countChildren()); |
| 557 while (m_firstChild) { | 561 while (m_firstChild) { |
| 558 removedChildren.append(m_firstChild); | 562 removedChildren.append(m_firstChild); |
| 559 removeBetween(0, m_firstChild->nextSibling(), *m_firstChild); | 563 removeBetween(0, m_firstChild->nextSibling(), *m_firstChild); |
| 560 } | 564 } |
| 561 } | 565 } |
| 562 | 566 |
| 563 childrenChanged(false, 0, 0, -static_cast<int>(removedChildren.size())); | 567 childrenChanged(false, 0, 0, -static_cast<int>(removedChildren.size())); |
| 564 | 568 |
| 565 for (size_t i = 0; i < removedChildren.size(); ++i) | 569 for (size_t i = 0; i < removedChildren.size(); ++i) |
| 566 ChildNodeRemovalNotifier(*this).notify(*removedChildren[i]); | 570 notifyNodeRemoved(*removedChildren[i]); |
| 567 } | 571 } |
| 568 | 572 |
| 569 dispatchSubtreeModifiedEvent(); | 573 dispatchSubtreeModifiedEvent(); |
| 570 } | 574 } |
| 571 | 575 |
| 572 void ContainerNode::appendChild(PassRefPtr<Node> newChild, ExceptionState& excep
tionState) | 576 void ContainerNode::appendChild(PassRefPtr<Node> newChild, ExceptionState& excep
tionState) |
| 573 { | 577 { |
| 574 RefPtr<ContainerNode> protect(this); | 578 RefPtr<ContainerNode> protect(this); |
| 575 | 579 |
| 576 #if !ENABLE(OILPAN) | 580 #if !ENABLE(OILPAN) |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 // FIXME: This method should take a PassRefPtr. | 647 // FIXME: This method should take a PassRefPtr. |
| 644 appendChildToContainer(*newChild, *this); | 648 appendChildToContainer(*newChild, *this); |
| 645 treeScope().adoptIfNeeded(*newChild); | 649 treeScope().adoptIfNeeded(*newChild); |
| 646 } | 650 } |
| 647 | 651 |
| 648 newChild->updateAncestorConnectedSubframeCountForInsertion(); | 652 newChild->updateAncestorConnectedSubframeCountForInsertion(); |
| 649 | 653 |
| 650 ChildListMutationScope(*this).childAdded(*newChild); | 654 ChildListMutationScope(*this).childAdded(*newChild); |
| 651 | 655 |
| 652 childrenChanged(true, last, 0, 1); | 656 childrenChanged(true, last, 0, 1); |
| 653 ChildNodeInsertionNotifier(*this).notify(*newChild); | 657 notifyNodeInserted(*newChild); |
| 658 } |
| 659 |
| 660 void ContainerNode::notifyNodeInserted(Node& root) |
| 661 { |
| 662 ASSERT(!NoEventDispatchAssertion::isEventDispatchForbidden()); |
| 663 |
| 664 InspectorInstrumentation::didInsertDOMNode(&root); |
| 665 |
| 666 RefPtr<Node> protectDocument(root.document()); |
| 667 RefPtr<Node> protectNode(root); |
| 668 |
| 669 NodeVector postInsertionNotificationTargets; |
| 670 |
| 671 { |
| 672 NoEventDispatchAssertion assertNoEventDispatch; |
| 673 ScriptForbiddenScope forbidScript; |
| 674 notifyNodeInsertedInternal(root, postInsertionNotificationTargets); |
| 675 } |
| 676 |
| 677 for (size_t i = 0; i < postInsertionNotificationTargets.size(); ++i) { |
| 678 Node* targetNode = postInsertionNotificationTargets[i].get(); |
| 679 if (targetNode->inDocument()) |
| 680 targetNode->didNotifySubtreeInsertionsToDocument(); |
| 681 } |
| 682 } |
| 683 |
| 684 void ContainerNode::notifyNodeInsertedInternal(Node& root, NodeVector& postInser
tionNotificationTargets) |
| 685 { |
| 686 for (Node* node = &root; node; node = NodeTraversal::next(*node, &root)) { |
| 687 // As an optimization we don't notify leaf nodes when when inserting |
| 688 // into detached subtrees. |
| 689 if (!inDocument() && !node->isContainerNode()) |
| 690 continue; |
| 691 if (Node::InsertionShouldCallDidNotifySubtreeInsertions == node->inserte
dInto(this)) |
| 692 postInsertionNotificationTargets.append(node); |
| 693 for (ShadowRoot* shadowRoot = node->youngestShadowRoot(); shadowRoot; sh
adowRoot = shadowRoot->olderShadowRoot()) |
| 694 notifyNodeInsertedInternal(*shadowRoot, postInsertionNotificationTar
gets); |
| 695 } |
| 696 } |
| 697 |
| 698 void ContainerNode::notifyNodeRemoved(Node& root) |
| 699 { |
| 700 ScriptForbiddenScope forbidScript; |
| 701 NoEventDispatchAssertion assertNoEventDispatch; |
| 702 |
| 703 Document& document = root.document(); |
| 704 for (Node* node = &root; node; node = NodeTraversal::next(*node, &root)) { |
| 705 // As an optimization we skip notifying Text nodes and other leaf nodes |
| 706 // of removal when they're not in the Document tree since the virtual |
| 707 // call to removedFrom is not needed. |
| 708 if (!node->inDocument() && !node->isContainerNode()) |
| 709 continue; |
| 710 if (document.cssTarget() == node) |
| 711 document.setCSSTarget(0); |
| 712 node->removedFrom(this); |
| 713 for (ShadowRoot* shadowRoot = node->youngestShadowRoot(); shadowRoot; sh
adowRoot = shadowRoot->olderShadowRoot()) |
| 714 notifyNodeRemoved(*shadowRoot); |
| 715 } |
| 654 } | 716 } |
| 655 | 717 |
| 656 void ContainerNode::attach(const AttachContext& context) | 718 void ContainerNode::attach(const AttachContext& context) |
| 657 { | 719 { |
| 658 attachChildren(context); | 720 attachChildren(context); |
| 659 clearChildNeedsStyleRecalc(); | 721 clearChildNeedsStyleRecalc(); |
| 660 Node::attach(context); | 722 Node::attach(context); |
| 661 } | 723 } |
| 662 | 724 |
| 663 void ContainerNode::detach(const AttachContext& context) | 725 void ContainerNode::detach(const AttachContext& context) |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1014 { | 1076 { |
| 1015 #if !ENABLE(OILPAN) | 1077 #if !ENABLE(OILPAN) |
| 1016 ASSERT(refCount()); | 1078 ASSERT(refCount()); |
| 1017 ASSERT(child.refCount()); | 1079 ASSERT(child.refCount()); |
| 1018 #endif | 1080 #endif |
| 1019 | 1081 |
| 1020 ChildListMutationScope(*this).childAdded(child); | 1082 ChildListMutationScope(*this).childAdded(child); |
| 1021 | 1083 |
| 1022 childrenChanged(false, child.previousSibling(), child.nextSibling(), 1); | 1084 childrenChanged(false, child.previousSibling(), child.nextSibling(), 1); |
| 1023 | 1085 |
| 1024 ChildNodeInsertionNotifier(*this).notify(child); | 1086 notifyNodeInserted(child); |
| 1025 | 1087 |
| 1026 dispatchChildInsertionEvents(child); | 1088 dispatchChildInsertionEvents(child); |
| 1027 } | 1089 } |
| 1028 | 1090 |
| 1029 bool ContainerNode::hasRestyleFlagInternal(DynamicRestyleFlags mask) const | 1091 bool ContainerNode::hasRestyleFlagInternal(DynamicRestyleFlags mask) const |
| 1030 { | 1092 { |
| 1031 return rareData()->hasRestyleFlag(mask); | 1093 return rareData()->hasRestyleFlag(mask); |
| 1032 } | 1094 } |
| 1033 | 1095 |
| 1034 bool ContainerNode::hasRestyleFlagsInternal() const | 1096 bool ContainerNode::hasRestyleFlagsInternal() const |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1216 return true; | 1278 return true; |
| 1217 | 1279 |
| 1218 if (node->isElementNode() && toElement(node)->shadow()) | 1280 if (node->isElementNode() && toElement(node)->shadow()) |
| 1219 return true; | 1281 return true; |
| 1220 | 1282 |
| 1221 return false; | 1283 return false; |
| 1222 } | 1284 } |
| 1223 #endif | 1285 #endif |
| 1224 | 1286 |
| 1225 } // namespace WebCore | 1287 } // namespace WebCore |
| OLD | NEW |