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

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: Fix DCHECK 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 15 matching lines...) Expand all
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 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;
85 min_span_ = config.min_scaling_span + kSlopEpsilon; 87 touch_max_major_ = std::min(config.min_scaling_span, 2.f * touch_min_major_);
88 if (use_touch_major_in_span_) {
89 min_span_ = config.min_scaling_span + kSlopEpsilon;
90 } else {
91 min_span_ =
92 std::max(kSlopEpsilon, config.min_scaling_span - touch_max_major_);
tdresser 2014/07/02 13:43:10 I'm not clear on why you're subtracting |touch_max
jdduke (slow) 2014/07/02 16:24:18 Certainly, and I've moved the subtraction logic ou
93 }
86 ResetTouchHistory(); 94 ResetTouchHistory();
87 SetQuickScaleEnabled(config.quick_scale_enabled); 95 SetQuickScaleEnabled(config.quick_scale_enabled);
88 } 96 }
89 97
90 ScaleGestureDetector::~ScaleGestureDetector() {} 98 ScaleGestureDetector::~ScaleGestureDetector() {}
91 99
92 bool ScaleGestureDetector::OnTouchEvent(const MotionEvent& event) { 100 bool ScaleGestureDetector::OnTouchEvent(const MotionEvent& event) {
93 curr_time_ = event.GetEventTime(); 101 curr_time_ = event.GetEventTime();
94 102
95 const int action = event.GetAction(); 103 const int action = event.GetAction();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 if (skip_index == i) 160 if (skip_index == i)
153 continue; 161 continue;
154 sum_x += event.GetX(i); 162 sum_x += event.GetX(i);
155 sum_y += event.GetY(i); 163 sum_y += event.GetY(i);
156 } 164 }
157 165
158 focus_x = sum_x * inverse_unreleased_point_count; 166 focus_x = sum_x * inverse_unreleased_point_count;
159 focus_y = sum_y * inverse_unreleased_point_count; 167 focus_y = sum_y * inverse_unreleased_point_count;
160 } 168 }
161 169
162 AddTouchHistory(event); 170 if (use_touch_major_in_span_)
171 AddTouchHistory(event);
163 172
164 // Determine average deviation from focal point. 173 // Determine average deviation from focal point.
165 float dev_sum_x = 0, dev_sum_y = 0; 174 float dev_sum_x = 0, dev_sum_y = 0;
166 for (int i = 0; i < count; i++) { 175 for (int i = 0; i < count; i++) {
167 if (skip_index == i) 176 if (skip_index == i)
168 continue; 177 continue;
169 178
170 dev_sum_x += std::abs(event.GetX(i) - focus_x); 179 dev_sum_x += std::abs(event.GetX(i) - focus_x);
171 dev_sum_y += std::abs(event.GetY(i) - focus_y); 180 dev_sum_y += std::abs(event.GetY(i) - focus_y);
172 } 181 }
173 // Convert the resulting diameter into a radius, to include touch 182 // Convert the resulting diameter into a radius, to include touch
174 // radius in overall deviation. 183 // radius in overall deviation.
175 const float touch_size = touch_history_last_accepted_ / 2; 184 const float touch_size =
185 use_touch_major_in_span_ ? touch_history_last_accepted_ / 2 : 0;
176 186
177 const float dev_x = (dev_sum_x * inverse_unreleased_point_count) + touch_size; 187 const float dev_x = (dev_sum_x * inverse_unreleased_point_count) + touch_size;
178 const float dev_y = (dev_sum_y * inverse_unreleased_point_count) + touch_size; 188 const float dev_y = (dev_sum_y * inverse_unreleased_point_count) + touch_size;
179 189
180 // Span is the average distance between touch points through the focal point; 190 // 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 191 // i.e. the diameter of the circle with a radius of the average deviation from
182 // the focal point. 192 // the focal point.
183 const float span_x = dev_x * 2; 193 const float span_x = dev_x * 2;
184 const float span_y = dev_y * 2; 194 const float span_y = dev_y * 2;
185 float span; 195 float span;
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 const int pointersample_count = history_size + 1; 331 const int pointersample_count = history_size + 1;
322 for (int h = 0; h < pointersample_count; h++) { 332 for (int h = 0; h < pointersample_count; h++) {
323 float major; 333 float major;
324 if (h < history_size) { 334 if (h < history_size) {
325 major = ev.GetHistoricalTouchMajor(i, h); 335 major = ev.GetHistoricalTouchMajor(i, h);
326 } else { 336 } else {
327 major = ev.GetTouchMajor(i); 337 major = ev.GetTouchMajor(i);
328 } 338 }
329 if (major < touch_min_major_) 339 if (major < touch_min_major_)
330 major = touch_min_major_; 340 major = touch_min_major_;
341 if (major > touch_max_major_)
342 major = touch_max_major_;
331 total += major; 343 total += major;
332 344
333 if (base::IsNaN(touch_upper_) || major > touch_upper_) { 345 if (base::IsNaN(touch_upper_) || major > touch_upper_) {
334 touch_upper_ = major; 346 touch_upper_ = major;
335 } 347 }
336 if (base::IsNaN(touch_lower_) || major < touch_lower_) { 348 if (base::IsNaN(touch_lower_) || major < touch_lower_) {
337 touch_lower_ = major; 349 touch_lower_ = major;
338 } 350 }
339 351
340 if (has_last_accepted) { 352 if (has_last_accepted) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 touch_history_last_accepted_time_ = base::TimeTicks(); 386 touch_history_last_accepted_time_ = base::TimeTicks();
375 } 387 }
376 388
377 void ScaleGestureDetector::ResetScaleWithSpan(float span) { 389 void ScaleGestureDetector::ResetScaleWithSpan(float span) {
378 in_progress_ = false; 390 in_progress_ = false;
379 initial_span_ = span; 391 initial_span_ = span;
380 double_tap_mode_ = DOUBLE_TAP_MODE_NONE; 392 double_tap_mode_ = DOUBLE_TAP_MODE_NONE;
381 } 393 }
382 394
383 } // namespace ui 395 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698