EventListenerMap.h [plain text]
#ifndef EventListenerMap_h
#define EventListenerMap_h
#include "RegisteredEventListener.h"
#include <wtf/Forward.h>
#include <wtf/HashMap.h>
#include <wtf/text/AtomicStringHash.h>
namespace WebCore {
class EventTarget;
typedef Vector<RegisteredEventListener, 1> EventListenerVector;
class EventListenerMap {
public:
EventListenerMap();
bool isEmpty() const;
bool contains(const AtomicString& eventType) const;
void clear();
bool add(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture);
bool remove(const AtomicString& eventType, EventListener*, bool useCapture, size_t& indexOfRemovedListener);
EventListenerVector* find(const AtomicString& eventType);
Vector<AtomicString> eventTypes() const;
#if ENABLE(SVG)
void removeFirstEventListenerCreatedFromMarkup(const AtomicString& eventType);
void copyEventListenersNotCreatedFromMarkupToTarget(EventTarget*);
#endif
private:
friend class EventListenerIterator;
void assertNoActiveIterators();
struct EventListenerHashMapTraits : HashTraits<WTF::AtomicString> {
static const int minimumTableSize = 32;
};
typedef HashMap<AtomicString, OwnPtr<EventListenerVector>, AtomicStringHash, EventListenerHashMapTraits> EventListenerHashMap;
OwnPtr<EventListenerHashMap> m_hashMap;
AtomicString m_singleEventListenerType;
OwnPtr<EventListenerVector> m_singleEventListenerVector;
#ifndef NDEBUG
int m_activeIteratorCount;
#endif
};
class EventListenerIterator {
WTF_MAKE_NONCOPYABLE(EventListenerIterator);
public:
EventListenerIterator();
EventListenerIterator(EventTarget*);
#ifndef NDEBUG
~EventListenerIterator();
#endif
EventListener* nextListener();
private:
EventListenerMap* m_map;
EventListenerMap::EventListenerHashMap::iterator m_mapIterator;
EventListenerMap::EventListenerHashMap::iterator m_mapEnd;
unsigned m_index;
};
#ifdef NDEBUG
inline void EventListenerMap::assertNoActiveIterators() { }
#endif
}
#endif // EventListenerMap_h