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

Side by Side Diff: third_party/WebKit/Source/core/svg/SVGDocumentExtensions.cpp

Issue 2633143002: SVG objects with same idrefs conflict when under different shadow root (Closed)
Patch Set: Tests Created 3 years, 11 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
OLDNEW
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 #if ENABLE(ASSERT) 34 #if ENABLE(ASSERT)
37 , 35 ,
38 m_inRelativeLengthSVGRootsInvalidation(false) 36 m_inRelativeLengthSVGRootsInvalidation(false)
39 #endif 37 #endif
40 { 38 {
41 } 39 }
42 40
43 SVGDocumentExtensions::~SVGDocumentExtensions() {} 41 SVGDocumentExtensions::~SVGDocumentExtensions() {}
44 42
45 void SVGDocumentExtensions::addTimeContainer(SVGSVGElement* element) { 43 void SVGDocumentExtensions::addTimeContainer(SVGSVGElement* element) {
46 m_timeContainers.add(element); 44 m_timeContainers.add(element);
47 } 45 }
48 46
49 void SVGDocumentExtensions::removeTimeContainer(SVGSVGElement* element) { 47 void SVGDocumentExtensions::removeTimeContainer(SVGSVGElement* element) {
50 m_timeContainers.remove(element); 48 m_timeContainers.remove(element);
51 } 49 }
52 50
53 void SVGDocumentExtensions::addWebAnimationsPendingSVGElement( 51 void SVGDocumentExtensions::addWebAnimationsPendingSVGElement(
54 SVGElement& element) { 52 SVGElement& element) {
55 ASSERT(RuntimeEnabledFeatures::webAnimationsSVGEnabled()); 53 ASSERT(RuntimeEnabledFeatures::webAnimationsSVGEnabled());
56 m_webAnimationsPendingSVGElements.add(&element); 54 m_webAnimationsPendingSVGElements.add(&element);
57 } 55 }
58 56
59 void SVGDocumentExtensions::addResource(const AtomicString& id,
60 LayoutSVGResourceContainer* resource) {
61 ASSERT(resource);
62
63 if (id.isEmpty())
64 return;
65
66 // Replaces resource if already present, to handle potential id changes
67 m_resources.set(id, resource);
68 }
69
70 void SVGDocumentExtensions::removeResource(const AtomicString& id) {
71 if (id.isEmpty())
72 return;
73
74 m_resources.remove(id);
75 }
76
77 LayoutSVGResourceContainer* SVGDocumentExtensions::resourceById(
78 const AtomicString& id) const {
79 if (id.isEmpty())
80 return nullptr;
81
82 return m_resources.get(id);
83 }
84
85 void SVGDocumentExtensions::serviceOnAnimationFrame(Document& document) { 57 void SVGDocumentExtensions::serviceOnAnimationFrame(Document& document) {
86 if (!document.svgExtensions()) 58 if (!document.svgExtensions())
87 return; 59 return;
88 document.accessSVGExtensions().serviceAnimations(); 60 document.accessSVGExtensions().serviceAnimations();
89 } 61 }
90 62
91 void SVGDocumentExtensions::serviceAnimations() { 63 void SVGDocumentExtensions::serviceAnimations() {
92 if (RuntimeEnabledFeatures::smilEnabled()) { 64 if (RuntimeEnabledFeatures::smilEnabled()) {
93 HeapVector<Member<SVGSVGElement>> timeContainers; 65 HeapVector<Member<SVGSVGElement>> timeContainers;
94 copyToVector(m_timeContainers, timeContainers); 66 copyToVector(m_timeContainers, timeContainers);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 outerSVG->sendSVGLoadEventIfPossible(); 116 outerSVG->sendSVGLoadEventIfPossible();
145 } 117 }
146 } 118 }
147 119
148 void SVGDocumentExtensions::reportError(const String& message) { 120 void SVGDocumentExtensions::reportError(const String& message) {
149 ConsoleMessage* consoleMessage = ConsoleMessage::create( 121 ConsoleMessage* consoleMessage = ConsoleMessage::create(
150 RenderingMessageSource, ErrorMessageLevel, "Error: " + message); 122 RenderingMessageSource, ErrorMessageLevel, "Error: " + message);
151 m_document->addConsoleMessage(consoleMessage); 123 m_document->addConsoleMessage(consoleMessage);
152 } 124 }
153 125
154 void SVGDocumentExtensions::addPendingResource(const AtomicString& id,
155 Element* element) {
156 ASSERT(element);
157 ASSERT(element->isConnected());
158
159 if (id.isEmpty())
160 return;
161
162 HeapHashMap<AtomicString, Member<SVGPendingElements>>::AddResult result =
163 m_pendingResources.add(id, nullptr);
164 if (result.isNewEntry)
165 result.storedValue->value = new SVGPendingElements;
166 result.storedValue->value->add(element);
167
168 element->setHasPendingResources();
169 }
170
171 bool SVGDocumentExtensions::hasPendingResource(const AtomicString& id) const {
172 if (id.isEmpty())
173 return false;
174
175 return m_pendingResources.contains(id);
176 }
177
178 bool SVGDocumentExtensions::isElementPendingResources(Element* element) const {
179 // This algorithm takes time proportional to the number of pending resources
180 // and need not. If performance becomes an issue we can keep a counted set of
181 // elements and answer the question efficiently.
182
183 ASSERT(element);
184
185 for (const auto& entry : m_pendingResources) {
186 SVGPendingElements* elements = entry.value.get();
187 ASSERT(elements);
188
189 if (elements->contains(element))
190 return true;
191 }
192 return false;
193 }
194
195 bool SVGDocumentExtensions::isElementPendingResource(
196 Element* element,
197 const AtomicString& id) const {
198 ASSERT(element);
199
200 if (!hasPendingResource(id))
201 return false;
202
203 return m_pendingResources.get(id)->contains(element);
204 }
205
206 void SVGDocumentExtensions::clearHasPendingResourcesIfPossible(
207 Element* element) {
208 if (!isElementPendingResources(element))
209 element->clearHasPendingResources();
210 }
211
212 void SVGDocumentExtensions::removeElementFromPendingResources(
213 Element* element) {
214 DCHECK(element);
215
216 // Remove the element from pending resources.
217 if (m_pendingResources.isEmpty() || !element->hasPendingResources())
218 return;
219
220 Vector<AtomicString> toBeRemoved;
221 for (const auto& entry : m_pendingResources) {
222 SVGPendingElements* elements = entry.value.get();
223 DCHECK(elements);
224 DCHECK(!elements->isEmpty());
225
226 elements->remove(element);
227 if (elements->isEmpty())
228 toBeRemoved.push_back(entry.key);
229 }
230
231 clearHasPendingResourcesIfPossible(element);
232
233 m_pendingResources.removeAll(toBeRemoved);
234 }
235
236 SVGDocumentExtensions::SVGPendingElements*
237 SVGDocumentExtensions::removePendingResource(const AtomicString& id) {
238 ASSERT(m_pendingResources.contains(id));
239 return m_pendingResources.take(id);
240 }
241
242 void SVGDocumentExtensions::addSVGRootWithRelativeLengthDescendents( 126 void SVGDocumentExtensions::addSVGRootWithRelativeLengthDescendents(
243 SVGSVGElement* svgRoot) { 127 SVGSVGElement* svgRoot) {
244 ASSERT(!m_inRelativeLengthSVGRootsInvalidation); 128 ASSERT(!m_inRelativeLengthSVGRootsInvalidation);
245 m_relativeLengthSVGRoots.add(svgRoot); 129 m_relativeLengthSVGRoots.add(svgRoot);
246 } 130 }
247 131
248 void SVGDocumentExtensions::removeSVGRootWithRelativeLengthDescendents( 132 void SVGDocumentExtensions::removeSVGRootWithRelativeLengthDescendents(
249 SVGSVGElement* svgRoot) { 133 SVGSVGElement* svgRoot) {
250 ASSERT(!m_inRelativeLengthSVGRootsInvalidation); 134 ASSERT(!m_inRelativeLengthSVGRootsInvalidation);
251 m_relativeLengthSVGRoots.remove(svgRoot); 135 m_relativeLengthSVGRoots.remove(svgRoot);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 SVGSVGElement* SVGDocumentExtensions::rootElement() const { 178 SVGSVGElement* SVGDocumentExtensions::rootElement() const {
295 ASSERT(m_document); 179 ASSERT(m_document);
296 return rootElement(*m_document); 180 return rootElement(*m_document);
297 } 181 }
298 182
299 DEFINE_TRACE(SVGDocumentExtensions) { 183 DEFINE_TRACE(SVGDocumentExtensions) {
300 visitor->trace(m_document); 184 visitor->trace(m_document);
301 visitor->trace(m_timeContainers); 185 visitor->trace(m_timeContainers);
302 visitor->trace(m_webAnimationsPendingSVGElements); 186 visitor->trace(m_webAnimationsPendingSVGElements);
303 visitor->trace(m_relativeLengthSVGRoots); 187 visitor->trace(m_relativeLengthSVGRoots);
304 visitor->trace(m_pendingResources);
305 } 188 }
306 189
307 } // namespace blink 190 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698