OLD | NEW |
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 Loading... |
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 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 Loading... |
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 Loading... |
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 (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::kBlocking: |
| 435 return DID_NOT_HANDLE; |
| 436 case cc::EventListenerProperties::kNone: |
| 437 return DROP_EVENT; |
| 438 default: |
| 439 NOTREACHED(); |
| 440 return DROP_EVENT; |
| 441 } |
| 442 } |
| 443 return ScrollByMouseWheel(wheel_event); |
| 444 } |
| 445 |
| 446 InputHandlerProxy::EventDisposition InputHandlerProxy::ScrollByMouseWheel( |
| 447 const WebMouseWheelEvent& wheel_event) { |
423 InputHandlerProxy::EventDisposition result = DID_NOT_HANDLE; | 448 InputHandlerProxy::EventDisposition result = DID_NOT_HANDLE; |
424 cc::InputHandlerScrollResult scroll_result; | 449 cc::InputHandlerScrollResult scroll_result; |
425 | 450 |
426 // TODO(ccameron): The rail information should be pushed down into | 451 // TODO(ccameron): The rail information should be pushed down into |
427 // InputHandler. | 452 // InputHandler. |
428 gfx::Vector2dF scroll_delta( | 453 gfx::Vector2dF scroll_delta( |
429 wheel_event.railsMode != WebInputEvent::RailsModeVertical | 454 wheel_event.railsMode != WebInputEvent::RailsModeVertical |
430 ? -wheel_event.deltaX | 455 ? -wheel_event.deltaX |
431 : 0, | 456 : 0, |
432 wheel_event.railsMode != WebInputEvent::RailsModeHorizontal | 457 wheel_event.railsMode != WebInputEvent::RailsModeHorizontal |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 } | 744 } |
720 | 745 |
721 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleTouchStart( | 746 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleTouchStart( |
722 const blink::WebTouchEvent& touch_event) { | 747 const blink::WebTouchEvent& touch_event) { |
723 for (size_t i = 0; i < touch_event.touchesLength; ++i) { | 748 for (size_t i = 0; i < touch_event.touchesLength; ++i) { |
724 if (touch_event.touches[i].state != WebTouchPoint::StatePressed) | 749 if (touch_event.touches[i].state != WebTouchPoint::StatePressed) |
725 continue; | 750 continue; |
726 if (input_handler_->DoTouchEventsBlockScrollAt( | 751 if (input_handler_->DoTouchEventsBlockScrollAt( |
727 gfx::Point(touch_event.touches[i].position.x, | 752 gfx::Point(touch_event.touches[i].position.x, |
728 touch_event.touches[i].position.y))) { | 753 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; | 754 return DID_NOT_HANDLE; |
732 } | 755 } |
733 } | 756 } |
734 return DROP_EVENT; | 757 |
| 758 switch (input_handler_->GetEventListenerProperties( |
| 759 cc::EventListenerClass::kTouch)) { |
| 760 case cc::EventListenerProperties::kPassive: |
| 761 return NON_BLOCKING; |
| 762 case cc::EventListenerProperties::kBlocking: |
| 763 return DID_NOT_HANDLE; |
| 764 case cc::EventListenerProperties::kNone: |
| 765 return DROP_EVENT; |
| 766 default: |
| 767 NOTREACHED(); |
| 768 return DROP_EVENT; |
| 769 } |
| 770 } |
| 771 |
| 772 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleTouchMove( |
| 773 const blink::WebTouchEvent& touch_event) { |
| 774 for (size_t i = 0; i < touch_event.touchesLength; ++i) { |
| 775 if (input_handler_->DoTouchEventsBlockScrollAt( |
| 776 gfx::Point(touch_event.touches[i].position.x, |
| 777 touch_event.touches[i].position.y))) { |
| 778 return DID_NOT_HANDLE; |
| 779 } |
| 780 } |
| 781 |
| 782 switch (input_handler_->GetEventListenerProperties( |
| 783 cc::EventListenerClass::kTouch)) { |
| 784 case cc::EventListenerProperties::kPassive: |
| 785 return NON_BLOCKING; |
| 786 case cc::EventListenerProperties::kBlocking: |
| 787 return DID_NOT_HANDLE; |
| 788 case cc::EventListenerProperties::kNone: |
| 789 return DROP_EVENT; |
| 790 default: |
| 791 NOTREACHED(); |
| 792 return DROP_EVENT; |
| 793 } |
735 } | 794 } |
736 | 795 |
737 bool InputHandlerProxy::FilterInputEventForFlingBoosting( | 796 bool InputHandlerProxy::FilterInputEventForFlingBoosting( |
738 const WebInputEvent& event) { | 797 const WebInputEvent& event) { |
739 if (!WebInputEvent::isGestureEventType(event.type)) | 798 if (!WebInputEvent::isGestureEventType(event.type)) |
740 return false; | 799 return false; |
741 | 800 |
742 if (!fling_curve_) { | 801 if (!fling_curve_) { |
743 DCHECK(!deferred_fling_cancel_time_seconds_); | 802 DCHECK(!deferred_fling_cancel_time_seconds_); |
744 return false; | 803 return false; |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1068 // flings always go through the normal InputHandler. | 1127 // flings always go through the normal InputHandler. |
1069 if (synchronous_input_handler_ && | 1128 if (synchronous_input_handler_ && |
1070 input_handler_->IsCurrentlyScrollingInnerViewport()) | 1129 input_handler_->IsCurrentlyScrollingInnerViewport()) |
1071 synchronous_input_handler_->SetNeedsSynchronousAnimateInput(); | 1130 synchronous_input_handler_->SetNeedsSynchronousAnimateInput(); |
1072 else | 1131 else |
1073 input_handler_->SetNeedsAnimateInput(); | 1132 input_handler_->SetNeedsAnimateInput(); |
1074 } | 1133 } |
1075 | 1134 |
1076 bool InputHandlerProxy::TouchpadFlingScroll( | 1135 bool InputHandlerProxy::TouchpadFlingScroll( |
1077 const WebFloatSize& increment) { | 1136 const WebFloatSize& increment) { |
1078 WebMouseWheelEvent synthetic_wheel; | 1137 InputHandlerProxy::EventDisposition disposition; |
1079 synthetic_wheel.type = WebInputEvent::MouseWheel; | 1138 cc::EventListenerProperties properties = |
1080 synthetic_wheel.timeStampSeconds = InSecondsF(base::TimeTicks::Now()); | 1139 input_handler_->GetEventListenerProperties( |
1081 synthetic_wheel.deltaX = increment.width; | 1140 cc::EventListenerClass::kMouseWheel); |
1082 synthetic_wheel.deltaY = increment.height; | 1141 switch (properties) { |
1083 synthetic_wheel.hasPreciseScrollingDeltas = true; | 1142 case cc::EventListenerProperties::kPassive: |
1084 synthetic_wheel.x = fling_parameters_.point.x; | 1143 disposition = NON_BLOCKING; |
1085 synthetic_wheel.y = fling_parameters_.point.y; | 1144 break; |
1086 synthetic_wheel.globalX = fling_parameters_.globalPoint.x; | 1145 case cc::EventListenerProperties::kBlocking: |
1087 synthetic_wheel.globalY = fling_parameters_.globalPoint.y; | 1146 disposition = DID_NOT_HANDLE; |
1088 synthetic_wheel.modifiers = fling_parameters_.modifiers; | 1147 break; |
| 1148 case cc::EventListenerProperties::kNone: { |
| 1149 WebMouseWheelEvent synthetic_wheel; |
| 1150 synthetic_wheel.type = WebInputEvent::MouseWheel; |
| 1151 synthetic_wheel.timeStampSeconds = InSecondsF(base::TimeTicks::Now()); |
| 1152 synthetic_wheel.deltaX = increment.width; |
| 1153 synthetic_wheel.deltaY = increment.height; |
| 1154 synthetic_wheel.hasPreciseScrollingDeltas = true; |
| 1155 synthetic_wheel.x = fling_parameters_.point.x; |
| 1156 synthetic_wheel.y = fling_parameters_.point.y; |
| 1157 synthetic_wheel.globalX = fling_parameters_.globalPoint.x; |
| 1158 synthetic_wheel.globalY = fling_parameters_.globalPoint.y; |
| 1159 synthetic_wheel.modifiers = fling_parameters_.modifiers; |
1089 | 1160 |
1090 InputHandlerProxy::EventDisposition disposition = | 1161 disposition = ScrollByMouseWheel(synthetic_wheel); |
1091 HandleInputEvent(synthetic_wheel); | 1162 break; |
| 1163 } |
| 1164 default: |
| 1165 NOTREACHED(); |
| 1166 return false; |
| 1167 } |
| 1168 |
1092 switch (disposition) { | 1169 switch (disposition) { |
1093 case DID_HANDLE: | 1170 case DID_HANDLE: |
1094 return true; | 1171 return true; |
1095 case DROP_EVENT: | 1172 case DROP_EVENT: |
1096 break; | 1173 break; |
| 1174 case NON_BLOCKING: |
| 1175 // TODO(dtapuska): Process the fling on the compositor thread |
| 1176 // but post the events to the main thread; for now just pass it to the |
| 1177 // main thread. |
1097 case DID_NOT_HANDLE: | 1178 case DID_NOT_HANDLE: |
1098 TRACE_EVENT_INSTANT0("input", | 1179 TRACE_EVENT_INSTANT0("input", |
1099 "InputHandlerProxy::scrollBy::AbortFling", | 1180 "InputHandlerProxy::scrollBy::AbortFling", |
1100 TRACE_EVENT_SCOPE_THREAD); | 1181 TRACE_EVENT_SCOPE_THREAD); |
1101 // If we got a DID_NOT_HANDLE, that means we need to deliver wheels on the | 1182 // 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 | 1183 // 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 | 1184 // 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 | 1185 // 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 | 1186 // subarea that we can't scroll on the thread if the fling starts outside |
1106 // the subarea but then is flung "under" the pointer. | 1187 // the subarea but then is flung "under" the pointer. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1171 // trigger a scroll, e.g., with a trivial time delta between fling updates. | 1252 // trigger a scroll, e.g., with a trivial time delta between fling updates. |
1172 // Return true in this case to prevent early fling termination. | 1253 // Return true in this case to prevent early fling termination. |
1173 if (std::abs(clipped_increment.width) < kScrollEpsilon && | 1254 if (std::abs(clipped_increment.width) < kScrollEpsilon && |
1174 std::abs(clipped_increment.height) < kScrollEpsilon) | 1255 std::abs(clipped_increment.height) < kScrollEpsilon) |
1175 return true; | 1256 return true; |
1176 | 1257 |
1177 return did_scroll; | 1258 return did_scroll; |
1178 } | 1259 } |
1179 | 1260 |
1180 } // namespace ui | 1261 } // namespace ui |
OLD | NEW |