| 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 <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 WebPoint global_point, | 119 WebPoint global_point, |
| 120 int modifiers) { | 120 int modifiers) { |
| 121 return CreateFling(base::TimeTicks(), | 121 return CreateFling(base::TimeTicks(), |
| 122 source_device, | 122 source_device, |
| 123 velocity, | 123 velocity, |
| 124 point, | 124 point, |
| 125 global_point, | 125 global_point, |
| 126 modifiers); | 126 modifiers); |
| 127 } | 127 } |
| 128 | 128 |
| 129 WebScopedInputEvent CreateGestureScrollOrPinch(WebInputEvent::Type type, | 129 WebScopedInputEvent CreateGestureScrollFlingPinch(WebInputEvent::Type type, |
| 130 float deltaYOrScale = 0, | 130 float deltaYOrScale = 0, |
| 131 int x = 0, | 131 int x = 0, |
| 132 int y = 0) { | 132 int y = 0) { |
| 133 WebGestureEvent gesture(type, WebInputEvent::NoModifiers, | 133 WebGestureEvent gesture(type, WebInputEvent::NoModifiers, |
| 134 WebInputEvent::TimeStampForTesting); | 134 WebInputEvent::TimeStampForTesting); |
| 135 gesture.sourceDevice = blink::WebGestureDeviceTouchpad; | 135 gesture.sourceDevice = blink::WebGestureDeviceTouchpad; |
| 136 if (type == WebInputEvent::GestureScrollUpdate) { | 136 if (type == WebInputEvent::GestureScrollUpdate) { |
| 137 gesture.data.scrollUpdate.deltaY = deltaYOrScale; | 137 gesture.data.scrollUpdate.deltaY = deltaYOrScale; |
| 138 } else if (type == WebInputEvent::GestureFlingStart) { |
| 139 gesture.data.flingStart.velocityY = deltaYOrScale; |
| 138 } else if (type == WebInputEvent::GesturePinchUpdate) { | 140 } else if (type == WebInputEvent::GesturePinchUpdate) { |
| 139 gesture.data.pinchUpdate.scale = deltaYOrScale; | 141 gesture.data.pinchUpdate.scale = deltaYOrScale; |
| 140 gesture.x = x; | 142 gesture.x = x; |
| 141 gesture.y = y; | 143 gesture.y = y; |
| 142 } | 144 } |
| 143 return WebInputEventTraits::Clone(gesture); | 145 return WebInputEventTraits::Clone(gesture); |
| 144 } | 146 } |
| 145 | 147 |
| 146 void OnTraceDataCollected(base::Closure quit_closure, | 148 void OnTraceDataCollected(base::Closure quit_closure, |
| 147 base::trace_event::TraceResultBuffer* buffer, | 149 base::trace_event::TraceResultBuffer* buffer, |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 return base::WrapUnique( | 536 return base::WrapUnique( |
| 535 trace_analyzer::TraceAnalyzer::Create(trace_output.json_output)); | 537 trace_analyzer::TraceAnalyzer::Create(trace_output.json_output)); |
| 536 } | 538 } |
| 537 | 539 |
| 538 void HandleGestureEvent(WebInputEvent::Type type, | 540 void HandleGestureEvent(WebInputEvent::Type type, |
| 539 float deltay_or_scale = 0, | 541 float deltay_or_scale = 0, |
| 540 int x = 0, | 542 int x = 0, |
| 541 int y = 0) { | 543 int y = 0) { |
| 542 LatencyInfo latency; | 544 LatencyInfo latency; |
| 543 input_handler_proxy_->HandleInputEventWithLatencyInfo( | 545 input_handler_proxy_->HandleInputEventWithLatencyInfo( |
| 544 CreateGestureScrollOrPinch(type, deltay_or_scale, x, y), latency, | 546 CreateGestureScrollFlingPinch(type, deltay_or_scale, x, y), latency, |
| 545 base::Bind( | 547 base::Bind( |
| 546 &InputHandlerProxyEventQueueTest::DidHandleInputEventAndOverscroll, | 548 &InputHandlerProxyEventQueueTest::DidHandleInputEventAndOverscroll, |
| 547 weak_ptr_factory_.GetWeakPtr())); | 549 weak_ptr_factory_.GetWeakPtr())); |
| 548 } | 550 } |
| 549 | 551 |
| 550 void DidHandleInputEventAndOverscroll( | 552 void DidHandleInputEventAndOverscroll( |
| 551 InputHandlerProxy::EventDisposition event_disposition, | 553 InputHandlerProxy::EventDisposition event_disposition, |
| 552 WebScopedInputEvent input_event, | 554 WebScopedInputEvent input_event, |
| 553 const ui::LatencyInfo& latency_info, | 555 const ui::LatencyInfo& latency_info, |
| 554 std::unique_ptr<ui::DidOverscrollParams> overscroll_params) { | 556 std::unique_ptr<ui::DidOverscrollParams> overscroll_params) { |
| (...skipping 2970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3525 // The ScrollUpdate of the pair doesn't carry original events and won't be | 3527 // The ScrollUpdate of the pair doesn't carry original events and won't be |
| 3526 // traced. | 3528 // traced. |
| 3527 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, | 3529 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, |
| 3528 end_events[3]->GetKnownArgAsInt("type")); | 3530 end_events[3]->GetKnownArgAsInt("type")); |
| 3529 EXPECT_EQ(4, end_events[3]->GetKnownArgAsInt("coalesced_count")); | 3531 EXPECT_EQ(4, end_events[3]->GetKnownArgAsInt("coalesced_count")); |
| 3530 EXPECT_EQ(WebInputEvent::GestureScrollEnd, | 3532 EXPECT_EQ(WebInputEvent::GestureScrollEnd, |
| 3531 end_events[4]->GetKnownArgAsInt("type")); | 3533 end_events[4]->GetKnownArgAsInt("type")); |
| 3532 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); | 3534 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); |
| 3533 } | 3535 } |
| 3534 | 3536 |
| 3537 TEST_F(InputHandlerProxyEventQueueTest, GestureScrollFlingOrder) { |
| 3538 // Handle scroll on compositor. |
| 3539 cc::InputHandlerScrollResult scroll_result_did_scroll_; |
| 3540 scroll_result_did_scroll_.did_scroll = true; |
| 3541 |
| 3542 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) |
| 3543 .WillRepeatedly(testing::Return(kImplThreadScrollState)); |
| 3544 EXPECT_CALL(mock_input_handler_, SetNeedsAnimateInput()) |
| 3545 .Times(::testing::AtLeast(1)); |
| 3546 EXPECT_CALL( |
| 3547 mock_input_handler_, |
| 3548 ScrollBy(testing::Property(&cc::ScrollState::delta_y, testing::Gt(0)))) |
| 3549 .WillRepeatedly(testing::Return(scroll_result_did_scroll_)); |
| 3550 EXPECT_CALL(mock_input_handler_, ScrollEnd(testing::_)) |
| 3551 .Times(::testing::AtLeast(1)); |
| 3552 |
| 3553 // Simulate scroll. |
| 3554 HandleGestureEvent(WebInputEvent::GestureScrollBegin); |
| 3555 HandleGestureEvent(WebInputEvent::GestureScrollUpdate, -20); |
| 3556 HandleGestureEvent(WebInputEvent::GestureScrollUpdate, -30); |
| 3557 HandleGestureEvent(WebInputEvent::GestureFlingStart, -10); |
| 3558 |
| 3559 // ScrollUpdate and FlingStart should be queued. |
| 3560 EXPECT_EQ(2ul, event_queue().size()); |
| 3561 EXPECT_EQ(1ul, event_disposition_recorder_.size()); |
| 3562 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, |
| 3563 event_queue()[0]->event().type()); |
| 3564 EXPECT_EQ(WebInputEvent::GestureFlingStart, event_queue()[1]->event().type()); |
| 3565 |
| 3566 // Dispatch events. |
| 3567 input_handler_proxy_->DeliverInputForBeginFrame(); |
| 3568 EXPECT_EQ(0ul, event_queue().size()); |
| 3569 EXPECT_EQ(4ul, event_disposition_recorder_.size()); |
| 3570 EXPECT_TRUE( |
| 3571 input_handler_proxy_->gesture_scroll_on_impl_thread_for_testing()); |
| 3572 |
| 3573 // Send FlingCancel to stop scrolling. |
| 3574 HandleGestureEvent(WebInputEvent::GestureFlingCancel); |
| 3575 EXPECT_EQ(1ul, event_queue().size()); |
| 3576 EXPECT_EQ(WebInputEvent::GestureFlingCancel, |
| 3577 event_queue()[0]->event().type()); |
| 3578 input_handler_proxy_->DeliverInputForBeginFrame(); |
| 3579 EXPECT_EQ(0ul, event_queue().size()); |
| 3580 EXPECT_EQ(5ul, event_disposition_recorder_.size()); |
| 3581 // Should stop scrolling. Note that no ScrollEnd was sent. |
| 3582 EXPECT_TRUE( |
| 3583 !input_handler_proxy_->gesture_scroll_on_impl_thread_for_testing()); |
| 3584 } |
| 3585 |
| 3535 INSTANTIATE_TEST_CASE_P(AnimateInput, | 3586 INSTANTIATE_TEST_CASE_P(AnimateInput, |
| 3536 InputHandlerProxyTest, | 3587 InputHandlerProxyTest, |
| 3537 testing::ValuesIn(test_types)); | 3588 testing::ValuesIn(test_types)); |
| 3538 | 3589 |
| 3539 } // namespace test | 3590 } // namespace test |
| 3540 } // namespace ui | 3591 } // namespace ui |
| OLD | NEW |