diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/dom/EventSender.h | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/dom/EventSender.h')
-rw-r--r-- | Source/WebCore/dom/EventSender.h | 46 |
1 files changed, 20 insertions, 26 deletions
diff --git a/Source/WebCore/dom/EventSender.h b/Source/WebCore/dom/EventSender.h index 2cb5aaf18..872d85a1a 100644 --- a/Source/WebCore/dom/EventSender.h +++ b/Source/WebCore/dom/EventSender.h @@ -23,8 +23,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EventSender_h -#define EventSender_h +#pragma once #include "Timer.h" #include <wtf/Vector.h> @@ -37,52 +36,50 @@ public: explicit EventSender(const AtomicString& eventType); const AtomicString& eventType() const { return m_eventType; } - void dispatchEventSoon(T*); - void cancelEvent(T*); + void dispatchEventSoon(T&); + void cancelEvent(T&); void dispatchPendingEvents(); #ifndef NDEBUG - bool hasPendingEvents(T* sender) const + bool hasPendingEvents(T& sender) const { - return m_dispatchSoonList.find(sender) != notFound || m_dispatchingList.find(sender) != notFound; + return m_dispatchSoonList.find(&sender) != notFound || m_dispatchingList.find(&sender) != notFound; } #endif private: - void timerFired(Timer<EventSender<T>>&) { dispatchPendingEvents(); } + void timerFired() { dispatchPendingEvents(); } AtomicString m_eventType; - Timer<EventSender<T>> m_timer; + Timer m_timer; Vector<T*> m_dispatchSoonList; Vector<T*> m_dispatchingList; }; template<typename T> EventSender<T>::EventSender(const AtomicString& eventType) : m_eventType(eventType) - , m_timer(this, &EventSender::timerFired) + , m_timer(*this, &EventSender::timerFired) { } -template<typename T> void EventSender<T>::dispatchEventSoon(T* sender) +template<typename T> void EventSender<T>::dispatchEventSoon(T& sender) { - m_dispatchSoonList.append(sender); + m_dispatchSoonList.append(&sender); if (!m_timer.isActive()) m_timer.startOneShot(0); } -template<typename T> void EventSender<T>::cancelEvent(T* sender) +template<typename T> void EventSender<T>::cancelEvent(T& sender) { // Remove instances of this sender from both lists. // Use loops because we allow multiple instances to get into the lists. - size_t size = m_dispatchSoonList.size(); - for (size_t i = 0; i < size; ++i) { - if (m_dispatchSoonList[i] == sender) - m_dispatchSoonList[i] = 0; + for (auto& event : m_dispatchSoonList) { + if (event == &sender) + event = nullptr; } - size = m_dispatchingList.size(); - for (size_t i = 0; i < size; ++i) { - if (m_dispatchingList[i] == sender) - m_dispatchingList[i] = 0; + for (auto& event : m_dispatchingList) { + if (event == &sender) + event = nullptr; } } @@ -99,10 +96,9 @@ template<typename T> void EventSender<T>::dispatchPendingEvents() m_dispatchSoonList.checkConsistency(); m_dispatchingList.swap(m_dispatchSoonList); - size_t size = m_dispatchingList.size(); - for (size_t i = 0; i < size; ++i) { - if (T* sender = m_dispatchingList[i]) { - m_dispatchingList[i] = 0; + for (auto& event : m_dispatchingList) { + if (T* sender = event) { + event = nullptr; sender->dispatchPendingEvent(this); } } @@ -110,5 +106,3 @@ template<typename T> void EventSender<T>::dispatchPendingEvents() } } // namespace WebCore - -#endif // EventSender_h |