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

Side by Side Diff: ui/events/blink/input_handler_proxy.cc

Issue 1631963002: Plumb firing passive event listeners. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master_wheel_passive_listeners_2a
Patch Set: Fix windows build 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "ui/events/blink/input_handler_proxy.h" 5 #include "ui/events/blink/input_handler_proxy.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 #ifndef NDEBUG 214 #ifndef NDEBUG
215 expect_scroll_update_end_(false), 215 expect_scroll_update_end_(false),
216 #endif 216 #endif
217 gesture_scroll_on_impl_thread_(false), 217 gesture_scroll_on_impl_thread_(false),
218 gesture_pinch_on_impl_thread_(false), 218 gesture_pinch_on_impl_thread_(false),
219 fling_may_be_active_on_main_thread_(false), 219 fling_may_be_active_on_main_thread_(false),
220 disallow_horizontal_fling_scroll_(false), 220 disallow_horizontal_fling_scroll_(false),
221 disallow_vertical_fling_scroll_(false), 221 disallow_vertical_fling_scroll_(false),
222 has_fling_animation_started_(false), 222 has_fling_animation_started_(false),
223 smooth_scroll_enabled_(false), 223 smooth_scroll_enabled_(false),
224 uma_latency_reporting_enabled_(base::TimeTicks::IsHighResolution()) { 224 uma_latency_reporting_enabled_(base::TimeTicks::IsHighResolution()),
225 use_gesture_events_for_mouse_wheel_(true) {
225 DCHECK(client); 226 DCHECK(client);
226 input_handler_->BindToClient(this); 227 input_handler_->BindToClient(this);
227 cc::ScrollElasticityHelper* scroll_elasticity_helper = 228 cc::ScrollElasticityHelper* scroll_elasticity_helper =
228 input_handler_->CreateScrollElasticityHelper(); 229 input_handler_->CreateScrollElasticityHelper();
229 if (scroll_elasticity_helper) { 230 if (scroll_elasticity_helper) {
230 scroll_elasticity_controller_.reset( 231 scroll_elasticity_controller_.reset(
231 new InputScrollElasticityController(scroll_elasticity_helper)); 232 new InputScrollElasticityController(scroll_elasticity_helper));
232 } 233 }
233 } 234 }
234 235
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 case WebInputEvent::GestureFlingCancel: 331 case WebInputEvent::GestureFlingCancel:
331 if (CancelCurrentFling()) 332 if (CancelCurrentFling())
332 return DID_HANDLE; 333 return DID_HANDLE;
333 else if (!fling_may_be_active_on_main_thread_) 334 else if (!fling_may_be_active_on_main_thread_)
334 return DROP_EVENT; 335 return DROP_EVENT;
335 return DID_NOT_HANDLE; 336 return DID_NOT_HANDLE;
336 337
337 case WebInputEvent::TouchStart: 338 case WebInputEvent::TouchStart:
338 return HandleTouchStart(static_cast<const WebTouchEvent&>(event)); 339 return HandleTouchStart(static_cast<const WebTouchEvent&>(event));
339 340
341 case WebInputEvent::TouchMove:
342 return HandleTouchMove(static_cast<const WebTouchEvent&>(event));
343
340 case WebInputEvent::MouseMove: { 344 case WebInputEvent::MouseMove: {
341 const WebMouseEvent& mouse_event = 345 const WebMouseEvent& mouse_event =
342 static_cast<const WebMouseEvent&>(event); 346 static_cast<const WebMouseEvent&>(event);
343 // TODO(tony): Ignore when mouse buttons are down? 347 // TODO(tony): Ignore when mouse buttons are down?
344 // TODO(davemoore): This should never happen, but bug #326635 showed some 348 // TODO(davemoore): This should never happen, but bug #326635 showed some
345 // surprising crashes. 349 // surprising crashes.
346 CHECK(input_handler_); 350 CHECK(input_handler_);
347 input_handler_->MouseMoveAt(gfx::Point(mouse_event.x, mouse_event.y)); 351 input_handler_->MouseMoveAt(gfx::Point(mouse_event.x, mouse_event.y));
348 return DID_NOT_HANDLE; 352 return DID_NOT_HANDLE;
349 } 353 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 #if defined(OS_MACOSX) 417 #if defined(OS_MACOSX)
414 // Mac does not smooth scroll wheel events (crbug.com/574283). 418 // Mac does not smooth scroll wheel events (crbug.com/574283).
415 return false; 419 return false;
416 #else 420 #else
417 return smooth_scroll_enabled_ && !event.hasPreciseScrollingDeltas; 421 return smooth_scroll_enabled_ && !event.hasPreciseScrollingDeltas;
418 #endif 422 #endif
419 } 423 }
420 424
421 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleMouseWheel( 425 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleMouseWheel(
422 const WebMouseWheelEvent& wheel_event) { 426 const WebMouseWheelEvent& wheel_event) {
427 if (use_gesture_events_for_mouse_wheel_) {
428 cc::EventListenerProperties properties =
429 input_handler_->GetEventListenerProperties(
430 cc::EventListenerClass::kMouseWheel);
431 switch (properties) {
432 case cc::EventListenerProperties::kPassive:
433 return NON_BLOCKING;
434 case cc::EventListenerProperties::kBlockingAndPassive:
435 case cc::EventListenerProperties::kBlocking:
436 return DID_NOT_HANDLE;
437 case cc::EventListenerProperties::kNone:
438 return DROP_EVENT;
439 default:
440 NOTREACHED();
441 return DROP_EVENT;
442 }
443 }
444 return ScrollByMouseWheel(wheel_event);
445 }
446
447 InputHandlerProxy::EventDisposition InputHandlerProxy::ScrollByMouseWheel(
448 const WebMouseWheelEvent& wheel_event) {
423 InputHandlerProxy::EventDisposition result = DID_NOT_HANDLE; 449 InputHandlerProxy::EventDisposition result = DID_NOT_HANDLE;
424 cc::InputHandlerScrollResult scroll_result; 450 cc::InputHandlerScrollResult scroll_result;
425 451
426 // TODO(ccameron): The rail information should be pushed down into 452 // TODO(ccameron): The rail information should be pushed down into
427 // InputHandler. 453 // InputHandler.
428 gfx::Vector2dF scroll_delta( 454 gfx::Vector2dF scroll_delta(
429 wheel_event.railsMode != WebInputEvent::RailsModeVertical 455 wheel_event.railsMode != WebInputEvent::RailsModeVertical
430 ? -wheel_event.deltaX 456 ? -wheel_event.deltaX
431 : 0, 457 : 0,
432 wheel_event.railsMode != WebInputEvent::RailsModeHorizontal 458 wheel_event.railsMode != WebInputEvent::RailsModeHorizontal
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 } 745 }
720 746
721 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleTouchStart( 747 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleTouchStart(
722 const blink::WebTouchEvent& touch_event) { 748 const blink::WebTouchEvent& touch_event) {
723 for (size_t i = 0; i < touch_event.touchesLength; ++i) { 749 for (size_t i = 0; i < touch_event.touchesLength; ++i) {
724 if (touch_event.touches[i].state != WebTouchPoint::StatePressed) 750 if (touch_event.touches[i].state != WebTouchPoint::StatePressed)
725 continue; 751 continue;
726 if (input_handler_->DoTouchEventsBlockScrollAt( 752 if (input_handler_->DoTouchEventsBlockScrollAt(
727 gfx::Point(touch_event.touches[i].position.x, 753 gfx::Point(touch_event.touches[i].position.x,
728 touch_event.touches[i].position.y))) { 754 touch_event.touches[i].position.y))) {
729 // TODO(rbyers): We should consider still sending the touch events to
730 // main asynchronously (crbug.com/455539).
731 return DID_NOT_HANDLE; 755 return DID_NOT_HANDLE;
732 } 756 }
733 } 757 }
734 return DROP_EVENT; 758
759 switch (input_handler_->GetEventListenerProperties(
760 cc::EventListenerClass::kTouch)) {
761 case cc::EventListenerProperties::kPassive:
762 return NON_BLOCKING;
763 case cc::EventListenerProperties::kBlocking:
764 // The touch area rects above already have checked whether it hits
765 // a blocking region. Since it does not the event can be dropped.
766 return DROP_EVENT;
767 case cc::EventListenerProperties::kBlockingAndPassive:
768 // There is at least one passive listener that needs to possibly
769 // be notified so it can't be dropped.
770 return NON_BLOCKING;
771 case cc::EventListenerProperties::kNone:
772 return DROP_EVENT;
773 default:
774 NOTREACHED();
775 return DROP_EVENT;
776 }
777 }
778
779 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleTouchMove(
780 const blink::WebTouchEvent& touch_event) {
781 for (size_t i = 0; i < touch_event.touchesLength; ++i) {
782 if (input_handler_->DoTouchEventsBlockScrollAt(
783 gfx::Point(touch_event.touches[i].position.x,
784 touch_event.touches[i].position.y))) {
785 return DID_NOT_HANDLE;
786 }
787 }
788
789 switch (input_handler_->GetEventListenerProperties(
790 cc::EventListenerClass::kTouch)) {
791 case cc::EventListenerProperties::kPassive:
792 return NON_BLOCKING;
793 case cc::EventListenerProperties::kBlocking:
794 return DID_NOT_HANDLE;
795 case cc::EventListenerProperties::kNone:
796 return DROP_EVENT;
797 default:
798 NOTREACHED();
799 return DROP_EVENT;
800 }
735 } 801 }
736 802
737 bool InputHandlerProxy::FilterInputEventForFlingBoosting( 803 bool InputHandlerProxy::FilterInputEventForFlingBoosting(
738 const WebInputEvent& event) { 804 const WebInputEvent& event) {
739 if (!WebInputEvent::isGestureEventType(event.type)) 805 if (!WebInputEvent::isGestureEventType(event.type))
740 return false; 806 return false;
741 807
742 if (!fling_curve_) { 808 if (!fling_curve_) {
743 DCHECK(!deferred_fling_cancel_time_seconds_); 809 DCHECK(!deferred_fling_cancel_time_seconds_);
744 return false; 810 return false;
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 // flings always go through the normal InputHandler. 1134 // flings always go through the normal InputHandler.
1069 if (synchronous_input_handler_ && 1135 if (synchronous_input_handler_ &&
1070 input_handler_->IsCurrentlyScrollingInnerViewport()) 1136 input_handler_->IsCurrentlyScrollingInnerViewport())
1071 synchronous_input_handler_->SetNeedsSynchronousAnimateInput(); 1137 synchronous_input_handler_->SetNeedsSynchronousAnimateInput();
1072 else 1138 else
1073 input_handler_->SetNeedsAnimateInput(); 1139 input_handler_->SetNeedsAnimateInput();
1074 } 1140 }
1075 1141
1076 bool InputHandlerProxy::TouchpadFlingScroll( 1142 bool InputHandlerProxy::TouchpadFlingScroll(
1077 const WebFloatSize& increment) { 1143 const WebFloatSize& increment) {
1078 WebMouseWheelEvent synthetic_wheel; 1144 InputHandlerProxy::EventDisposition disposition;
1079 synthetic_wheel.type = WebInputEvent::MouseWheel; 1145 cc::EventListenerProperties properties =
1080 synthetic_wheel.timeStampSeconds = InSecondsF(base::TimeTicks::Now()); 1146 input_handler_->GetEventListenerProperties(
1081 synthetic_wheel.deltaX = increment.width; 1147 cc::EventListenerClass::kMouseWheel);
1082 synthetic_wheel.deltaY = increment.height; 1148 switch (properties) {
1083 synthetic_wheel.hasPreciseScrollingDeltas = true; 1149 case cc::EventListenerProperties::kPassive:
1084 synthetic_wheel.x = fling_parameters_.point.x; 1150 disposition = NON_BLOCKING;
1085 synthetic_wheel.y = fling_parameters_.point.y; 1151 break;
1086 synthetic_wheel.globalX = fling_parameters_.globalPoint.x; 1152 case cc::EventListenerProperties::kBlocking:
1087 synthetic_wheel.globalY = fling_parameters_.globalPoint.y; 1153 disposition = DID_NOT_HANDLE;
1088 synthetic_wheel.modifiers = fling_parameters_.modifiers; 1154 break;
1155 case cc::EventListenerProperties::kNone: {
1156 WebMouseWheelEvent synthetic_wheel;
1157 synthetic_wheel.type = WebInputEvent::MouseWheel;
1158 synthetic_wheel.timeStampSeconds = InSecondsF(base::TimeTicks::Now());
1159 synthetic_wheel.deltaX = increment.width;
1160 synthetic_wheel.deltaY = increment.height;
1161 synthetic_wheel.hasPreciseScrollingDeltas = true;
1162 synthetic_wheel.x = fling_parameters_.point.x;
1163 synthetic_wheel.y = fling_parameters_.point.y;
1164 synthetic_wheel.globalX = fling_parameters_.globalPoint.x;
1165 synthetic_wheel.globalY = fling_parameters_.globalPoint.y;
1166 synthetic_wheel.modifiers = fling_parameters_.modifiers;
1089 1167
1090 InputHandlerProxy::EventDisposition disposition = 1168 disposition = ScrollByMouseWheel(synthetic_wheel);
1091 HandleInputEvent(synthetic_wheel); 1169 break;
1170 }
1171 default:
1172 NOTREACHED();
1173 return false;
1174 }
1175
1092 switch (disposition) { 1176 switch (disposition) {
1093 case DID_HANDLE: 1177 case DID_HANDLE:
1094 return true; 1178 return true;
1095 case DROP_EVENT: 1179 case DROP_EVENT:
1096 break; 1180 break;
1181 case NON_BLOCKING:
1182 // TODO(dtapuska): Process the fling on the compositor thread
1183 // but post the events to the main thread; for now just pass it to the
1184 // main thread.
1097 case DID_NOT_HANDLE: 1185 case DID_NOT_HANDLE:
1098 TRACE_EVENT_INSTANT0("input", 1186 TRACE_EVENT_INSTANT0("input",
1099 "InputHandlerProxy::scrollBy::AbortFling", 1187 "InputHandlerProxy::scrollBy::AbortFling",
1100 TRACE_EVENT_SCOPE_THREAD); 1188 TRACE_EVENT_SCOPE_THREAD);
1101 // If we got a DID_NOT_HANDLE, that means we need to deliver wheels on the 1189 // If we got a DID_NOT_HANDLE, that means we need to deliver wheels on the
1102 // main thread. In this case we need to schedule a commit and transfer the 1190 // main thread. In this case we need to schedule a commit and transfer the
1103 // fling curve over to the main thread and run the rest of the wheels from 1191 // fling curve over to the main thread and run the rest of the wheels from
1104 // there. This can happen when flinging a page that contains a scrollable 1192 // there. This can happen when flinging a page that contains a scrollable
1105 // subarea that we can't scroll on the thread if the fling starts outside 1193 // subarea that we can't scroll on the thread if the fling starts outside
1106 // the subarea but then is flung "under" the pointer. 1194 // the subarea but then is flung "under" the pointer.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 // trigger a scroll, e.g., with a trivial time delta between fling updates. 1259 // trigger a scroll, e.g., with a trivial time delta between fling updates.
1172 // Return true in this case to prevent early fling termination. 1260 // Return true in this case to prevent early fling termination.
1173 if (std::abs(clipped_increment.width) < kScrollEpsilon && 1261 if (std::abs(clipped_increment.width) < kScrollEpsilon &&
1174 std::abs(clipped_increment.height) < kScrollEpsilon) 1262 std::abs(clipped_increment.height) < kScrollEpsilon)
1175 return true; 1263 return true;
1176 1264
1177 return did_scroll; 1265 return did_scroll;
1178 } 1266 }
1179 1267
1180 } // namespace ui 1268 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698