| 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 907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 918 | 918 |
| 919 return scroll_result.did_scroll ? DID_HANDLE : DROP_EVENT; | 919 return scroll_result.did_scroll ? DID_HANDLE : DROP_EVENT; |
| 920 } | 920 } |
| 921 | 921 |
| 922 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleGestureScrollEnd( | 922 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleGestureScrollEnd( |
| 923 const WebGestureEvent& gesture_event) { | 923 const WebGestureEvent& gesture_event) { |
| 924 #ifndef NDEBUG | 924 #ifndef NDEBUG |
| 925 DCHECK(expect_scroll_update_end_); | 925 DCHECK(expect_scroll_update_end_); |
| 926 expect_scroll_update_end_ = false; | 926 expect_scroll_update_end_ = false; |
| 927 #endif | 927 #endif |
| 928 input_handler_->SnapAfterGestureScroll( |
| 929 gfx::Point(gesture_event.x, gesture_event.y)); |
| 930 |
| 928 if (ShouldAnimate(gesture_event.data.scroll_end.delta_units != | 931 if (ShouldAnimate(gesture_event.data.scroll_end.delta_units != |
| 929 blink::WebGestureEvent::ScrollUnits::kPixels)) { | 932 blink::WebGestureEvent::ScrollUnits::kPixels)) { |
| 930 // Do nothing if the scroll is being animated; the scroll animation will | 933 // Do nothing if the scroll is being animated; the scroll animation will |
| 931 // generate the ScrollEnd when it is done. | 934 // generate the ScrollEnd when it is done. |
| 932 } else { | 935 } else { |
| 933 cc::ScrollState scroll_state = CreateScrollStateForGesture(gesture_event); | 936 cc::ScrollState scroll_state = CreateScrollStateForGesture(gesture_event); |
| 934 input_handler_->ScrollEnd(&scroll_state); | 937 input_handler_->ScrollEnd(&scroll_state); |
| 935 } | 938 } |
| 939 |
| 936 if (!gesture_scroll_on_impl_thread_) | 940 if (!gesture_scroll_on_impl_thread_) |
| 937 return DID_NOT_HANDLE; | 941 return DID_NOT_HANDLE; |
| 938 | 942 |
| 939 if (scroll_elasticity_controller_) | 943 if (scroll_elasticity_controller_) |
| 940 HandleScrollElasticityOverscroll(gesture_event, | 944 HandleScrollElasticityOverscroll(gesture_event, |
| 941 cc::InputHandlerScrollResult()); | 945 cc::InputHandlerScrollResult()); |
| 942 | 946 |
| 943 gesture_scroll_on_impl_thread_ = false; | 947 gesture_scroll_on_impl_thread_ = false; |
| 944 return DID_HANDLE; | 948 return DID_HANDLE; |
| 945 } | 949 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 // Note that the timestamp will only be used to kickstart the animation if | 1006 // Note that the timestamp will only be used to kickstart the animation if |
| 1003 // its sufficiently close to the timestamp of the first call |Animate()|. | 1007 // its sufficiently close to the timestamp of the first call |Animate()|. |
| 1004 has_fling_animation_started_ = false; | 1008 has_fling_animation_started_ = false; |
| 1005 fling_parameters_.start_time = gesture_event.TimeStampSeconds(); | 1009 fling_parameters_.start_time = gesture_event.TimeStampSeconds(); |
| 1006 fling_parameters_.delta = WebFloatPoint(vx, vy); | 1010 fling_parameters_.delta = WebFloatPoint(vx, vy); |
| 1007 fling_parameters_.point = WebPoint(gesture_event.x, gesture_event.y); | 1011 fling_parameters_.point = WebPoint(gesture_event.x, gesture_event.y); |
| 1008 fling_parameters_.global_point = | 1012 fling_parameters_.global_point = |
| 1009 WebPoint(gesture_event.global_x, gesture_event.global_y); | 1013 WebPoint(gesture_event.global_x, gesture_event.global_y); |
| 1010 fling_parameters_.modifiers = gesture_event.GetModifiers(); | 1014 fling_parameters_.modifiers = gesture_event.GetModifiers(); |
| 1011 fling_parameters_.source_device = gesture_event.source_device; | 1015 fling_parameters_.source_device = gesture_event.source_device; |
| 1012 RequestAnimation(); | 1016 if (AdjustFlingCurveToSnapPoints()) |
| 1017 RequestAnimation(); |
| 1018 else |
| 1019 fling_curve_.reset(); |
| 1013 return DID_HANDLE; | 1020 return DID_HANDLE; |
| 1014 } | 1021 } |
| 1015 case cc::InputHandler::SCROLL_UNKNOWN: | 1022 case cc::InputHandler::SCROLL_UNKNOWN: |
| 1016 case cc::InputHandler::SCROLL_ON_MAIN_THREAD: { | 1023 case cc::InputHandler::SCROLL_ON_MAIN_THREAD: { |
| 1017 TRACE_EVENT_INSTANT0("input,rail", | 1024 TRACE_EVENT_INSTANT0("input,rail", |
| 1018 "InputHandlerProxy::HandleGestureFling::" | 1025 "InputHandlerProxy::HandleGestureFling::" |
| 1019 "scroll_on_main_thread", | 1026 "scroll_on_main_thread", |
| 1020 TRACE_EVENT_SCOPE_THREAD); | 1027 TRACE_EVENT_SCOPE_THREAD); |
| 1021 gesture_scroll_on_impl_thread_ = false; | 1028 gesture_scroll_on_impl_thread_ = false; |
| 1022 fling_may_be_active_on_main_thread_ = true; | 1029 fling_may_be_active_on_main_thread_ = true; |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1284 void InputHandlerProxy::ExtendBoostedFlingTimeout( | 1291 void InputHandlerProxy::ExtendBoostedFlingTimeout( |
| 1285 const blink::WebGestureEvent& event) { | 1292 const blink::WebGestureEvent& event) { |
| 1286 TRACE_EVENT_INSTANT0("input", | 1293 TRACE_EVENT_INSTANT0("input", |
| 1287 "InputHandlerProxy::ExtendBoostedFlingTimeout", | 1294 "InputHandlerProxy::ExtendBoostedFlingTimeout", |
| 1288 TRACE_EVENT_SCOPE_THREAD); | 1295 TRACE_EVENT_SCOPE_THREAD); |
| 1289 deferred_fling_cancel_time_seconds_ = | 1296 deferred_fling_cancel_time_seconds_ = |
| 1290 event.TimeStampSeconds() + kFlingBoostTimeoutDelaySeconds; | 1297 event.TimeStampSeconds() + kFlingBoostTimeoutDelaySeconds; |
| 1291 last_fling_boost_event_ = event; | 1298 last_fling_boost_event_ = event; |
| 1292 } | 1299 } |
| 1293 | 1300 |
| 1301 bool InputHandlerProxy::AdjustFlingCurveToSnapPoints() { |
| 1302 gfx::Vector2dF original_offset; |
| 1303 fling_curve_->ComputeTotalScrollOffset(original_offset); |
| 1304 gfx::Vector2dF snapped_offset; |
| 1305 input_handler_->FindSnappedOffset(&snapped_offset, original_offset); |
| 1306 return fling_curve_->ResetCurveBySnappedOffset(snapped_offset); |
| 1307 } |
| 1308 |
| 1294 void InputHandlerProxy::Animate(base::TimeTicks time) { | 1309 void InputHandlerProxy::Animate(base::TimeTicks time) { |
| 1295 // If using synchronous animate, then only expect Animate attempts started by | 1310 // If using synchronous animate, then only expect Animate attempts started by |
| 1296 // the synchronous system. Don't let the InputHandler try to Animate also. | 1311 // the synchronous system. Don't let the InputHandler try to Animate also. |
| 1297 DCHECK(!input_handler_->IsCurrentlyScrollingViewport() || | 1312 DCHECK(!input_handler_->IsCurrentlyScrollingViewport() || |
| 1298 allow_root_animate_); | 1313 allow_root_animate_); |
| 1299 | 1314 |
| 1300 if (scroll_elasticity_controller_) | 1315 if (scroll_elasticity_controller_) |
| 1301 scroll_elasticity_controller_->Animate(time); | 1316 scroll_elasticity_controller_->Animate(time); |
| 1302 | 1317 |
| 1303 if (!fling_curve_) | 1318 if (!fling_curve_) |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1661 scroll_elasticity_controller_->GetWeakPtr(), gesture_event, | 1676 scroll_elasticity_controller_->GetWeakPtr(), gesture_event, |
| 1662 scroll_result)); | 1677 scroll_result)); |
| 1663 } | 1678 } |
| 1664 | 1679 |
| 1665 void InputHandlerProxy::SetTickClockForTesting( | 1680 void InputHandlerProxy::SetTickClockForTesting( |
| 1666 std::unique_ptr<base::TickClock> tick_clock) { | 1681 std::unique_ptr<base::TickClock> tick_clock) { |
| 1667 tick_clock_ = std::move(tick_clock); | 1682 tick_clock_ = std::move(tick_clock); |
| 1668 } | 1683 } |
| 1669 | 1684 |
| 1670 } // namespace ui | 1685 } // namespace ui |
| OLD | NEW |