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

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 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
« no previous file with comments | « ui/events/blink/input_handler_proxy.h ('k') | ui/events/blink/input_handler_proxy_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 17 matching lines...) Expand all
28 using blink::WebGestureEvent; 28 using blink::WebGestureEvent;
29 using blink::WebInputEvent; 29 using blink::WebInputEvent;
30 using blink::WebMouseEvent; 30 using blink::WebMouseEvent;
31 using blink::WebMouseWheelEvent; 31 using blink::WebMouseWheelEvent;
32 using blink::WebPoint; 32 using blink::WebPoint;
33 using blink::WebTouchEvent; 33 using blink::WebTouchEvent;
34 using blink::WebTouchPoint; 34 using blink::WebTouchPoint;
35 35
36 namespace { 36 namespace {
37 37
38 const int32_t kEventDispositionUndefined = -1;
39
38 // Maximum time between a fling event's timestamp and the first |Animate| call 40 // Maximum time between a fling event's timestamp and the first |Animate| call
39 // for the fling curve to use the fling timestamp as the initial animation time. 41 // for the fling curve to use the fling timestamp as the initial animation time.
40 // Two frames allows a minor delay between event creation and the first animate. 42 // Two frames allows a minor delay between event creation and the first animate.
41 const double kMaxSecondsFromFlingTimestampToFirstAnimate = 2. / 60.; 43 const double kMaxSecondsFromFlingTimestampToFirstAnimate = 2. / 60.;
42 44
43 // Threshold for determining whether a fling scroll delta should have caused the 45 // Threshold for determining whether a fling scroll delta should have caused the
44 // client to scroll. 46 // client to scroll.
45 const float kScrollEpsilon = 0.1f; 47 const float kScrollEpsilon = 0.1f;
46 48
47 // Minimum fling velocity required for the active fling and new fling for the 49 // Minimum fling velocity required for the active fling and new fling for the
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 #ifndef NDEBUG 216 #ifndef NDEBUG
215 expect_scroll_update_end_(false), 217 expect_scroll_update_end_(false),
216 #endif 218 #endif
217 gesture_scroll_on_impl_thread_(false), 219 gesture_scroll_on_impl_thread_(false),
218 gesture_pinch_on_impl_thread_(false), 220 gesture_pinch_on_impl_thread_(false),
219 fling_may_be_active_on_main_thread_(false), 221 fling_may_be_active_on_main_thread_(false),
220 disallow_horizontal_fling_scroll_(false), 222 disallow_horizontal_fling_scroll_(false),
221 disallow_vertical_fling_scroll_(false), 223 disallow_vertical_fling_scroll_(false),
222 has_fling_animation_started_(false), 224 has_fling_animation_started_(false),
223 smooth_scroll_enabled_(false), 225 smooth_scroll_enabled_(false),
224 uma_latency_reporting_enabled_(base::TimeTicks::IsHighResolution()) { 226 uma_latency_reporting_enabled_(base::TimeTicks::IsHighResolution()),
227 use_gesture_events_for_mouse_wheel_(true),
228 touch_start_result_(kEventDispositionUndefined) {
225 DCHECK(client); 229 DCHECK(client);
226 input_handler_->BindToClient(this); 230 input_handler_->BindToClient(this);
227 cc::ScrollElasticityHelper* scroll_elasticity_helper = 231 cc::ScrollElasticityHelper* scroll_elasticity_helper =
228 input_handler_->CreateScrollElasticityHelper(); 232 input_handler_->CreateScrollElasticityHelper();
229 if (scroll_elasticity_helper) { 233 if (scroll_elasticity_helper) {
230 scroll_elasticity_controller_.reset( 234 scroll_elasticity_controller_.reset(
231 new InputScrollElasticityController(scroll_elasticity_helper)); 235 new InputScrollElasticityController(scroll_elasticity_helper));
232 } 236 }
233 } 237 }
234 238
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 case WebInputEvent::GestureFlingCancel: 334 case WebInputEvent::GestureFlingCancel:
331 if (CancelCurrentFling()) 335 if (CancelCurrentFling())
332 return DID_HANDLE; 336 return DID_HANDLE;
333 else if (!fling_may_be_active_on_main_thread_) 337 else if (!fling_may_be_active_on_main_thread_)
334 return DROP_EVENT; 338 return DROP_EVENT;
335 return DID_NOT_HANDLE; 339 return DID_NOT_HANDLE;
336 340
337 case WebInputEvent::TouchStart: 341 case WebInputEvent::TouchStart:
338 return HandleTouchStart(static_cast<const WebTouchEvent&>(event)); 342 return HandleTouchStart(static_cast<const WebTouchEvent&>(event));
339 343
344 case WebInputEvent::TouchMove:
345 return HandleTouchMove(static_cast<const WebTouchEvent&>(event));
346
347 case WebInputEvent::TouchEnd:
348 return HandleTouchEnd(static_cast<const WebTouchEvent&>(event));
349
340 case WebInputEvent::MouseMove: { 350 case WebInputEvent::MouseMove: {
341 const WebMouseEvent& mouse_event = 351 const WebMouseEvent& mouse_event =
342 static_cast<const WebMouseEvent&>(event); 352 static_cast<const WebMouseEvent&>(event);
343 // TODO(tony): Ignore when mouse buttons are down? 353 // TODO(tony): Ignore when mouse buttons are down?
344 // TODO(davemoore): This should never happen, but bug #326635 showed some 354 // TODO(davemoore): This should never happen, but bug #326635 showed some
345 // surprising crashes. 355 // surprising crashes.
346 CHECK(input_handler_); 356 CHECK(input_handler_);
347 input_handler_->MouseMoveAt(gfx::Point(mouse_event.x, mouse_event.y)); 357 input_handler_->MouseMoveAt(gfx::Point(mouse_event.x, mouse_event.y));
348 return DID_NOT_HANDLE; 358 return DID_NOT_HANDLE;
349 } 359 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 #if defined(OS_MACOSX) 423 #if defined(OS_MACOSX)
414 // Mac does not smooth scroll wheel events (crbug.com/574283). 424 // Mac does not smooth scroll wheel events (crbug.com/574283).
415 return false; 425 return false;
416 #else 426 #else
417 return smooth_scroll_enabled_ && !event.hasPreciseScrollingDeltas; 427 return smooth_scroll_enabled_ && !event.hasPreciseScrollingDeltas;
418 #endif 428 #endif
419 } 429 }
420 430
421 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleMouseWheel( 431 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleMouseWheel(
422 const WebMouseWheelEvent& wheel_event) { 432 const WebMouseWheelEvent& wheel_event) {
433 if (use_gesture_events_for_mouse_wheel_) {
434 cc::EventListenerProperties properties =
435 input_handler_->GetEventListenerProperties(
436 cc::EventListenerClass::kMouseWheel);
437 switch (properties) {
438 case cc::EventListenerProperties::kPassive:
439 return NON_BLOCKING;
440 case cc::EventListenerProperties::kBlockingAndPassive:
441 case cc::EventListenerProperties::kBlocking:
442 return DID_NOT_HANDLE;
443 case cc::EventListenerProperties::kNone:
444 return DROP_EVENT;
445 default:
446 NOTREACHED();
447 return DROP_EVENT;
448 }
449 }
450 return ScrollByMouseWheel(wheel_event);
451 }
452
453 InputHandlerProxy::EventDisposition InputHandlerProxy::ScrollByMouseWheel(
454 const WebMouseWheelEvent& wheel_event) {
423 InputHandlerProxy::EventDisposition result = DID_NOT_HANDLE; 455 InputHandlerProxy::EventDisposition result = DID_NOT_HANDLE;
424 cc::InputHandlerScrollResult scroll_result; 456 cc::InputHandlerScrollResult scroll_result;
425 457
426 // TODO(ccameron): The rail information should be pushed down into 458 // TODO(ccameron): The rail information should be pushed down into
427 // InputHandler. 459 // InputHandler.
428 gfx::Vector2dF scroll_delta( 460 gfx::Vector2dF scroll_delta(
429 wheel_event.railsMode != WebInputEvent::RailsModeVertical 461 wheel_event.railsMode != WebInputEvent::RailsModeVertical
430 ? -wheel_event.deltaX 462 ? -wheel_event.deltaX
431 : 0, 463 : 0,
432 wheel_event.railsMode != WebInputEvent::RailsModeHorizontal 464 wheel_event.railsMode != WebInputEvent::RailsModeHorizontal
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 return DID_NOT_HANDLE; 745 return DID_NOT_HANDLE;
714 } 746 }
715 return DROP_EVENT; 747 return DROP_EVENT;
716 } 748 }
717 } 749 }
718 return DID_NOT_HANDLE; 750 return DID_NOT_HANDLE;
719 } 751 }
720 752
721 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleTouchStart( 753 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleTouchStart(
722 const blink::WebTouchEvent& touch_event) { 754 const blink::WebTouchEvent& touch_event) {
755 EventDisposition result = DROP_EVENT;
723 for (size_t i = 0; i < touch_event.touchesLength; ++i) { 756 for (size_t i = 0; i < touch_event.touchesLength; ++i) {
724 if (touch_event.touches[i].state != WebTouchPoint::StatePressed) 757 if (touch_event.touches[i].state != WebTouchPoint::StatePressed)
725 continue; 758 continue;
726 if (input_handler_->DoTouchEventsBlockScrollAt( 759 if (input_handler_->DoTouchEventsBlockScrollAt(
727 gfx::Point(touch_event.touches[i].position.x, 760 gfx::Point(touch_event.touches[i].position.x,
728 touch_event.touches[i].position.y))) { 761 touch_event.touches[i].position.y))) {
729 // TODO(rbyers): We should consider still sending the touch events to 762 result = DID_NOT_HANDLE;
730 // main asynchronously (crbug.com/455539). 763 break;
731 return DID_NOT_HANDLE;
732 } 764 }
733 } 765 }
734 return DROP_EVENT; 766
767 // If |result| is DROP_EVENT it wasn't processed above.
768 if (result == DROP_EVENT) {
769 switch (input_handler_->GetEventListenerProperties(
770 cc::EventListenerClass::kTouch)) {
771 case cc::EventListenerProperties::kPassive:
772 result = NON_BLOCKING;
773 break;
774 case cc::EventListenerProperties::kBlocking:
775 // The touch area rects above already have checked whether it hits
776 // a blocking region. Since it does not the event can be dropped.
777 result = DROP_EVENT;
778 break;
779 case cc::EventListenerProperties::kBlockingAndPassive:
780 // There is at least one passive listener that needs to possibly
781 // be notified so it can't be dropped.
782 result = NON_BLOCKING;
783 break;
784 case cc::EventListenerProperties::kNone:
785 result = DROP_EVENT;
786 break;
787 default:
788 NOTREACHED();
789 result = DROP_EVENT;
790 break;
791 }
792 }
793
794 // Merge |touch_start_result_| and |result| so the result has the highest
795 // priority value according to the sequence; (DID_NOT_HANDLE,
796 // NON_BLOCKING, DROP_EVENT).
tdresser 2016/02/11 14:24:02 I would have expected this list to be in the oppos
797 if (touch_start_result_ == kEventDispositionUndefined ||
798 touch_start_result_ == DROP_EVENT || result == DID_NOT_HANDLE)
799 touch_start_result_ = result;
800
801 return result;
802 }
803
804 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleTouchMove(
805 const blink::WebTouchEvent& touch_event) {
806 if (touch_start_result_ != kEventDispositionUndefined)
807 return static_cast<EventDisposition>(touch_start_result_);
808 return DID_NOT_HANDLE;
809 }
810
811 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleTouchEnd(
812 const blink::WebTouchEvent& touch_event) {
813 if (touch_event.touchesLength == 1)
814 touch_start_result_ = kEventDispositionUndefined;
815 return DID_NOT_HANDLE;
735 } 816 }
736 817
737 bool InputHandlerProxy::FilterInputEventForFlingBoosting( 818 bool InputHandlerProxy::FilterInputEventForFlingBoosting(
738 const WebInputEvent& event) { 819 const WebInputEvent& event) {
739 if (!WebInputEvent::isGestureEventType(event.type)) 820 if (!WebInputEvent::isGestureEventType(event.type))
740 return false; 821 return false;
741 822
742 if (!fling_curve_) { 823 if (!fling_curve_) {
743 DCHECK(!deferred_fling_cancel_time_seconds_); 824 DCHECK(!deferred_fling_cancel_time_seconds_);
744 return false; 825 return false;
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 // flings always go through the normal InputHandler. 1149 // flings always go through the normal InputHandler.
1069 if (synchronous_input_handler_ && 1150 if (synchronous_input_handler_ &&
1070 input_handler_->IsCurrentlyScrollingInnerViewport()) 1151 input_handler_->IsCurrentlyScrollingInnerViewport())
1071 synchronous_input_handler_->SetNeedsSynchronousAnimateInput(); 1152 synchronous_input_handler_->SetNeedsSynchronousAnimateInput();
1072 else 1153 else
1073 input_handler_->SetNeedsAnimateInput(); 1154 input_handler_->SetNeedsAnimateInput();
1074 } 1155 }
1075 1156
1076 bool InputHandlerProxy::TouchpadFlingScroll( 1157 bool InputHandlerProxy::TouchpadFlingScroll(
1077 const WebFloatSize& increment) { 1158 const WebFloatSize& increment) {
1078 WebMouseWheelEvent synthetic_wheel; 1159 InputHandlerProxy::EventDisposition disposition;
1079 synthetic_wheel.type = WebInputEvent::MouseWheel; 1160 cc::EventListenerProperties properties =
1080 synthetic_wheel.timeStampSeconds = InSecondsF(base::TimeTicks::Now()); 1161 input_handler_->GetEventListenerProperties(
1081 synthetic_wheel.deltaX = increment.width; 1162 cc::EventListenerClass::kMouseWheel);
1082 synthetic_wheel.deltaY = increment.height; 1163 switch (properties) {
1083 synthetic_wheel.hasPreciseScrollingDeltas = true; 1164 case cc::EventListenerProperties::kPassive:
1084 synthetic_wheel.x = fling_parameters_.point.x; 1165 disposition = NON_BLOCKING;
1085 synthetic_wheel.y = fling_parameters_.point.y; 1166 break;
1086 synthetic_wheel.globalX = fling_parameters_.globalPoint.x; 1167 case cc::EventListenerProperties::kBlocking:
1087 synthetic_wheel.globalY = fling_parameters_.globalPoint.y; 1168 disposition = DID_NOT_HANDLE;
1088 synthetic_wheel.modifiers = fling_parameters_.modifiers; 1169 break;
1170 case cc::EventListenerProperties::kNone: {
1171 WebMouseWheelEvent synthetic_wheel;
1172 synthetic_wheel.type = WebInputEvent::MouseWheel;
1173 synthetic_wheel.timeStampSeconds = InSecondsF(base::TimeTicks::Now());
1174 synthetic_wheel.deltaX = increment.width;
1175 synthetic_wheel.deltaY = increment.height;
1176 synthetic_wheel.hasPreciseScrollingDeltas = true;
1177 synthetic_wheel.x = fling_parameters_.point.x;
1178 synthetic_wheel.y = fling_parameters_.point.y;
1179 synthetic_wheel.globalX = fling_parameters_.globalPoint.x;
1180 synthetic_wheel.globalY = fling_parameters_.globalPoint.y;
1181 synthetic_wheel.modifiers = fling_parameters_.modifiers;
1089 1182
1090 InputHandlerProxy::EventDisposition disposition = 1183 disposition = ScrollByMouseWheel(synthetic_wheel);
1091 HandleInputEvent(synthetic_wheel); 1184 break;
1185 }
1186 default:
1187 NOTREACHED();
1188 return false;
1189 }
1190
1092 switch (disposition) { 1191 switch (disposition) {
1093 case DID_HANDLE: 1192 case DID_HANDLE:
1094 return true; 1193 return true;
1095 case DROP_EVENT: 1194 case DROP_EVENT:
1096 break; 1195 break;
1196 case NON_BLOCKING:
1197 // TODO(dtapuska): Process the fling on the compositor thread
1198 // but post the events to the main thread; for now just pass it to the
1199 // main thread.
1097 case DID_NOT_HANDLE: 1200 case DID_NOT_HANDLE:
1098 TRACE_EVENT_INSTANT0("input", 1201 TRACE_EVENT_INSTANT0("input",
1099 "InputHandlerProxy::scrollBy::AbortFling", 1202 "InputHandlerProxy::scrollBy::AbortFling",
1100 TRACE_EVENT_SCOPE_THREAD); 1203 TRACE_EVENT_SCOPE_THREAD);
1101 // If we got a DID_NOT_HANDLE, that means we need to deliver wheels on the 1204 // 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 1205 // 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 1206 // 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 1207 // 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 1208 // subarea that we can't scroll on the thread if the fling starts outside
1106 // the subarea but then is flung "under" the pointer. 1209 // 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. 1274 // trigger a scroll, e.g., with a trivial time delta between fling updates.
1172 // Return true in this case to prevent early fling termination. 1275 // Return true in this case to prevent early fling termination.
1173 if (std::abs(clipped_increment.width) < kScrollEpsilon && 1276 if (std::abs(clipped_increment.width) < kScrollEpsilon &&
1174 std::abs(clipped_increment.height) < kScrollEpsilon) 1277 std::abs(clipped_increment.height) < kScrollEpsilon)
1175 return true; 1278 return true;
1176 1279
1177 return did_scroll; 1280 return did_scroll;
1178 } 1281 }
1179 1282
1180 } // namespace ui 1283 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/blink/input_handler_proxy.h ('k') | ui/events/blink/input_handler_proxy_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698