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

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

Issue 15871005: Avoid N^2 walk placing renderers when building the render tree (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Merging ToT 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
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 namespace WebCore { 43 namespace WebCore {
44 44
45 static void dispatchChildInsertionEvents(Node*); 45 static void dispatchChildInsertionEvents(Node*);
46 static void dispatchChildRemovalEvents(Node*); 46 static void dispatchChildRemovalEvents(Node*);
47 static void updateTreeAfterInsertion(ContainerNode*, Node*, AttachBehavior); 47 static void updateTreeAfterInsertion(ContainerNode*, Node*, AttachBehavior);
48 48
49 typedef pair<NodeCallback, RefPtr<Node> > CallbackInfo; 49 typedef pair<NodeCallback, RefPtr<Node> > CallbackInfo;
50 typedef Vector<CallbackInfo> NodeCallbackQueue; 50 typedef Vector<CallbackInfo> NodeCallbackQueue;
51 51
52 static NodeCallbackQueue* s_postAttachCallbackQueue; 52 static NodeCallbackQueue* s_postAttachCallbackQueue;
53 static NodeCallbackQueue* s_insertionCallbackQueue;
53 54
55 static size_t s_insertionDepth;
54 static size_t s_attachDepth; 56 static size_t s_attachDepth;
55 57
56 ChildNodesLazySnapshot* ChildNodesLazySnapshot::latestSnapshot = 0; 58 ChildNodesLazySnapshot* ChildNodesLazySnapshot::latestSnapshot = 0;
57 59
58 #ifndef NDEBUG 60 #ifndef NDEBUG
59 unsigned NoEventDispatchAssertion::s_count = 0; 61 unsigned NoEventDispatchAssertion::s_count = 0;
60 #endif 62 #endif
61 63
62 static void collectChildrenAndRemoveFromOldParent(Node* node, NodeVector& nodes, ExceptionCode& ec) 64 static void collectChildrenAndRemoveFromOldParent(Node* node, NodeVector& nodes, ExceptionCode& ec)
63 { 65 {
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 { 678 {
677 if (s_attachDepth == 1) { 679 if (s_attachDepth == 1) {
678 RefPtr<ContainerNode> protect(this); 680 RefPtr<ContainerNode> protect(this);
679 681
680 if (s_postAttachCallbackQueue) 682 if (s_postAttachCallbackQueue)
681 dispatchPostAttachCallbacks(); 683 dispatchPostAttachCallbacks();
682 } 684 }
683 --s_attachDepth; 685 --s_attachDepth;
684 } 686 }
685 687
688 void ContainerNode::suspendInsertionCallbacks()
689 {
690 ++s_insertionDepth;
691 }
692
693 void ContainerNode::resumeInsertionCallbacks()
694 {
695 if (s_insertionDepth == 1 && s_insertionCallbackQueue)
696 dispatchInsertionCallbacks();
697 --s_insertionDepth;
698 }
699
700 void ContainerNode::queueInsertionCallback(NodeCallback callback, Node* node)
701 {
702 if (!s_insertionDepth) {
703 (*callback)(node);
704 return;
705 }
706 if (!s_insertionCallbackQueue)
707 s_insertionCallbackQueue = new NodeCallbackQueue;
708 s_insertionCallbackQueue->append(CallbackInfo(callback, node));
709 }
710
686 void ContainerNode::queuePostAttachCallback(NodeCallback callback, Node* node) 711 void ContainerNode::queuePostAttachCallback(NodeCallback callback, Node* node)
687 { 712 {
688 if (!s_postAttachCallbackQueue) 713 if (!s_postAttachCallbackQueue)
689 s_postAttachCallbackQueue = new NodeCallbackQueue; 714 s_postAttachCallbackQueue = new NodeCallbackQueue;
690 s_postAttachCallbackQueue->append(CallbackInfo(callback, node)); 715 s_postAttachCallbackQueue->append(CallbackInfo(callback, node));
691 } 716 }
692 717
693 bool ContainerNode::postAttachCallbacksAreSuspended() 718 bool ContainerNode::postAttachCallbacksAreSuspended()
694 { 719 {
695 return s_attachDepth; 720 return s_attachDepth;
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 if (c->parentNode() && document->hasListenerType(Document::DOMNODEREMOVED_LI STENER)) 902 if (c->parentNode() && document->hasListenerType(Document::DOMNODEREMOVED_LI STENER))
878 c->dispatchScopedEvent(MutationEvent::create(eventNames().DOMNodeRemoved Event, true, c->parentNode())); 903 c->dispatchScopedEvent(MutationEvent::create(eventNames().DOMNodeRemoved Event, true, c->parentNode()));
879 904
880 // dispatch the DOMNodeRemovedFromDocument event to all descendants 905 // dispatch the DOMNodeRemovedFromDocument event to all descendants
881 if (c->inDocument() && document->hasListenerType(Document::DOMNODEREMOVEDFRO MDOCUMENT_LISTENER)) { 906 if (c->inDocument() && document->hasListenerType(Document::DOMNODEREMOVEDFRO MDOCUMENT_LISTENER)) {
882 for (; c; c = NodeTraversal::next(c.get(), child)) 907 for (; c; c = NodeTraversal::next(c.get(), child))
883 c->dispatchScopedEvent(MutationEvent::create(eventNames().DOMNodeRem ovedFromDocumentEvent, false)); 908 c->dispatchScopedEvent(MutationEvent::create(eventNames().DOMNodeRem ovedFromDocumentEvent, false));
884 } 909 }
885 } 910 }
886 911
912 void ContainerNode::dispatchInsertionCallbacks()
913 {
914 for (size_t i = s_insertionCallbackQueue->size(); i; --i) {
915 const CallbackInfo& info = (*s_insertionCallbackQueue)[i - 1];
916 info.first(info.second.get());
917 }
918 s_insertionCallbackQueue->clear();
919 }
920
887 static void updateTreeAfterInsertion(ContainerNode* parent, Node* child, AttachB ehavior attachBehavior) 921 static void updateTreeAfterInsertion(ContainerNode* parent, Node* child, AttachB ehavior attachBehavior)
888 { 922 {
889 ASSERT(parent->refCount()); 923 ASSERT(parent->refCount());
890 ASSERT(child->refCount()); 924 ASSERT(child->refCount());
891 925
892 ChildListMutationScope(parent).childAdded(child); 926 ChildListMutationScope(parent).childAdded(child);
893 927
894 parent->childrenChanged(false, child->previousSibling(), child->nextSibling( ), 1); 928 parent->childrenChanged(false, child->previousSibling(), child->nextSibling( ), 1);
895 929
896 ChildNodeInsertionNotifier(parent).notify(child); 930 ChildNodeInsertionNotifier(parent).notify(child);
(...skipping 20 matching lines...) Expand all
917 return true; 951 return true;
918 952
919 if (node->isElementNode() && toElement(node)->shadow()) 953 if (node->isElementNode() && toElement(node)->shadow())
920 return true; 954 return true;
921 955
922 return false; 956 return false;
923 } 957 }
924 #endif 958 #endif
925 959
926 } // namespace WebCore 960 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698