Home | History | Annotate | Download | only in events
      1 /*
      2  * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org)
      3  *           (C) 1999 Antti Koivisto (koivisto (at) kde.org)
      4  *           (C) 2001 Dirk Mueller (mueller (at) kde.org)
      5  * Copyright (C) 2004, 2005, 2006, 2007, 2012 Apple Inc. All rights reserved.
      6  * Copyright (C) 2006 Alexey Proskuryakov (ap (at) webkit.org)
      7  *           (C) 2007, 2008 Nikolas Zimmermann <zimmermann (at) kde.org>
      8  * Copyright (C) 2011 Andreas Kling (kling (at) 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/events/RegisteredEventListener.h"
     37 #include "wtf/PassOwnPtr.h"
     38 #include "wtf/text/AtomicStringHash.h"
     39 
     40 namespace blink {
     41 
     42 class EventTarget;
     43 
     44 typedef Vector<RegisteredEventListener, 1> EventListenerVector;
     45 
     46 class EventListenerMap {
     47 public:
     48     EventListenerMap();
     49 
     50     bool isEmpty() const { return m_entries.isEmpty(); }
     51     bool contains(const AtomicString& eventType) const;
     52     bool containsCapturing(const AtomicString& eventType) const;
     53 
     54     void clear();
     55     bool add(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture);
     56     bool remove(const AtomicString& eventType, EventListener*, bool useCapture, size_t& indexOfRemovedListener);
     57     EventListenerVector* find(const AtomicString& eventType);
     58     Vector<AtomicString> eventTypes() const;
     59 
     60     void removeFirstEventListenerCreatedFromMarkup(const AtomicString& eventType);
     61     void copyEventListenersNotCreatedFromMarkupToTarget(EventTarget*);
     62 
     63 private:
     64     friend class EventListenerIterator;
     65 
     66     void assertNoActiveIterators();
     67 
     68     Vector<std::pair<AtomicString, OwnPtr<EventListenerVector> >, 2> m_entries;
     69 
     70 #if ENABLE(ASSERT)
     71     int m_activeIteratorCount;
     72 #endif
     73 };
     74 
     75 class EventListenerIterator {
     76     WTF_MAKE_NONCOPYABLE(EventListenerIterator);
     77 public:
     78     EventListenerIterator();
     79     EventListenerIterator(EventTarget*);
     80 #if ENABLE(ASSERT)
     81     ~EventListenerIterator();
     82 #endif
     83 
     84     EventListener* nextListener();
     85 
     86 private:
     87     EventListenerMap* m_map;
     88     unsigned m_entryIndex;
     89     unsigned m_index;
     90 };
     91 
     92 #if !ENABLE(ASSERT)
     93 inline void EventListenerMap::assertNoActiveIterators() { }
     94 #endif
     95 
     96 } // namespace blink
     97 
     98 #endif // EventListenerMap_h
     99