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 * |
11 * This library is distributed in the hope that it will be useful, | 11 * This library is distributed in the hope that it will be useful, |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 * Library General Public License for more details. | 14 * Library General Public License for more details. |
15 * | 15 * |
16 * You should have received a copy of the GNU Library General Public License | 16 * You should have received a copy of the GNU Library General Public License |
17 * along with this library; see the file COPYING.LIB. If not, write to | 17 * along with this library; see the file COPYING.LIB. If not, write to |
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 * Boston, MA 02110-1301, USA. | 19 * Boston, MA 02110-1301, USA. |
20 */ | 20 */ |
21 | 21 |
22 #include "core/svg/SVGDocumentExtensions.h" | 22 #include "core/svg/SVGDocumentExtensions.h" |
23 | 23 |
24 #include "core/dom/Document.h" | 24 #include "core/dom/Document.h" |
25 #include "core/inspector/ConsoleMessage.h" | 25 #include "core/inspector/ConsoleMessage.h" |
26 #include "core/layout/svg/LayoutSVGResourceContainer.h" | |
27 #include "core/svg/SVGSVGElement.h" | 26 #include "core/svg/SVGSVGElement.h" |
28 #include "core/svg/animation/SMILTimeContainer.h" | 27 #include "core/svg/animation/SMILTimeContainer.h" |
29 #include "wtf/AutoReset.h" | 28 #include "wtf/AutoReset.h" |
30 #include "wtf/text/AtomicString.h" | |
31 | 29 |
32 namespace blink { | 30 namespace blink { |
33 | 31 |
34 SVGDocumentExtensions::SVGDocumentExtensions(Document* document) | 32 SVGDocumentExtensions::SVGDocumentExtensions(Document* document) |
35 : m_document(document) | 33 : m_document(document) |
36 { | 34 { |
37 } | 35 } |
38 | 36 |
39 SVGDocumentExtensions::~SVGDocumentExtensions() {} | 37 SVGDocumentExtensions::~SVGDocumentExtensions() {} |
40 | 38 |
41 void SVGDocumentExtensions::addTimeContainer(SVGSVGElement* element) { | 39 void SVGDocumentExtensions::addTimeContainer(SVGSVGElement* element) { |
42 m_timeContainers.add(element); | 40 m_timeContainers.add(element); |
43 } | 41 } |
44 | 42 |
45 void SVGDocumentExtensions::removeTimeContainer(SVGSVGElement* element) { | 43 void SVGDocumentExtensions::removeTimeContainer(SVGSVGElement* element) { |
46 m_timeContainers.remove(element); | 44 m_timeContainers.remove(element); |
47 } | 45 } |
48 | 46 |
49 void SVGDocumentExtensions::addWebAnimationsPendingSVGElement( | 47 void SVGDocumentExtensions::addWebAnimationsPendingSVGElement( |
50 SVGElement& element) { | 48 SVGElement& element) { |
51 ASSERT(RuntimeEnabledFeatures::webAnimationsSVGEnabled()); | 49 ASSERT(RuntimeEnabledFeatures::webAnimationsSVGEnabled()); |
52 m_webAnimationsPendingSVGElements.add(&element); | 50 m_webAnimationsPendingSVGElements.add(&element); |
53 } | 51 } |
54 | 52 |
55 void SVGDocumentExtensions::addResource(const AtomicString& id, | |
56 LayoutSVGResourceContainer* resource) { | |
57 ASSERT(resource); | |
58 | |
59 if (id.isEmpty()) | |
60 return; | |
61 | |
62 // Replaces resource if already present, to handle potential id changes | |
63 m_resources.set(id, resource); | |
64 } | |
65 | |
66 void SVGDocumentExtensions::removeResource(const AtomicString& id) { | |
67 if (id.isEmpty()) | |
68 return; | |
69 | |
70 m_resources.remove(id); | |
71 } | |
72 | |
73 LayoutSVGResourceContainer* SVGDocumentExtensions::resourceById( | |
74 const AtomicString& id) const { | |
75 if (id.isEmpty()) | |
76 return nullptr; | |
77 | |
78 return m_resources.get(id); | |
79 } | |
80 | |
81 void SVGDocumentExtensions::serviceOnAnimationFrame(Document& document) { | 53 void SVGDocumentExtensions::serviceOnAnimationFrame(Document& document) { |
82 if (!document.svgExtensions()) | 54 if (!document.svgExtensions()) |
83 return; | 55 return; |
84 document.accessSVGExtensions().serviceAnimations(); | 56 document.accessSVGExtensions().serviceAnimations(); |
85 } | 57 } |
86 | 58 |
87 void SVGDocumentExtensions::serviceAnimations() { | 59 void SVGDocumentExtensions::serviceAnimations() { |
88 if (RuntimeEnabledFeatures::smilEnabled()) { | 60 if (RuntimeEnabledFeatures::smilEnabled()) { |
89 HeapVector<Member<SVGSVGElement>> timeContainers; | 61 HeapVector<Member<SVGSVGElement>> timeContainers; |
90 copyToVector(m_timeContainers, timeContainers); | 62 copyToVector(m_timeContainers, timeContainers); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 outerSVG->sendSVGLoadEventIfPossible(); | 112 outerSVG->sendSVGLoadEventIfPossible(); |
141 } | 113 } |
142 } | 114 } |
143 | 115 |
144 void SVGDocumentExtensions::reportError(const String& message) { | 116 void SVGDocumentExtensions::reportError(const String& message) { |
145 ConsoleMessage* consoleMessage = ConsoleMessage::create( | 117 ConsoleMessage* consoleMessage = ConsoleMessage::create( |
146 RenderingMessageSource, ErrorMessageLevel, "Error: " + message); | 118 RenderingMessageSource, ErrorMessageLevel, "Error: " + message); |
147 m_document->addConsoleMessage(consoleMessage); | 119 m_document->addConsoleMessage(consoleMessage); |
148 } | 120 } |
149 | 121 |
150 void SVGDocumentExtensions::addPendingResource(const AtomicString& id, | |
151 Element* element) { | |
152 ASSERT(element); | |
153 ASSERT(element->isConnected()); | |
154 | |
155 if (id.isEmpty()) | |
156 return; | |
157 | |
158 HeapHashMap<AtomicString, Member<SVGPendingElements>>::AddResult result = | |
159 m_pendingResources.add(id, nullptr); | |
160 if (result.isNewEntry) | |
161 result.storedValue->value = new SVGPendingElements; | |
162 result.storedValue->value->add(element); | |
163 | |
164 element->setHasPendingResources(); | |
165 } | |
166 | |
167 bool SVGDocumentExtensions::hasPendingResource(const AtomicString& id) const { | |
168 if (id.isEmpty()) | |
169 return false; | |
170 | |
171 return m_pendingResources.contains(id); | |
172 } | |
173 | |
174 bool SVGDocumentExtensions::isElementPendingResources(Element* element) const { | |
175 // This algorithm takes time proportional to the number of pending resources | |
176 // and need not. If performance becomes an issue we can keep a counted set of | |
177 // elements and answer the question efficiently. | |
178 | |
179 ASSERT(element); | |
180 | |
181 for (const auto& entry : m_pendingResources) { | |
182 SVGPendingElements* elements = entry.value.get(); | |
183 ASSERT(elements); | |
184 | |
185 if (elements->contains(element)) | |
186 return true; | |
187 } | |
188 return false; | |
189 } | |
190 | |
191 bool SVGDocumentExtensions::isElementPendingResource( | |
192 Element* element, | |
193 const AtomicString& id) const { | |
194 ASSERT(element); | |
195 | |
196 if (!hasPendingResource(id)) | |
197 return false; | |
198 | |
199 return m_pendingResources.get(id)->contains(element); | |
200 } | |
201 | |
202 void SVGDocumentExtensions::clearHasPendingResourcesIfPossible( | |
203 Element* element) { | |
204 if (!isElementPendingResources(element)) | |
205 element->clearHasPendingResources(); | |
206 } | |
207 | |
208 void SVGDocumentExtensions::removeElementFromPendingResources( | |
209 Element* element) { | |
210 DCHECK(element); | |
211 | |
212 // Remove the element from pending resources. | |
213 if (m_pendingResources.isEmpty() || !element->hasPendingResources()) | |
214 return; | |
215 | |
216 Vector<AtomicString> toBeRemoved; | |
217 for (const auto& entry : m_pendingResources) { | |
218 SVGPendingElements* elements = entry.value.get(); | |
219 DCHECK(elements); | |
220 DCHECK(!elements->isEmpty()); | |
221 | |
222 elements->remove(element); | |
223 if (elements->isEmpty()) | |
224 toBeRemoved.push_back(entry.key); | |
225 } | |
226 | |
227 clearHasPendingResourcesIfPossible(element); | |
228 | |
229 m_pendingResources.removeAll(toBeRemoved); | |
230 } | |
231 | |
232 SVGDocumentExtensions::SVGPendingElements* | |
233 SVGDocumentExtensions::removePendingResource(const AtomicString& id) { | |
234 ASSERT(m_pendingResources.contains(id)); | |
235 return m_pendingResources.take(id); | |
236 } | |
237 | |
238 void SVGDocumentExtensions::addSVGRootWithRelativeLengthDescendents( | 122 void SVGDocumentExtensions::addSVGRootWithRelativeLengthDescendents( |
239 SVGSVGElement* svgRoot) { | 123 SVGSVGElement* svgRoot) { |
240 ASSERT(!m_inRelativeLengthSVGRootsInvalidation); | 124 ASSERT(!m_inRelativeLengthSVGRootsInvalidation); |
241 m_relativeLengthSVGRoots.add(svgRoot); | 125 m_relativeLengthSVGRoots.add(svgRoot); |
242 } | 126 } |
243 | 127 |
244 void SVGDocumentExtensions::removeSVGRootWithRelativeLengthDescendents( | 128 void SVGDocumentExtensions::removeSVGRootWithRelativeLengthDescendents( |
245 SVGSVGElement* svgRoot) { | 129 SVGSVGElement* svgRoot) { |
246 ASSERT(!m_inRelativeLengthSVGRootsInvalidation); | 130 ASSERT(!m_inRelativeLengthSVGRootsInvalidation); |
247 m_relativeLengthSVGRoots.remove(svgRoot); | 131 m_relativeLengthSVGRoots.remove(svgRoot); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 SVGSVGElement* SVGDocumentExtensions::rootElement() const { | 174 SVGSVGElement* SVGDocumentExtensions::rootElement() const { |
291 ASSERT(m_document); | 175 ASSERT(m_document); |
292 return rootElement(*m_document); | 176 return rootElement(*m_document); |
293 } | 177 } |
294 | 178 |
295 DEFINE_TRACE(SVGDocumentExtensions) { | 179 DEFINE_TRACE(SVGDocumentExtensions) { |
296 visitor->trace(m_document); | 180 visitor->trace(m_document); |
297 visitor->trace(m_timeContainers); | 181 visitor->trace(m_timeContainers); |
298 visitor->trace(m_webAnimationsPendingSVGElements); | 182 visitor->trace(m_webAnimationsPendingSVGElements); |
299 visitor->trace(m_relativeLengthSVGRoots); | 183 visitor->trace(m_relativeLengthSVGRoots); |
300 visitor->trace(m_pendingResources); | |
301 } | 184 } |
302 | 185 |
303 } // namespace blink | 186 } // namespace blink |
OLD | NEW |