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

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

Issue 2107153002: SVG object with same idrefs get conflicted even they are under different shadow root Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rename the method in TreeScope class Created 4 years, 5 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
(Empty)
1 #include "core/svg/SVGTreeScopeResources.h"
2
3 #include "core/dom/Element.h"
4 #include "core/dom/TreeScope.h"
5 #include "wtf/text/AtomicString.h"
6
7 namespace blink {
8
9 SVGTreeScopeResources::SVGTreeScopeResources(TreeScope* treeScope)
10 : m_treeScope(treeScope)
11 {
12 // Whenever an object of SVGTreeScopeResources is created, to keep the code behave as before,
13 // the document should also have an instance of SVGDocumentExtensions create d.
14 // Thus below lines are added
15 if (!treeScope->document().svgExtensions())
16 treeScope->document().accessSVGExtensions();
17 }
18 SVGTreeScopeResources::~SVGTreeScopeResources()
19 {
20 }
21 void SVGTreeScopeResources::addResource(const AtomicString& id, LayoutSVGResourc eContainer* resource)
22 {
23 DCHECK(resource);
24
25 if (id.isEmpty())
26 return;
27 // Replaces resource if already present, to handle potential id changes
28 m_resources.set(id, resource);
29 }
30
31 void SVGTreeScopeResources::removeResource(const AtomicString& id)
32 {
33 if (id.isEmpty())
34 return;
35
36 m_resources.remove(id);
37 }
38
39 LayoutSVGResourceContainer* SVGTreeScopeResources::resourceById(const AtomicStri ng& id) const
40 {
41 if (id.isEmpty())
42 return nullptr;
43 return m_resources.get(id);
44 }
45 void SVGTreeScopeResources::addPendingResource(const AtomicString& id, blink::El ement* element)
46 {
47 DCHECK(element);
48 DCHECK(element->inShadowIncludingDocument());
49
50 if (id.isEmpty())
51 return;
52
53 HeapHashMap<AtomicString, Member<SVGPendingElements>>::AddResult result = m_ pendingResources.add(id, nullptr);
54 if (result.isNewEntry)
55 result.storedValue->value = new SVGPendingElements;
56 result.storedValue->value->add(element);
57
58 element->setHasPendingResources();
59 }
60
61 bool SVGTreeScopeResources::hasPendingResource(const AtomicString& id) const
62 {
63 if (id.isEmpty())
64 return false;
65
66 return m_pendingResources.contains(id);
67 }
68
69 bool SVGTreeScopeResources::isElementPendingResources(Element* element) const
70 {
71 // This algorithm takes time proportional to the number of pending resources and need not.
72 // If performance becomes an issue we can keep a counted set of elements and answer the question efficiently.
73
74 DCHECK(element);
75
76 for (const auto& entry : m_pendingResources) {
77 SVGPendingElements* elements = entry.value.get();
78 DCHECK(elements);
79
80 if (elements->contains(element))
81 return true;
82 }
83 return false;
84 }
85
86 bool SVGTreeScopeResources::isElementPendingResource(Element* element, const Ato micString& id) const
87 {
88 DCHECK(element);
89
90 if (!hasPendingResource(id))
91 return false;
92
93 return m_pendingResources.get(id)->contains(element);
94 }
95
96 void SVGTreeScopeResources::clearHasPendingResourcesIfPossible(Element* element)
97 {
98 if (!isElementPendingResources(element))
99 element->clearHasPendingResources();
100 }
101
102 void SVGTreeScopeResources::removeElementFromPendingResources(Element* element)
103 {
104 DCHECK(element);
105
106 // Remove the element from pending resources.
107 if (!m_pendingResources.isEmpty() && element->hasPendingResources()) {
108 Vector<AtomicString> toBeRemoved;
109 for (const auto& entry : m_pendingResources) {
110 SVGPendingElements* elements = entry.value.get();
111 DCHECK(elements);
112 DCHECK(!elements->isEmpty());
113
114 elements->remove(element);
115 if (elements->isEmpty())
116 toBeRemoved.append(entry.key);
117 }
118
119 clearHasPendingResourcesIfPossible(element);
120
121 // We use the removePendingResource function here because it deals with set lifetime correctly.
122 for (const AtomicString& id : toBeRemoved)
123 removePendingResource(id);
124 }
125
126 // Remove the element from pending resources that were scheduled for removal .
127 if (!m_pendingResourcesForRemoval.isEmpty()) {
128 Vector<AtomicString> toBeRemoved;
129 for (const auto& entry : m_pendingResourcesForRemoval) {
130 SVGPendingElements* elements = entry.value.get();
131 DCHECK(elements);
132 DCHECK(!elements->isEmpty());
133
134 elements->remove(element);
135 if (elements->isEmpty())
136 toBeRemoved.append(entry.key);
137 }
138
139 // We use the removePendingResourceForRemoval function here because it d eals with set lifetime correctly.
140 for (const AtomicString& id : toBeRemoved)
141 removePendingResourceForRemoval(id);
142 }
143 }
144
145 SVGTreeScopeResources::SVGPendingElements* SVGTreeScopeResources::removePendingR esource(const AtomicString& id)
146 {
147 DCHECK(m_pendingResources.contains(id));
148 return m_pendingResources.take(id);
149 }
150
151 SVGTreeScopeResources::SVGPendingElements* SVGTreeScopeResources::removePendingR esourceForRemoval(const AtomicString& id)
152 {
153 DCHECK(m_pendingResourcesForRemoval.contains(id));
154 return m_pendingResourcesForRemoval.take(id);
155 }
156
157 void SVGTreeScopeResources::markPendingResourcesForRemoval(const AtomicString& i d)
158 {
159 if (id.isEmpty())
160 return;
161
162 DCHECK(!m_pendingResourcesForRemoval.contains(id));
163
164 Member<SVGPendingElements> existing = m_pendingResources.take(id);
165 if (existing && !existing->isEmpty())
166 m_pendingResourcesForRemoval.add(id, existing.release());
167 }
168
169 Element* SVGTreeScopeResources::removeElementFromPendingResourcesForRemoval(cons t AtomicString& id)
170 {
171 if (id.isEmpty())
172 return nullptr;
173
174 SVGPendingElements* resourceSet = m_pendingResourcesForRemoval.get(id);
175 if (!resourceSet || resourceSet->isEmpty())
176 return nullptr;
177
178 SVGPendingElements::iterator firstElement = resourceSet->begin();
179 Element* element = *firstElement;
180
181 resourceSet->remove(firstElement);
182
183 if (resourceSet->isEmpty())
184 removePendingResourceForRemoval(id);
185
186 return element;
187 }
188 DEFINE_TRACE(SVGTreeScopeResources)
189 {
190 visitor->trace(m_treeScope);
191 visitor->trace(m_pendingResources);
192 visitor->trace(m_pendingResourcesForRemoval);
193 }
194 }
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/svg/SVGTreeScopeResources.h ('k') | third_party/WebKit/Source/core/svg/SVGUseElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698