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 "core/frame/EventHandlerRegistry.h" | 5 #include "core/frame/EventHandlerRegistry.h" |
6 | 6 |
7 #include "core/events/EventListenerOptions.h" | 7 #include "core/events/EventListenerOptions.h" |
8 #include "core/events/EventUtil.h" | 8 #include "core/events/EventUtil.h" |
9 #include "core/frame/LocalDOMWindow.h" | 9 #include "core/frame/LocalDOMWindow.h" |
10 #include "core/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 } | 112 } |
113 | 113 |
114 void EventHandlerRegistry::updateEventHandlerInternal( | 114 void EventHandlerRegistry::updateEventHandlerInternal( |
115 ChangeOperation op, | 115 ChangeOperation op, |
116 EventHandlerClass handlerClass, | 116 EventHandlerClass handlerClass, |
117 EventTarget* target) { | 117 EventTarget* target) { |
118 bool hadHandlers = m_targets[handlerClass].size(); | 118 bool hadHandlers = m_targets[handlerClass].size(); |
119 bool targetSetChanged = updateEventHandlerTargets(op, handlerClass, target); | 119 bool targetSetChanged = updateEventHandlerTargets(op, handlerClass, target); |
120 bool hasHandlers = m_targets[handlerClass].size(); | 120 bool hasHandlers = m_targets[handlerClass].size(); |
121 | 121 |
122 if (hadHandlers != hasHandlers) { | 122 if (hadHandlers != hasHandlers) |
123 LocalFrame* frame = nullptr; | 123 notifyHasHandlersChanged(handlerClass, hasHandlers); |
124 if (Node* node = target->toNode()) { | |
125 frame = node->document().frame(); | |
126 } else if (LocalDOMWindow* domWindow = target->toLocalDOMWindow()) { | |
127 frame = domWindow->frame(); | |
128 } else { | |
129 NOTREACHED() << "Unexpected target type for event handler."; | |
130 } | |
131 | |
132 notifyHasHandlersChanged(frame, handlerClass, hasHandlers); | |
133 } | |
134 | 124 |
135 if (targetSetChanged) | 125 if (targetSetChanged) |
136 notifyDidAddOrRemoveEventHandlerTarget(handlerClass); | 126 notifyDidAddOrRemoveEventHandlerTarget(handlerClass); |
137 } | 127 } |
138 | 128 |
139 void EventHandlerRegistry::updateEventHandlerOfType( | 129 void EventHandlerRegistry::updateEventHandlerOfType( |
140 ChangeOperation op, | 130 ChangeOperation op, |
141 const AtomicString& eventType, | 131 const AtomicString& eventType, |
142 const AddEventListenerOptions& options, | 132 const AddEventListenerOptions& options, |
143 EventTarget* target) { | 133 EventTarget* target) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 } | 188 } |
199 | 189 |
200 void EventHandlerRegistry::didRemoveAllEventHandlers(EventTarget& target) { | 190 void EventHandlerRegistry::didRemoveAllEventHandlers(EventTarget& target) { |
201 for (size_t i = 0; i < EventHandlerClassCount; ++i) { | 191 for (size_t i = 0; i < EventHandlerClassCount; ++i) { |
202 EventHandlerClass handlerClass = static_cast<EventHandlerClass>(i); | 192 EventHandlerClass handlerClass = static_cast<EventHandlerClass>(i); |
203 updateEventHandlerInternal(RemoveAll, handlerClass, &target); | 193 updateEventHandlerInternal(RemoveAll, handlerClass, &target); |
204 } | 194 } |
205 } | 195 } |
206 | 196 |
207 void EventHandlerRegistry::notifyHasHandlersChanged( | 197 void EventHandlerRegistry::notifyHasHandlersChanged( |
208 LocalFrame* frame, | |
209 EventHandlerClass handlerClass, | 198 EventHandlerClass handlerClass, |
210 bool hasActiveHandlers) { | 199 bool hasActiveHandlers) { |
211 switch (handlerClass) { | 200 switch (handlerClass) { |
212 case ScrollEvent: | 201 case ScrollEvent: |
213 m_frameHost->chromeClient().setHasScrollEventHandlers(frame, | 202 m_frameHost->chromeClient().setHasScrollEventHandlers(hasActiveHandlers); |
214 hasActiveHandlers); | |
215 break; | 203 break; |
216 case WheelEventBlocking: | 204 case WheelEventBlocking: |
217 case WheelEventPassive: | 205 case WheelEventPassive: |
218 m_frameHost->chromeClient().setEventListenerProperties( | 206 m_frameHost->chromeClient().setEventListenerProperties( |
219 frame, WebEventListenerClass::MouseWheel, | 207 WebEventListenerClass::MouseWheel, |
220 webEventListenerProperties(hasEventHandlers(WheelEventBlocking), | 208 webEventListenerProperties(hasEventHandlers(WheelEventBlocking), |
221 hasEventHandlers(WheelEventPassive))); | 209 hasEventHandlers(WheelEventPassive))); |
222 break; | 210 break; |
223 case TouchStartOrMoveEventBlocking: | 211 case TouchStartOrMoveEventBlocking: |
224 case TouchStartOrMoveEventPassive: | 212 case TouchStartOrMoveEventPassive: |
225 m_frameHost->chromeClient().setEventListenerProperties( | 213 m_frameHost->chromeClient().setEventListenerProperties( |
226 frame, WebEventListenerClass::TouchStartOrMove, | 214 WebEventListenerClass::TouchStartOrMove, |
227 webEventListenerProperties( | 215 webEventListenerProperties( |
228 hasEventHandlers(TouchStartOrMoveEventBlocking), | 216 hasEventHandlers(TouchStartOrMoveEventBlocking), |
229 hasEventHandlers(TouchStartOrMoveEventPassive))); | 217 hasEventHandlers(TouchStartOrMoveEventPassive))); |
230 break; | 218 break; |
231 case TouchEndOrCancelEventBlocking: | 219 case TouchEndOrCancelEventBlocking: |
232 case TouchEndOrCancelEventPassive: | 220 case TouchEndOrCancelEventPassive: |
233 m_frameHost->chromeClient().setEventListenerProperties( | 221 m_frameHost->chromeClient().setEventListenerProperties( |
234 frame, WebEventListenerClass::TouchEndOrCancel, | 222 WebEventListenerClass::TouchEndOrCancel, |
235 webEventListenerProperties( | 223 webEventListenerProperties( |
236 hasEventHandlers(TouchEndOrCancelEventBlocking), | 224 hasEventHandlers(TouchEndOrCancelEventBlocking), |
237 hasEventHandlers(TouchEndOrCancelEventPassive))); | 225 hasEventHandlers(TouchEndOrCancelEventPassive))); |
238 break; | 226 break; |
239 #if DCHECK_IS_ON() | 227 #if DCHECK_IS_ON() |
240 case EventsForTesting: | 228 case EventsForTesting: |
241 break; | 229 break; |
242 #endif | 230 #endif |
243 default: | 231 default: |
244 ASSERT_NOT_REACHED(); | 232 ASSERT_NOT_REACHED(); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 ASSERT(window->frame()); | 313 ASSERT(window->frame()); |
326 ASSERT(window->frame()->host()); | 314 ASSERT(window->frame()->host()); |
327 ASSERT(window->frame()->host() == m_frameHost); | 315 ASSERT(window->frame()->host() == m_frameHost); |
328 } | 316 } |
329 } | 317 } |
330 } | 318 } |
331 #endif // DCHECK_IS_ON() | 319 #endif // DCHECK_IS_ON() |
332 } | 320 } |
333 | 321 |
334 } // namespace blink | 322 } // namespace blink |
OLD | NEW |