Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/gesture_detection/gesture_provider.h" | 5 #include "ui/events/gesture_detection/gesture_provider.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 938 kFakeCoordY + delta_y); | 938 kFakeCoordY + delta_y); |
| 939 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 939 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 940 EXPECT_TRUE(gesture_provider_->IsScrollInProgress()); | 940 EXPECT_TRUE(gesture_provider_->IsScrollInProgress()); |
| 941 | 941 |
| 942 const GestureEventData* scroll_begin_gesture = GetActiveScrollBeginEvent(); | 942 const GestureEventData* scroll_begin_gesture = GetActiveScrollBeginEvent(); |
| 943 ASSERT_TRUE(scroll_begin_gesture); | 943 ASSERT_TRUE(scroll_begin_gesture); |
| 944 EXPECT_EQ(delta_x, scroll_begin_gesture->details.scroll_x_hint()); | 944 EXPECT_EQ(delta_x, scroll_begin_gesture->details.scroll_x_hint()); |
| 945 EXPECT_EQ(delta_y, scroll_begin_gesture->details.scroll_y_hint()); | 945 EXPECT_EQ(delta_y, scroll_begin_gesture->details.scroll_y_hint()); |
| 946 } | 946 } |
| 947 | 947 |
| 948 // The follwoing three tests verify that slop regions are checked for | |
| 949 // one and two finger scrolls. Three-finger tap doesn't exist, so, | |
| 950 // no slop region check is needed for three-finger scrolls. | |
|
tdresser
2016/07/01 14:29:15
following
Maybe add a blank line after this comme
sahel
2016/07/05 20:36:35
Done.
| |
| 951 TEST_F(GestureProviderTest, SlopRegionCheckOnOneFingerScroll) { | |
| 952 EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta()); | |
| 953 const float scaled_touch_slop = GetTouchSlop(); | |
| 954 | |
| 955 base::TimeTicks event_time = base::TimeTicks::Now(); | |
| 956 | |
| 957 MockMotionEvent event = | |
| 958 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, 0, 0); | |
| 959 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 960 | |
| 961 // Move within slop region. | |
| 962 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_MOVE, 0, | |
| 963 scaled_touch_slop / 2); | |
| 964 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 965 | |
| 966 // Exceed slop region. | |
| 967 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_MOVE, 0, | |
| 968 2 * scaled_touch_slop); | |
| 969 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 970 | |
| 971 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP, 0, | |
| 972 2 * scaled_touch_slop); | |
| 973 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 974 | |
| 975 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type()); | |
| 976 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type()); | |
| 977 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetReceivedGesture(2).type()); | |
| 978 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetReceivedGesture(3).type()); | |
| 979 EXPECT_EQ(4U, GetReceivedGestureCount()); | |
| 980 } | |
| 981 | |
| 982 TEST_F(GestureProviderTest, SlopRegionCheckOnTwoFingerScroll) { | |
| 983 EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta()); | |
| 984 const float scaled_touch_slop = GetTouchSlop(); | |
| 985 | |
| 986 base::TimeTicks event_time = base::TimeTicks::Now(); | |
| 987 | |
| 988 MockMotionEvent event = | |
| 989 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, 0, 0); | |
| 990 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 991 | |
| 992 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_DOWN, 0, 0, | |
| 993 kMaxTwoFingerTapSeparation / 2, 0); | |
| 994 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 995 | |
| 996 // Move within slop region: two-finger tap happens. | |
| 997 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_MOVE, 0, | |
| 998 scaled_touch_slop / 2, | |
| 999 kMaxTwoFingerTapSeparation / 2, 0); | |
| 1000 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 1001 | |
| 1002 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_UP, 0, | |
| 1003 scaled_touch_slop / 2, | |
| 1004 kMaxTwoFingerTapSeparation / 2, 0); | |
| 1005 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 1006 | |
| 1007 // Exceed slop region: scroll. | |
| 1008 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_DOWN, 0, | |
| 1009 scaled_touch_slop / 2, | |
| 1010 kMaxTwoFingerTapSeparation / 2, 0); | |
| 1011 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 1012 | |
| 1013 event = ObtainMotionEvent( | |
| 1014 event_time, MotionEvent::ACTION_MOVE, 0, scaled_touch_slop / 2, | |
| 1015 kMaxTwoFingerTapSeparation / 2, 2 * scaled_touch_slop); | |
| 1016 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 1017 | |
| 1018 event = ObtainMotionEvent( | |
| 1019 event_time, MotionEvent::ACTION_POINTER_UP, 0, scaled_touch_slop / 2, | |
| 1020 kMaxTwoFingerTapSeparation / 2, 2 * scaled_touch_slop); | |
| 1021 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 1022 | |
| 1023 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP, 0, | |
| 1024 scaled_touch_slop / 2); | |
| 1025 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 1026 | |
| 1027 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type()); | |
| 1028 EXPECT_EQ(ET_GESTURE_TWO_FINGER_TAP, GetReceivedGesture(1).type()); | |
| 1029 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(2).type()); | |
| 1030 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetReceivedGesture(3).type()); | |
| 1031 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetReceivedGesture(4).type()); | |
| 1032 EXPECT_EQ(5U, GetReceivedGestureCount()); | |
| 1033 } | |
| 1034 | |
| 1035 TEST_F(GestureProviderTest, NoSlopRegionCheckOnThreeFingerScroll) { | |
| 1036 EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta()); | |
| 1037 const float scaled_touch_slop = GetTouchSlop(); | |
| 1038 | |
| 1039 base::TimeTicks event_time = base::TimeTicks::Now(); | |
| 1040 | |
| 1041 MockMotionEvent event = | |
| 1042 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, 0, 0); | |
| 1043 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 1044 | |
| 1045 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_DOWN, 0, 0, | |
| 1046 kMaxTwoFingerTapSeparation / 2, 0); | |
| 1047 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 1048 | |
| 1049 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_DOWN, 0, 0, | |
| 1050 kMaxTwoFingerTapSeparation / 2, 0, | |
| 1051 2 * kMaxTwoFingerTapSeparation, 0); | |
| 1052 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 1053 | |
| 1054 // Move within slop region, three-finger scroll always happens. | |
| 1055 event = ObtainMotionEvent( | |
| 1056 event_time, MotionEvent::ACTION_MOVE, 0, scaled_touch_slop / 2, | |
| 1057 kMaxTwoFingerTapSeparation / 2, 0, 2 * kMaxTwoFingerTapSeparation, 0); | |
| 1058 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 1059 | |
| 1060 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type()); | |
| 1061 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type()); | |
| 1062 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetReceivedGesture(2).type()); | |
| 1063 EXPECT_EQ(3U, GetReceivedGestureCount()); | |
| 1064 } | |
| 1065 | |
| 948 TEST_F(GestureProviderTest, LongPressAndTapCancelledWhenScrollBegins) { | 1066 TEST_F(GestureProviderTest, LongPressAndTapCancelledWhenScrollBegins) { |
| 949 base::TimeTicks event_time = base::TimeTicks::Now(); | 1067 base::TimeTicks event_time = base::TimeTicks::Now(); |
| 950 | 1068 |
| 951 MockMotionEvent event = | 1069 MockMotionEvent event = |
| 952 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | 1070 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); |
| 953 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 1071 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 954 event = ObtainMotionEvent(event_time + kOneMicrosecond, | 1072 event = ObtainMotionEvent(event_time + kOneMicrosecond, |
| 955 MotionEvent::ACTION_MOVE, | 1073 MotionEvent::ACTION_MOVE, |
| 956 kFakeCoordX * 5, | 1074 kFakeCoordX * 5, |
| 957 kFakeCoordY * 5); | 1075 kFakeCoordY * 5); |
| (...skipping 1194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2152 | 2270 |
| 2153 event = ObtainMotionEvent(event_time, | 2271 event = ObtainMotionEvent(event_time, |
| 2154 MotionEvent::ACTION_POINTER_UP, | 2272 MotionEvent::ACTION_POINTER_UP, |
| 2155 0, | 2273 0, |
| 2156 0, | 2274 0, |
| 2157 kMaxTwoFingerTapSeparation, | 2275 kMaxTwoFingerTapSeparation, |
| 2158 0); | 2276 0); |
| 2159 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 2277 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 2160 | 2278 |
| 2161 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type()); | 2279 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type()); |
| 2162 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type()); | 2280 EXPECT_EQ(ET_GESTURE_TWO_FINGER_TAP, GetReceivedGesture(1).type()); |
| 2163 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetReceivedGesture(2).type()); | 2281 EXPECT_EQ(2U, GetReceivedGestureCount()); |
| 2164 EXPECT_EQ(ET_GESTURE_TWO_FINGER_TAP, GetReceivedGesture(3).type()); | |
| 2165 EXPECT_EQ(4U, GetReceivedGestureCount()); | |
| 2166 | |
| 2167 EXPECT_EQ(kMockTouchRadius * 2, | 2282 EXPECT_EQ(kMockTouchRadius * 2, |
| 2168 GetReceivedGesture(3).details.first_finger_width()); | 2283 GetReceivedGesture(1).details.first_finger_width()); |
| 2169 EXPECT_EQ(kMockTouchRadius * 2, | 2284 EXPECT_EQ(kMockTouchRadius * 2, |
| 2170 GetReceivedGesture(3).details.first_finger_height()); | 2285 GetReceivedGesture(1).details.first_finger_height()); |
| 2171 } | 2286 } |
| 2172 | 2287 |
| 2173 // Test preventing a two finger tap via finger movement. | 2288 // Test preventing a two finger tap via finger movement. |
| 2174 TEST_F(GestureProviderTest, TwoFingerTapCancelledByFingerMovement) { | 2289 TEST_F(GestureProviderTest, TwoFingerTapCancelledByFingerMovement) { |
| 2175 EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta()); | 2290 EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta()); |
| 2176 const float scaled_touch_slop = GetTouchSlop(); | 2291 const float scaled_touch_slop = GetTouchSlop(); |
| 2177 base::TimeTicks event_time = base::TimeTicks::Now(); | 2292 base::TimeTicks event_time = base::TimeTicks::Now(); |
| 2178 | 2293 |
| 2179 MockMotionEvent event = ObtainMotionEvent( | 2294 MockMotionEvent event = ObtainMotionEvent( |
| 2180 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); | 2295 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); |
| 2181 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 2296 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 2182 | 2297 |
| 2183 event = ObtainMotionEvent(event_time, | 2298 event = ObtainMotionEvent(event_time, |
| 2184 MotionEvent::ACTION_POINTER_DOWN, | 2299 MotionEvent::ACTION_POINTER_DOWN, |
| 2185 kFakeCoordX, | 2300 kFakeCoordX, |
| 2186 kFakeCoordY, | 2301 kFakeCoordY, |
| 2187 kFakeCoordX, | 2302 kFakeCoordX, |
| 2188 kFakeCoordY); | 2303 kFakeCoordY); |
| 2189 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 2304 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 2190 | 2305 |
| 2191 event = ObtainMotionEvent(event_time, | 2306 event = ObtainMotionEvent( |
| 2192 MotionEvent::ACTION_MOVE, | 2307 event_time, MotionEvent::ACTION_MOVE, kFakeCoordX, kFakeCoordY, |
| 2193 kFakeCoordX, | 2308 kFakeCoordX + 2 * scaled_touch_slop + 2, kFakeCoordY); |
| 2194 kFakeCoordY, | |
| 2195 kFakeCoordX + scaled_touch_slop + 0.1, | |
| 2196 kFakeCoordY); | |
| 2197 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 2309 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 2198 | 2310 |
| 2199 event = ObtainMotionEvent(event_time, | 2311 event = ObtainMotionEvent(event_time, |
| 2200 MotionEvent::ACTION_POINTER_UP, | 2312 MotionEvent::ACTION_POINTER_UP, |
| 2201 kFakeCoordX, | 2313 kFakeCoordX, |
| 2202 kFakeCoordY, | 2314 kFakeCoordY, |
| 2203 kFakeCoordX, | 2315 kFakeCoordX, |
| 2204 kFakeCoordY); | 2316 kFakeCoordY); |
| 2205 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 2317 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 2206 | 2318 |
| 2207 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type()); | 2319 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type()); |
| 2208 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type()); | 2320 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type()); |
| 2209 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetReceivedGesture(2).type()); | 2321 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetReceivedGesture(2).type()); |
| 2210 EXPECT_FLOAT_EQ((scaled_touch_slop + 0.1) / 2, | 2322 // d_x = 2 * scaled_touch_slop + 2, |
| 2323 // d_focus_x = scaled_touch_slop + 1, | |
| 2324 // touch_slop / event.GetPointerCount() is deducted from first scroll, | |
| 2325 // scroll_x = scaled_touch_slop + 1 - scaled_touch_slop / 2 | |
| 2326 EXPECT_FLOAT_EQ(scaled_touch_slop / 2 + 1, | |
| 2211 GetReceivedGesture(2).details.scroll_x()); | 2327 GetReceivedGesture(2).details.scroll_x()); |
| 2212 EXPECT_EQ(0, GetReceivedGesture(2).details.scroll_y()); | 2328 EXPECT_EQ(0, GetReceivedGesture(2).details.scroll_y()); |
| 2213 EXPECT_EQ(3U, GetReceivedGestureCount()); | 2329 EXPECT_EQ(3U, GetReceivedGestureCount()); |
| 2214 } | 2330 } |
| 2215 | 2331 |
| 2216 // Test preventing a two finger tap by waiting too long before releasing the | 2332 // Test preventing a two finger tap by waiting too long before releasing the |
| 2217 // secondary pointer. | 2333 // secondary pointer. |
| 2218 TEST_F(GestureProviderTest, TwoFingerTapCancelledByDelay) { | 2334 TEST_F(GestureProviderTest, TwoFingerTapCancelledByDelay) { |
| 2219 base::TimeDelta two_finger_tap_timeout = kOneSecond; | 2335 base::TimeDelta two_finger_tap_timeout = kOneSecond; |
| 2220 EnableTwoFingerTap(kMaxTwoFingerTapSeparation, two_finger_tap_timeout); | 2336 EnableTwoFingerTap(kMaxTwoFingerTapSeparation, two_finger_tap_timeout); |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2643 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, | 2759 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, |
| 2644 kFakeCoordY + GetTouchSlop() / 2); | 2760 kFakeCoordY + GetTouchSlop() / 2); |
| 2645 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 2761 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 2646 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP); | 2762 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP); |
| 2647 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 2763 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 2648 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); | 2764 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); |
| 2649 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count()); | 2765 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count()); |
| 2650 } | 2766 } |
| 2651 | 2767 |
| 2652 } // namespace ui | 2768 } // namespace ui |
| OLD | NEW |