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/Forward.h"
     38 #include "wtf/PassOwnPtr.h"
     39 #include "wtf/text/AtomicStringHash.h"
     40 
     41 namespace WebCore {
     42 
     43 class EventTarget;
     44 
     45 typedef Vector<RegisteredEventListener, 1> EventListenerVector;
     46 
     47 class EventListenerMap {
     48 public:
     49     EventListenerMap();
     50 
     51     bool isEmpty() const { return m_entries.isEmpty(); }
     52     bool contains(const AtomicString& eventType) const;
     53     bool containsCapturing(const AtomicString& eventType) const;
     54 
     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 
     61     void removeFirstEventListenerCreatedFromMarkup(const AtomicString& eventType);
     62     void copyEventListenersNotCreatedFromMarkupToTarget(EventTarget*);
     63 
     64 private:
     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 
     76 class EventListenerIterator {
     77     WTF_MAKE_NONCOPYABLE(EventListenerIterator);
     78 public:
     79     EventListenerIterator();
     80     EventListenerIterator(EventTarget*);
     81 #ifndef NDEBUG
     82     ~EventListenerIterator();
     83 #endif
     84 
     85     EventListener* nextListener();
     86 
     87 private:
     88     EventListenerMap* m_map;
     89     unsigned m_entryIndex;
     90     unsigned m_index;
     91 };
     92 
     93 #ifdef NDEBUG
     94 inline void EventListenerMap::assertNoActiveIterators() { }
     95 #endif
     96 
     97 } // namespace WebCore
     98 
     99 #endif // EventListenerMap_h
    100