https://bugs.webkit.org/show_bug.cgi?id=123408
Reviewed by Darin Adler.
Clean up the ScopedEventQueue implementation. ScopedEventQueue::instance() should return a reference to a
NeverDestroyed<ScopedEventQueue> object. The static ScopedEventQueue::s_instance pointer is removed.
The ScopedEventQueue destructor, the dispatchAllEvents method and the scope level incrementation/decrementation
methods are made private. NeverDestroyed<ScopedEventQueue> and EventQueueScope are made friends of the
ScopedEventQueue class so they can access the constructor and the incrementation/decrementation methods, respectively.
ScopedEventQueue method definitions are reordered to follow the order of their declarations in the header file.
ScopedEventQueue::dispatchAllEvents() now uses std::move to efficiently dispatch and clear all currently queued events.
* dom/EventDispatcher.cpp:
(WebCore::EventDispatcher::dispatchScopedEvent):
* dom/ScopedEventQueue.cpp:
(WebCore::ScopedEventQueue::instance):
(WebCore::ScopedEventQueue::dispatchAllEvents):
* dom/ScopedEventQueue.h:
(WebCore::EventQueueScope::EventQueueScope):
(WebCore::EventQueueScope::~EventQueueScope):
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@158182
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2013-10-28 Zan Dobersek <zdobersek@igalia.com>
+
+ Clean up ScopedEventQueue
+ https://bugs.webkit.org/show_bug.cgi?id=123408
+
+ Reviewed by Darin Adler.
+
+ Clean up the ScopedEventQueue implementation. ScopedEventQueue::instance() should return a reference to a
+ NeverDestroyed<ScopedEventQueue> object. The static ScopedEventQueue::s_instance pointer is removed.
+
+ The ScopedEventQueue destructor, the dispatchAllEvents method and the scope level incrementation/decrementation
+ methods are made private. NeverDestroyed<ScopedEventQueue> and EventQueueScope are made friends of the
+ ScopedEventQueue class so they can access the constructor and the incrementation/decrementation methods, respectively.
+
+ ScopedEventQueue method definitions are reordered to follow the order of their declarations in the header file.
+ ScopedEventQueue::dispatchAllEvents() now uses std::move to efficiently dispatch and clear all currently queued events.
+
+ * dom/EventDispatcher.cpp:
+ (WebCore::EventDispatcher::dispatchScopedEvent):
+ * dom/ScopedEventQueue.cpp:
+ (WebCore::ScopedEventQueue::instance):
+ (WebCore::ScopedEventQueue::dispatchAllEvents):
+ * dom/ScopedEventQueue.h:
+ (WebCore::EventQueueScope::EventQueueScope):
+ (WebCore::EventQueueScope::~EventQueueScope):
+
2013-10-28 Andreas Kling <akling@apple.com>
applyTextTransform() should take a const RenderStyle&.
{
// We need to set the target here because it can go away by the time we actually fire the event.
event->setTarget(&eventTargetRespectingTargetRules(node));
- ScopedEventQueue::instance()->enqueueEvent(event);
+ ScopedEventQueue::instance().enqueueEvent(event);
}
void EventDispatcher::dispatchSimulatedClick(Element* element, Event* underlyingEvent, SimulatedClickMouseEventOptions mouseEventOptions, SimulatedClickVisualOptions visualOptions)
#include "Event.h"
#include "EventDispatcher.h"
#include "EventTarget.h"
-#include <wtf/OwnPtr.h>
#include <wtf/RefPtr.h>
namespace WebCore {
-ScopedEventQueue* ScopedEventQueue::s_instance = 0;
-
ScopedEventQueue::ScopedEventQueue()
: m_scopingLevel(0)
{
ASSERT(!m_queuedEvents.size());
}
-void ScopedEventQueue::initialize()
+ScopedEventQueue& ScopedEventQueue::instance()
{
- ASSERT(!s_instance);
- OwnPtr<ScopedEventQueue> instance = adoptPtr(new ScopedEventQueue);
- s_instance = instance.leakPtr();
+ static NeverDestroyed<ScopedEventQueue> scopedEventQueue;
+ return scopedEventQueue;
}
void ScopedEventQueue::enqueueEvent(PassRefPtr<Event> event)
dispatchEvent(event);
}
-void ScopedEventQueue::dispatchAllEvents()
-{
- Vector<RefPtr<Event>> queuedEvents;
- queuedEvents.swap(m_queuedEvents);
-
- for (size_t i = 0; i < queuedEvents.size(); i++)
- dispatchEvent(queuedEvents[i].release());
-}
-
void ScopedEventQueue::dispatchEvent(PassRefPtr<Event> event) const
{
ASSERT(event->target());
EventDispatcher::dispatchEvent(node, event);
}
-ScopedEventQueue* ScopedEventQueue::instance()
+void ScopedEventQueue::dispatchAllEvents()
{
- if (!s_instance)
- initialize();
-
- return s_instance;
+ Vector<RefPtr<Event>> queuedEvents = std::move(m_queuedEvents);
+ for (size_t i = 0; i < queuedEvents.size(); i++)
+ dispatchEvent(queuedEvents[i].release());
}
void ScopedEventQueue::incrementScopingLevel()
#ifndef ScopedEventQueue_h
#define ScopedEventQueue_h
+#include <wtf/NeverDestroyed.h>
#include <wtf/Noncopyable.h>
#include <wtf/PassRefPtr.h>
#include <wtf/RefPtr.h>
namespace WebCore {
class Event;
+class EventQueueScope;
class ScopedEventQueue {
WTF_MAKE_NONCOPYABLE(ScopedEventQueue); WTF_MAKE_FAST_ALLOCATED;
public:
- ~ScopedEventQueue();
-
+ static ScopedEventQueue& instance();
void enqueueEvent(PassRefPtr<Event>);
- void dispatchAllEvents();
- static ScopedEventQueue* instance();
-
- void incrementScopingLevel();
- void decrementScopingLevel();
private:
ScopedEventQueue();
- static void initialize();
+ ~ScopedEventQueue();
+
void dispatchEvent(PassRefPtr<Event>) const;
+ void dispatchAllEvents();
+ void incrementScopingLevel();
+ void decrementScopingLevel();
Vector<RefPtr<Event>> m_queuedEvents;
unsigned m_scopingLevel;
- static ScopedEventQueue* s_instance;
+ friend NeverDestroyed<ScopedEventQueue>;
+ friend EventQueueScope;
};
class EventQueueScope {
WTF_MAKE_NONCOPYABLE(EventQueueScope);
-
public:
- EventQueueScope() { ScopedEventQueue::instance()->incrementScopingLevel(); }
- ~EventQueueScope() { ScopedEventQueue::instance()->decrementScopingLevel(); }
+ EventQueueScope() { ScopedEventQueue::instance().incrementScopingLevel(); }
+ ~EventQueueScope() { ScopedEventQueue::instance().decrementScopingLevel(); }
};
}