Chromium Code Reviews| Index: Source/core/page/EventHandlerRegistry.cpp |
| diff --git a/Source/core/dom/EventHandlerRegistry.cpp b/Source/core/page/EventHandlerRegistry.cpp |
| similarity index 69% |
| rename from Source/core/dom/EventHandlerRegistry.cpp |
| rename to Source/core/page/EventHandlerRegistry.cpp |
| index b72b465ffaadc0a31187c14559227570e38b81e7..e02158f90e92a62e981ff4c140836dab659bd185 100644 |
| --- a/Source/core/dom/EventHandlerRegistry.cpp |
| +++ b/Source/core/page/EventHandlerRegistry.cpp |
| @@ -3,30 +3,15 @@ |
| // found in the LICENSE file. |
| #include "config.h" |
| -#include "core/dom/EventHandlerRegistry.h" |
| +#include "core/page/EventHandlerRegistry.h" |
| -#include "core/dom/Document.h" |
| #include "core/events/ThreadLocalEventNames.h" |
| -#include "core/events/WheelEvent.h" |
| -#include "core/frame/FrameHost.h" |
| -#include "core/frame/LocalFrame.h" |
| -#include "core/page/Chrome.h" |
| -#include "core/page/ChromeClient.h" |
| -#include "core/page/Page.h" |
| #include "core/page/scrolling/ScrollingCoordinator.h" |
| namespace WebCore { |
| -EventHandlerRegistry::HandlerState::HandlerState() |
| -{ |
| -} |
| - |
| -EventHandlerRegistry::HandlerState::~HandlerState() |
| -{ |
| -} |
| - |
| -EventHandlerRegistry::EventHandlerRegistry(Document& document) |
| - : m_document(document) |
| +EventHandlerRegistry::EventHandlerRegistry(Page& page) |
| + : m_page(page) |
| { |
| } |
| @@ -39,12 +24,12 @@ const char* EventHandlerRegistry::supplementName() |
| return "EventHandlerRegistry"; |
| } |
| -EventHandlerRegistry* EventHandlerRegistry::from(Document& document) |
| +EventHandlerRegistry* EventHandlerRegistry::from(Page& page) |
| { |
| - EventHandlerRegistry* registry = static_cast<EventHandlerRegistry*>(DocumentSupplement::from(document, supplementName())); |
| + EventHandlerRegistry* registry = static_cast<EventHandlerRegistry*>(Supplement<Page>::from(page, supplementName())); |
| if (!registry) { |
| - registry = new EventHandlerRegistry(document); |
| - DocumentSupplement::provideTo(document, supplementName(), adoptPtr(registry)); |
| + registry = new EventHandlerRegistry(page); |
| + Supplement<Page>::provideTo(page, supplementName(), adoptPtr(registry)); |
| } |
| return registry; |
| } |
| @@ -61,29 +46,18 @@ bool EventHandlerRegistry::eventTypeToClass(const AtomicString& eventType, Event |
| const EventTargetSet* EventHandlerRegistry::eventHandlerTargets(EventHandlerClass handlerClass) const |
| { |
| - return m_eventHandlers[handlerClass].targets.get(); |
| + return &m_targets[handlerClass]; |
| } |
| bool EventHandlerRegistry::hasEventHandlers(EventHandlerClass handlerClass) const |
| { |
| - EventTargetSet* targets = m_eventHandlers[handlerClass].targets.get(); |
| - return targets && targets->size(); |
| + return m_targets[handlerClass].size(); |
| } |
| bool EventHandlerRegistry::updateEventHandlerTargets(ChangeOperation op, EventHandlerClass handlerClass, EventTarget* target) |
| { |
| - EventTargetSet* targets = m_eventHandlers[handlerClass].targets.get(); |
| + EventTargetSet* targets = &m_targets[handlerClass]; |
| if (op == Add) { |
| -#if ASSERT_ENABLED |
| - if (Node* node = target->toNode()) |
| - ASSERT(&node->document() == &m_document); |
| -#endif // ASSERT_ENABLED |
| - |
| - if (!targets) { |
| - m_eventHandlers[handlerClass].targets = adoptPtr(new EventTargetSet); |
| - targets = m_eventHandlers[handlerClass].targets.get(); |
| - } |
| - |
| if (!targets->add(target).isNewEntry) { |
| // Just incremented refcount, no real change. |
| return false; |
| @@ -93,8 +67,6 @@ bool EventHandlerRegistry::updateEventHandlerTargets(ChangeOperation op, EventHa |
| // it might be in the process of moving out of it. |
| ASSERT(op == Remove || op == RemoveAll); |
| ASSERT(op == RemoveAll || targets->contains(target)); |
| - if (!targets) |
| - return false; |
| if (op == RemoveAll) { |
| if (!targets->contains(target)) |
| @@ -112,19 +84,11 @@ bool EventHandlerRegistry::updateEventHandlerTargets(ChangeOperation op, EventHa |
| void EventHandlerRegistry::updateEventHandlerInternal(ChangeOperation op, EventHandlerClass handlerClass, EventTarget* target) |
| { |
| - // After the document has stopped, all updates become no-ops. |
| - if (!m_document.isActive()) { |
| - return; |
| - } |
| - |
| bool hadHandlers = hasEventHandlers(handlerClass); |
| updateEventHandlerTargets(op, handlerClass, target); |
| bool hasHandlers = hasEventHandlers(handlerClass); |
| - // Notify the parent document's registry if we added the first or removed |
| - // the last handler. |
| - if (hadHandlers != hasHandlers && !m_document.parentDocument()) { |
| - // This is the root registry; notify clients accordingly. |
| + if (hadHandlers != hasHandlers) { |
| notifyHasHandlersChanged(handlerClass, hasHandlers); |
| } |
| } |
| @@ -159,7 +123,11 @@ void EventHandlerRegistry::didRemoveEventHandler(EventTarget& target, EventHandl |
| void EventHandlerRegistry::didMoveFromOtherDocument(EventTarget& target, Document& oldDocument) |
| { |
| - EventHandlerRegistry* oldRegistry = EventHandlerRegistry::from(oldDocument); |
| + if (!oldDocument.page()) |
| + return; |
| + EventHandlerRegistry* oldRegistry = EventHandlerRegistry::from(*oldDocument.page()); |
| + if (oldRegistry == this) |
|
Rick Byers
2014/04/24 21:30:12
Do you know in what scenarios this won't be true?
Sami
2014/04/25 19:51:15
No, I don't have evidence whether this can actuall
|
| + return; |
| for (size_t i = 0; i < EventHandlerClassCount; ++i) { |
| EventHandlerClass handlerClass = static_cast<EventHandlerClass>(i); |
| const EventTargetSet* targets = oldRegistry->eventHandlerTargets(handlerClass); |
| @@ -176,17 +144,13 @@ void EventHandlerRegistry::didRemoveAllEventHandlers(EventTarget& target) |
| { |
| for (size_t i = 0; i < EventHandlerClassCount; ++i) { |
| EventHandlerClass handlerClass = static_cast<EventHandlerClass>(i); |
| - const EventTargetSet* targets = eventHandlerTargets(handlerClass); |
| - if (!targets) |
| - continue; |
| updateEventHandlerInternal(RemoveAll, handlerClass, &target); |
| } |
| } |
| void EventHandlerRegistry::notifyHasHandlersChanged(EventHandlerClass handlerClass, bool hasActiveHandlers) |
| { |
| - Page* page = m_document.page(); |
| - ScrollingCoordinator* scrollingCoordinator = page ? page->scrollingCoordinator() : 0; |
| + ScrollingCoordinator* scrollingCoordinator = m_page.scrollingCoordinator(); |
| switch (handlerClass) { |
| case ScrollEvent: |