OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "core/svg/SVGElementProxy.h" | |
6 | |
7 #include "core/fetch/FetchInitiatorTypeNames.h" | |
8 #include "core/fetch/FetchRequest.h" | |
9 #include "core/fetch/ResourceFetcher.h" | |
10 #include "core/svg/SVGDocumentExtensions.h" | |
11 #include "core/svg/SVGElement.h" | |
12 #include "core/svg/SVGFilterElement.h" | |
13 #include "core/svg/SVGResourceClient.h" | |
14 | |
15 namespace blink { | |
16 | |
17 SVGElementProxy::SVGElementProxy(const AtomicString& id) | |
18 : m_id(id), m_generation(0), m_isLocal(true) {} | |
19 | |
20 SVGElementProxy::SVGElementProxy(const String& url, const AtomicString& id) | |
21 : m_id(id), m_url(url), m_generation(0), m_isLocal(false) {} | |
22 | |
23 SVGElementProxy::~SVGElementProxy() {} | |
24 | |
25 void SVGElementProxy::addClient(SVGResourceClient* client) { | |
26 m_clients.add(client); | |
27 } | |
28 | |
29 void SVGElementProxy::removeClient(SVGResourceClient* client) { | |
30 m_clients.remove(client); | |
31 } | |
32 | |
33 void SVGElementProxy::resolve(Document& document) { | |
34 if (m_isLocal || m_url.isEmpty()) | |
35 return; | |
36 FetchRequest request(ResourceRequest(m_url), FetchInitiatorTypeNames::css); | |
37 m_document = DocumentResource::fetchSVGDocument(request, document.fetcher()); | |
38 m_url = String(); | |
39 if (m_document) { | |
40 m_document->addClient(this); | |
41 ThreadState::current()->registerPreFinalizer(this); | |
42 } | |
43 } | |
44 | |
45 TreeScope* SVGElementProxy::treeScopeForLookup(TreeScope& treeScope) const { | |
46 if (m_isLocal) | |
47 return &treeScope; | |
48 if (!m_document) | |
49 return nullptr; | |
50 return m_document->document(); | |
51 } | |
52 | |
53 SVGElement* SVGElementProxy::element(TreeScope& treeScope) { | |
54 // An empty id will never be a valid element reference. | |
55 if (m_id.isEmpty()) | |
56 return nullptr; | |
57 TreeScope* lookupScope = treeScopeForLookup(treeScope); | |
58 if (!lookupScope) | |
59 return nullptr; | |
60 if (Element* targetElement = lookupScope->getElementById(m_id)) { | |
61 if (isSVGFilterElement(*targetElement)) { | |
62 toSVGFilterElement(*targetElement) | |
63 .elementProxyTracker() | |
64 .attachElementProxy(*this); | |
65 return toSVGElement(targetElement); | |
66 } | |
67 } | |
68 // For external references we wait for the document to finish loading. If the | |
69 // reference is not valid then it will never be (because the document will | |
70 // not mutate.) | |
71 if (!m_isLocal) | |
72 return nullptr; | |
73 // If the lookup fails for some reason (no element with said 'id' or no | |
74 // element of the required type), attach the proxy to SVGDocumentExtensions. | |
75 // It will then send notifications when an element with the associated id is | |
76 // added to the tree etc. | |
77 treeScope.document().accessSVGExtensions().attachPendingProxy(*this); | |
78 return nullptr; | |
79 } | |
80 | |
81 void SVGElementProxy::contentChanged() { | |
82 HeapVector<Member<SVGResourceClient>> clients; | |
83 copyToVector(m_clients, clients); | |
84 for (SVGResourceClient* client : clients) | |
85 client->resourceContentChanged(this); | |
86 } | |
87 | |
88 void SVGElementProxy::referenceChanged() { | |
89 nextGeneration(); | |
90 HeapVector<Member<SVGResourceClient>> clients; | |
91 copyToVector(m_clients, clients); | |
92 for (SVGResourceClient* client : clients) | |
93 client->resourceReferenceChanged(this); | |
94 } | |
95 | |
96 void SVGElementProxy::notifyFinished(Resource*) { | |
97 referenceChanged(); | |
98 } | |
99 | |
100 void SVGElementProxy::detachDocumentClient() { | |
101 m_document->removeClient(this); | |
102 m_document = nullptr; | |
103 } | |
104 | |
105 DEFINE_TRACE(SVGElementProxy) { | |
106 visitor->trace(m_clients); | |
107 visitor->trace(m_document); | |
108 DocumentResourceClient::trace(visitor); | |
109 } | |
110 | |
111 void SVGElementProxyTracker::attachElementProxy(SVGElementProxy& elementProxy) { | |
112 m_elementProxies.add(&elementProxy); | |
113 } | |
114 | |
115 bool SVGElementProxyTracker::isEmpty() const { | |
116 return m_elementProxies.isEmpty(); | |
117 } | |
118 | |
119 void SVGElementProxyTracker::invalidateProxyClients() { | |
120 for (SVGElementProxy* proxy : m_elementProxies) | |
121 proxy->contentChanged(); | |
122 } | |
123 | |
124 void SVGElementProxyTracker::invalidateProxies() { | |
125 for (SVGElementProxy* proxy : m_elementProxies) | |
pdr.
2016/10/20 03:11:05
Should we save off the proxies, clear them, then i
fs
2016/10/20 11:28:00
Sure. Reworked.
| |
126 proxy->referenceChanged(); | |
127 m_elementProxies.clear(); | |
128 } | |
129 | |
130 DEFINE_TRACE(SVGElementProxyTracker) { | |
131 visitor->trace(m_elementProxies); | |
132 } | |
133 | |
134 } // namespace blink | |
OLD | NEW |