Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "core/dom/EventHandlerRegistry.h" | 6 #include "core/dom/EventHandlerRegistry.h" |
| 7 | 7 |
| 8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 9 #include "core/events/ThreadLocalEventNames.h" | 9 #include "core/events/ThreadLocalEventNames.h" |
| 10 #include "core/events/WheelEvent.h" | 10 #include "core/events/WheelEvent.h" |
| 11 #include "core/frame/FrameHost.h" | 11 #include "core/frame/FrameHost.h" |
| 12 #include "core/frame/LocalFrame.h" | 12 #include "core/frame/LocalFrame.h" |
| 13 #include "core/page/Chrome.h" | 13 #include "core/page/Chrome.h" |
| 14 #include "core/page/ChromeClient.h" | 14 #include "core/page/ChromeClient.h" |
| 15 #include "core/page/Page.h" | 15 #include "core/page/Page.h" |
| 16 #include "core/page/scrolling/ScrollingCoordinator.h" | 16 #include "core/page/scrolling/ScrollingCoordinator.h" |
| 17 | 17 |
| 18 namespace WebCore { | 18 namespace WebCore { |
| 19 | 19 |
| 20 EventHandlerRegistry::DocumentObserver::DocumentObserver(Document& document) | |
| 21 : ActiveDOMObject(&document) | |
| 22 { | |
| 23 suspendIfNeeded(); | |
|
abarth-chromium
2014/04/22 16:18:23
As a general pattern, we don't call suspendIfNeede
Sami
2014/04/22 18:05:18
Okay, it sounds like I can move the call to suspen
| |
| 24 } | |
| 25 | |
| 26 EventHandlerRegistry::DocumentObserver::~DocumentObserver() | |
| 27 { | |
| 28 } | |
| 29 | |
| 30 void EventHandlerRegistry::DocumentObserver::stop() | |
| 31 { | |
| 32 Document* document = static_cast<Document*>(lifecycleContext()); | |
| 33 Document* parentDocument = document->parentDocument(); | |
| 34 if (!parentDocument) | |
| 35 return; | |
| 36 EventHandlerRegistry* parentRegistry = EventHandlerRegistry::from(*parentDoc ument); | |
| 37 parentRegistry->didRemoveAllEventHandlers(*document); | |
| 38 } | |
| 39 | |
| 20 EventHandlerRegistry::HandlerState::HandlerState() | 40 EventHandlerRegistry::HandlerState::HandlerState() |
| 21 { | 41 { |
| 22 } | 42 } |
| 23 | 43 |
| 24 EventHandlerRegistry::HandlerState::~HandlerState() | 44 EventHandlerRegistry::HandlerState::~HandlerState() |
| 25 { | 45 { |
| 26 } | 46 } |
| 27 | 47 |
| 28 EventHandlerRegistry::EventHandlerRegistry(Document& document) | 48 EventHandlerRegistry::EventHandlerRegistry(Document& document) |
| 29 : m_document(document) | 49 : m_document(document) |
| 50 , m_documentObserver(DocumentObserver(document)) | |
| 30 { | 51 { |
|
abarth-chromium
2014/04/22 16:18:23
What's the point of having a separate DocumentObse
Sami
2014/04/22 18:05:18
First, it better isolates the implementation from
| |
| 31 } | 52 } |
| 32 | 53 |
| 33 EventHandlerRegistry::~EventHandlerRegistry() | 54 EventHandlerRegistry::~EventHandlerRegistry() |
| 34 { | 55 { |
| 35 } | 56 } |
| 36 | 57 |
| 37 const char* EventHandlerRegistry::supplementName() | 58 const char* EventHandlerRegistry::supplementName() |
| 38 { | 59 { |
| 39 return "EventHandlerRegistry"; | 60 return "EventHandlerRegistry"; |
| 40 } | 61 } |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 68 { | 89 { |
| 69 EventTargetSet* targets = m_eventHandlers[handlerClass].targets.get(); | 90 EventTargetSet* targets = m_eventHandlers[handlerClass].targets.get(); |
| 70 return targets && targets->size(); | 91 return targets && targets->size(); |
| 71 } | 92 } |
| 72 | 93 |
| 73 bool EventHandlerRegistry::updateEventHandlerTargets(ChangeOperation op, EventHa ndlerClass handlerClass, EventTarget* target) | 94 bool EventHandlerRegistry::updateEventHandlerTargets(ChangeOperation op, EventHa ndlerClass handlerClass, EventTarget* target) |
| 74 { | 95 { |
| 75 EventTargetSet* targets = m_eventHandlers[handlerClass].targets.get(); | 96 EventTargetSet* targets = m_eventHandlers[handlerClass].targets.get(); |
| 76 if (op == Add) { | 97 if (op == Add) { |
| 77 #if ASSERT_ENABLED | 98 #if ASSERT_ENABLED |
| 78 if (Node* node = target->toNode()) | 99 if (Node* node = target->toNode()) { |
| 79 ASSERT(&node->document() == &m_document); | 100 // The node should either be in the document, or be the Document nod e of a child |
| 101 // of the document. | |
| 102 ASSERT(&node->document() == &m_document | |
| 103 || (node->isDocumentNode() && toDocument(node)->parentDocument() == &m_document)); | |
| 104 } | |
| 80 #endif // ASSERT_ENABLED | 105 #endif // ASSERT_ENABLED |
| 81 | 106 |
| 82 if (!targets) { | 107 if (!targets) { |
| 83 m_eventHandlers[handlerClass].targets = adoptPtr(new EventTargetSet) ; | 108 m_eventHandlers[handlerClass].targets = adoptPtr(new EventTargetSet) ; |
| 84 targets = m_eventHandlers[handlerClass].targets.get(); | 109 targets = m_eventHandlers[handlerClass].targets.get(); |
| 85 } | 110 } |
| 86 | 111 |
| 87 if (!targets->add(target).isNewEntry) { | 112 if (!targets->add(target).isNewEntry) { |
| 88 // Just incremented refcount, no real change. | 113 // Just incremented refcount, no real change. |
| 114 #if ASSERT_ENABLED | |
| 115 // If this is a child document node, then the count should never go above 1. | |
| 116 if (Node* node = target->toNode()) | |
| 117 ASSERT(!node->isDocumentNode() || &node->document() == &m_docume nt); | |
| 118 #endif // ASSERT_ENABLED | |
| 89 return false; | 119 return false; |
| 90 } | 120 } |
| 91 } else { | 121 } else { |
| 92 // Note that we can't assert that |target| is in this document because | 122 // Note that we can't assert that |target| is in this document because |
| 93 // it might be in the process of moving out of it. | 123 // it might be in the process of moving out of it. |
| 94 ASSERT(op == Remove || op == RemoveAll); | 124 ASSERT(op == Remove || op == RemoveAll); |
| 95 ASSERT(op == RemoveAll || targets->contains(target)); | 125 ASSERT(op == RemoveAll || targets->contains(target)); |
| 96 if (!targets) | 126 if (!targets) |
| 97 return false; | 127 return false; |
| 98 | 128 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 116 if (!m_document.isActive()) { | 146 if (!m_document.isActive()) { |
| 117 return; | 147 return; |
| 118 } | 148 } |
| 119 | 149 |
| 120 bool hadHandlers = hasEventHandlers(handlerClass); | 150 bool hadHandlers = hasEventHandlers(handlerClass); |
| 121 updateEventHandlerTargets(op, handlerClass, target); | 151 updateEventHandlerTargets(op, handlerClass, target); |
| 122 bool hasHandlers = hasEventHandlers(handlerClass); | 152 bool hasHandlers = hasEventHandlers(handlerClass); |
| 123 | 153 |
| 124 // Notify the parent document's registry if we added the first or removed | 154 // Notify the parent document's registry if we added the first or removed |
| 125 // the last handler. | 155 // the last handler. |
| 126 if (hadHandlers != hasHandlers && !m_document.parentDocument()) { | 156 if (hadHandlers != hasHandlers) { |
| 127 // This is the root registry; notify clients accordingly. | 157 if (Document* parent = m_document.parentDocument()) { |
| 128 notifyHasHandlersChanged(handlerClass, hasHandlers); | 158 // Report change to parent with our Document as the target. |
| 159 EventHandlerRegistry::from(*parent)->updateEventHandlerInternal(op, handlerClass, &m_document); | |
| 160 } else { | |
| 161 // This is the root registry; notify clients accordingly. | |
| 162 notifyHasHandlersChanged(handlerClass, hasHandlers); | |
| 163 } | |
|
abarth-chromium
2014/04/22 16:18:23
Can we implement this algorithm iteratively instea
Sami
2014/04/22 18:05:18
Sure, done. I'm having trouble deciding which way
| |
| 129 } | 164 } |
| 130 } | 165 } |
| 131 | 166 |
| 132 void EventHandlerRegistry::updateEventHandlerOfType(ChangeOperation op, const At omicString& eventType, EventTarget* target) | 167 void EventHandlerRegistry::updateEventHandlerOfType(ChangeOperation op, const At omicString& eventType, EventTarget* target) |
| 133 { | 168 { |
| 134 EventHandlerClass handlerClass; | 169 EventHandlerClass handlerClass; |
| 135 if (!eventTypeToClass(eventType, &handlerClass)) | 170 if (!eventTypeToClass(eventType, &handlerClass)) |
| 136 return; | 171 return; |
| 137 updateEventHandlerInternal(op, handlerClass, target); | 172 updateEventHandlerInternal(op, handlerClass, target); |
| 138 } | 173 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 if (scrollingCoordinator) | 228 if (scrollingCoordinator) |
| 194 scrollingCoordinator->updateHaveScrollEventHandlers(); | 229 scrollingCoordinator->updateHaveScrollEventHandlers(); |
| 195 break; | 230 break; |
| 196 default: | 231 default: |
| 197 ASSERT_NOT_REACHED(); | 232 ASSERT_NOT_REACHED(); |
| 198 break; | 233 break; |
| 199 } | 234 } |
| 200 } | 235 } |
| 201 | 236 |
| 202 } // namespace WebCore | 237 } // namespace WebCore |
| OLD | NEW |