OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef SVGTreeScopeResources_h | 5 #ifndef SVGTreeScopeResources_h |
6 #define SVGTreeScopeResources_h | 6 #define SVGTreeScopeResources_h |
7 | 7 |
| 8 #include "core/dom/IdTargetObserver.h" |
8 #include "platform/heap/Handle.h" | 9 #include "platform/heap/Handle.h" |
9 #include "platform/wtf/Forward.h" | 10 #include "platform/wtf/Forward.h" |
10 #include "platform/wtf/HashMap.h" | 11 #include "platform/wtf/HashMap.h" |
11 #include "platform/wtf/HashSet.h" | 12 #include "platform/wtf/HashSet.h" |
12 #include "platform/wtf/text/AtomicStringHash.h" | 13 #include "platform/wtf/text/AtomicStringHash.h" |
13 | 14 |
14 namespace blink { | 15 namespace blink { |
15 | 16 |
16 class Element; | 17 class Element; |
| 18 class LayoutSVGResourceContainer; |
| 19 class SVGElement; |
17 class TreeScope; | 20 class TreeScope; |
18 class LayoutSVGResourceContainer; | |
19 | 21 |
20 // This class keeps track of SVG resources and pending references to such for a | 22 // This class keeps track of SVG resources and pending references to such for a |
21 // TreeScope. It's per-TreeScope because that matches the lookup scope of an | 23 // TreeScope. It's per-TreeScope because that matches the lookup scope of an |
22 // element's id (which is used to identify a resource.) | 24 // element's id (which is used to identify a resource.) |
23 class SVGTreeScopeResources | 25 class SVGTreeScopeResources |
24 : public GarbageCollectedFinalized<SVGTreeScopeResources> { | 26 : public GarbageCollectedFinalized<SVGTreeScopeResources> { |
25 WTF_MAKE_NONCOPYABLE(SVGTreeScopeResources); | 27 WTF_MAKE_NONCOPYABLE(SVGTreeScopeResources); |
26 | 28 |
27 public: | 29 public: |
28 explicit SVGTreeScopeResources(TreeScope*); | 30 explicit SVGTreeScopeResources(TreeScope*); |
29 ~SVGTreeScopeResources(); | 31 ~SVGTreeScopeResources(); |
30 | 32 |
31 void UpdateResource(const AtomicString& id, LayoutSVGResourceContainer*); | 33 class Resource : public IdTargetObserver { |
32 void UpdateResource(const AtomicString& old_id, | 34 public: |
33 const AtomicString& new_id, | 35 Resource(TreeScope&, const AtomicString& id); |
34 LayoutSVGResourceContainer*); | 36 ~Resource() override; |
35 void RemoveResource(const AtomicString& id, LayoutSVGResourceContainer*); | |
36 LayoutSVGResourceContainer* ResourceById(const AtomicString& id) const; | |
37 | 37 |
38 // Pending resources are such which are referenced by any object in the SVG | 38 Element* Target() const { return target_; } |
39 // document, but do NOT exist yet. For instance, dynamically built gradients | 39 LayoutSVGResourceContainer* ResourceContainer() const; |
40 // / patterns / clippers... | 40 |
41 void AddPendingResource(const AtomicString& id, Element&); | 41 void AddWatch(SVGElement&); |
42 bool IsElementPendingResource(Element&, const AtomicString& id) const; | 42 void RemoveWatch(SVGElement&); |
43 void NotifyResourceAvailable(const AtomicString& id); | 43 |
44 void RemoveElementFromPendingResources(Element&); | 44 bool IsEmpty() const; |
| 45 |
| 46 DECLARE_TRACE(); |
| 47 |
| 48 void NotifyResourceClients(); |
| 49 |
| 50 private: |
| 51 void IdTargetChanged() override; |
| 52 |
| 53 Member<TreeScope> tree_scope_; |
| 54 Member<Element> target_; |
| 55 HeapHashSet<Member<SVGElement>> pending_clients_; |
| 56 }; |
| 57 Resource* ResourceForId(const AtomicString& id); |
| 58 Resource* ExistingResourceForId(const AtomicString& id) const; |
| 59 |
| 60 void RemoveUnreferencedResources(); |
| 61 void RemoveWatchesForElement(SVGElement&); |
45 | 62 |
46 DECLARE_TRACE(); | 63 DECLARE_TRACE(); |
47 | 64 |
48 private: | 65 private: |
49 void ClearHasPendingResourcesIfPossible(Element&); | 66 HeapHashMap<AtomicString, Member<Resource>> resources_; |
50 | |
51 using SVGPendingElements = HeapHashSet<Member<Element>>; | |
52 using ResourceMap = HashMap<AtomicString, LayoutSVGResourceContainer*>; | |
53 | |
54 void RegisterResource(const AtomicString& id, LayoutSVGResourceContainer*); | |
55 void UnregisterResource(ResourceMap::iterator); | |
56 void NotifyPendingClients(const AtomicString& id); | |
57 | |
58 ResourceMap resources_; | |
59 // Resources that are pending. | |
60 HeapHashMap<AtomicString, Member<SVGPendingElements>> pending_resources_; | |
61 Member<TreeScope> tree_scope_; | 67 Member<TreeScope> tree_scope_; |
62 }; | 68 }; |
63 | 69 |
64 } // namespace blink | 70 } // namespace blink |
65 | 71 |
66 #endif // SVGTreeScopeResources_h | 72 #endif // SVGTreeScopeResources_h |
OLD | NEW |