Chromium Code Reviews| 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) { | |
|
tdresser
2017/03/10 15:31:06
Should we have a test involving a fling cancel?
chongz
2017/03/14 14:51:06
I've improved the test to cover FlingCancel better
| |
| 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 HandleGestureEvent(WebInputEvent::GestureFlingCancel); | |
| 3559 | |
| 3560 // ScrollUpdate and Fling should be queued. | |
| 3561 EXPECT_EQ(3ul, event_queue().size()); | |
| 3562 EXPECT_EQ(1ul, event_disposition_recorder_.size()); | |
| 3563 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, | |
| 3564 event_queue()[0]->event().type()); | |
| 3565 EXPECT_EQ(WebInputEvent::GestureFlingStart, event_queue()[1]->event().type()); | |
| 3566 EXPECT_EQ(WebInputEvent::GestureFlingCancel, | |
| 3567 event_queue()[2]->event().type()); | |
| 3568 | |
| 3569 // Dispatch all events. | |
| 3570 input_handler_proxy_->DeliverInputForBeginFrame(); | |
| 3571 EXPECT_EQ(0ul, event_queue().size()); | |
| 3572 EXPECT_EQ(5ul, event_disposition_recorder_.size()); | |
| 3573 } | |
| 3574 | |
| 3535 INSTANTIATE_TEST_CASE_P(AnimateInput, | 3575 INSTANTIATE_TEST_CASE_P(AnimateInput, |
| 3536 InputHandlerProxyTest, | 3576 InputHandlerProxyTest, |
| 3537 testing::ValuesIn(test_types)); | 3577 testing::ValuesIn(test_types)); |
| 3538 | 3578 |
| 3539 } // namespace test | 3579 } // namespace test |
| 3540 } // namespace ui | 3580 } // namespace ui |
| OLD | NEW |