Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: ui/events/gesture_detection/scale_gesture_detector.cc

Issue 220063002: [Android] Use DIP coordinates with MotionEventAndroid (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More fixes Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 13
14 using base::TimeDelta; 14 using base::TimeDelta;
15 using base::TimeTicks; 15 using base::TimeTicks;
16 16
17 namespace ui { 17 namespace ui {
18 namespace { 18 namespace {
19 19
20 // Using a small epsilon when comparing slop distances allows pixel perfect
21 // slop determination when using fractional DPI coordinates (assuming the slop
22 // region and DPI scale are reasonably proportioned).
23 const float SLOP_EPSILON = .05f;
24
20 const int kTouchStabilizeTimeMs = 128; 25 const int kTouchStabilizeTimeMs = 128;
21 26
22 const float kScaleFactor = .5f; 27 const float kScaleFactor = .5f;
23 28
24 } // namespace 29 } // namespace
25 30
26 // Note: These constants were taken directly from the default (unscaled) 31 // Note: These constants were taken directly from the default (unscaled)
27 // versions found in Android's ViewConfiguration. 32 // versions found in Android's ViewConfiguration.
28 ScaleGestureDetector::Config::Config() 33 ScaleGestureDetector::Config::Config()
29 : quick_scale_enabled(true), 34 : min_scaling_touch_major(48),
30 min_scaling_touch_major(48), 35 min_scaling_span(200),
31 min_scaling_span(200) {} 36 quick_scale_enabled(true) {}
32 37
33 ScaleGestureDetector::Config::~Config() {} 38 ScaleGestureDetector::Config::~Config() {}
34 39
35 bool ScaleGestureDetector::SimpleScaleGestureListener::OnScale( 40 bool ScaleGestureDetector::SimpleScaleGestureListener::OnScale(
36 const ScaleGestureDetector&, const MotionEvent&) { 41 const ScaleGestureDetector&, const MotionEvent&) {
37 return false; 42 return false;
38 } 43 }
39 44
40 bool ScaleGestureDetector::SimpleScaleGestureListener::OnScaleBegin( 45 bool ScaleGestureDetector::SimpleScaleGestureListener::OnScaleBegin(
41 const ScaleGestureDetector&, const MotionEvent&) { 46 const ScaleGestureDetector&, const MotionEvent&) {
(...skipping 23 matching lines...) Expand all
65 touch_upper_(0), 70 touch_upper_(0),
66 touch_lower_(0), 71 touch_lower_(0),
67 touch_history_last_accepted_(0), 72 touch_history_last_accepted_(0),
68 touch_history_direction_(0), 73 touch_history_direction_(0),
69 touch_min_major_(0), 74 touch_min_major_(0),
70 double_tap_focus_x_(0), 75 double_tap_focus_x_(0),
71 double_tap_focus_y_(0), 76 double_tap_focus_y_(0),
72 double_tap_mode_(DOUBLE_TAP_MODE_NONE), 77 double_tap_mode_(DOUBLE_TAP_MODE_NONE),
73 event_before_or_above_starting_gesture_event_(false) { 78 event_before_or_above_starting_gesture_event_(false) {
74 DCHECK(listener_); 79 DCHECK(listener_);
75 span_slop_ = config.gesture_detector_config.scaled_touch_slop * 2; 80 span_slop_ =
81 (config.gesture_detector_config.touch_slop + SLOP_EPSILON) * 2;
76 touch_min_major_ = config.min_scaling_touch_major; 82 touch_min_major_ = config.min_scaling_touch_major;
77 min_span_ = config.min_scaling_span; 83 min_span_ = config.min_scaling_span + SLOP_EPSILON;
78 SetQuickScaleEnabled(config.quick_scale_enabled); 84 SetQuickScaleEnabled(config.quick_scale_enabled);
79 } 85 }
80 86
81 ScaleGestureDetector::~ScaleGestureDetector() {} 87 ScaleGestureDetector::~ScaleGestureDetector() {}
82 88
83 bool ScaleGestureDetector::OnTouchEvent(const MotionEvent& event) { 89 bool ScaleGestureDetector::OnTouchEvent(const MotionEvent& event) {
84 curr_time_ = event.GetEventTime(); 90 curr_time_ = event.GetEventTime();
85 91
86 const int action = event.GetAction(); 92 const int action = event.GetAction();
87 93
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 in_progress_ = false; 197 in_progress_ = false;
192 initial_span_ = span; 198 initial_span_ = span;
193 double_tap_mode_ = DOUBLE_TAP_MODE_NONE; 199 double_tap_mode_ = DOUBLE_TAP_MODE_NONE;
194 } 200 }
195 if (config_changed) { 201 if (config_changed) {
196 prev_span_x_ = curr_span_x_ = span_x; 202 prev_span_x_ = curr_span_x_ = span_x;
197 prev_span_y_ = curr_span_y_ = span_y; 203 prev_span_y_ = curr_span_y_ = span_y;
198 initial_span_ = prev_span_ = curr_span_ = span; 204 initial_span_ = prev_span_ = curr_span_ = span;
199 } 205 }
200 206
201 const int min_span = InDoubleTapMode() ? span_slop_ : min_span_; 207 const float min_span = InDoubleTapMode() ? span_slop_ : min_span_;
202 if (!in_progress_ && span >= min_span && 208 if (!in_progress_ && span >= min_span &&
203 (was_in_progress || std::abs(span - initial_span_) > span_slop_)) { 209 (was_in_progress || std::abs(span - initial_span_) > span_slop_)) {
204 prev_span_x_ = curr_span_x_ = span_x; 210 prev_span_x_ = curr_span_x_ = span_x;
205 prev_span_y_ = curr_span_y_ = span_y; 211 prev_span_y_ = curr_span_y_ = span_y;
206 prev_span_ = curr_span_ = span; 212 prev_span_ = curr_span_ = span;
207 prev_time_ = curr_time_; 213 prev_time_ = curr_time_;
208 in_progress_ = listener_->OnScaleBegin(*this, event); 214 in_progress_ = listener_->OnScaleBegin(*this, event);
209 } 215 }
210 216
211 // Handle motion; focal point and span/scale factor are changing. 217 // Handle motion; focal point and span/scale factor are changing.
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 364
359 void ScaleGestureDetector::ClearTouchHistory() { 365 void ScaleGestureDetector::ClearTouchHistory() {
360 touch_upper_ = std::numeric_limits<float>::quiet_NaN(); 366 touch_upper_ = std::numeric_limits<float>::quiet_NaN();
361 touch_lower_ = std::numeric_limits<float>::quiet_NaN(); 367 touch_lower_ = std::numeric_limits<float>::quiet_NaN();
362 touch_history_last_accepted_ = std::numeric_limits<float>::quiet_NaN(); 368 touch_history_last_accepted_ = std::numeric_limits<float>::quiet_NaN();
363 touch_history_direction_ = 0; 369 touch_history_direction_ = 0;
364 touch_history_last_accepted_time_ = base::TimeTicks(); 370 touch_history_last_accepted_time_ = base::TimeTicks();
365 } 371 }
366 372
367 } // namespace ui 373 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698