TreeScopeOrderedMap.h [plain text]
#pragma once
#include <wtf/HashMap.h>
#include <wtf/HashSet.h>
#include <wtf/Vector.h>
#include <wtf/text/AtomStringImpl.h>
namespace WebCore {
class Element;
class HTMLImageElement;
class HTMLLabelElement;
class HTMLMapElement;
class TreeScope;
class TreeScopeOrderedMap {
WTF_MAKE_FAST_ALLOCATED;
public:
void add(const AtomStringImpl&, Element&, const TreeScope&);
void remove(const AtomStringImpl&, Element&);
void clear();
bool contains(const AtomStringImpl&) const;
bool containsSingle(const AtomStringImpl&) const;
bool containsMultiple(const AtomStringImpl&) const;
Element* getElementById(const AtomStringImpl&, const TreeScope&) const;
Element* getElementByName(const AtomStringImpl&, const TreeScope&) const;
HTMLMapElement* getElementByMapName(const AtomStringImpl&, const TreeScope&) const;
HTMLImageElement* getElementByUsemap(const AtomStringImpl&, const TreeScope&) const;
HTMLLabelElement* getElementByLabelForAttribute(const AtomStringImpl&, const TreeScope&) const;
Element* getElementByWindowNamedItem(const AtomStringImpl&, const TreeScope&) const;
Element* getElementByDocumentNamedItem(const AtomStringImpl&, const TreeScope&) const;
const Vector<Element*>* getAllElementsById(const AtomStringImpl&, const TreeScope&) const;
const Vector<AtomString> keys() const;
private:
template <typename KeyMatchingFunction>
Element* get(const AtomStringImpl&, const TreeScope&, const KeyMatchingFunction&) const;
struct MapEntry {
MapEntry() { }
explicit MapEntry(Element* firstElement)
: element(firstElement)
, count(1)
{ }
Element* element { nullptr };
unsigned count { 0 };
Vector<Element*> orderedList;
#if ASSERT_ENABLED || ENABLE(SECURITY_ASSERTIONS)
HashSet<Element*> registeredElements;
#endif
};
typedef HashMap<const AtomStringImpl*, MapEntry> Map;
mutable Map m_map;
};
inline bool TreeScopeOrderedMap::containsSingle(const AtomStringImpl& id) const
{
auto it = m_map.find(&id);
return it != m_map.end() && it->value.count == 1;
}
inline bool TreeScopeOrderedMap::contains(const AtomStringImpl& id) const
{
return m_map.contains(&id);
}
inline bool TreeScopeOrderedMap::containsMultiple(const AtomStringImpl& id) const
{
auto it = m_map.find(&id);
return it != m_map.end() && it->value.count > 1;
}
}