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

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

Issue 16629006: Revert 151996 "Avoid N^2 walk placing renderers when building th..." (Closed) Base URL: svn://svn.chromium.org/blink/
Patch Set: Update to head Created 7 years, 6 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/ContainerNodeAlgorithms.h » ('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 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 namespace WebCore { 45 namespace WebCore {
46 46
47 static void dispatchChildInsertionEvents(Node*); 47 static void dispatchChildInsertionEvents(Node*);
48 static void dispatchChildRemovalEvents(Node*); 48 static void dispatchChildRemovalEvents(Node*);
49 static void updateTreeAfterInsertion(ContainerNode*, Node*, AttachBehavior); 49 static void updateTreeAfterInsertion(ContainerNode*, Node*, AttachBehavior);
50 50
51 typedef pair<NodeCallback, RefPtr<Node> > CallbackInfo; 51 typedef pair<NodeCallback, RefPtr<Node> > CallbackInfo;
52 typedef Vector<CallbackInfo> NodeCallbackQueue; 52 typedef Vector<CallbackInfo> NodeCallbackQueue;
53 53
54 static NodeCallbackQueue* s_postAttachCallbackQueue; 54 static NodeCallbackQueue* s_postAttachCallbackQueue;
55 static NodeCallbackQueue* s_insertionCallbackQueue;
56 55
57 static size_t s_insertionDepth;
58 static size_t s_attachDepth; 56 static size_t s_attachDepth;
59 57
60 ChildNodesLazySnapshot* ChildNodesLazySnapshot::latestSnapshot = 0; 58 ChildNodesLazySnapshot* ChildNodesLazySnapshot::latestSnapshot = 0;
61 59
62 #ifndef NDEBUG 60 #ifndef NDEBUG
63 unsigned NoEventDispatchAssertion::s_count = 0; 61 unsigned NoEventDispatchAssertion::s_count = 0;
64 #endif 62 #endif
65 63
66 static void collectChildrenAndRemoveFromOldParent(Node* node, NodeVector& nodes, ExceptionCode& ec) 64 static void collectChildrenAndRemoveFromOldParent(Node* node, NodeVector& nodes, ExceptionCode& ec)
67 { 65 {
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 { 678 {
681 if (s_attachDepth == 1) { 679 if (s_attachDepth == 1) {
682 RefPtr<ContainerNode> protect(this); 680 RefPtr<ContainerNode> protect(this);
683 681
684 if (s_postAttachCallbackQueue) 682 if (s_postAttachCallbackQueue)
685 dispatchPostAttachCallbacks(); 683 dispatchPostAttachCallbacks();
686 } 684 }
687 --s_attachDepth; 685 --s_attachDepth;
688 } 686 }
689 687
690 void ContainerNode::suspendInsertionCallbacks()
691 {
692 ++s_insertionDepth;
693 }
694
695 void ContainerNode::resumeInsertionCallbacks()
696 {
697 if (s_insertionDepth == 1 && s_insertionCallbackQueue)
698 dispatchInsertionCallbacks();
699 --s_insertionDepth;
700 }
701
702 void ContainerNode::queueInsertionCallback(NodeCallback callback, Node* node)
703 {
704 if (!s_insertionDepth) {
705 (*callback)(node);
706 return;
707 }
708 if (!s_insertionCallbackQueue)
709 s_insertionCallbackQueue = new NodeCallbackQueue;
710 s_insertionCallbackQueue->append(CallbackInfo(callback, node));
711 }
712
713 void ContainerNode::queuePostAttachCallback(NodeCallback callback, Node* node) 688 void ContainerNode::queuePostAttachCallback(NodeCallback callback, Node* node)
714 { 689 {
715 if (!s_postAttachCallbackQueue) 690 if (!s_postAttachCallbackQueue)
716 s_postAttachCallbackQueue = new NodeCallbackQueue; 691 s_postAttachCallbackQueue = new NodeCallbackQueue;
717 s_postAttachCallbackQueue->append(CallbackInfo(callback, node)); 692 s_postAttachCallbackQueue->append(CallbackInfo(callback, node));
718 } 693 }
719 694
720 bool ContainerNode::postAttachCallbacksAreSuspended() 695 bool ContainerNode::postAttachCallbacksAreSuspended()
721 { 696 {
722 return s_attachDepth; 697 return s_attachDepth;
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 if (c->parentNode() && document->hasListenerType(Document::DOMNODEREMOVED_LI STENER)) 1011 if (c->parentNode() && document->hasListenerType(Document::DOMNODEREMOVED_LI STENER))
1037 c->dispatchScopedEvent(MutationEvent::create(eventNames().DOMNodeRemoved Event, true, c->parentNode())); 1012 c->dispatchScopedEvent(MutationEvent::create(eventNames().DOMNodeRemoved Event, true, c->parentNode()));
1038 1013
1039 // dispatch the DOMNodeRemovedFromDocument event to all descendants 1014 // dispatch the DOMNodeRemovedFromDocument event to all descendants
1040 if (c->inDocument() && document->hasListenerType(Document::DOMNODEREMOVEDFRO MDOCUMENT_LISTENER)) { 1015 if (c->inDocument() && document->hasListenerType(Document::DOMNODEREMOVEDFRO MDOCUMENT_LISTENER)) {
1041 for (; c; c = NodeTraversal::next(c.get(), child)) 1016 for (; c; c = NodeTraversal::next(c.get(), child))
1042 c->dispatchScopedEvent(MutationEvent::create(eventNames().DOMNodeRem ovedFromDocumentEvent, false)); 1017 c->dispatchScopedEvent(MutationEvent::create(eventNames().DOMNodeRem ovedFromDocumentEvent, false));
1043 } 1018 }
1044 } 1019 }
1045 1020
1046 void ContainerNode::dispatchInsertionCallbacks()
1047 {
1048 for (size_t i = s_insertionCallbackQueue->size(); i; --i) {
1049 const CallbackInfo& info = (*s_insertionCallbackQueue)[i - 1];
1050 info.first(info.second.get());
1051 }
1052 s_insertionCallbackQueue->clear();
1053 }
1054
1055 static void updateTreeAfterInsertion(ContainerNode* parent, Node* child, AttachB ehavior attachBehavior) 1021 static void updateTreeAfterInsertion(ContainerNode* parent, Node* child, AttachB ehavior attachBehavior)
1056 { 1022 {
1057 ASSERT(parent->refCount()); 1023 ASSERT(parent->refCount());
1058 ASSERT(child->refCount()); 1024 ASSERT(child->refCount());
1059 1025
1060 ChildListMutationScope(parent).childAdded(child); 1026 ChildListMutationScope(parent).childAdded(child);
1061 1027
1062 parent->childrenChanged(false, child->previousSibling(), child->nextSibling( ), 1); 1028 parent->childrenChanged(false, child->previousSibling(), child->nextSibling( ), 1);
1063 1029
1064 ChildNodeInsertionNotifier(parent).notify(child); 1030 ChildNodeInsertionNotifier(parent).notify(child);
(...skipping 20 matching lines...) Expand all
1085 return true; 1051 return true;
1086 1052
1087 if (node->isElementNode() && toElement(node)->shadow()) 1053 if (node->isElementNode() && toElement(node)->shadow())
1088 return true; 1054 return true;
1089 1055
1090 return false; 1056 return false;
1091 } 1057 }
1092 #endif 1058 #endif
1093 1059
1094 } // namespace WebCore 1060 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/ContainerNode.h ('k') | Source/core/dom/ContainerNodeAlgorithms.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698