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

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

Issue 2633143002: SVG objects with same idrefs conflict when under different shadow root (Closed)
Patch Set: ensureSVGTreeScopedResources(); add comment 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) Research In Motion Limited 2010. All rights reserved. 2 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details. 12 * Library General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU Library General Public License 14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to 15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA. 17 * Boston, MA 02110-1301, USA.
18 */ 18 */
19 19
20 #include "core/layout/svg/LayoutSVGResourceContainer.h" 20 #include "core/layout/svg/LayoutSVGResourceContainer.h"
21 21
22 #include "core/layout/svg/SVGResources.h" 22 #include "core/layout/svg/SVGResources.h"
23 #include "core/layout/svg/SVGResourcesCache.h" 23 #include "core/layout/svg/SVGResourcesCache.h"
24 #include "core/svg/SVGElementProxy.h" 24 #include "core/svg/SVGElementProxy.h"
25 #include "core/svg/SVGTreeScopeResources.h"
25 #include "wtf/AutoReset.h" 26 #include "wtf/AutoReset.h"
26 27
27 namespace blink { 28 namespace blink {
28 29
29 static inline SVGDocumentExtensions& svgExtensionsFromElement( 30 static inline SVGTreeScopeResources& svgTreeScopeResourcesFromElement(
30 Element* element) { 31 Element* element) {
31 ASSERT(element); 32 DCHECK(element);
32 return element->document().accessSVGExtensions(); 33 return element->treeScope().ensureSVGTreeScopedResources();
33 } 34 }
34 35
35 LayoutSVGResourceContainer::LayoutSVGResourceContainer(SVGElement* node) 36 LayoutSVGResourceContainer::LayoutSVGResourceContainer(SVGElement* node)
36 : LayoutSVGHiddenContainer(node), 37 : LayoutSVGHiddenContainer(node),
37 m_isInLayout(false), 38 m_isInLayout(false),
38 m_id(node->getIdAttribute()), 39 m_id(node->getIdAttribute()),
39 m_invalidationMask(0), 40 m_invalidationMask(0),
40 m_registered(false), 41 m_registered(false),
41 m_isInvalidating(false) {} 42 m_isInvalidating(false) {}
42 43
(...skipping 24 matching lines...) Expand all
67 } 68 }
68 69
69 void LayoutSVGResourceContainer::willBeDestroyed() { 70 void LayoutSVGResourceContainer::willBeDestroyed() {
70 // Detach all clients referring to this resource. If the resource itself is 71 // Detach all clients referring to this resource. If the resource itself is
71 // a client, it will be detached from any such resources by the call to 72 // a client, it will be detached from any such resources by the call to
72 // LayoutSVGHiddenContainer::willBeDestroyed() below. 73 // LayoutSVGHiddenContainer::willBeDestroyed() below.
73 detachAllClients(); 74 detachAllClients();
74 75
75 LayoutSVGHiddenContainer::willBeDestroyed(); 76 LayoutSVGHiddenContainer::willBeDestroyed();
76 if (m_registered) 77 if (m_registered)
77 svgExtensionsFromElement(element()).removeResource(m_id); 78 svgTreeScopeResourcesFromElement(element()).removeResource(m_id);
78 } 79 }
79 80
80 void LayoutSVGResourceContainer::styleDidChange(StyleDifference diff, 81 void LayoutSVGResourceContainer::styleDidChange(StyleDifference diff,
81 const ComputedStyle* oldStyle) { 82 const ComputedStyle* oldStyle) {
82 LayoutSVGHiddenContainer::styleDidChange(diff, oldStyle); 83 LayoutSVGHiddenContainer::styleDidChange(diff, oldStyle);
83 84
84 if (!m_registered) { 85 if (!m_registered) {
85 m_registered = true; 86 m_registered = true;
86 registerResource(); 87 registerResource();
87 } 88 }
88 } 89 }
89 90
90 void LayoutSVGResourceContainer::detachAllClients() { 91 void LayoutSVGResourceContainer::detachAllClients() {
91 for (auto* client : m_clients) { 92 for (auto* client : m_clients) {
92 // Unlink the resource from the client's SVGResources. (The actual 93 // Unlink the resource from the client's SVGResources. (The actual
93 // removal will be signaled after processing all the clients.) 94 // removal will be signaled after processing all the clients.)
94 SVGResources* resources = 95 SVGResources* resources =
95 SVGResourcesCache::cachedResourcesForLayoutObject(client); 96 SVGResourcesCache::cachedResourcesForLayoutObject(client);
96 // Or else the client wouldn't be in the list in the first place. 97 // Or else the client wouldn't be in the list in the first place.
97 DCHECK(resources); 98 DCHECK(resources);
98 resources->resourceDestroyed(this); 99 resources->resourceDestroyed(this);
99 100
100 // Add a pending resolution based on the id of the old resource. 101 // Add a pending resolution based on the id of the old resource.
101 Element* clientElement = toElement(client->node()); 102 Element* clientElement = toElement(client->node());
102 svgExtensionsFromElement(clientElement) 103 svgTreeScopeResourcesFromElement(clientElement)
103 .addPendingResource(m_id, clientElement); 104 .addPendingResource(m_id, clientElement);
104 } 105 }
105 106
106 removeAllClientsFromCache(); 107 removeAllClientsFromCache();
107 } 108 }
108 109
109 void LayoutSVGResourceContainer::idChanged() { 110 void LayoutSVGResourceContainer::idChanged() {
110 // Invalidate all our current clients. 111 // Invalidate all our current clients.
111 removeAllClientsFromCache(); 112 removeAllClientsFromCache();
112 113
113 // Remove old id, that is guaranteed to be present in cache. 114 // Remove old id, that is guaranteed to be present in cache.
114 SVGDocumentExtensions& extensions = svgExtensionsFromElement(element()); 115 SVGTreeScopeResources& treeScopeResources =
115 extensions.removeResource(m_id); 116 svgTreeScopeResourcesFromElement(element());
117 treeScopeResources.removeResource(m_id);
116 m_id = element()->getIdAttribute(); 118 m_id = element()->getIdAttribute();
117 119
118 registerResource(); 120 registerResource();
119 } 121 }
120 122
121 void LayoutSVGResourceContainer::markAllClientsForInvalidation( 123 void LayoutSVGResourceContainer::markAllClientsForInvalidation(
122 InvalidationMode mode) { 124 InvalidationMode mode) {
123 if (m_isInvalidating) 125 if (m_isInvalidating)
124 return; 126 return;
125 SVGElementProxySet* proxySet = elementProxySet(); 127 SVGElementProxySet* proxySet = elementProxySet();
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 203
202 setNeedsLayoutAndFullPaintInvalidation( 204 setNeedsLayoutAndFullPaintInvalidation(
203 LayoutInvalidationReason::SvgResourceInvalidated, MarkContainerChain, 205 LayoutInvalidationReason::SvgResourceInvalidated, MarkContainerChain,
204 layoutScope); 206 layoutScope);
205 207
206 if (everHadLayout()) 208 if (everHadLayout())
207 removeAllClientsFromCache(); 209 removeAllClientsFromCache();
208 } 210 }
209 211
210 void LayoutSVGResourceContainer::registerResource() { 212 void LayoutSVGResourceContainer::registerResource() {
211 SVGDocumentExtensions& extensions = svgExtensionsFromElement(element()); 213 SVGTreeScopeResources& treeScopeResources =
212 if (!extensions.hasPendingResource(m_id)) { 214 svgTreeScopeResourcesFromElement(element());
213 extensions.addResource(m_id, this); 215 if (!treeScopeResources.hasPendingResource(m_id)) {
216 treeScopeResources.addResource(m_id, this);
214 return; 217 return;
215 } 218 }
216 219
217 SVGDocumentExtensions::SVGPendingElements* clients( 220 SVGTreeScopeResources::SVGPendingElements* clients(
218 extensions.removePendingResource(m_id)); 221 treeScopeResources.removePendingResource(m_id));
219 222
220 // Cache us with the new id. 223 // Cache us with the new id.
221 extensions.addResource(m_id, this); 224 treeScopeResources.addResource(m_id, this);
222 225
223 // Update cached resources of pending clients. 226 // Update cached resources of pending clients.
224 for (const auto& pendingClient : *clients) { 227 for (const auto& pendingClient : *clients) {
225 DCHECK(pendingClient->hasPendingResources()); 228 DCHECK(pendingClient->hasPendingResources());
226 extensions.clearHasPendingResourcesIfPossible(pendingClient); 229 treeScopeResources.clearHasPendingResourcesIfPossible(pendingClient);
227 LayoutObject* layoutObject = pendingClient->layoutObject(); 230 LayoutObject* layoutObject = pendingClient->layoutObject();
228 if (!layoutObject) 231 if (!layoutObject)
229 continue; 232 continue;
230 DCHECK(layoutObject->isSVG() && (resourceType() != FilterResourceType || 233 DCHECK(layoutObject->isSVG() && (resourceType() != FilterResourceType ||
231 !layoutObject->isSVGRoot())); 234 !layoutObject->isSVGRoot()));
232 235
233 StyleDifference diff; 236 StyleDifference diff;
234 diff.setNeedsFullLayout(); 237 diff.setNeedsFullLayout();
235 SVGResourcesCache::clientStyleChanged(layoutObject, diff, 238 SVGResourcesCache::clientStyleChanged(layoutObject, diff,
236 layoutObject->styleRef()); 239 layoutObject->styleRef());
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 // This will process the rest of the ancestors. 302 // This will process the rest of the ancestors.
300 toLayoutSVGResourceContainer(current)->removeAllClientsFromCache(); 303 toLayoutSVGResourceContainer(current)->removeAllClientsFromCache();
301 break; 304 break;
302 } 305 }
303 306
304 current = current->parent(); 307 current = current->parent();
305 } 308 }
306 } 309 }
307 310
308 } // namespace blink 311 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698