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 notifyHasHandlersChanged(handlerClass, hasHandlers); | 123 LocalFrame* frame = nullptr; |
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 DCHECK(false) << "Unexpected target type for event handler."; | |
dcheng
2017/01/16 11:05:40
Nit: NOTREACHED()
wjmaclean
2017/01/17 18:23:27
Done.
| |
130 } | |
131 | |
132 notifyHasHandlersChanged(frame, handlerClass, hasHandlers); | |
133 } | |
124 | 134 |
125 if (targetSetChanged) | 135 if (targetSetChanged) |
126 notifyDidAddOrRemoveEventHandlerTarget(handlerClass); | 136 notifyDidAddOrRemoveEventHandlerTarget(handlerClass); |
127 } | 137 } |
128 | 138 |
129 void EventHandlerRegistry::updateEventHandlerOfType( | 139 void EventHandlerRegistry::updateEventHandlerOfType( |
130 ChangeOperation op, | 140 ChangeOperation op, |
131 const AtomicString& eventType, | 141 const AtomicString& eventType, |
132 const AddEventListenerOptions& options, | 142 const AddEventListenerOptions& options, |
133 EventTarget* target) { | 143 EventTarget* target) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 } | 206 } |
197 | 207 |
198 void EventHandlerRegistry::didRemoveAllEventHandlers(EventTarget& target) { | 208 void EventHandlerRegistry::didRemoveAllEventHandlers(EventTarget& target) { |
199 for (size_t i = 0; i < EventHandlerClassCount; ++i) { | 209 for (size_t i = 0; i < EventHandlerClassCount; ++i) { |
200 EventHandlerClass handlerClass = static_cast<EventHandlerClass>(i); | 210 EventHandlerClass handlerClass = static_cast<EventHandlerClass>(i); |
201 updateEventHandlerInternal(RemoveAll, handlerClass, &target); | 211 updateEventHandlerInternal(RemoveAll, handlerClass, &target); |
202 } | 212 } |
203 } | 213 } |
204 | 214 |
205 void EventHandlerRegistry::notifyHasHandlersChanged( | 215 void EventHandlerRegistry::notifyHasHandlersChanged( |
216 LocalFrame* frame, | |
206 EventHandlerClass handlerClass, | 217 EventHandlerClass handlerClass, |
207 bool hasActiveHandlers) { | 218 bool hasActiveHandlers) { |
208 switch (handlerClass) { | 219 switch (handlerClass) { |
209 case ScrollEvent: | 220 case ScrollEvent: |
210 m_frameHost->chromeClient().setHasScrollEventHandlers(hasActiveHandlers); | 221 m_frameHost->chromeClient().setHasScrollEventHandlers(frame, |
222 hasActiveHandlers); | |
211 break; | 223 break; |
212 case WheelEventBlocking: | 224 case WheelEventBlocking: |
213 case WheelEventPassive: | 225 case WheelEventPassive: |
214 m_frameHost->chromeClient().setEventListenerProperties( | 226 m_frameHost->chromeClient().setEventListenerProperties( |
215 WebEventListenerClass::MouseWheel, | 227 frame, WebEventListenerClass::MouseWheel, |
216 webEventListenerProperties(hasEventHandlers(WheelEventBlocking), | 228 webEventListenerProperties(hasEventHandlers(WheelEventBlocking), |
217 hasEventHandlers(WheelEventPassive))); | 229 hasEventHandlers(WheelEventPassive))); |
218 break; | 230 break; |
219 case TouchStartOrMoveEventBlocking: | 231 case TouchStartOrMoveEventBlocking: |
220 case TouchStartOrMoveEventPassive: | 232 case TouchStartOrMoveEventPassive: |
221 m_frameHost->chromeClient().setEventListenerProperties( | 233 m_frameHost->chromeClient().setEventListenerProperties( |
222 WebEventListenerClass::TouchStartOrMove, | 234 frame, WebEventListenerClass::TouchStartOrMove, |
223 webEventListenerProperties( | 235 webEventListenerProperties( |
224 hasEventHandlers(TouchStartOrMoveEventBlocking), | 236 hasEventHandlers(TouchStartOrMoveEventBlocking), |
225 hasEventHandlers(TouchStartOrMoveEventPassive))); | 237 hasEventHandlers(TouchStartOrMoveEventPassive))); |
226 break; | 238 break; |
227 case TouchEndOrCancelEventBlocking: | 239 case TouchEndOrCancelEventBlocking: |
228 case TouchEndOrCancelEventPassive: | 240 case TouchEndOrCancelEventPassive: |
229 m_frameHost->chromeClient().setEventListenerProperties( | 241 m_frameHost->chromeClient().setEventListenerProperties( |
230 WebEventListenerClass::TouchEndOrCancel, | 242 frame, WebEventListenerClass::TouchEndOrCancel, |
231 webEventListenerProperties( | 243 webEventListenerProperties( |
232 hasEventHandlers(TouchEndOrCancelEventBlocking), | 244 hasEventHandlers(TouchEndOrCancelEventBlocking), |
233 hasEventHandlers(TouchEndOrCancelEventPassive))); | 245 hasEventHandlers(TouchEndOrCancelEventPassive))); |
234 break; | 246 break; |
235 #if ENABLE(ASSERT) | 247 #if ENABLE(ASSERT) |
236 case EventsForTesting: | 248 case EventsForTesting: |
237 break; | 249 break; |
238 #endif | 250 #endif |
239 default: | 251 default: |
240 ASSERT_NOT_REACHED(); | 252 ASSERT_NOT_REACHED(); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
321 ASSERT(window->frame()); | 333 ASSERT(window->frame()); |
322 ASSERT(window->frame()->host()); | 334 ASSERT(window->frame()->host()); |
323 ASSERT(window->frame()->host() == m_frameHost); | 335 ASSERT(window->frame()->host() == m_frameHost); |
324 } | 336 } |
325 } | 337 } |
326 } | 338 } |
327 #endif // ENABLE(ASSERT) | 339 #endif // ENABLE(ASSERT) |
328 } | 340 } |
329 | 341 |
330 } // namespace blink | 342 } // namespace blink |
OLD | NEW |