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/scale_gesture_detector.h" | 5 #include "ui/events/gesture_detection/scale_gesture_detector.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/float_util.h" | 10 #include "base/float_util.h" |
(...skipping 15 matching lines...) Expand all Loading... | |
26 | 26 |
27 const float kScaleFactor = .5f; | 27 const float kScaleFactor = .5f; |
28 | 28 |
29 } // namespace | 29 } // namespace |
30 | 30 |
31 // Note: These constants were taken directly from the default (unscaled) | 31 // Note: These constants were taken directly from the default (unscaled) |
32 // versions found in Android's ViewConfiguration. | 32 // versions found in Android's ViewConfiguration. |
33 ScaleGestureDetector::Config::Config() | 33 ScaleGestureDetector::Config::Config() |
34 : min_scaling_touch_major(48), | 34 : min_scaling_touch_major(48), |
35 min_scaling_span(200), | 35 min_scaling_span(200), |
36 quick_scale_enabled(true) {} | 36 quick_scale_enabled(true), |
37 min_pinch_update_distance(0) {} | |
37 | 38 |
38 ScaleGestureDetector::Config::~Config() {} | 39 ScaleGestureDetector::Config::~Config() {} |
39 | 40 |
40 bool ScaleGestureDetector::SimpleScaleGestureListener::OnScale( | 41 bool ScaleGestureDetector::SimpleScaleGestureListener::OnScale( |
41 const ScaleGestureDetector&, const MotionEvent&) { | 42 const ScaleGestureDetector&, const MotionEvent&) { |
42 return false; | 43 return false; |
43 } | 44 } |
44 | 45 |
45 bool ScaleGestureDetector::SimpleScaleGestureListener::OnScaleBegin( | 46 bool ScaleGestureDetector::SimpleScaleGestureListener::OnScaleBegin( |
46 const ScaleGestureDetector&, const MotionEvent&) { | 47 const ScaleGestureDetector&, const MotionEvent&) { |
(...skipping 26 matching lines...) Expand all Loading... | |
73 touch_history_direction_(0), | 74 touch_history_direction_(0), |
74 touch_min_major_(0), | 75 touch_min_major_(0), |
75 double_tap_focus_x_(0), | 76 double_tap_focus_x_(0), |
76 double_tap_focus_y_(0), | 77 double_tap_focus_y_(0), |
77 double_tap_mode_(DOUBLE_TAP_MODE_NONE), | 78 double_tap_mode_(DOUBLE_TAP_MODE_NONE), |
78 event_before_or_above_starting_gesture_event_(false) { | 79 event_before_or_above_starting_gesture_event_(false) { |
79 DCHECK(listener_); | 80 DCHECK(listener_); |
80 span_slop_ = | 81 span_slop_ = |
81 (config.gesture_detector_config.touch_slop + kSlopEpsilon) * 2; | 82 (config.gesture_detector_config.touch_slop + kSlopEpsilon) * 2; |
82 touch_min_major_ = config.min_scaling_touch_major; | 83 touch_min_major_ = config.min_scaling_touch_major; |
84 min_pinch_update_distance_ = config.min_pinch_update_distance; | |
83 min_span_ = config.min_scaling_span + kSlopEpsilon; | 85 min_span_ = config.min_scaling_span + kSlopEpsilon; |
84 SetQuickScaleEnabled(config.quick_scale_enabled); | 86 SetQuickScaleEnabled(config.quick_scale_enabled); |
85 } | 87 } |
86 | 88 |
87 ScaleGestureDetector::~ScaleGestureDetector() {} | 89 ScaleGestureDetector::~ScaleGestureDetector() {} |
88 | 90 |
89 bool ScaleGestureDetector::OnTouchEvent(const MotionEvent& event) { | 91 bool ScaleGestureDetector::OnTouchEvent(const MotionEvent& event) { |
90 curr_time_ = event.GetEventTime(); | 92 curr_time_ = event.GetEventTime(); |
91 | 93 |
92 const int action = event.GetAction(); | 94 const int action = event.GetAction(); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 in_progress_ = false; | 200 in_progress_ = false; |
199 initial_span_ = span; | 201 initial_span_ = span; |
200 double_tap_mode_ = DOUBLE_TAP_MODE_NONE; | 202 double_tap_mode_ = DOUBLE_TAP_MODE_NONE; |
201 } | 203 } |
202 if (config_changed) { | 204 if (config_changed) { |
203 prev_span_x_ = curr_span_x_ = span_x; | 205 prev_span_x_ = curr_span_x_ = span_x; |
204 prev_span_y_ = curr_span_y_ = span_y; | 206 prev_span_y_ = curr_span_y_ = span_y; |
205 initial_span_ = prev_span_ = curr_span_ = span; | 207 initial_span_ = prev_span_ = curr_span_ = span; |
206 } | 208 } |
207 | 209 |
210 bool pinch_occured = | |
211 std::abs(span - prev_span_) >= min_pinch_update_distance_; | |
jdduke (slow)
2014/05/21 19:30:37
Can we move this check into the ACTION_MOVE portio
tdresser
2014/05/22 12:31:44
We need to read prev_span_ before it is modified b
| |
212 | |
208 const float min_span = InDoubleTapMode() ? span_slop_ : min_span_; | 213 const float min_span = InDoubleTapMode() ? span_slop_ : min_span_; |
209 if (!in_progress_ && span >= min_span && | 214 if (!in_progress_ && span >= min_span && |
210 (was_in_progress || std::abs(span - initial_span_) > span_slop_)) { | 215 (was_in_progress || std::abs(span - initial_span_) > span_slop_)) { |
211 prev_span_x_ = curr_span_x_ = span_x; | 216 prev_span_x_ = curr_span_x_ = span_x; |
212 prev_span_y_ = curr_span_y_ = span_y; | 217 prev_span_y_ = curr_span_y_ = span_y; |
213 prev_span_ = curr_span_ = span; | 218 prev_span_ = curr_span_ = span; |
tdresser
2014/05/22 12:31:44
Need to read prev_span_ before this line.
| |
214 prev_time_ = curr_time_; | 219 prev_time_ = curr_time_; |
215 in_progress_ = listener_->OnScaleBegin(*this, event); | 220 in_progress_ = listener_->OnScaleBegin(*this, event); |
216 } | 221 } |
217 | 222 |
218 // Handle motion; focal point and span/scale factor are changing. | 223 // Handle motion; focal point and span/scale factor are changing. |
219 if (action == MotionEvent::ACTION_MOVE) { | 224 if (action == MotionEvent::ACTION_MOVE) { |
225 if (!pinch_occured) | |
226 return true; | |
227 | |
220 curr_span_x_ = span_x; | 228 curr_span_x_ = span_x; |
221 curr_span_y_ = span_y; | 229 curr_span_y_ = span_y; |
222 curr_span_ = span; | 230 curr_span_ = span; |
223 | 231 |
224 bool update_prev = true; | 232 bool update_prev = true; |
225 | 233 |
226 if (in_progress_) { | 234 if (in_progress_) { |
227 update_prev = listener_->OnScale(*this, event); | 235 update_prev = listener_->OnScale(*this, event); |
228 } | 236 } |
229 | 237 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
365 | 373 |
366 void ScaleGestureDetector::ClearTouchHistory() { | 374 void ScaleGestureDetector::ClearTouchHistory() { |
367 touch_upper_ = std::numeric_limits<float>::quiet_NaN(); | 375 touch_upper_ = std::numeric_limits<float>::quiet_NaN(); |
368 touch_lower_ = std::numeric_limits<float>::quiet_NaN(); | 376 touch_lower_ = std::numeric_limits<float>::quiet_NaN(); |
369 touch_history_last_accepted_ = std::numeric_limits<float>::quiet_NaN(); | 377 touch_history_last_accepted_ = std::numeric_limits<float>::quiet_NaN(); |
370 touch_history_direction_ = 0; | 378 touch_history_direction_ = 0; |
371 touch_history_last_accepted_time_ = base::TimeTicks(); | 379 touch_history_last_accepted_time_ = base::TimeTicks(); |
372 } | 380 } |
373 | 381 |
374 } // namespace ui | 382 } // namespace ui |
OLD | NEW |