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" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "ui/events/gesture_detection/motion_event.h" | 12 #include "ui/events/gesture_detection/motion_event.h" |
| 13 #include "ui/events/gesture_detection/scale_gesture_listeners.h" |
13 | 14 |
14 using base::TimeDelta; | 15 using base::TimeDelta; |
15 using base::TimeTicks; | 16 using base::TimeTicks; |
16 | 17 |
17 namespace ui { | 18 namespace ui { |
18 namespace { | 19 namespace { |
19 | 20 |
20 // Using a small epsilon when comparing slop distances allows pixel perfect | 21 // Using a small epsilon when comparing slop distances allows pixel perfect |
21 // slop determination when using fractional DPI coordinates (assuming the slop | 22 // slop determination when using fractional DPI coordinates (assuming the slop |
22 // region and DPI scale are reasonably proportioned). | 23 // region and DPI scale are reasonably proportioned). |
23 const float kSlopEpsilon = .05f; | 24 const float kSlopEpsilon = .05f; |
24 | 25 |
25 const int kTouchStabilizeTimeMs = 128; | 26 const int kTouchStabilizeTimeMs = 128; |
26 | 27 |
27 const float kScaleFactor = .5f; | 28 const float kScaleFactor = .5f; |
28 | 29 |
29 } // namespace | 30 } // namespace |
30 | 31 |
31 // Note: These constants were taken directly from the default (unscaled) | 32 // Note: These constants were taken directly from the default (unscaled) |
32 // versions found in Android's ViewConfiguration. | 33 // versions found in Android's ViewConfiguration. |
33 ScaleGestureDetector::Config::Config() | 34 ScaleGestureDetector::Config::Config() |
34 : span_slop(16), | 35 : span_slop(16), |
35 min_scaling_touch_major(48), | 36 min_scaling_touch_major(48), |
36 min_scaling_span(200), | 37 min_scaling_span(200), |
37 min_pinch_update_span_delta(0) { | 38 min_pinch_update_span_delta(0) { |
38 } | 39 } |
39 | 40 |
40 ScaleGestureDetector::Config::~Config() {} | 41 ScaleGestureDetector::Config::~Config() {} |
41 | 42 |
42 bool ScaleGestureDetector::SimpleScaleGestureListener::OnScale( | |
43 const ScaleGestureDetector&, const MotionEvent&) { | |
44 return false; | |
45 } | |
46 | |
47 bool ScaleGestureDetector::SimpleScaleGestureListener::OnScaleBegin( | |
48 const ScaleGestureDetector&, const MotionEvent&) { | |
49 return true; | |
50 } | |
51 | |
52 void ScaleGestureDetector::SimpleScaleGestureListener::OnScaleEnd( | |
53 const ScaleGestureDetector&, const MotionEvent&) {} | |
54 | |
55 ScaleGestureDetector::ScaleGestureDetector(const Config& config, | 43 ScaleGestureDetector::ScaleGestureDetector(const Config& config, |
56 ScaleGestureListener* listener) | 44 ScaleGestureListener* listener) |
57 : listener_(listener), | 45 : listener_(listener), |
58 focus_x_(0), | 46 focus_x_(0), |
59 focus_y_(0), | 47 focus_y_(0), |
60 curr_span_(0), | 48 curr_span_(0), |
61 prev_span_(0), | 49 prev_span_(0), |
62 initial_span_(0), | 50 initial_span_(0), |
63 curr_span_x_(0), | 51 curr_span_x_(0), |
64 curr_span_y_(0), | 52 curr_span_y_(0), |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 touch_history_last_accepted_time_ = base::TimeTicks(); | 345 touch_history_last_accepted_time_ = base::TimeTicks(); |
358 } | 346 } |
359 | 347 |
360 void ScaleGestureDetector::ResetScaleWithSpan(float span) { | 348 void ScaleGestureDetector::ResetScaleWithSpan(float span) { |
361 in_progress_ = false; | 349 in_progress_ = false; |
362 initial_span_ = span; | 350 initial_span_ = span; |
363 double_tap_mode_ = DOUBLE_TAP_MODE_NONE; | 351 double_tap_mode_ = DOUBLE_TAP_MODE_NONE; |
364 } | 352 } |
365 | 353 |
366 } // namespace ui | 354 } // namespace ui |
OLD | NEW |