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

Side by Side Diff: third_party/WebKit/Source/core/svg/SVGElementProxy.h

Issue 2490163002: Reland of "Tracking reference filter mutation via SVGElementProxy" (Closed)
Patch Set: Fix double observer unregistration; simplify scope selection; add tests Created 4 years, 1 month 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 // 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 #ifndef SVGElementProxy_h
6 #define SVGElementProxy_h
7
8 #include "core/fetch/DocumentResource.h"
9 #include "platform/heap/Handle.h"
10 #include "wtf/text/AtomicString.h"
11 #include "wtf/text/WTFString.h"
12
13 namespace blink {
14
15 class Document;
16 class SVGElement;
17 class SVGResourceClient;
18 class TreeScope;
19
20 // A proxy to an SVGElement. Allows access to an element with a certain 'id',
21 // and provides its clients with notifications when the proxied element
22 // changes.
23 //
24 // SVGElements can be referenced using CSS, for example like:
25 //
26 // filter: url(#baz);
27 //
28 // or
29 //
30 // filter: url(foo.com/bar.svg#baz);
31 //
32 // SVGElementProxy provide a mechanism to persistently reference an SVGElement
33 // in such cases - regardless of if the proxied element reside in the same
34 // document (read: tree scope) or in an external (resource) document. Loading
35 // events related to external documents case needs be handled by the clients
36 // (SVGResourceClient's default implementation does this.)
37 //
38 // The proxy uses an 'id' (c.f getElementById) to determine which element to
39 // proxy. The id is looked up in the TreeScope provided by the client for a
40 // same-document reference and in the TreeScope of the Document for a external
41 // document reference.
42 //
43 // For same document references, the proxy will track changes that could affect
44 // the 'id' lookup, to handle elements being added, removed or having their
45 // 'id' mutated. (This does not apply for the external document case because
46 // it's assumed they will not mutate after load, due to scripts not being run
47 // etc.)
48 //
49 // SVGElementProxys are created by CSSURIValue, and have SVGResourceClients as
50 // a means to deliver change notifications. Clients that are interested in
51 // change notifications hence need to register a SVGResourceClient with the
52 // proxy. Most commonly this registration would take place when the
53 // ComputedStyle changes.
54 //
55 // Registration of a client does not establish a link to the proxied element
56 // right away. That is instead deferred until findElement(...) is called on the
57 // SVGElementProxy. At this point, the proxy will be registered with the
58 // element if the lookup is successful. (For external references lookups will
59 // not be registered, per the same assumption as mentioned above.)
60 //
61 // As content is mutated, clients will get notified via the proxied element
62 // which in turn will notify all registered proxies, which will notify all
63 // registered clients.
64 //
65 // <event> -> SVG...Element -> SVGElementProxy(0..N) -> SVGResourceClient(0..N)
66 //
67 class SVGElementProxy : public GarbageCollectedFinalized<SVGElementProxy> {
68 public:
69 // Create a proxy to an element in the same document. (See also
70 // SVGURLReferenceResolver and the definition of 'local url'.)
71 static SVGElementProxy* create(const AtomicString& id) {
72 return new SVGElementProxy(id);
73 }
74
75 // Create a proxy to an element in a different document (indicated by |url|.)
76 static SVGElementProxy* create(const String& url, const AtomicString& id) {
77 return new SVGElementProxy(url, id);
78 }
79 virtual ~SVGElementProxy();
80
81 void addClient(SVGResourceClient*);
82 void removeClient(SVGResourceClient*);
83
84 // Resolve a potentially external document reference.
85 void resolve(Document&);
86
87 // Returns the proxied element, or null if the proxy is invalid.
88 SVGElement* findElement(TreeScope&);
89
90 // Notify the proxy that the structure of the subtree rooted at the proxied
91 // element has mutated. This should generally only be called via a proxy set.
92 void contentChanged(TreeScope&);
93
94 const AtomicString& id() const { return m_id; }
95
96 DECLARE_VIRTUAL_TRACE();
97
98 private:
99 explicit SVGElementProxy(const AtomicString&);
100 SVGElementProxy(const String&, const AtomicString&);
101
102 TreeScope* treeScopeForLookup(TreeScope&) const;
103
104 class IdObserver;
105
106 HeapHashMap<Member<SVGResourceClient>, Member<IdObserver>> m_clients;
107 HeapHashMap<Member<TreeScope>, Member<IdObserver>> m_observers;
108 Member<DocumentResource> m_document;
109 AtomicString m_id;
110 // URL for resolving references to external resource documents. Contains an
111 // absolute URL to the resource to load. Cleared when a load has been
112 // initiated. Ignored if m_isLocal is true.
113 String m_url;
114 bool m_isLocal;
115 };
116
117 // Collection of SVGElementProxys. This is hosted by elements that can be
118 // subject to proxies (currently only SVGFilterElement), and is mainly a helper
119 // for dealing with the many-to-one structure of SVGElementProxy.
120 class SVGElementProxySet : public GarbageCollected<SVGElementProxySet> {
121 public:
122 void add(SVGElementProxy&);
123 bool isEmpty() const;
124
125 // Notify proxy clients that the (content of the) proxied element has
126 // changed.
127 void notifyContentChanged(TreeScope&);
128
129 DECLARE_TRACE();
130
131 private:
132 using ProxySet = HeapHashSet<WeakMember<SVGElementProxy>>;
133 ProxySet m_elementProxies;
134 };
135
136 } // namespace blink
137
138 #endif // SVGElementProxy_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/svg/SVGDocumentExtensions.cpp ('k') | third_party/WebKit/Source/core/svg/SVGElementProxy.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698