This source file includes following definitions.
- m_eventQueue
- fired
- create
- m_isClosed
- enqueueEvent
- cancelEvent
- close
- pendingEventTimerFired
- dispatchEvent
#include "config.h"
#include "core/events/DOMWindowEventQueue.h"
#include "core/dom/Document.h"
#include "core/events/Event.h"
#include "core/frame/DOMWindow.h"
#include "core/frame/SuspendableTimer.h"
namespace WebCore {
class DOMWindowEventQueueTimer : public SuspendableTimer {
WTF_MAKE_NONCOPYABLE(DOMWindowEventQueueTimer);
public:
DOMWindowEventQueueTimer(DOMWindowEventQueue* eventQueue, ExecutionContext* context)
: SuspendableTimer(context)
, m_eventQueue(eventQueue) { }
private:
virtual void fired() { m_eventQueue->pendingEventTimerFired(); }
DOMWindowEventQueue* m_eventQueue;
};
PassRefPtr<DOMWindowEventQueue> DOMWindowEventQueue::create(ExecutionContext* context)
{
return adoptRef(new DOMWindowEventQueue(context));
}
DOMWindowEventQueue::DOMWindowEventQueue(ExecutionContext* context)
: m_pendingEventTimer(adoptPtr(new DOMWindowEventQueueTimer(this, context)))
, m_isClosed(false)
{
m_pendingEventTimer->suspendIfNeeded();
}
DOMWindowEventQueue::~DOMWindowEventQueue()
{
}
bool DOMWindowEventQueue::enqueueEvent(PassRefPtrWillBeRawPtr<Event> event)
{
if (m_isClosed)
return false;
ASSERT(event->target());
bool wasAdded = m_queuedEvents.add(event).isNewEntry;
ASSERT_UNUSED(wasAdded, wasAdded);
if (!m_pendingEventTimer->isActive())
m_pendingEventTimer->startOneShot(0, FROM_HERE);
return true;
}
bool DOMWindowEventQueue::cancelEvent(Event* event)
{
ListHashSet<RefPtrWillBePersistent<Event>, 16>::iterator it = m_queuedEvents.find(event);
bool found = it != m_queuedEvents.end();
if (found)
m_queuedEvents.remove(it);
if (m_queuedEvents.isEmpty())
m_pendingEventTimer->stop();
return found;
}
void DOMWindowEventQueue::close()
{
m_isClosed = true;
m_pendingEventTimer->stop();
m_queuedEvents.clear();
}
void DOMWindowEventQueue::pendingEventTimerFired()
{
ASSERT(!m_pendingEventTimer->isActive());
ASSERT(!m_queuedEvents.isEmpty());
ASSERT(!m_queuedEvents.contains(nullptr));
bool wasAdded = m_queuedEvents.add(nullptr).isNewEntry;
ASSERT_UNUSED(wasAdded, wasAdded);
RefPtr<DOMWindowEventQueue> protector(this);
while (!m_queuedEvents.isEmpty()) {
ListHashSet<RefPtrWillBePersistent<Event>, 16>::iterator iter = m_queuedEvents.begin();
RefPtrWillBeRawPtr<Event> event = *iter;
m_queuedEvents.remove(iter);
if (!event)
break;
dispatchEvent(event.get());
}
}
void DOMWindowEventQueue::dispatchEvent(PassRefPtrWillBeRawPtr<Event> event)
{
EventTarget* eventTarget = event->target();
if (eventTarget->toDOMWindow())
eventTarget->toDOMWindow()->dispatchEvent(event, nullptr);
else
eventTarget->dispatchEvent(event);
}
}