| 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 NOTREACHED() << "Unexpected target type for event handler."; |
| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 } | 198 } |
| 189 | 199 |
| 190 void EventHandlerRegistry::didRemoveAllEventHandlers(EventTarget& target) { | 200 void EventHandlerRegistry::didRemoveAllEventHandlers(EventTarget& target) { |
| 191 for (size_t i = 0; i < EventHandlerClassCount; ++i) { | 201 for (size_t i = 0; i < EventHandlerClassCount; ++i) { |
| 192 EventHandlerClass handlerClass = static_cast<EventHandlerClass>(i); | 202 EventHandlerClass handlerClass = static_cast<EventHandlerClass>(i); |
| 193 updateEventHandlerInternal(RemoveAll, handlerClass, &target); | 203 updateEventHandlerInternal(RemoveAll, handlerClass, &target); |
| 194 } | 204 } |
| 195 } | 205 } |
| 196 | 206 |
| 197 void EventHandlerRegistry::notifyHasHandlersChanged( | 207 void EventHandlerRegistry::notifyHasHandlersChanged( |
| 208 LocalFrame* frame, |
| 198 EventHandlerClass handlerClass, | 209 EventHandlerClass handlerClass, |
| 199 bool hasActiveHandlers) { | 210 bool hasActiveHandlers) { |
| 200 switch (handlerClass) { | 211 switch (handlerClass) { |
| 201 case ScrollEvent: | 212 case ScrollEvent: |
| 202 m_frameHost->chromeClient().setHasScrollEventHandlers(hasActiveHandlers); | 213 m_frameHost->chromeClient().setHasScrollEventHandlers(frame, |
| 214 hasActiveHandlers); |
| 203 break; | 215 break; |
| 204 case WheelEventBlocking: | 216 case WheelEventBlocking: |
| 205 case WheelEventPassive: | 217 case WheelEventPassive: |
| 206 m_frameHost->chromeClient().setEventListenerProperties( | 218 m_frameHost->chromeClient().setEventListenerProperties( |
| 207 WebEventListenerClass::MouseWheel, | 219 frame, WebEventListenerClass::MouseWheel, |
| 208 webEventListenerProperties(hasEventHandlers(WheelEventBlocking), | 220 webEventListenerProperties(hasEventHandlers(WheelEventBlocking), |
| 209 hasEventHandlers(WheelEventPassive))); | 221 hasEventHandlers(WheelEventPassive))); |
| 210 break; | 222 break; |
| 211 case TouchStartOrMoveEventBlocking: | 223 case TouchStartOrMoveEventBlocking: |
| 212 case TouchStartOrMoveEventPassive: | 224 case TouchStartOrMoveEventPassive: |
| 213 m_frameHost->chromeClient().setEventListenerProperties( | 225 m_frameHost->chromeClient().setEventListenerProperties( |
| 214 WebEventListenerClass::TouchStartOrMove, | 226 frame, WebEventListenerClass::TouchStartOrMove, |
| 215 webEventListenerProperties( | 227 webEventListenerProperties( |
| 216 hasEventHandlers(TouchStartOrMoveEventBlocking), | 228 hasEventHandlers(TouchStartOrMoveEventBlocking), |
| 217 hasEventHandlers(TouchStartOrMoveEventPassive))); | 229 hasEventHandlers(TouchStartOrMoveEventPassive))); |
| 218 break; | 230 break; |
| 219 case TouchEndOrCancelEventBlocking: | 231 case TouchEndOrCancelEventBlocking: |
| 220 case TouchEndOrCancelEventPassive: | 232 case TouchEndOrCancelEventPassive: |
| 221 m_frameHost->chromeClient().setEventListenerProperties( | 233 m_frameHost->chromeClient().setEventListenerProperties( |
| 222 WebEventListenerClass::TouchEndOrCancel, | 234 frame, WebEventListenerClass::TouchEndOrCancel, |
| 223 webEventListenerProperties( | 235 webEventListenerProperties( |
| 224 hasEventHandlers(TouchEndOrCancelEventBlocking), | 236 hasEventHandlers(TouchEndOrCancelEventBlocking), |
| 225 hasEventHandlers(TouchEndOrCancelEventPassive))); | 237 hasEventHandlers(TouchEndOrCancelEventPassive))); |
| 226 break; | 238 break; |
| 227 #if DCHECK_IS_ON() | 239 #if DCHECK_IS_ON() |
| 228 case EventsForTesting: | 240 case EventsForTesting: |
| 229 break; | 241 break; |
| 230 #endif | 242 #endif |
| 231 default: | 243 default: |
| 232 ASSERT_NOT_REACHED(); | 244 ASSERT_NOT_REACHED(); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 ASSERT(window->frame()); | 325 ASSERT(window->frame()); |
| 314 ASSERT(window->frame()->host()); | 326 ASSERT(window->frame()->host()); |
| 315 ASSERT(window->frame()->host() == m_frameHost); | 327 ASSERT(window->frame()->host() == m_frameHost); |
| 316 } | 328 } |
| 317 } | 329 } |
| 318 } | 330 } |
| 319 #endif // DCHECK_IS_ON() | 331 #endif // DCHECK_IS_ON() |
| 320 } | 332 } |
| 321 | 333 |
| 322 } // namespace blink | 334 } // namespace blink |
| OLD | NEW |