diff options
Diffstat (limited to 'Source/WebCore/dom/GenericEventQueue.cpp')
-rw-r--r-- | Source/WebCore/dom/GenericEventQueue.cpp | 62 |
1 files changed, 40 insertions, 22 deletions
diff --git a/Source/WebCore/dom/GenericEventQueue.cpp b/Source/WebCore/dom/GenericEventQueue.cpp index f27885642..7f56f45fa 100644 --- a/Source/WebCore/dom/GenericEventQueue.cpp +++ b/Source/WebCore/dom/GenericEventQueue.cpp @@ -10,10 +10,10 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR @@ -28,12 +28,14 @@ #include "Event.h" #include "EventTarget.h" +#include "ScriptExecutionContext.h" +#include "Timer.h" +#include <wtf/MainThread.h> namespace WebCore { GenericEventQueue::GenericEventQueue(EventTarget& owner) : m_owner(owner) - , m_timer(this, &GenericEventQueue::timerFired) , m_isClosed(false) { } @@ -42,54 +44,70 @@ GenericEventQueue::~GenericEventQueue() { } -bool GenericEventQueue::enqueueEvent(PassRefPtr<Event> event) +void GenericEventQueue::enqueueEvent(RefPtr<Event>&& event) { if (m_isClosed) - return false; + return; if (event->target() == &m_owner) - event->setTarget(0); + event->setTarget(nullptr); - m_pendingEvents.append(event); + m_pendingEvents.append(WTFMove(event)); - if (!m_timer.isActive()) - m_timer.startOneShot(0); + if (m_isSuspended) + return; - return true; + m_taskQueue.enqueueTask(std::bind(&GenericEventQueue::dispatchOneEvent, this)); } -void GenericEventQueue::timerFired(Timer<GenericEventQueue>&) +void GenericEventQueue::dispatchOneEvent() { - ASSERT(!m_timer.isActive()); ASSERT(!m_pendingEvents.isEmpty()); - Vector<RefPtr<Event>> pendingEvents; - m_pendingEvents.swap(pendingEvents); - Ref<EventTarget> protect(m_owner); - for (unsigned i = 0; i < pendingEvents.size(); ++i) { - EventTarget& target = pendingEvents[i]->target() ? *pendingEvents[i]->target() : m_owner; - target.dispatchEvent(pendingEvents[i].release()); - } + RefPtr<Event> event = m_pendingEvents.takeFirst(); + EventTarget& target = event->target() ? *event->target() : m_owner; + target.dispatchEvent(*event); } void GenericEventQueue::close() { m_isClosed = true; - m_timer.stop(); + m_taskQueue.close(); m_pendingEvents.clear(); } void GenericEventQueue::cancelAllEvents() { - m_timer.stop(); + m_taskQueue.cancelAllTasks(); m_pendingEvents.clear(); } bool GenericEventQueue::hasPendingEvents() const { - return m_pendingEvents.size(); + return !m_pendingEvents.isEmpty(); +} + +void GenericEventQueue::suspend() +{ + ASSERT(!m_isSuspended); + m_isSuspended = true; + m_taskQueue.cancelAllTasks(); +} + +void GenericEventQueue::resume() +{ + if (!m_isSuspended) + return; + + m_isSuspended = false; + + if (m_pendingEvents.isEmpty()) + return; + + for (unsigned i = 0; i < m_pendingEvents.size(); ++i) + m_taskQueue.enqueueTask(std::bind(&GenericEventQueue::dispatchOneEvent, this)); } } |