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

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

Issue 2722543002: Improve handling of duplicate id's for SVG resources (Closed)
Patch Set: Rebase Created 3 years, 9 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
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 SVGElementProxySet* LayoutSVGResourceContainer::elementProxySet() { 60 SVGElementProxySet* LayoutSVGResourceContainer::elementProxySet() {
61 return element()->elementProxySet(); 61 return element()->elementProxySet();
62 } 62 }
63 63
64 void LayoutSVGResourceContainer::notifyContentChanged() { 64 void LayoutSVGResourceContainer::notifyContentChanged() {
65 if (SVGElementProxySet* proxySet = elementProxySet()) 65 if (SVGElementProxySet* proxySet = elementProxySet())
66 proxySet->notifyContentChanged(element()->treeScope()); 66 proxySet->notifyContentChanged(element()->treeScope());
67 } 67 }
68 68
69 void LayoutSVGResourceContainer::willBeDestroyed() { 69 void LayoutSVGResourceContainer::willBeDestroyed() {
70 // 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 // LayoutSVGHiddenContainer::willBeDestroyed() below.
73 detachAllClients();
74
75 LayoutSVGHiddenContainer::willBeDestroyed(); 70 LayoutSVGHiddenContainer::willBeDestroyed();
76 if (!m_registered)
77 return;
78 svgTreeScopeResourcesFromElement(element()).removeResource( 71 svgTreeScopeResourcesFromElement(element()).removeResource(
79 element()->getIdAttribute()); 72 element()->getIdAttribute(), this);
73 DCHECK(m_clients.isEmpty());
80 } 74 }
81 75
82 void LayoutSVGResourceContainer::styleDidChange(StyleDifference diff, 76 void LayoutSVGResourceContainer::styleDidChange(StyleDifference diff,
83 const ComputedStyle* oldStyle) { 77 const ComputedStyle* oldStyle) {
84 LayoutSVGHiddenContainer::styleDidChange(diff, oldStyle); 78 LayoutSVGHiddenContainer::styleDidChange(diff, oldStyle);
85
86 if (m_registered)
87 return;
88 m_registered = true;
89 svgTreeScopeResourcesFromElement(element()).updateResource( 79 svgTreeScopeResourcesFromElement(element()).updateResource(
90 element()->getIdAttribute(), this); 80 element()->getIdAttribute(), this);
91 } 81 }
92 82
93 void LayoutSVGResourceContainer::detachAllClients() { 83 void LayoutSVGResourceContainer::detachAllClients(const AtomicString& toId) {
94 const AtomicString& id = element()->getIdAttribute(); 84 removeAllClientsFromCache();
85
95 for (auto* client : m_clients) { 86 for (auto* client : m_clients) {
96 // Unlink the resource from the client's SVGResources. (The actual 87 // Unlink the resource from the client's SVGResources. (The actual
97 // removal will be signaled after processing all the clients.) 88 // removal will be signaled after processing all the clients.)
98 SVGResources* resources = 89 SVGResources* resources =
99 SVGResourcesCache::cachedResourcesForLayoutObject(client); 90 SVGResourcesCache::cachedResourcesForLayoutObject(client);
100 // Or else the client wouldn't be in the list in the first place. 91 // Or else the client wouldn't be in the list in the first place.
101 DCHECK(resources); 92 DCHECK(resources);
102 resources->resourceDestroyed(this); 93 resources->resourceDestroyed(this);
103 94
104 // Add a pending resolution based on the id of the old resource. 95 // Add a pending resolution based on the id of the old resource.
105 Element* clientElement = toElement(client->node()); 96 Element* clientElement = toElement(client->node());
106 svgTreeScopeResourcesFromElement(clientElement) 97 svgTreeScopeResourcesFromElement(clientElement)
107 .addPendingResource(id, *clientElement); 98 .addPendingResource(toId, *clientElement);
108 } 99 }
109 100 m_clients.clear();
110 removeAllClientsFromCache();
111 } 101 }
112 102
113 void LayoutSVGResourceContainer::idChanged(const AtomicString& oldId, 103 void LayoutSVGResourceContainer::idChanged(const AtomicString& oldId,
114 const AtomicString& newId) { 104 const AtomicString& newId) {
115 // Invalidate all our current clients. 105 svgTreeScopeResourcesFromElement(element()).updateResource(oldId, newId,
116 removeAllClientsFromCache(); 106 this);
117
118 // Remove old id, that is guaranteed to be present in cache.
119 SVGTreeScopeResources& treeScopeResources =
120 svgTreeScopeResourcesFromElement(element());
121 treeScopeResources.removeResource(oldId);
122 treeScopeResources.updateResource(newId, this);
123 } 107 }
124 108
125 void LayoutSVGResourceContainer::markAllClientsForInvalidation( 109 void LayoutSVGResourceContainer::markAllClientsForInvalidation(
126 InvalidationMode mode) { 110 InvalidationMode mode) {
127 if (m_isInvalidating) 111 if (m_isInvalidating)
128 return; 112 return;
129 SVGElementProxySet* proxySet = elementProxySet(); 113 SVGElementProxySet* proxySet = elementProxySet();
130 if (m_clients.isEmpty() && (!proxySet || proxySet->isEmpty())) 114 if (m_clients.isEmpty() && (!proxySet || proxySet->isEmpty()))
131 return; 115 return;
132 if (m_invalidationMask & mode) 116 if (m_invalidationMask & mode)
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 // This will process the rest of the ancestors. 255 // This will process the rest of the ancestors.
272 toLayoutSVGResourceContainer(current)->removeAllClientsFromCache(); 256 toLayoutSVGResourceContainer(current)->removeAllClientsFromCache();
273 break; 257 break;
274 } 258 }
275 259
276 current = current->parent(); 260 current = current->parent();
277 } 261 }
278 } 262 }
279 263
280 } // namespace blink 264 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698