Chromium Code Reviews| Index: third_party/WebKit/Source/core/dom/CompositorIdToElementMap.cpp |
| diff --git a/third_party/WebKit/Source/core/dom/CompositorIdToElementMap.cpp b/third_party/WebKit/Source/core/dom/CompositorIdToElementMap.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3d26c9e2905ccf02c8adb429cb8ffc3f8a83019e |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/dom/CompositorIdToElementMap.cpp |
| @@ -0,0 +1,64 @@ |
| +// 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. |
| + |
| +#include "core/dom/CompositorIdToElementMap.h" |
| + |
| +#include "core/dom/Element.h" |
| +#include "core/dom/WeakIdentifierMap.h" |
| +#include "platform/heap/Handle.h" |
| +#include "wtf/HashMap.h" |
| + |
| +namespace blink { |
| + |
| +class WeakIdToElementMap : public GarbageCollected<WeakIdToElementMap> { |
| +public: |
| + static void put(CompositorElementId elementId, Element* element) |
| + { |
| + ASSERT(element); |
| + instance().m_IdToElement->set(elementId, element); |
| + } |
| + |
| + static Element* lookup(CompositorElementId elementId) |
| + { |
| + return instance().m_IdToElement->get(elementId); |
| + } |
| + |
| + static void notifyObjectDestroyed(Element* object) { } |
| + |
| + DEFINE_INLINE_TRACE() |
| + { |
| + visitor->trace(m_IdToElement); |
| + } |
| + |
| +private: |
| + static WeakIdToElementMap& instance() |
| + { |
| + DEFINE_STATIC_LOCAL(WeakIdToElementMap, mapInstance, (new WeakIdToElementMap())); |
| + return mapInstance; |
| + } |
| + |
| + WeakIdToElementMap() |
| + : m_IdToElement(new IdToElement()) |
| + { |
| + } |
| + |
| + 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.
|
| + Member<IdToElement> m_IdToElement; |
| +}; |
| + |
| + |
| +// static |
| +void CompositorIdToElementMap::registerElement(Element& element) |
| +{ |
| + ASSERT(element.compositorElementId()); |
| + WeakIdToElementMap::put(element.compositorElementId(), &element); |
| +} |
| + |
| +// static |
| +Element* CompositorIdToElementMap::getById(CompositorElementId elementId) |
| +{ |
| + return WeakIdToElementMap::lookup(elementId); |
| +} |
| + |
| +} // namespace blink |