Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: third_party/WebKit/Source/core/frame/EventHandlerRegistry.cpp

Issue 1577263004: Communicate whether passive event listeners exist to cc. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master_wheel_passive_listeners
Patch Set: Rebase Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/frame/LocalDOMWindow.h" 8 #include "core/frame/LocalDOMWindow.h"
8 #include "core/frame/LocalFrame.h" 9 #include "core/frame/LocalFrame.h"
9 #include "core/html/HTMLFrameOwnerElement.h" 10 #include "core/html/HTMLFrameOwnerElement.h"
10 #include "core/page/ChromeClient.h" 11 #include "core/page/ChromeClient.h"
11 #include "core/page/Page.h" 12 #include "core/page/Page.h"
12 #include "core/page/scrolling/ScrollingCoordinator.h" 13 #include "core/page/scrolling/ScrollingCoordinator.h"
13 14
14 namespace blink { 15 namespace blink {
15 16
16 namespace { 17 namespace {
(...skipping 13 matching lines...) Expand all
30 || eventType == EventTypeNames::pointercancel 31 || eventType == EventTypeNames::pointercancel
31 || eventType == EventTypeNames::pointerdown 32 || eventType == EventTypeNames::pointerdown
32 || eventType == EventTypeNames::pointerenter 33 || eventType == EventTypeNames::pointerenter
33 || eventType == EventTypeNames::pointerleave 34 || eventType == EventTypeNames::pointerleave
34 || eventType == EventTypeNames::pointermove 35 || eventType == EventTypeNames::pointermove
35 || eventType == EventTypeNames::pointerout 36 || eventType == EventTypeNames::pointerout
36 || eventType == EventTypeNames::pointerover 37 || eventType == EventTypeNames::pointerover
37 || eventType == EventTypeNames::pointerup; 38 || eventType == EventTypeNames::pointerup;
38 } 39 }
39 40
41 WebEventListenerProperties webEventListenerProperties(bool hasBlocking, bool has Passive)
42 {
43 if (hasBlocking)
44 return WebEventListenerProperties::Blocking;
45 if (hasPassive)
46 return WebEventListenerProperties::Passive;
47 return WebEventListenerProperties::Nothing;
48 }
49
40 } // namespace 50 } // namespace
41 51
42 EventHandlerRegistry::EventHandlerRegistry(FrameHost& frameHost) 52 EventHandlerRegistry::EventHandlerRegistry(FrameHost& frameHost)
43 : m_frameHost(&frameHost) 53 : m_frameHost(&frameHost)
44 { 54 {
45 } 55 }
46 56
47 EventHandlerRegistry::~EventHandlerRegistry() 57 EventHandlerRegistry::~EventHandlerRegistry()
48 { 58 {
49 checkConsistency(); 59 checkConsistency();
50 } 60 }
51 61
52 bool EventHandlerRegistry::eventTypeToClass(const AtomicString& eventType, Event HandlerClass* result) 62 bool EventHandlerRegistry::eventTypeToClass(const AtomicString& eventType, const EventListenerOptions& options, EventHandlerClass* result)
53 { 63 {
54 if (eventType == EventTypeNames::scroll) { 64 if (eventType == EventTypeNames::scroll) {
55 *result = ScrollEvent; 65 *result = ScrollEvent;
56 } else if (eventType == EventTypeNames::wheel || eventType == EventTypeNames ::mousewheel) { 66 } else if (eventType == EventTypeNames::wheel || eventType == EventTypeNames ::mousewheel) {
57 *result = WheelEvent; 67 *result = options.passive() ? WheelEventPassive : WheelEventBlocking;
58 } else if (isTouchEventType(eventType)) { 68 } else if (isTouchEventType(eventType)) {
59 *result = TouchEvent; 69 *result = options.passive() ? TouchEventPassive : TouchEventBlocking;
60 } else if (isPointerEventType(eventType)) { 70 } else if (isPointerEventType(eventType)) {
61 // The EventHandlerClass is still TouchEvent below since we are firing P ointerEvents only from 71 // The EventHandlerClass is TouchEventPassive since the events
62 // EventHandler::handleTouchEvent for now. See crbug.com/476565. 72 // do not block scrolling and only the compositor cares
63 *result = TouchEvent; 73 // about touch events for now.
Rick Byers 2016/02/04 22:18:57 nit: I'm confused by the "for now". The composito
74 *result = TouchEventPassive;
64 #if ENABLE(ASSERT) 75 #if ENABLE(ASSERT)
65 } else if (eventType == EventTypeNames::load || eventType == EventTypeNames: :mousemove || eventType == EventTypeNames::touchstart) { 76 } else if (eventType == EventTypeNames::load || eventType == EventTypeNames: :mousemove || eventType == EventTypeNames::touchstart) {
66 *result = EventsForTesting; 77 *result = EventsForTesting;
67 #endif 78 #endif
68 } else { 79 } else {
69 return false; 80 return false;
70 } 81 }
71 return true; 82 return true;
72 } 83 }
73 84
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 bool targetSetChanged = updateEventHandlerTargets(op, handlerClass, target); 126 bool targetSetChanged = updateEventHandlerTargets(op, handlerClass, target);
116 bool hasHandlers = m_targets[handlerClass].size(); 127 bool hasHandlers = m_targets[handlerClass].size();
117 128
118 if (hadHandlers != hasHandlers) 129 if (hadHandlers != hasHandlers)
119 notifyHasHandlersChanged(handlerClass, hasHandlers); 130 notifyHasHandlersChanged(handlerClass, hasHandlers);
120 131
121 if (targetSetChanged) 132 if (targetSetChanged)
122 notifyDidAddOrRemoveEventHandlerTarget(handlerClass); 133 notifyDidAddOrRemoveEventHandlerTarget(handlerClass);
123 } 134 }
124 135
125 void EventHandlerRegistry::updateEventHandlerOfType(ChangeOperation op, const At omicString& eventType, EventTarget* target) 136 void EventHandlerRegistry::updateEventHandlerOfType(ChangeOperation op, const At omicString& eventType, const EventListenerOptions& options, EventTarget* target)
126 { 137 {
127 EventHandlerClass handlerClass; 138 EventHandlerClass handlerClass;
128 if (!eventTypeToClass(eventType, &handlerClass)) 139 if (!eventTypeToClass(eventType, options, &handlerClass))
129 return; 140 return;
130 updateEventHandlerInternal(op, handlerClass, target); 141 updateEventHandlerInternal(op, handlerClass, target);
131 } 142 }
132 143
133 void EventHandlerRegistry::didAddEventHandler(EventTarget& target, const AtomicS tring& eventType) 144 void EventHandlerRegistry::didAddEventHandler(EventTarget& target, const AtomicS tring& eventType, const EventListenerOptions& options)
134 { 145 {
135 updateEventHandlerOfType(Add, eventType, &target); 146 updateEventHandlerOfType(Add, eventType, options, &target);
136 } 147 }
137 148
138 void EventHandlerRegistry::didRemoveEventHandler(EventTarget& target, const Atom icString& eventType) 149 void EventHandlerRegistry::didRemoveEventHandler(EventTarget& target, const Atom icString& eventType, const EventListenerOptions& options)
139 { 150 {
140 updateEventHandlerOfType(Remove, eventType, &target); 151 updateEventHandlerOfType(Remove, eventType, options, &target);
141 } 152 }
142 153
143 void EventHandlerRegistry::didAddEventHandler(EventTarget& target, EventHandlerC lass handlerClass) 154 void EventHandlerRegistry::didAddEventHandler(EventTarget& target, EventHandlerC lass handlerClass)
144 { 155 {
145 updateEventHandlerInternal(Add, handlerClass, &target); 156 updateEventHandlerInternal(Add, handlerClass, &target);
146 } 157 }
147 158
148 void EventHandlerRegistry::didRemoveEventHandler(EventTarget& target, EventHandl erClass handlerClass) 159 void EventHandlerRegistry::didRemoveEventHandler(EventTarget& target, EventHandl erClass handlerClass)
149 { 160 {
150 updateEventHandlerInternal(Remove, handlerClass, &target); 161 updateEventHandlerInternal(Remove, handlerClass, &target);
151 } 162 }
152 163
153 void EventHandlerRegistry::didMoveIntoFrameHost(EventTarget& target) 164 void EventHandlerRegistry::didMoveIntoFrameHost(EventTarget& target)
154 { 165 {
155 if (!target.hasEventListeners()) 166 if (!target.hasEventListeners())
156 return; 167 return;
157 168
169 // This code is not efficient at all.
158 Vector<AtomicString> eventTypes = target.eventTypes(); 170 Vector<AtomicString> eventTypes = target.eventTypes();
159 for (size_t i = 0; i < eventTypes.size(); ++i) { 171 for (size_t i = 0; i < eventTypes.size(); ++i) {
160 EventHandlerClass handlerClass;
161 if (!eventTypeToClass(eventTypes[i], &handlerClass))
162 continue;
163 EventListenerVector* listeners = target.getEventListeners(eventTypes[i]) ; 172 EventListenerVector* listeners = target.getEventListeners(eventTypes[i]) ;
164 if (!listeners) 173 if (!listeners)
165 continue; 174 continue;
166 for (unsigned count = listeners->size(); count > 0; --count) 175 for (unsigned count = listeners->size(); count > 0; --count) {
176 EventHandlerClass handlerClass;
177 if (!eventTypeToClass(eventTypes[i], (*listeners)[count - 1].options (), &handlerClass))
178 continue;
179
167 didAddEventHandler(target, handlerClass); 180 didAddEventHandler(target, handlerClass);
181 }
168 } 182 }
169 } 183 }
170 184
171 void EventHandlerRegistry::didMoveOutOfFrameHost(EventTarget& target) 185 void EventHandlerRegistry::didMoveOutOfFrameHost(EventTarget& target)
172 { 186 {
173 didRemoveAllEventHandlers(target); 187 didRemoveAllEventHandlers(target);
174 } 188 }
175 189
176 void EventHandlerRegistry::didMoveBetweenFrameHosts(EventTarget& target, FrameHo st* oldFrameHost, FrameHost* newFrameHost) 190 void EventHandlerRegistry::didMoveBetweenFrameHosts(EventTarget& target, FrameHo st* oldFrameHost, FrameHost* newFrameHost)
177 { 191 {
(...skipping 14 matching lines...) Expand all
192 updateEventHandlerInternal(RemoveAll, handlerClass, &target); 206 updateEventHandlerInternal(RemoveAll, handlerClass, &target);
193 } 207 }
194 } 208 }
195 209
196 void EventHandlerRegistry::notifyHasHandlersChanged(EventHandlerClass handlerCla ss, bool hasActiveHandlers) 210 void EventHandlerRegistry::notifyHasHandlersChanged(EventHandlerClass handlerCla ss, bool hasActiveHandlers)
197 { 211 {
198 switch (handlerClass) { 212 switch (handlerClass) {
199 case ScrollEvent: 213 case ScrollEvent:
200 m_frameHost->chromeClient().setHaveScrollEventHandlers(hasActiveHandlers ); 214 m_frameHost->chromeClient().setHaveScrollEventHandlers(hasActiveHandlers );
201 break; 215 break;
202 case WheelEvent: 216 case WheelEventBlocking:
203 m_frameHost->chromeClient().setHaveWheelEventHandlers(hasActiveHandlers) ; 217 case WheelEventPassive:
218 m_frameHost->chromeClient().setEventListenerProperties(WebEventListenerC lass::MouseWheel, webEventListenerProperties(hasEventHandlers(WheelEventBlocking ), hasEventHandlers(WheelEventPassive)));
204 break; 219 break;
205 case TouchEvent: 220 case TouchEventBlocking:
206 m_frameHost->chromeClient().needTouchEvents(hasActiveHandlers); 221 case TouchEventPassive:
222 m_frameHost->chromeClient().setEventListenerProperties(WebEventListenerC lass::Touch, webEventListenerProperties(hasEventHandlers(TouchEventBlocking), ha sEventHandlers(TouchEventPassive)));
207 break; 223 break;
208 #if ENABLE(ASSERT) 224 #if ENABLE(ASSERT)
209 case EventsForTesting: 225 case EventsForTesting:
210 break; 226 break;
211 #endif 227 #endif
212 default: 228 default:
213 ASSERT_NOT_REACHED(); 229 ASSERT_NOT_REACHED();
214 break; 230 break;
215 } 231 }
216 } 232 }
217 233
218 void EventHandlerRegistry::notifyDidAddOrRemoveEventHandlerTarget(EventHandlerCl ass handlerClass) 234 void EventHandlerRegistry::notifyDidAddOrRemoveEventHandlerTarget(EventHandlerCl ass handlerClass)
219 { 235 {
220 ScrollingCoordinator* scrollingCoordinator = m_frameHost->page().scrollingCo ordinator(); 236 ScrollingCoordinator* scrollingCoordinator = m_frameHost->page().scrollingCo ordinator();
221 if (scrollingCoordinator && handlerClass == TouchEvent) 237 if (scrollingCoordinator && handlerClass == TouchEventBlocking)
222 scrollingCoordinator->touchEventTargetRectsDidChange(); 238 scrollingCoordinator->touchEventTargetRectsDidChange();
223 } 239 }
224 240
225 DEFINE_TRACE(EventHandlerRegistry) 241 DEFINE_TRACE(EventHandlerRegistry)
226 { 242 {
227 visitor->trace(m_frameHost); 243 visitor->trace(m_frameHost);
228 visitor->template registerWeakMembers<EventHandlerRegistry, &EventHandlerReg istry::clearWeakMembers>(this); 244 visitor->template registerWeakMembers<EventHandlerRegistry, &EventHandlerReg istry::clearWeakMembers>(this);
229 } 245 }
230 246
231 void EventHandlerRegistry::clearWeakMembers(Visitor* visitor) 247 void EventHandlerRegistry::clearWeakMembers(Visitor* visitor)
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 ASSERT(window->frame()); 308 ASSERT(window->frame());
293 ASSERT(window->frame()->host()); 309 ASSERT(window->frame()->host());
294 ASSERT(window->frame()->host() == m_frameHost); 310 ASSERT(window->frame()->host() == m_frameHost);
295 } 311 }
296 } 312 }
297 } 313 }
298 #endif // ENABLE(ASSERT) 314 #endif // ENABLE(ASSERT)
299 } 315 }
300 316
301 } // namespace blink 317 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698