OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006 Apple Inc. All rights reserved. |
3 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> | 3 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> |
4 * Copyright (C) 2007 Rob Buis <buis@kde.org> | 4 * Copyright (C) 2007 Rob Buis <buis@kde.org> |
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 { | 52 { |
53 m_timeContainers.remove(element); | 53 m_timeContainers.remove(element); |
54 } | 54 } |
55 | 55 |
56 void SVGDocumentExtensions::addWebAnimationsPendingSVGElement(SVGElement& elemen
t) | 56 void SVGDocumentExtensions::addWebAnimationsPendingSVGElement(SVGElement& elemen
t) |
57 { | 57 { |
58 ASSERT(RuntimeEnabledFeatures::webAnimationsSVGEnabled()); | 58 ASSERT(RuntimeEnabledFeatures::webAnimationsSVGEnabled()); |
59 m_webAnimationsPendingSVGElements.add(&element); | 59 m_webAnimationsPendingSVGElements.add(&element); |
60 } | 60 } |
61 | 61 |
62 void SVGDocumentExtensions::addResource(const AtomicString& id, LayoutSVGResourc
eContainer* resource) | |
63 { | |
64 ASSERT(resource); | |
65 | |
66 if (id.isEmpty()) | |
67 return; | |
68 | |
69 // Replaces resource if already present, to handle potential id changes | |
70 m_resources.set(id, resource); | |
71 } | |
72 | |
73 void SVGDocumentExtensions::removeResource(const AtomicString& id) | |
74 { | |
75 if (id.isEmpty()) | |
76 return; | |
77 | |
78 m_resources.remove(id); | |
79 } | |
80 | |
81 LayoutSVGResourceContainer* SVGDocumentExtensions::resourceById(const AtomicStri
ng& id) const | |
82 { | |
83 if (id.isEmpty()) | |
84 return nullptr; | |
85 | |
86 return m_resources.get(id); | |
87 } | |
88 | |
89 void SVGDocumentExtensions::serviceOnAnimationFrame(Document& document) | 62 void SVGDocumentExtensions::serviceOnAnimationFrame(Document& document) |
90 { | 63 { |
91 if (!document.svgExtensions()) | 64 if (!document.svgExtensions()) |
92 return; | 65 return; |
93 document.accessSVGExtensions().serviceAnimations(); | 66 document.accessSVGExtensions().serviceAnimations(); |
94 } | 67 } |
95 | 68 |
96 void SVGDocumentExtensions::serviceAnimations() | 69 void SVGDocumentExtensions::serviceAnimations() |
97 { | 70 { |
98 if (RuntimeEnabledFeatures::smilEnabled()) { | 71 if (RuntimeEnabledFeatures::smilEnabled()) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 outerSVG->sendSVGLoadEventIfPossible(); | 120 outerSVG->sendSVGLoadEventIfPossible(); |
148 } | 121 } |
149 } | 122 } |
150 | 123 |
151 void SVGDocumentExtensions::reportError(const String& message) | 124 void SVGDocumentExtensions::reportError(const String& message) |
152 { | 125 { |
153 ConsoleMessage* consoleMessage = ConsoleMessage::create(RenderingMessageSour
ce, ErrorMessageLevel, "Error: " + message); | 126 ConsoleMessage* consoleMessage = ConsoleMessage::create(RenderingMessageSour
ce, ErrorMessageLevel, "Error: " + message); |
154 m_document->addConsoleMessage(consoleMessage); | 127 m_document->addConsoleMessage(consoleMessage); |
155 } | 128 } |
156 | 129 |
157 void SVGDocumentExtensions::addPendingResource(const AtomicString& id, Element*
element) | |
158 { | |
159 ASSERT(element); | |
160 ASSERT(element->inShadowIncludingDocument()); | |
161 | |
162 if (id.isEmpty()) | |
163 return; | |
164 | |
165 HeapHashMap<AtomicString, Member<SVGPendingElements>>::AddResult result = m_
pendingResources.add(id, nullptr); | |
166 if (result.isNewEntry) | |
167 result.storedValue->value = new SVGPendingElements; | |
168 result.storedValue->value->add(element); | |
169 | |
170 element->setHasPendingResources(); | |
171 } | |
172 | |
173 bool SVGDocumentExtensions::hasPendingResource(const AtomicString& id) const | |
174 { | |
175 if (id.isEmpty()) | |
176 return false; | |
177 | |
178 return m_pendingResources.contains(id); | |
179 } | |
180 | |
181 bool SVGDocumentExtensions::isElementPendingResources(Element* element) const | |
182 { | |
183 // This algorithm takes time proportional to the number of pending resources
and need not. | |
184 // If performance becomes an issue we can keep a counted set of elements and
answer the question efficiently. | |
185 | |
186 ASSERT(element); | |
187 | |
188 for (const auto& entry : m_pendingResources) { | |
189 SVGPendingElements* elements = entry.value.get(); | |
190 ASSERT(elements); | |
191 | |
192 if (elements->contains(element)) | |
193 return true; | |
194 } | |
195 return false; | |
196 } | |
197 | |
198 bool SVGDocumentExtensions::isElementPendingResource(Element* element, const Ato
micString& id) const | |
199 { | |
200 ASSERT(element); | |
201 | |
202 if (!hasPendingResource(id)) | |
203 return false; | |
204 | |
205 return m_pendingResources.get(id)->contains(element); | |
206 } | |
207 | |
208 void SVGDocumentExtensions::clearHasPendingResourcesIfPossible(Element* element) | |
209 { | |
210 if (!isElementPendingResources(element)) | |
211 element->clearHasPendingResources(); | |
212 } | |
213 | |
214 void SVGDocumentExtensions::removeElementFromPendingResources(Element* element) | |
215 { | |
216 ASSERT(element); | |
217 | |
218 // Remove the element from pending resources. | |
219 if (!m_pendingResources.isEmpty() && element->hasPendingResources()) { | |
220 Vector<AtomicString> toBeRemoved; | |
221 for (const auto& entry : m_pendingResources) { | |
222 SVGPendingElements* elements = entry.value.get(); | |
223 ASSERT(elements); | |
224 ASSERT(!elements->isEmpty()); | |
225 | |
226 elements->remove(element); | |
227 if (elements->isEmpty()) | |
228 toBeRemoved.append(entry.key); | |
229 } | |
230 | |
231 clearHasPendingResourcesIfPossible(element); | |
232 | |
233 // We use the removePendingResource function here because it deals with
set lifetime correctly. | |
234 for (const AtomicString& id : toBeRemoved) | |
235 removePendingResource(id); | |
236 } | |
237 | |
238 // Remove the element from pending resources that were scheduled for removal
. | |
239 if (!m_pendingResourcesForRemoval.isEmpty()) { | |
240 Vector<AtomicString> toBeRemoved; | |
241 for (const auto& entry : m_pendingResourcesForRemoval) { | |
242 SVGPendingElements* elements = entry.value.get(); | |
243 ASSERT(elements); | |
244 ASSERT(!elements->isEmpty()); | |
245 | |
246 elements->remove(element); | |
247 if (elements->isEmpty()) | |
248 toBeRemoved.append(entry.key); | |
249 } | |
250 | |
251 // We use the removePendingResourceForRemoval function here because it d
eals with set lifetime correctly. | |
252 for (const AtomicString& id : toBeRemoved) | |
253 removePendingResourceForRemoval(id); | |
254 } | |
255 } | |
256 | |
257 SVGDocumentExtensions::SVGPendingElements* SVGDocumentExtensions::removePendingR
esource(const AtomicString& id) | |
258 { | |
259 ASSERT(m_pendingResources.contains(id)); | |
260 return m_pendingResources.take(id); | |
261 } | |
262 | |
263 SVGDocumentExtensions::SVGPendingElements* SVGDocumentExtensions::removePendingR
esourceForRemoval(const AtomicString& id) | |
264 { | |
265 ASSERT(m_pendingResourcesForRemoval.contains(id)); | |
266 return m_pendingResourcesForRemoval.take(id); | |
267 } | |
268 | |
269 void SVGDocumentExtensions::markPendingResourcesForRemoval(const AtomicString& i
d) | |
270 { | |
271 if (id.isEmpty()) | |
272 return; | |
273 | |
274 ASSERT(!m_pendingResourcesForRemoval.contains(id)); | |
275 | |
276 Member<SVGPendingElements> existing = m_pendingResources.take(id); | |
277 if (existing && !existing->isEmpty()) | |
278 m_pendingResourcesForRemoval.add(id, existing.release()); | |
279 } | |
280 | |
281 Element* SVGDocumentExtensions::removeElementFromPendingResourcesForRemoval(cons
t AtomicString& id) | |
282 { | |
283 if (id.isEmpty()) | |
284 return nullptr; | |
285 | |
286 SVGPendingElements* resourceSet = m_pendingResourcesForRemoval.get(id); | |
287 if (!resourceSet || resourceSet->isEmpty()) | |
288 return nullptr; | |
289 | |
290 SVGPendingElements::iterator firstElement = resourceSet->begin(); | |
291 Element* element = *firstElement; | |
292 | |
293 resourceSet->remove(firstElement); | |
294 | |
295 if (resourceSet->isEmpty()) | |
296 removePendingResourceForRemoval(id); | |
297 | |
298 return element; | |
299 } | |
300 | |
301 void SVGDocumentExtensions::addSVGRootWithRelativeLengthDescendents(SVGSVGElemen
t* svgRoot) | 130 void SVGDocumentExtensions::addSVGRootWithRelativeLengthDescendents(SVGSVGElemen
t* svgRoot) |
302 { | 131 { |
303 ASSERT(!m_inRelativeLengthSVGRootsInvalidation); | 132 ASSERT(!m_inRelativeLengthSVGRootsInvalidation); |
304 m_relativeLengthSVGRoots.add(svgRoot); | 133 m_relativeLengthSVGRoots.add(svgRoot); |
305 } | 134 } |
306 | 135 |
307 void SVGDocumentExtensions::removeSVGRootWithRelativeLengthDescendents(SVGSVGEle
ment* svgRoot) | 136 void SVGDocumentExtensions::removeSVGRootWithRelativeLengthDescendents(SVGSVGEle
ment* svgRoot) |
308 { | 137 { |
309 ASSERT(!m_inRelativeLengthSVGRootsInvalidation); | 138 ASSERT(!m_inRelativeLengthSVGRootsInvalidation); |
310 m_relativeLengthSVGRoots.remove(svgRoot); | 139 m_relativeLengthSVGRoots.remove(svgRoot); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 ASSERT(m_document); | 185 ASSERT(m_document); |
357 return rootElement(*m_document); | 186 return rootElement(*m_document); |
358 } | 187 } |
359 | 188 |
360 DEFINE_TRACE(SVGDocumentExtensions) | 189 DEFINE_TRACE(SVGDocumentExtensions) |
361 { | 190 { |
362 visitor->trace(m_document); | 191 visitor->trace(m_document); |
363 visitor->trace(m_timeContainers); | 192 visitor->trace(m_timeContainers); |
364 visitor->trace(m_webAnimationsPendingSVGElements); | 193 visitor->trace(m_webAnimationsPendingSVGElements); |
365 visitor->trace(m_relativeLengthSVGRoots); | 194 visitor->trace(m_relativeLengthSVGRoots); |
366 visitor->trace(m_pendingResources); | |
367 visitor->trace(m_pendingResourcesForRemoval); | |
368 } | 195 } |
369 | 196 |
370 } // namespace blink | 197 } // namespace blink |
OLD | NEW |