Chromium Code Reviews| 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); | |
|
esprehn
2016/10/25 01:18:42
What about this feature needs a preFinalizer?
fs
2016/10/25 15:00:53
It's for calling removeClient on m_document (balan
| |
| 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).elementProxySet().add(*this); | |
| 63 return toSVGElement(targetElement); | |
| 64 } | |
| 65 } | |
| 66 // For external references we wait for the document to finish loading. If the | |
| 67 // reference is not valid then it will never be (because the document will | |
| 68 // not mutate.) | |
| 69 if (!m_isLocal) | |
| 70 return nullptr; | |
| 71 // If the lookup fails for some reason (no element with said 'id' or no | |
| 72 // element of the required type), attach the proxy to SVGDocumentExtensions. | |
| 73 // It will then send notifications when an element with the associated id is | |
| 74 // added to the tree etc. | |
| 75 treeScope.document().accessSVGExtensions().attachPendingProxy(*this); | |
| 76 return nullptr; | |
| 77 } | |
| 78 | |
| 79 void SVGElementProxy::contentChanged() { | |
| 80 HeapVector<Member<SVGResourceClient>> clients; | |
| 81 copyToVector(m_clients, clients); | |
| 82 for (SVGResourceClient* client : clients) | |
| 83 client->resourceContentChanged(); | |
| 84 } | |
| 85 | |
| 86 void SVGElementProxy::proxiedElementChanged() { | |
| 87 incrementGeneration(); | |
| 88 HeapVector<Member<SVGResourceClient>> clients; | |
| 89 copyToVector(m_clients, clients); | |
| 90 for (SVGResourceClient* client : clients) | |
| 91 client->resourceElementChanged(); | |
| 92 } | |
| 93 | |
| 94 void SVGElementProxy::notifyFinished(Resource*) { | |
| 95 proxiedElementChanged(); | |
| 96 } | |
| 97 | |
| 98 void SVGElementProxy::detachDocumentClient() { | |
| 99 m_document->removeClient(this); | |
| 100 m_document = nullptr; | |
| 101 } | |
| 102 | |
| 103 DEFINE_TRACE(SVGElementProxy) { | |
| 104 visitor->trace(m_clients); | |
| 105 visitor->trace(m_document); | |
| 106 DocumentResourceClient::trace(visitor); | |
| 107 } | |
| 108 | |
| 109 void SVGElementProxySet::add(SVGElementProxy& elementProxy) { | |
| 110 m_elementProxies.add(&elementProxy); | |
| 111 } | |
| 112 | |
| 113 bool SVGElementProxySet::isEmpty() const { | |
| 114 return m_elementProxies.isEmpty(); | |
| 115 } | |
| 116 | |
| 117 void SVGElementProxySet::notifyContentChanged() { | |
| 118 for (SVGElementProxy* proxy : m_elementProxies) | |
| 119 proxy->contentChanged(); | |
| 120 } | |
| 121 | |
| 122 void SVGElementProxySet::invalidateProxies() { | |
| 123 ProxySet elementProxies; | |
| 124 elementProxies.swap(m_elementProxies); | |
| 125 for (SVGElementProxy* proxy : elementProxies) | |
| 126 proxy->proxiedElementChanged(); | |
| 127 } | |
| 128 | |
| 129 DEFINE_TRACE(SVGElementProxySet) { | |
| 130 visitor->trace(m_elementProxies); | |
| 131 } | |
| 132 | |
| 133 } // namespace blink | |
| OLD | NEW |