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/dom/CompositorIdToElementMap.h" | |
6 | |
7 #include "core/dom/Element.h" | |
8 #include "core/dom/WeakIdentifierMap.h" | |
9 #include "platform/heap/Handle.h" | |
10 #include "wtf/HashMap.h" | |
11 | |
12 namespace blink { | |
13 | |
14 class WeakIdToElementMap : public GarbageCollected<WeakIdToElementMap> { | |
15 public: | |
16 static void put(CompositorElementId elementId, Element* element) | |
17 { | |
18 ASSERT(element); | |
19 instance().m_IdToElement->set(elementId, element); | |
20 } | |
21 | |
22 static Element* lookup(CompositorElementId elementId) | |
23 { | |
24 return instance().m_IdToElement->get(elementId); | |
25 } | |
26 | |
27 static void notifyObjectDestroyed(Element* object) { } | |
28 | |
29 DEFINE_INLINE_TRACE() | |
30 { | |
31 visitor->trace(m_IdToElement); | |
32 } | |
33 | |
34 private: | |
35 static WeakIdToElementMap& instance() | |
36 { | |
37 DEFINE_STATIC_LOCAL(WeakIdToElementMap, mapInstance, (new WeakIdToElemen tMap())); | |
38 return mapInstance; | |
39 } | |
40 | |
41 WeakIdToElementMap() | |
42 : m_IdToElement(new IdToElement()) | |
43 { | |
44 } | |
45 | |
46 using IdToElement = HeapHashMap<CompositorElementId, WeakMember<Element>>; | |
esprehn
2016/05/10 22:46:57
I don't want to add more maps, use DOMNodeIds for
loyso (OOO)
2016/05/12 05:55:39
Acknowledged.
| |
47 Member<IdToElement> m_IdToElement; | |
48 }; | |
49 | |
50 | |
51 // static | |
52 void CompositorIdToElementMap::registerElement(Element& element) | |
53 { | |
54 ASSERT(element.compositorElementId()); | |
55 WeakIdToElementMap::put(element.compositorElementId(), &element); | |
56 } | |
57 | |
58 // static | |
59 Element* CompositorIdToElementMap::getById(CompositorElementId elementId) | |
60 { | |
61 return WeakIdToElementMap::lookup(elementId); | |
62 } | |
63 | |
64 } // namespace blink | |
OLD | NEW |