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

Side by Side Diff: Source/core/dom/ContainerNodeAlgorithms.h

Issue 323253002: Remove NodeRemovalDispatcher (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 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 | « no previous file | no next file » | 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) 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2007 Apple Inc. All rights reserved.
3 * (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> 3 * (C) 2008 Nikolas Zimmermann <zimmermann@kde.org>
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 } else { 78 } else {
79 container.setFirstChild(&child); 79 container.setFirstChild(&child);
80 } 80 }
81 81
82 container.setLastChild(&child); 82 container.setLastChild(&child);
83 } 83 }
84 84
85 // Helper methods for removeDetachedChildrenInContainer, hidden from WebCore nam espace 85 // Helper methods for removeDetachedChildrenInContainer, hidden from WebCore nam espace
86 namespace Private { 86 namespace Private {
87 87
88 template<class GenericNode, class GenericNodeContainer, bool dispatchRemoval Notification>
89 struct NodeRemovalDispatcher {
90 static void dispatch(GenericNode&, GenericNodeContainer&)
91 {
92 // no-op, by default
93 }
94 };
95
96 template<class GenericNode, class GenericNodeContainer>
97 struct NodeRemovalDispatcher<GenericNode, GenericNodeContainer, true> {
98 static void dispatch(GenericNode& node, GenericNodeContainer& container)
99 {
100 container.document().adoptIfNeeded(node);
101 if (node.inDocument())
102 container.notifyNodeRemoved(node);
103 }
104 };
105
106 template<class GenericNode>
107 struct ShouldDispatchRemovalNotification {
108 static const bool value = false;
109 };
110
111 template<>
112 struct ShouldDispatchRemovalNotification<Node> {
113 static const bool value = true;
114 };
115
116 template<class GenericNode, class GenericNodeContainer> 88 template<class GenericNode, class GenericNodeContainer>
117 void addChildNodesToDeletionQueue(GenericNode*& head, GenericNode*& tail, Ge nericNodeContainer& container) 89 void addChildNodesToDeletionQueue(GenericNode*& head, GenericNode*& tail, Ge nericNodeContainer& container)
118 { 90 {
119 // We have to tell all children that their parent has died. 91 // We have to tell all children that their parent has died.
120 GenericNode* next = 0; 92 GenericNode* next = 0;
121 for (GenericNode* n = container.firstChild(); n; n = next) { 93 for (GenericNode* n = container.firstChild(); n; n = next) {
122 ASSERT_WITH_SECURITY_IMPLICATION(!n->m_deletionHasBegun); 94 ASSERT_WITH_SECURITY_IMPLICATION(!n->m_deletionHasBegun);
123 95
124 next = n->nextSibling(); 96 next = n->nextSibling();
125 n->setNextSibling(0); 97 n->setNextSibling(0);
126 n->setParentOrShadowHostNode(0); 98 n->setParentOrShadowHostNode(0);
127 container.setFirstChild(next); 99 container.setFirstChild(next);
128 if (next) 100 if (next)
129 next->setPreviousSibling(0); 101 next->setPreviousSibling(0);
130 102
131 if (!n->refCount()) { 103 if (!n->refCount()) {
132 #if SECURITY_ASSERT_ENABLED 104 #if SECURITY_ASSERT_ENABLED
133 n->m_deletionHasBegun = true; 105 n->m_deletionHasBegun = true;
134 #endif 106 #endif
135 // Add the node to the list of nodes to be deleted. 107 // Add the node to the list of nodes to be deleted.
136 // Reuse the nextSibling pointer for this purpose. 108 // Reuse the nextSibling pointer for this purpose.
137 if (tail) 109 if (tail)
138 tail->setNextSibling(n); 110 tail->setNextSibling(n);
139 else 111 else
140 head = n; 112 head = n;
141 113
142 tail = n; 114 tail = n;
143 } else { 115 } else {
144 RefPtrWillBeRawPtr<GenericNode> protect(n); // removedFromDocume nt may remove all references to this node. 116 RefPtrWillBeRawPtr<GenericNode> protect(n); // removedFromDocume nt may remove all references to this node.
145 NodeRemovalDispatcher<GenericNode, GenericNodeContainer, ShouldD ispatchRemovalNotification<GenericNode>::value>::dispatch(*n, container); 117 container.document().adoptIfNeeded(*n);
118 if (n->inDocument())
119 container.notifyNodeRemoved(*n);
146 } 120 }
147 } 121 }
148 122
149 container.setLastChild(0); 123 container.setLastChild(0);
150 } 124 }
151 125
152 } // namespace Private 126 } // namespace Private
153 127
154 } // namespace WebCore 128 } // namespace WebCore
155 129
156 #endif // ContainerNodeAlgorithms_h 130 #endif // ContainerNodeAlgorithms_h
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698