| 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 "content/renderer/input/input_handler_proxy.h" | 5 #include "content/renderer/input/input_handler_proxy.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "cc/base/swap_promise_monitor.h" | 9 #include "cc/base/swap_promise_monitor.h" |
| 10 #include "content/common/input/did_overscroll_params.h" |
| 10 #include "content/renderer/input/input_handler_proxy_client.h" | 11 #include "content/renderer/input/input_handler_proxy_client.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "third_party/WebKit/public/platform/WebFloatPoint.h" | 14 #include "third_party/WebKit/public/platform/WebFloatPoint.h" |
| 14 #include "third_party/WebKit/public/platform/WebFloatSize.h" | 15 #include "third_party/WebKit/public/platform/WebFloatSize.h" |
| 15 #include "third_party/WebKit/public/platform/WebGestureCurve.h" | 16 #include "third_party/WebKit/public/platform/WebGestureCurve.h" |
| 16 #include "third_party/WebKit/public/platform/WebPoint.h" | 17 #include "third_party/WebKit/public/platform/WebPoint.h" |
| 17 #include "third_party/WebKit/public/web/WebInputEvent.h" | 18 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 18 #include "ui/events/latency_info.h" | 19 #include "ui/events/latency_info.h" |
| 19 | 20 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 return scoped_ptr<cc::SwapPromiseMonitor>(); | 61 return scoped_ptr<cc::SwapPromiseMonitor>(); |
| 61 } | 62 } |
| 62 | 63 |
| 63 virtual void BindToClient(cc::InputHandlerClient* client) OVERRIDE {} | 64 virtual void BindToClient(cc::InputHandlerClient* client) OVERRIDE {} |
| 64 | 65 |
| 65 virtual void StartPageScaleAnimation(const gfx::Vector2d& target_offset, | 66 virtual void StartPageScaleAnimation(const gfx::Vector2d& target_offset, |
| 66 bool anchor_point, | 67 bool anchor_point, |
| 67 float page_scale, | 68 float page_scale, |
| 68 base::TimeDelta duration) OVERRIDE {} | 69 base::TimeDelta duration) OVERRIDE {} |
| 69 | 70 |
| 70 virtual void NotifyCurrentFlingVelocity( | |
| 71 const gfx::Vector2dF& velocity) OVERRIDE {} | |
| 72 virtual void MouseMoveAt(const gfx::Point& mouse_position) OVERRIDE {} | 71 virtual void MouseMoveAt(const gfx::Point& mouse_position) OVERRIDE {} |
| 73 | 72 |
| 74 MOCK_METHOD1(HaveTouchEventHandlersAt, bool(const gfx::Point& point)); | 73 MOCK_METHOD1(HaveTouchEventHandlersAt, bool(const gfx::Point& point)); |
| 75 | 74 |
| 76 virtual void SetRootLayerScrollOffsetDelegate( | 75 virtual void SetRootLayerScrollOffsetDelegate( |
| 77 cc::LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) | 76 cc::LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) |
| 78 OVERRIDE {} | 77 OVERRIDE {} |
| 79 | 78 |
| 80 virtual void OnRootLayerDelegatedScrollOffsetChanged() OVERRIDE {} | 79 virtual void OnRootLayerDelegatedScrollOffsetChanged() OVERRIDE {} |
| 81 | 80 |
| 82 DISALLOW_COPY_AND_ASSIGN(MockInputHandler); | 81 DISALLOW_COPY_AND_ASSIGN(MockInputHandler); |
| 83 }; | 82 }; |
| 84 | 83 |
| 85 // A simple WebGestureCurve implementation that flings at a constant velocity | 84 // A simple WebGestureCurve implementation that flings at a constant velocity |
| 86 // indefinitely. | 85 // indefinitely. |
| 87 class FakeWebGestureCurve : public blink::WebGestureCurve { | 86 class FakeWebGestureCurve : public blink::WebGestureCurve { |
| 88 public: | 87 public: |
| 89 FakeWebGestureCurve(const blink::WebFloatPoint& velocity, | 88 FakeWebGestureCurve(const blink::WebFloatSize& velocity, |
| 90 const blink::WebSize& cumulative_scroll) | 89 const blink::WebFloatSize& cumulative_scroll) |
| 91 : velocity_(velocity), cumulative_scroll_(cumulative_scroll) {} | 90 : velocity_(velocity), cumulative_scroll_(cumulative_scroll) {} |
| 92 | 91 |
| 93 virtual ~FakeWebGestureCurve() {} | 92 virtual ~FakeWebGestureCurve() {} |
| 94 | 93 |
| 95 // Returns false if curve has finished and can no longer be applied. | 94 // Returns false if curve has finished and can no longer be applied. |
| 96 virtual bool apply(double time, blink::WebGestureCurveTarget* target) { | 95 virtual bool apply(double time, blink::WebGestureCurveTarget* target) { |
| 97 blink::WebSize displacement(velocity_.x * time, velocity_.y * time); | 96 blink::WebFloatSize displacement(velocity_.width * time, |
| 97 velocity_.height * time); |
| 98 blink::WebFloatSize increment( | 98 blink::WebFloatSize increment( |
| 99 displacement.width - cumulative_scroll_.width, | 99 displacement.width - cumulative_scroll_.width, |
| 100 displacement.height - cumulative_scroll_.height); | 100 displacement.height - cumulative_scroll_.height); |
| 101 cumulative_scroll_ = displacement; | 101 cumulative_scroll_ = displacement; |
| 102 // scrollBy() could delete this curve if the animation is over, so don't | 102 // scrollBy() could delete this curve if the animation is over, so don't |
| 103 // touch any member variables after making that call. | 103 // touch any member variables after making that call. |
| 104 target->scrollBy(increment); | 104 target->scrollBy(increment, velocity_); |
| 105 return true; | 105 return true; |
| 106 } | 106 } |
| 107 | 107 |
| 108 private: | 108 private: |
| 109 blink::WebFloatPoint velocity_; | 109 blink::WebFloatSize velocity_; |
| 110 blink::WebSize cumulative_scroll_; | 110 blink::WebFloatSize cumulative_scroll_; |
| 111 | 111 |
| 112 DISALLOW_COPY_AND_ASSIGN(FakeWebGestureCurve); | 112 DISALLOW_COPY_AND_ASSIGN(FakeWebGestureCurve); |
| 113 }; | 113 }; |
| 114 | 114 |
| 115 class MockInputHandlerProxyClient | 115 class MockInputHandlerProxyClient |
| 116 : public content::InputHandlerProxyClient { | 116 : public content::InputHandlerProxyClient { |
| 117 public: | 117 public: |
| 118 MockInputHandlerProxyClient() {} | 118 MockInputHandlerProxyClient() {} |
| 119 virtual ~MockInputHandlerProxyClient() {} | 119 virtual ~MockInputHandlerProxyClient() {} |
| 120 | 120 |
| 121 virtual void WillShutdown() OVERRIDE {} | 121 virtual void WillShutdown() OVERRIDE {} |
| 122 | 122 |
| 123 MOCK_METHOD1(TransferActiveWheelFlingAnimation, | 123 MOCK_METHOD1(TransferActiveWheelFlingAnimation, |
| 124 void(const WebActiveWheelFlingParameters&)); | 124 void(const WebActiveWheelFlingParameters&)); |
| 125 | 125 |
| 126 virtual blink::WebGestureCurve* CreateFlingAnimationCurve( | 126 virtual blink::WebGestureCurve* CreateFlingAnimationCurve( |
| 127 int deviceSource, | 127 int deviceSource, |
| 128 const WebFloatPoint& velocity, | 128 const WebFloatPoint& velocity, |
| 129 const WebSize& cumulative_scroll) OVERRIDE { | 129 const WebSize& cumulative_scroll) OVERRIDE { |
| 130 return new FakeWebGestureCurve(velocity, cumulative_scroll); | 130 return new FakeWebGestureCurve( |
| 131 blink::WebFloatSize(velocity.x, velocity.y), |
| 132 blink::WebFloatSize(cumulative_scroll.width, cumulative_scroll.height)); |
| 131 } | 133 } |
| 132 | 134 |
| 133 virtual void DidOverscroll(const cc::DidOverscrollParams& params) OVERRIDE {} | 135 MOCK_METHOD1(DidOverscroll, void(const DidOverscrollParams&)); |
| 134 virtual void DidStopFlinging() OVERRIDE {} | 136 virtual void DidStopFlinging() OVERRIDE {} |
| 135 | 137 |
| 136 private: | 138 private: |
| 137 DISALLOW_COPY_AND_ASSIGN(MockInputHandlerProxyClient); | 139 DISALLOW_COPY_AND_ASSIGN(MockInputHandlerProxyClient); |
| 138 }; | 140 }; |
| 139 | 141 |
| 140 WebTouchPoint CreateWebTouchPoint(WebTouchPoint::State state, float x, | 142 WebTouchPoint CreateWebTouchPoint(WebTouchPoint::State state, float x, |
| 141 float y) { | 143 float y) { |
| 142 WebTouchPoint point; | 144 WebTouchPoint point; |
| 143 point.state = state; | 145 point.state = state; |
| (...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1078 EXPECT_CALL(mock_input_handler_, | 1080 EXPECT_CALL(mock_input_handler_, |
| 1079 ScrollBy(testing::_, | 1081 ScrollBy(testing::_, |
| 1080 testing::Property(&gfx::Vector2dF::y, testing::Lt(0)))) | 1082 testing::Property(&gfx::Vector2dF::y, testing::Lt(0)))) |
| 1081 .WillOnce(testing::Return(true)); | 1083 .WillOnce(testing::Return(true)); |
| 1082 EXPECT_CALL(mock_input_handler_, ScrollEnd()); | 1084 EXPECT_CALL(mock_input_handler_, ScrollEnd()); |
| 1083 time += base::TimeDelta::FromMilliseconds(100); | 1085 time += base::TimeDelta::FromMilliseconds(100); |
| 1084 input_handler_->Animate(time); | 1086 input_handler_->Animate(time); |
| 1085 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); | 1087 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); |
| 1086 | 1088 |
| 1087 // Simulate hitting the bottom content edge. | 1089 // Simulate hitting the bottom content edge. |
| 1088 cc::DidOverscrollParams overscroll_params; | 1090 gfx::Vector2dF accumulated_overscroll(0, 100); |
| 1089 overscroll_params.accumulated_overscroll = gfx::Vector2dF(0, 100); | 1091 gfx::Vector2dF latest_overscroll_delta(0, 10); |
| 1090 overscroll_params.current_fling_velocity = gfx::Vector2dF(0, 10); | 1092 EXPECT_CALL(mock_client_, |
| 1091 input_handler_->DidOverscroll(overscroll_params); | 1093 DidOverscroll(testing::AllOf( |
| 1094 testing::Field(&DidOverscrollParams::accumulated_overscroll, |
| 1095 testing::Eq(accumulated_overscroll)), |
| 1096 testing::Field(&DidOverscrollParams::latest_overscroll_delta, |
| 1097 testing::Eq(latest_overscroll_delta)), |
| 1098 testing::Field( |
| 1099 &DidOverscrollParams::current_fling_velocity, |
| 1100 testing::Property(&gfx::Vector2dF::y, testing::Gt(0)))))); |
| 1101 input_handler_->DidOverscroll(accumulated_overscroll, |
| 1102 latest_overscroll_delta); |
| 1092 | 1103 |
| 1093 // The next call to animate will no longer scroll vertically. | 1104 // The next call to animate will no longer scroll vertically. |
| 1094 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); | 1105 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); |
| 1095 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) | 1106 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) |
| 1096 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted)); | 1107 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted)); |
| 1097 EXPECT_CALL(mock_input_handler_, | 1108 EXPECT_CALL(mock_input_handler_, |
| 1098 ScrollBy(testing::_, | 1109 ScrollBy(testing::_, |
| 1099 testing::Property(&gfx::Vector2dF::y, testing::Eq(0)))) | 1110 testing::Property(&gfx::Vector2dF::y, testing::Eq(0)))) |
| 1100 .WillOnce(testing::Return(true)); | 1111 .WillOnce(testing::Return(true)); |
| 1101 EXPECT_CALL(mock_input_handler_, ScrollEnd()); | 1112 EXPECT_CALL(mock_input_handler_, ScrollEnd()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1138 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); | 1149 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); |
| 1139 EXPECT_CALL(mock_input_handler_, | 1150 EXPECT_CALL(mock_input_handler_, |
| 1140 ScrollBy(testing::_, | 1151 ScrollBy(testing::_, |
| 1141 testing::Property(&gfx::Vector2dF::y, testing::Lt(0)))) | 1152 testing::Property(&gfx::Vector2dF::y, testing::Lt(0)))) |
| 1142 .WillOnce(testing::Return(true)); | 1153 .WillOnce(testing::Return(true)); |
| 1143 time += base::TimeDelta::FromMilliseconds(10); | 1154 time += base::TimeDelta::FromMilliseconds(10); |
| 1144 input_handler_->Animate(time); | 1155 input_handler_->Animate(time); |
| 1145 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); | 1156 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); |
| 1146 | 1157 |
| 1147 // Simulate hitting the bottom content edge. | 1158 // Simulate hitting the bottom content edge. |
| 1148 cc::DidOverscrollParams overscroll_params; | 1159 gfx::Vector2dF accumulated_overscroll(0, 100); |
| 1149 overscroll_params.accumulated_overscroll = gfx::Vector2dF(0, 100); | 1160 gfx::Vector2dF latest_overscroll_delta(0, 100); |
| 1150 input_handler_->DidOverscroll(overscroll_params); | 1161 EXPECT_CALL(mock_client_, |
| 1162 DidOverscroll(testing::AllOf( |
| 1163 testing::Field(&DidOverscrollParams::accumulated_overscroll, |
| 1164 testing::Eq(accumulated_overscroll)), |
| 1165 testing::Field(&DidOverscrollParams::latest_overscroll_delta, |
| 1166 testing::Eq(latest_overscroll_delta)), |
| 1167 testing::Field( |
| 1168 &DidOverscrollParams::current_fling_velocity, |
| 1169 testing::Property(&gfx::Vector2dF::y, testing::Gt(0)))))); |
| 1170 input_handler_->DidOverscroll(accumulated_overscroll, |
| 1171 latest_overscroll_delta); |
| 1151 | 1172 |
| 1152 // The next call to animate will no longer scroll vertically. | 1173 // The next call to animate will no longer scroll vertically. |
| 1153 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); | 1174 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); |
| 1154 EXPECT_CALL(mock_input_handler_, | 1175 EXPECT_CALL(mock_input_handler_, |
| 1155 ScrollBy(testing::_, | 1176 ScrollBy(testing::_, |
| 1156 testing::Property(&gfx::Vector2dF::y, testing::Eq(0)))) | 1177 testing::Property(&gfx::Vector2dF::y, testing::Eq(0)))) |
| 1157 .WillOnce(testing::Return(true)); | 1178 .WillOnce(testing::Return(true)); |
| 1158 time += base::TimeDelta::FromMilliseconds(10); | 1179 time += base::TimeDelta::FromMilliseconds(10); |
| 1159 input_handler_->Animate(time); | 1180 input_handler_->Animate(time); |
| 1160 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); | 1181 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); |
| 1161 | 1182 |
| 1162 // Simulate hitting the right content edge. | 1183 // Simulate hitting the right content edge. |
| 1163 overscroll_params.accumulated_overscroll = gfx::Vector2dF(100, 100); | 1184 accumulated_overscroll = gfx::Vector2dF(100, 100); |
| 1164 input_handler_->DidOverscroll(overscroll_params); | 1185 latest_overscroll_delta = gfx::Vector2dF(100, 0); |
| 1165 | 1186 EXPECT_CALL(mock_client_, |
| 1187 DidOverscroll(testing::AllOf( |
| 1188 testing::Field(&DidOverscrollParams::accumulated_overscroll, |
| 1189 testing::Eq(accumulated_overscroll)), |
| 1190 testing::Field(&DidOverscrollParams::latest_overscroll_delta, |
| 1191 testing::Eq(latest_overscroll_delta)), |
| 1192 testing::Field( |
| 1193 &DidOverscrollParams::current_fling_velocity, |
| 1194 testing::Property(&gfx::Vector2dF::x, testing::Gt(0)))))); |
| 1195 input_handler_->DidOverscroll(accumulated_overscroll, |
| 1196 latest_overscroll_delta); |
| 1166 // The next call to animate will no longer scroll horizontally or vertically, | 1197 // The next call to animate will no longer scroll horizontally or vertically, |
| 1167 // and the fling should be cancelled. | 1198 // and the fling should be cancelled. |
| 1168 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()).Times(0); | 1199 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()).Times(0); |
| 1169 EXPECT_CALL(mock_input_handler_, ScrollBy(testing::_, testing::_)).Times(0); | 1200 EXPECT_CALL(mock_input_handler_, ScrollBy(testing::_, testing::_)).Times(0); |
| 1170 EXPECT_CALL(mock_input_handler_, ScrollEnd()); | 1201 EXPECT_CALL(mock_input_handler_, ScrollEnd()); |
| 1171 time += base::TimeDelta::FromMilliseconds(10); | 1202 time += base::TimeDelta::FromMilliseconds(10); |
| 1172 input_handler_->Animate(time); | 1203 input_handler_->Animate(time); |
| 1173 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); | 1204 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); |
| 1174 EXPECT_FALSE(input_handler_->gesture_scroll_on_impl_thread_for_testing()); | 1205 EXPECT_FALSE(input_handler_->gesture_scroll_on_impl_thread_for_testing()); |
| 1175 } | 1206 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1221 | 1252 |
| 1222 touch.touchesLength = 3; | 1253 touch.touchesLength = 3; |
| 1223 touch.touches[0] = CreateWebTouchPoint(WebTouchPoint::StatePressed, 0, 0); | 1254 touch.touches[0] = CreateWebTouchPoint(WebTouchPoint::StatePressed, 0, 0); |
| 1224 touch.touches[1] = CreateWebTouchPoint(WebTouchPoint::StatePressed, 10, 10); | 1255 touch.touches[1] = CreateWebTouchPoint(WebTouchPoint::StatePressed, 10, 10); |
| 1225 touch.touches[2] = CreateWebTouchPoint(WebTouchPoint::StatePressed, -10, 10); | 1256 touch.touches[2] = CreateWebTouchPoint(WebTouchPoint::StatePressed, -10, 10); |
| 1226 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(touch)); | 1257 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(touch)); |
| 1227 } | 1258 } |
| 1228 | 1259 |
| 1229 } // namespace | 1260 } // namespace |
| 1230 } // namespace content | 1261 } // namespace content |
| OLD | NEW |