This source file includes following definitions.
- initialize
- enqueueEventDispatchMediator
- dispatchAllEvents
- dispatchEvent
- instance
- incrementScopingLevel
- decrementScopingLevel
#include "config.h"
#include "core/events/ScopedEventQueue.h"
#include "core/events/Event.h"
#include "core/events/EventDispatchMediator.h"
#include "core/events/EventDispatcher.h"
#include "core/events/EventTarget.h"
#include "wtf/OwnPtr.h"
namespace WebCore {
ScopedEventQueue* ScopedEventQueue::s_instance = 0;
ScopedEventQueue::ScopedEventQueue()
: m_scopingLevel(0)
{
}
ScopedEventQueue::~ScopedEventQueue()
{
ASSERT(!m_scopingLevel);
ASSERT(!m_queuedEventDispatchMediators.size());
}
void ScopedEventQueue::initialize()
{
ASSERT(!s_instance);
OwnPtr<ScopedEventQueue> instance = adoptPtr(new ScopedEventQueue);
s_instance = instance.leakPtr();
}
void ScopedEventQueue::enqueueEventDispatchMediator(PassRefPtr<EventDispatchMediator> mediator)
{
if (m_scopingLevel)
m_queuedEventDispatchMediators.append(mediator);
else
dispatchEvent(mediator);
}
void ScopedEventQueue::dispatchAllEvents()
{
Vector<RefPtr<EventDispatchMediator> > queuedEventDispatchMediators;
queuedEventDispatchMediators.swap(m_queuedEventDispatchMediators);
for (size_t i = 0; i < queuedEventDispatchMediators.size(); i++)
dispatchEvent(queuedEventDispatchMediators[i].release());
}
void ScopedEventQueue::dispatchEvent(PassRefPtr<EventDispatchMediator> mediator) const
{
ASSERT(mediator->event()->target());
Node* node = mediator->event()->target()->toNode();
EventDispatcher::dispatchEvent(node, mediator);
}
ScopedEventQueue* ScopedEventQueue::instance()
{
if (!s_instance)
initialize();
return s_instance;
}
void ScopedEventQueue::incrementScopingLevel()
{
m_scopingLevel++;
}
void ScopedEventQueue::decrementScopingLevel()
{
ASSERT(m_scopingLevel);
m_scopingLevel--;
if (!m_scopingLevel)
dispatchAllEvents();
}
}