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

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

Issue 340343013: Provide max gesture bounds and option to ignore touch size during pinch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review Created 6 years, 5 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"
(...skipping 14 matching lines...) Expand all
25 const int kTouchStabilizeTimeMs = 128; 25 const int kTouchStabilizeTimeMs = 128;
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(100),
36 use_touch_major_in_span(false),
36 quick_scale_enabled(true), 37 quick_scale_enabled(true),
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 bool ScaleGestureDetector::SimpleScaleGestureListener::OnScale(
43 const ScaleGestureDetector&, const MotionEvent&) { 44 const ScaleGestureDetector&, const MotionEvent&) {
44 return false; 45 return false;
45 } 46 }
(...skipping 16 matching lines...) Expand all
62 curr_span_(0), 63 curr_span_(0),
63 prev_span_(0), 64 prev_span_(0),
64 initial_span_(0), 65 initial_span_(0),
65 curr_span_x_(0), 66 curr_span_x_(0),
66 curr_span_y_(0), 67 curr_span_y_(0),
67 prev_span_x_(0), 68 prev_span_x_(0),
68 prev_span_y_(0), 69 prev_span_y_(0),
69 in_progress_(0), 70 in_progress_(0),
70 span_slop_(0), 71 span_slop_(0),
71 min_span_(0), 72 min_span_(0),
73 use_touch_major_in_span_(config.use_touch_major_in_span),
72 touch_upper_(0), 74 touch_upper_(0),
73 touch_lower_(0), 75 touch_lower_(0),
74 touch_history_last_accepted_(0), 76 touch_history_last_accepted_(0),
75 touch_history_direction_(0), 77 touch_history_direction_(0),
76 touch_min_major_(0), 78 touch_min_major_(0),
79 touch_max_major_(0),
77 double_tap_focus_x_(0), 80 double_tap_focus_x_(0),
78 double_tap_focus_y_(0), 81 double_tap_focus_y_(0),
79 double_tap_mode_(DOUBLE_TAP_MODE_NONE), 82 double_tap_mode_(DOUBLE_TAP_MODE_NONE),
80 event_before_or_above_starting_gesture_event_(false) { 83 event_before_or_above_starting_gesture_event_(false) {
81 DCHECK(listener_); 84 DCHECK(listener_);
82 span_slop_ = 85 span_slop_ = (config.gesture_detector_config.touch_slop + kSlopEpsilon) * 2;
83 (config.gesture_detector_config.touch_slop + kSlopEpsilon) * 2;
84 touch_min_major_ = config.min_scaling_touch_major; 86 touch_min_major_ = config.min_scaling_touch_major;
87 touch_max_major_ = std::min(config.min_scaling_span, 2.f * touch_min_major_);
85 min_span_ = config.min_scaling_span + kSlopEpsilon; 88 min_span_ = config.min_scaling_span + kSlopEpsilon;
86 ResetTouchHistory(); 89 ResetTouchHistory();
87 SetQuickScaleEnabled(config.quick_scale_enabled); 90 SetQuickScaleEnabled(config.quick_scale_enabled);
88 } 91 }
89 92
90 ScaleGestureDetector::~ScaleGestureDetector() {} 93 ScaleGestureDetector::~ScaleGestureDetector() {}
91 94
92 bool ScaleGestureDetector::OnTouchEvent(const MotionEvent& event) { 95 bool ScaleGestureDetector::OnTouchEvent(const MotionEvent& event) {
93 curr_time_ = event.GetEventTime(); 96 curr_time_ = event.GetEventTime();
94 97
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 if (skip_index == i) 155 if (skip_index == i)
153 continue; 156 continue;
154 sum_x += event.GetX(i); 157 sum_x += event.GetX(i);
155 sum_y += event.GetY(i); 158 sum_y += event.GetY(i);
156 } 159 }
157 160
158 focus_x = sum_x * inverse_unreleased_point_count; 161 focus_x = sum_x * inverse_unreleased_point_count;
159 focus_y = sum_y * inverse_unreleased_point_count; 162 focus_y = sum_y * inverse_unreleased_point_count;
160 } 163 }
161 164
162 AddTouchHistory(event); 165 if (use_touch_major_in_span_)
166 AddTouchHistory(event);
163 167
164 // Determine average deviation from focal point. 168 // Determine average deviation from focal point.
165 float dev_sum_x = 0, dev_sum_y = 0; 169 float dev_sum_x = 0, dev_sum_y = 0;
166 for (int i = 0; i < count; i++) { 170 for (int i = 0; i < count; i++) {
167 if (skip_index == i) 171 if (skip_index == i)
168 continue; 172 continue;
169 173
170 dev_sum_x += std::abs(event.GetX(i) - focus_x); 174 dev_sum_x += std::abs(event.GetX(i) - focus_x);
171 dev_sum_y += std::abs(event.GetY(i) - focus_y); 175 dev_sum_y += std::abs(event.GetY(i) - focus_y);
172 } 176 }
173 // Convert the resulting diameter into a radius, to include touch 177 // Convert the resulting diameter into a radius, to include touch
174 // radius in overall deviation. 178 // radius in overall deviation.
175 const float touch_size = touch_history_last_accepted_ / 2; 179 const float touch_radius =
180 use_touch_major_in_span_ ? touch_history_last_accepted_ / 2 : 0;
176 181
177 const float dev_x = (dev_sum_x * inverse_unreleased_point_count) + touch_size; 182 const float dev_x = dev_sum_x * inverse_unreleased_point_count + touch_radius;
178 const float dev_y = (dev_sum_y * inverse_unreleased_point_count) + touch_size; 183 const float dev_y = dev_sum_y * inverse_unreleased_point_count + touch_radius;
179 184
180 // Span is the average distance between touch points through the focal point; 185 // Span is the average distance between touch points through the focal point;
181 // i.e. the diameter of the circle with a radius of the average deviation from 186 // i.e. the diameter of the circle with a radius of the average deviation from
182 // the focal point. 187 // the focal point.
183 const float span_x = dev_x * 2; 188 const float span_x = dev_x * 2;
184 const float span_y = dev_y * 2; 189 const float span_y = dev_y * 2;
185 float span; 190 float span;
186 if (InDoubleTapMode()) { 191 if (InDoubleTapMode()) {
187 span = span_y; 192 span = span_y;
188 } else { 193 } else {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 const int pointersample_count = history_size + 1; 326 const int pointersample_count = history_size + 1;
322 for (int h = 0; h < pointersample_count; h++) { 327 for (int h = 0; h < pointersample_count; h++) {
323 float major; 328 float major;
324 if (h < history_size) { 329 if (h < history_size) {
325 major = ev.GetHistoricalTouchMajor(i, h); 330 major = ev.GetHistoricalTouchMajor(i, h);
326 } else { 331 } else {
327 major = ev.GetTouchMajor(i); 332 major = ev.GetTouchMajor(i);
328 } 333 }
329 if (major < touch_min_major_) 334 if (major < touch_min_major_)
330 major = touch_min_major_; 335 major = touch_min_major_;
336 if (major > touch_max_major_)
337 major = touch_max_major_;
331 total += major; 338 total += major;
332 339
333 if (base::IsNaN(touch_upper_) || major > touch_upper_) { 340 if (base::IsNaN(touch_upper_) || major > touch_upper_) {
334 touch_upper_ = major; 341 touch_upper_ = major;
335 } 342 }
336 if (base::IsNaN(touch_lower_) || major < touch_lower_) { 343 if (base::IsNaN(touch_lower_) || major < touch_lower_) {
337 touch_lower_ = major; 344 touch_lower_ = major;
338 } 345 }
339 346
340 if (has_last_accepted) { 347 if (has_last_accepted) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 touch_history_last_accepted_time_ = base::TimeTicks(); 381 touch_history_last_accepted_time_ = base::TimeTicks();
375 } 382 }
376 383
377 void ScaleGestureDetector::ResetScaleWithSpan(float span) { 384 void ScaleGestureDetector::ResetScaleWithSpan(float span) {
378 in_progress_ = false; 385 in_progress_ = false;
379 initial_span_ = span; 386 initial_span_ = span;
380 double_tap_mode_ = DOUBLE_TAP_MODE_NONE; 387 double_tap_mode_ = DOUBLE_TAP_MODE_NONE;
381 } 388 }
382 389
383 } // namespace ui 390 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/gesture_detection/scale_gesture_detector.h ('k') | ui/events/gestures/gesture_configuration.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698