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 // MSVC++ requires this to be set before any other includes to get M_PI. | 5 // MSVC++ requires this to be set before any other includes to get M_PI. |
6 #define _USE_MATH_DEFINES | 6 #define _USE_MATH_DEFINES |
7 | 7 |
8 #include "ui/events/gesture_detection/gesture_detector.h" | 8 #include "ui/events/gesture_detection/gesture_detector.h" |
9 | 9 |
10 #include <cmath> | 10 #include <cmath> |
11 | 11 |
12 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
| 13 #include "ui/events/gesture_detection/gesture_listeners.h" |
13 #include "ui/events/gesture_detection/motion_event.h" | 14 #include "ui/events/gesture_detection/motion_event.h" |
14 | 15 |
15 namespace ui { | 16 namespace ui { |
16 namespace { | 17 namespace { |
17 | 18 |
18 // Using a small epsilon when comparing slop distances allows pixel perfect | 19 // Using a small epsilon when comparing slop distances allows pixel perfect |
19 // slop determination when using fractional DIP coordinates (assuming the slop | 20 // slop determination when using fractional DIP coordinates (assuming the slop |
20 // region and DPI scale are reasonably proportioned). | 21 // region and DPI scale are reasonably proportioned). |
21 const float kSlopEpsilon = .05f; | 22 const float kSlopEpsilon = .05f; |
22 | 23 |
(...skipping 27 matching lines...) Expand all Loading... |
50 swipe_enabled(false), | 51 swipe_enabled(false), |
51 minimum_swipe_velocity(20), | 52 minimum_swipe_velocity(20), |
52 maximum_swipe_deviation_angle(20.f), | 53 maximum_swipe_deviation_angle(20.f), |
53 two_finger_tap_enabled(false), | 54 two_finger_tap_enabled(false), |
54 two_finger_tap_max_separation(300), | 55 two_finger_tap_max_separation(300), |
55 two_finger_tap_timeout(base::TimeDelta::FromMilliseconds(700)) { | 56 two_finger_tap_timeout(base::TimeDelta::FromMilliseconds(700)) { |
56 } | 57 } |
57 | 58 |
58 GestureDetector::Config::~Config() {} | 59 GestureDetector::Config::~Config() {} |
59 | 60 |
60 bool GestureDetector::SimpleGestureListener::OnDown(const MotionEvent& e) { | |
61 return false; | |
62 } | |
63 | |
64 void GestureDetector::SimpleGestureListener::OnShowPress(const MotionEvent& e) { | |
65 } | |
66 | |
67 bool GestureDetector::SimpleGestureListener::OnSingleTapUp( | |
68 const MotionEvent& e) { | |
69 return false; | |
70 } | |
71 | |
72 void GestureDetector::SimpleGestureListener::OnLongPress(const MotionEvent& e) { | |
73 } | |
74 | |
75 bool GestureDetector::SimpleGestureListener::OnScroll(const MotionEvent& e1, | |
76 const MotionEvent& e2, | |
77 float distance_x, | |
78 float distance_y) { | |
79 return false; | |
80 } | |
81 | |
82 bool GestureDetector::SimpleGestureListener::OnFling(const MotionEvent& e1, | |
83 const MotionEvent& e2, | |
84 float velocity_x, | |
85 float velocity_y) { | |
86 return false; | |
87 } | |
88 | |
89 bool GestureDetector::SimpleGestureListener::OnSwipe(const MotionEvent& e1, | |
90 const MotionEvent& e2, | |
91 float velocity_x, | |
92 float velocity_y) { | |
93 return false; | |
94 } | |
95 | |
96 bool GestureDetector::SimpleGestureListener::OnTwoFingerTap( | |
97 const MotionEvent& e1, | |
98 const MotionEvent& e2) { | |
99 return false; | |
100 } | |
101 | |
102 bool GestureDetector::SimpleGestureListener::OnSingleTapConfirmed( | |
103 const MotionEvent& e) { | |
104 return false; | |
105 } | |
106 | |
107 bool GestureDetector::SimpleGestureListener::OnDoubleTap(const MotionEvent& e) { | |
108 return false; | |
109 } | |
110 | |
111 bool GestureDetector::SimpleGestureListener::OnDoubleTapEvent( | |
112 const MotionEvent& e) { | |
113 return false; | |
114 } | |
115 | |
116 class GestureDetector::TimeoutGestureHandler { | 61 class GestureDetector::TimeoutGestureHandler { |
117 public: | 62 public: |
118 TimeoutGestureHandler(const Config& config, GestureDetector* gesture_detector) | 63 TimeoutGestureHandler(const Config& config, GestureDetector* gesture_detector) |
119 : gesture_detector_(gesture_detector) { | 64 : gesture_detector_(gesture_detector) { |
120 DCHECK(config.showpress_timeout <= config.longpress_timeout); | 65 DCHECK(config.showpress_timeout <= config.longpress_timeout); |
121 | 66 |
122 timeout_callbacks_[SHOW_PRESS] = &GestureDetector::OnShowPressTimeout; | 67 timeout_callbacks_[SHOW_PRESS] = &GestureDetector::OnShowPressTimeout; |
123 timeout_delays_[SHOW_PRESS] = config.showpress_timeout; | 68 timeout_delays_[SHOW_PRESS] = config.showpress_timeout; |
124 | 69 |
125 timeout_callbacks_[LONG_PRESS] = &GestureDetector::OnLongPressTimeout; | 70 timeout_callbacks_[LONG_PRESS] = &GestureDetector::OnLongPressTimeout; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 defer_confirm_single_tap_(false), | 125 defer_confirm_single_tap_(false), |
181 always_in_tap_region_(false), | 126 always_in_tap_region_(false), |
182 always_in_bigger_tap_region_(false), | 127 always_in_bigger_tap_region_(false), |
183 two_finger_tap_allowed_for_gesture_(false), | 128 two_finger_tap_allowed_for_gesture_(false), |
184 is_double_tapping_(false), | 129 is_double_tapping_(false), |
185 last_focus_x_(0), | 130 last_focus_x_(0), |
186 last_focus_y_(0), | 131 last_focus_y_(0), |
187 down_focus_x_(0), | 132 down_focus_x_(0), |
188 down_focus_y_(0), | 133 down_focus_y_(0), |
189 longpress_enabled_(true), | 134 longpress_enabled_(true), |
| 135 showpress_enabled_(true), |
190 swipe_enabled_(false), | 136 swipe_enabled_(false), |
191 two_finger_tap_enabled_(false) { | 137 two_finger_tap_enabled_(false) { |
192 DCHECK(listener_); | 138 DCHECK(listener_); |
193 Init(config); | 139 Init(config); |
194 } | 140 } |
195 | 141 |
196 GestureDetector::~GestureDetector() {} | 142 GestureDetector::~GestureDetector() {} |
197 | 143 |
198 bool GestureDetector::OnTouchEvent(const MotionEvent& ev) { | 144 bool GestureDetector::OnTouchEvent(const MotionEvent& ev) { |
199 const MotionEvent::Action action = ev.GetAction(); | 145 const MotionEvent::Action action = ev.GetAction(); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 | 254 |
309 secondary_pointer_down_event_.reset(); | 255 secondary_pointer_down_event_.reset(); |
310 always_in_tap_region_ = true; | 256 always_in_tap_region_ = true; |
311 always_in_bigger_tap_region_ = true; | 257 always_in_bigger_tap_region_ = true; |
312 still_down_ = true; | 258 still_down_ = true; |
313 defer_confirm_single_tap_ = false; | 259 defer_confirm_single_tap_ = false; |
314 two_finger_tap_allowed_for_gesture_ = two_finger_tap_enabled_; | 260 two_finger_tap_allowed_for_gesture_ = two_finger_tap_enabled_; |
315 | 261 |
316 // Always start the SHOW_PRESS timer before the LONG_PRESS timer to ensure | 262 // Always start the SHOW_PRESS timer before the LONG_PRESS timer to ensure |
317 // proper timeout ordering. | 263 // proper timeout ordering. |
318 timeout_handler_->StartTimeout(SHOW_PRESS); | 264 if (showpress_enabled_) |
| 265 timeout_handler_->StartTimeout(SHOW_PRESS); |
319 if (longpress_enabled_) | 266 if (longpress_enabled_) |
320 timeout_handler_->StartTimeout(LONG_PRESS); | 267 timeout_handler_->StartTimeout(LONG_PRESS); |
321 handled |= listener_->OnDown(ev); | 268 handled |= listener_->OnDown(ev); |
322 break; | 269 break; |
323 | 270 |
324 case MotionEvent::ACTION_MOVE: | 271 case MotionEvent::ACTION_MOVE: |
325 { | 272 { |
326 const float scroll_x = last_focus_x_ - focus_x; | 273 const float scroll_x = last_focus_x_ - focus_x; |
327 const float scroll_y = last_focus_y_ - focus_y; | 274 const float scroll_y = last_focus_y_ - focus_y; |
328 if (is_double_tapping_) { | 275 if (is_double_tapping_) { |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 return false; | 491 return false; |
545 | 492 |
546 if (vx_abs > vy_abs) | 493 if (vx_abs > vy_abs) |
547 vy = 0; | 494 vy = 0; |
548 else | 495 else |
549 vx = 0; | 496 vx = 0; |
550 return listener_->OnSwipe(*current_down_event_, up, vx, vy); | 497 return listener_->OnSwipe(*current_down_event_, up, vx, vy); |
551 } | 498 } |
552 | 499 |
553 } // namespace ui | 500 } // namespace ui |
OLD | NEW |