Index: third_party/WebKit/Source/core/svg/SVGElementProxy.h |
diff --git a/third_party/WebKit/Source/core/svg/SVGElementProxy.h b/third_party/WebKit/Source/core/svg/SVGElementProxy.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8ede10cbb56738c656ff04fb7414e48e9bd07364 |
--- /dev/null |
+++ b/third_party/WebKit/Source/core/svg/SVGElementProxy.h |
@@ -0,0 +1,166 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef SVGElementProxy_h |
+#define SVGElementProxy_h |
+ |
+#include "core/fetch/DocumentResource.h" |
+#include "platform/heap/Handle.h" |
+#include "wtf/text/AtomicString.h" |
+#include "wtf/text/WTFString.h" |
+ |
+namespace blink { |
+ |
+class Document; |
+class SVGElement; |
+class SVGResourceClient; |
+class TreeScope; |
+ |
+// A proxy to an SVGElement. Allows access to an element with a certain 'id', |
+// and provides its clients with notifications when the proxied element |
+// changes. |
+// |
+// SVGElements can be referenced using CSS, for example like: |
+// |
+// filter: url(#baz); |
+// |
+// or |
+// |
+// filter: url(foo.com/bar.svg#baz); |
+// |
+// SVGElementProxy provide a mechanism to persistently reference an SVGElement |
+// in such cases - regardless of if the proxied element reside in the same |
+// document (read: tree scope) or in an external (resource) document. In the |
+// latter case, SVGElementProxy will transparently take care of the loading of |
+// the document (if requested, see SVGElementProxy::resolve.) |
+// |
+// The proxy uses an 'id' (c.f getElementById) to determine which element to |
+// proxy. The id is looked up in the TreeScope of the element for a |
+// same-document reference and in the TreeScope of the Document for a external |
+// document reference. |
+// |
+// For same document references, the proxy will track changes that could affect |
+// the 'id' lookup, to handle elements being added, removed or having their |
+// 'id' mutated. (This does not apply for the external document case because |
+// it's assumed they will not mutate after load, due to scripts not being run |
+// et.c.) |
+// |
+// SVGElementProxys are created by CSSURIValue, and have SVGResourceClients as |
+// a means to deliver change notifications. Clients that are interested in |
+// change notifications hence need to register a SVGResourceClient with the |
+// proxy. Most commonly this registration would take place when the |
+// ComputedStyle changes. |
+// |
+// Registration of a client does not establish a link to the proxied element |
+// right away. That is instead deferred until element(...) is called on the |
+// SVGElementProxy. At this point, the proxy will be registered with either the |
+// element (on success) or a set of "pending proxies" managed by |
+// SVGDocumentExtensions. (For external references lookups will not be |
+// registered, per the same assumption as mentioned above.) |
+// |
+// As content is mutated, clients will get notified via the proxied element |
+// which in turn will notify all registered proxies, which will notify all |
+// registered clients. |
+// |
+// <event> -> SVG...Element -> SVGElementProxy(0..N) -> SVGResourceClient(0..N) |
+// |
+class SVGElementProxy : public GarbageCollectedFinalized<SVGElementProxy>, |
+ private DocumentResourceClient { |
+ USING_GARBAGE_COLLECTED_MIXIN(SVGElementProxy); |
+ USING_PRE_FINALIZER(SVGElementProxy, detachDocumentClient); |
+ |
+ public: |
+ // Create a proxy to an element in the same document. (See also |
+ // SVGURLReferenceResolver and the definition of 'local url'.) |
+ static SVGElementProxy* create(const AtomicString& id) { |
+ return new SVGElementProxy(id); |
+ } |
+ |
+ // Create a proxy to an element in a different document (indicated by |url|.) |
+ static SVGElementProxy* create(const String& url, const AtomicString& id) { |
+ return new SVGElementProxy(url, id); |
+ } |
+ virtual ~SVGElementProxy(); |
+ |
+ void addClient(SVGResourceClient*); |
+ void removeClient(SVGResourceClient*); |
+ |
+ // Resolve a potentially external document reference. |
+ void resolve(Document&); |
+ |
+ // Returns the proxied element, or null if the proxy is invalid. |
+ SVGElement* element(TreeScope&); |
esprehn
2016/10/25 01:18:42
getElement or findElement?
fs
2016/10/25 15:00:53
Done.
|
+ |
+ // Notify the proxy that the structure of the subtree rooted at the proxied |
+ // element has mutated. This should generally only be called via a proxy |
+ // tracker. |
+ void contentChanged(); |
+ |
+ // Notify the proxy that the reference to the proxied element may now be |
+ // pointing somewhere else (the id of an element changed, the resource |
+ // document of the proxy finished loading, the element was removed from the |
+ // document tree etc.) This should generally only be called via a proxy |
+ // tracker. |
+ void proxiedElementChanged(); |
+ |
+ const AtomicString& id() const { return m_id; } |
+ |
+ // The current "generation" of this proxy. This is essentially a sequence |
+ // number (or counter) incremented with each change to the proxied element |
+ // (or its descendants, although that depends on the type of element being |
+ // proxied.) |
+ unsigned generation() const { return m_generation; } |
esprehn
2016/10/25 01:18:42
I'd prefer a dirty bit specific to the subtree or
fs
2016/10/25 15:00:53
This mechanism is only here for the case of the ta
|
+ |
+ DECLARE_VIRTUAL_TRACE(); |
+ |
+ private: |
+ explicit SVGElementProxy(const AtomicString&); |
+ SVGElementProxy(const String&, const AtomicString&); |
+ |
+ void detachDocumentClient(); |
+ // ResourceClient implementation. Used when referencing an external resource |
+ // document. |
+ void notifyFinished(Resource*) override; |
+ String debugName() const override { return "SVGElementProxy"; } |
+ |
+ void incrementGeneration() { m_generation++; } |
+ TreeScope* treeScopeForLookup(TreeScope&) const; |
+ |
+ HeapHashSet<Member<SVGResourceClient>> m_clients; |
+ Member<DocumentResource> m_document; |
+ AtomicString m_id; |
+ // URL for resolving references to external resource documents. Contains an |
+ // absolute URL to the resource to load. Cleared when a load has been |
+ // initiated. Ignored if m_isLocal is true. |
+ String m_url; |
+ unsigned m_generation; |
+ bool m_isLocal; |
+}; |
+ |
+// Collection of SVGElementProxys. This is hosted by elements that can be |
+// subject to proxies (currently only SVGFilterElement), and is mainly a helper |
+// for dealing with the many-to-one structure of SVGElementProxy. |
+class SVGElementProxySet : public GarbageCollected<SVGElementProxySet> { |
+ public: |
+ void add(SVGElementProxy&); |
+ bool isEmpty() const; |
+ |
+ // Notify proxy clients that the (content of the) proxied element has |
+ // changed. |
+ void notifyContentChanged(); |
+ |
+ // Notify proxy clients that the reference to the proxied element is no |
+ // longer valid. This also clears references to the proxied element. |
+ void invalidateProxies(); |
+ |
+ DECLARE_TRACE(); |
+ |
+ private: |
+ using ProxySet = HeapHashSet<WeakMember<SVGElementProxy>>; |
+ ProxySet m_elementProxies; |
+}; |
+ |
+} // namespace blink |
+ |
+#endif // SVGElementProxy_h |