blob: 4889d94a1d984bd00071437ea872531559a51edf [file] [log] [blame]
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +01001/*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2012 Apple Inc. All rights reserved.
6 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
7 * (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
8 * Copyright (C) 2011 Andreas Kling (kling@webkit.org)
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
27 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 */
32
33#ifndef EventListenerMap_h
34#define EventListenerMap_h
35
36#include "core/dom/RegisteredEventListener.h"
Ben Murdoche69819b2013-07-17 14:56:49 +010037#include "wtf/Forward.h"
38#include "wtf/PassOwnPtr.h"
39#include "wtf/text/AtomicStringHash.h"
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010040
41namespace WebCore {
42
43class EventTarget;
44
45typedef Vector<RegisteredEventListener, 1> EventListenerVector;
46
47class EventListenerMap {
48public:
49 EventListenerMap();
50
51 bool isEmpty() const { return m_entries.isEmpty(); }
52 bool contains(const AtomicString& eventType) const;
Ben Murdoche69819b2013-07-17 14:56:49 +010053 bool containsCapturing(const AtomicString& eventType) const;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010054
55 void clear();
56 bool add(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture);
57 bool remove(const AtomicString& eventType, EventListener*, bool useCapture, size_t& indexOfRemovedListener);
58 EventListenerVector* find(const AtomicString& eventType);
59 Vector<AtomicString> eventTypes() const;
60
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010061 void removeFirstEventListenerCreatedFromMarkup(const AtomicString& eventType);
62 void copyEventListenersNotCreatedFromMarkupToTarget(EventTarget*);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010063
64private:
65 friend class EventListenerIterator;
66
67 void assertNoActiveIterators();
68
69 Vector<std::pair<AtomicString, OwnPtr<EventListenerVector> >, 2> m_entries;
70
71#ifndef NDEBUG
72 int m_activeIteratorCount;
73#endif
74};
75
76class EventListenerIterator {
77 WTF_MAKE_NONCOPYABLE(EventListenerIterator);
78public:
79 EventListenerIterator();
80 EventListenerIterator(EventTarget*);
81#ifndef NDEBUG
82 ~EventListenerIterator();
83#endif
84
85 EventListener* nextListener();
86
87private:
88 EventListenerMap* m_map;
89 unsigned m_entryIndex;
90 unsigned m_index;
91};
92
93#ifdef NDEBUG
94inline void EventListenerMap::assertNoActiveIterators() { }
95#endif
96
97} // namespace WebCore
98
99#endif // EventListenerMap_h