OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> |
3 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 3 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
4 * Copyright (C) 2011 Torch Mobile (Beijing) Co. Ltd. All rights reserved. | 4 * Copyright (C) 2011 Torch Mobile (Beijing) Co. Ltd. All rights reserved. |
5 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
10 * | 10 * |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 , m_element(originalElement) | 92 , m_element(originalElement) |
93 , m_previousSibling(0) | 93 , m_previousSibling(0) |
94 , m_nextSibling(0) | 94 , m_nextSibling(0) |
95 , m_firstChild(0) | 95 , m_firstChild(0) |
96 , m_lastChild(0) | 96 , m_lastChild(0) |
97 { | 97 { |
98 ASSERT(m_correspondingUseElement); | 98 ASSERT(m_correspondingUseElement); |
99 ASSERT(m_element); | 99 ASSERT(m_element); |
100 ScriptWrappable::init(this); | 100 ScriptWrappable::init(this); |
101 | 101 |
102 // Register as instance for passed element. | |
103 m_element->mapInstanceToElement(this); | |
104 | |
105 #ifndef NDEBUG | 102 #ifndef NDEBUG |
106 instanceCounter.increment(); | 103 instanceCounter.increment(); |
107 #endif | 104 #endif |
108 } | 105 } |
109 | 106 |
110 SVGElementInstance::~SVGElementInstance() | 107 SVGElementInstance::~SVGElementInstance() |
111 { | 108 { |
112 // Call detach because we may be deleted directly if we are a child of a det
ached instance. | 109 // Call detach because we may be deleted directly if we are a child of a det
ached instance. |
113 detach(); | 110 detach(); |
114 | 111 |
(...skipping 18 matching lines...) Expand all Loading... |
133 | 130 |
134 void SVGElementInstance::detach() | 131 void SVGElementInstance::detach() |
135 { | 132 { |
136 // Clear all pointers. When the node is detached from the shadow DOM it shou
ld be removed but, | 133 // Clear all pointers. When the node is detached from the shadow DOM it shou
ld be removed but, |
137 // due to ref counting, it may not be. So clear everything to avoid dangling
pointers. | 134 // due to ref counting, it may not be. So clear everything to avoid dangling
pointers. |
138 | 135 |
139 for (SVGElementInstance* node = firstChild(); node; node = node->nextSibling
()) | 136 for (SVGElementInstance* node = firstChild(); node; node = node->nextSibling
()) |
140 node->detach(); | 137 node->detach(); |
141 | 138 |
142 // Deregister as instance for passed element, if we haven't already. | 139 // Deregister as instance for passed element, if we haven't already. |
143 if (m_element->instancesForElement().contains(this)) | 140 if (m_element->instancesForElement().contains(shadowTreeElement())) |
144 m_element->removeInstanceMapping(this); | 141 m_element->removeInstanceMapping(this); |
145 // DO NOT clear ref to m_element because JavaScriptCore uses it for garbage
collection | 142 // DO NOT clear ref to m_element because JavaScriptCore uses it for garbage
collection |
146 | 143 |
147 m_shadowTreeElement = nullptr; | 144 m_shadowTreeElement = nullptr; |
148 | 145 |
149 m_directUseElement = 0; | 146 m_directUseElement = 0; |
150 m_correspondingUseElement = 0; | 147 m_correspondingUseElement = 0; |
151 | 148 |
152 removeDetachedChildrenInContainer<SVGElementInstance, SVGElementInstance>(*t
his); | 149 removeDetachedChildrenInContainer<SVGElementInstance, SVGElementInstance>(*t
his); |
153 } | 150 } |
154 | 151 |
155 void SVGElementInstance::setShadowTreeElement(SVGElement* element) | 152 void SVGElementInstance::setShadowTreeElement(SVGElement* element) |
156 { | 153 { |
157 ASSERT(element); | 154 ASSERT(element); |
158 m_shadowTreeElement = element; | 155 m_shadowTreeElement = element; |
| 156 // Register as instance for passed element. |
| 157 m_element->mapInstanceToElement(this); |
| 158 |
159 } | 159 } |
160 | 160 |
161 void SVGElementInstance::appendChild(PassRefPtr<SVGElementInstance> child) | 161 void SVGElementInstance::appendChild(PassRefPtr<SVGElementInstance> child) |
162 { | 162 { |
163 appendChildToContainer<SVGElementInstance, SVGElementInstance>(*child, *this
); | 163 appendChildToContainer<SVGElementInstance, SVGElementInstance>(*child, *this
); |
164 } | 164 } |
165 | 165 |
166 void SVGElementInstance::invalidateAllInstancesOfElement(SVGElement* element) | 166 void SVGElementInstance::invalidateAllInstancesOfElement(SVGElement* element) |
167 { | 167 { |
168 if (!element || !element->inDocument()) | 168 if (!element || !element->inDocument()) |
169 return; | 169 return; |
170 | 170 |
171 if (element->instanceUpdatesBlocked()) | 171 if (element->instanceUpdatesBlocked()) |
172 return; | 172 return; |
173 | 173 |
174 const HashSet<SVGElementInstance*>& set = element->instancesForElement(); | 174 const HashSet<SVGElement*>& set = element->instancesForElement(); |
175 if (set.isEmpty()) | 175 if (set.isEmpty()) |
176 return; | 176 return; |
177 | 177 |
178 // Mark all use elements referencing 'element' for rebuilding | 178 // Mark all use elements referencing 'element' for rebuilding |
179 const HashSet<SVGElementInstance*>::const_iterator end = set.end(); | 179 const HashSet<SVGElement*>::const_iterator end = set.end(); |
180 for (HashSet<SVGElementInstance*>::const_iterator it = set.begin(); it != en
d; ++it) { | 180 for (HashSet<SVGElement*>::const_iterator it = set.begin(); it != end; ++it)
{ |
181 ASSERT((*it)->shadowTreeElement()); | 181 (*it)->setCorrespondingElement(0); |
182 ASSERT((*it)->shadowTreeElement()->correspondingElement()); | |
183 ASSERT((*it)->shadowTreeElement()->correspondingElement() == (*it)->corr
espondingElement()); | |
184 ASSERT((*it)->correspondingElement() == element); | |
185 (*it)->shadowTreeElement()->setCorrespondingElement(0); | |
186 | 182 |
187 if (SVGUseElement* element = (*it)->correspondingUseElement()) { | 183 if (SVGUseElement* element = (*it)->correspondingUseElement()) { |
188 ASSERT(element->inDocument()); | 184 ASSERT(element->inDocument()); |
189 element->invalidateShadowTree(); | 185 element->invalidateShadowTree(); |
190 } | 186 } |
191 } | 187 } |
192 | 188 |
193 element->document().updateRenderTreeIfNeeded(); | 189 element->document().updateRenderTreeIfNeeded(); |
194 } | 190 } |
195 | 191 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 m_targetElement->setInstanceUpdatesBlocked(true); | 254 m_targetElement->setInstanceUpdatesBlocked(true); |
259 } | 255 } |
260 | 256 |
261 SVGElementInstance::InstanceUpdateBlocker::~InstanceUpdateBlocker() | 257 SVGElementInstance::InstanceUpdateBlocker::~InstanceUpdateBlocker() |
262 { | 258 { |
263 if (m_targetElement) | 259 if (m_targetElement) |
264 m_targetElement->setInstanceUpdatesBlocked(false); | 260 m_targetElement->setInstanceUpdatesBlocked(false); |
265 } | 261 } |
266 | 262 |
267 } | 263 } |
OLD | NEW |