OLD | NEW |
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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 lastChild->setNextSibling(child); | 76 lastChild->setNextSibling(child); |
77 } else | 77 } else |
78 container->setFirstChild(child); | 78 container->setFirstChild(child); |
79 | 79 |
80 container->setLastChild(child); | 80 container->setLastChild(child); |
81 } | 81 } |
82 | 82 |
83 // Helper methods for removeAllChildrenInContainer, hidden from WebCore namespac
e | 83 // Helper methods for removeAllChildrenInContainer, hidden from WebCore namespac
e |
84 namespace Private { | 84 namespace Private { |
85 | 85 |
86 template<class GenericNode, bool dispatchRemovalNotification> | 86 template<class GenericNode, class GenericNodeContainer, bool dispatchRemoval
Notification> |
87 struct NodeRemovalDispatcher { | 87 struct NodeRemovalDispatcher { |
88 static void dispatch(GenericNode*) | 88 static void dispatch(GenericNode*, GenericNodeContainer*) |
89 { | 89 { |
90 // no-op, by default | 90 // no-op, by default |
91 } | 91 } |
92 }; | 92 }; |
93 | 93 |
94 template<class GenericNode> | 94 template<class GenericNode, class GenericNodeContainer> |
95 struct NodeRemovalDispatcher<GenericNode, true> { | 95 struct NodeRemovalDispatcher<GenericNode, GenericNodeContainer, true> { |
96 static void dispatch(GenericNode* node) | 96 static void dispatch(GenericNode* node, GenericNodeContainer* container) |
97 { | 97 { |
| 98 // Clean up any TreeScope to a removed tree. |
| 99 if (Document* containerDocument = container->ownerDocument()) |
| 100 containerDocument->adoptIfNeeded(node); |
98 if (node->inDocument()) | 101 if (node->inDocument()) |
99 node->removedFromDocument(); | 102 node->removedFromDocument(); |
100 } | 103 } |
101 }; | 104 }; |
102 | 105 |
103 template<class GenericNode> | 106 template<class GenericNode> |
104 struct ShouldDispatchRemovalNotification { | 107 struct ShouldDispatchRemovalNotification { |
105 static const bool value = false; | 108 static const bool value = false; |
106 }; | 109 }; |
107 | 110 |
(...skipping 22 matching lines...) Expand all Loading... |
130 // Add the node to the list of nodes to be deleted. | 133 // Add the node to the list of nodes to be deleted. |
131 // Reuse the nextSibling pointer for this purpose. | 134 // Reuse the nextSibling pointer for this purpose. |
132 if (tail) | 135 if (tail) |
133 tail->setNextSibling(n); | 136 tail->setNextSibling(n); |
134 else | 137 else |
135 head = n; | 138 head = n; |
136 | 139 |
137 tail = n; | 140 tail = n; |
138 } else { | 141 } else { |
139 RefPtr<GenericNode> protect(n); // removedFromDocument may remov
e remove all references to this node. | 142 RefPtr<GenericNode> protect(n); // removedFromDocument may remov
e remove all references to this node. |
140 NodeRemovalDispatcher<GenericNode, ShouldDispatchRemovalNotifica
tion<GenericNode>::value>::dispatch(n); | 143 NodeRemovalDispatcher<GenericNode, GenericNodeContainer, ShouldD
ispatchRemovalNotification<GenericNode>::value>::dispatch(n, container); |
141 } | 144 } |
142 } | 145 } |
143 | 146 |
144 container->setFirstChild(0); | 147 container->setFirstChild(0); |
145 container->setLastChild(0); | 148 container->setLastChild(0); |
146 } | 149 } |
147 }; | 150 }; |
148 | 151 |
149 } // namespace WebCore | 152 } // namespace WebCore |
150 | 153 |
151 #endif // ContainerNodeAlgorithms_h | 154 #endif // ContainerNodeAlgorithms_h |
OLD | NEW |