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

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

Issue 212663010: Store the id of a contributing motion event in GestureEventData (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update test. 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 | Annotate | Revision Log
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 // Note: These constants were taken directly from the default (unscaled) 26 // Note: These constants were taken directly from the default (unscaled)
27 // versions found in Android's ViewConfiguration. 27 // versions found in Android's ViewConfiguration.
28 ScaleGestureDetector::Config::Config() 28 ScaleGestureDetector::Config::Config()
29 : quick_scale_enabled(true), 29 : quick_scale_enabled(true),
30 min_scaling_touch_major(48), 30 min_scaling_touch_major(48),
31 min_scaling_span(200) {} 31 min_scaling_span(200) {}
32 32
33 ScaleGestureDetector::Config::~Config() {} 33 ScaleGestureDetector::Config::~Config() {}
34 34
35 bool ScaleGestureDetector::SimpleScaleGestureListener::OnScale( 35 bool ScaleGestureDetector::SimpleScaleGestureListener::OnScale(
36 const ScaleGestureDetector&) { 36 const ScaleGestureDetector&, const MotionEvent&) {
37 return false; 37 return false;
38 } 38 }
39 39
40 bool ScaleGestureDetector::SimpleScaleGestureListener::OnScaleBegin( 40 bool ScaleGestureDetector::SimpleScaleGestureListener::OnScaleBegin(
41 const ScaleGestureDetector&) { 41 const ScaleGestureDetector&, const MotionEvent&) {
42 return true; 42 return true;
43 } 43 }
44 44
45 void ScaleGestureDetector::SimpleScaleGestureListener::OnScaleEnd( 45 void ScaleGestureDetector::SimpleScaleGestureListener::OnScaleEnd(
46 const ScaleGestureDetector&) {} 46 const ScaleGestureDetector&, const MotionEvent&) {}
47 47
48 ScaleGestureDetector::ScaleGestureDetector(const Config& config, 48 ScaleGestureDetector::ScaleGestureDetector(const Config& config,
49 ScaleGestureListener* listener) 49 ScaleGestureListener* listener)
50 : listener_(listener), 50 : listener_(listener),
51 config_(config), 51 config_(config),
52 focus_x_(0), 52 focus_x_(0),
53 focus_y_(0), 53 focus_y_(0),
54 quick_scale_enabled_(false), 54 quick_scale_enabled_(false),
55 curr_span_(0), 55 curr_span_(0),
56 prev_span_(0), 56 prev_span_(0),
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 } 92 }
93 93
94 const bool stream_complete = 94 const bool stream_complete =
95 action == MotionEvent::ACTION_UP || action == MotionEvent::ACTION_CANCEL; 95 action == MotionEvent::ACTION_UP || action == MotionEvent::ACTION_CANCEL;
96 96
97 if (action == MotionEvent::ACTION_DOWN || stream_complete) { 97 if (action == MotionEvent::ACTION_DOWN || stream_complete) {
98 // Reset any scale in progress with the listener. 98 // Reset any scale in progress with the listener.
99 // If it's an ACTION_DOWN we're beginning a new event stream. 99 // If it's an ACTION_DOWN we're beginning a new event stream.
100 // This means the app probably didn't give us all the events. Shame on it. 100 // This means the app probably didn't give us all the events. Shame on it.
101 if (in_progress_) { 101 if (in_progress_) {
102 listener_->OnScaleEnd(*this); 102 listener_->OnScaleEnd(*this, event);
103 in_progress_ = false; 103 in_progress_ = false;
104 initial_span_ = 0; 104 initial_span_ = 0;
105 double_tap_mode_ = DOUBLE_TAP_MODE_NONE; 105 double_tap_mode_ = DOUBLE_TAP_MODE_NONE;
106 } else if (double_tap_mode_ == DOUBLE_TAP_MODE_IN_PROGRESS && 106 } else if (double_tap_mode_ == DOUBLE_TAP_MODE_IN_PROGRESS &&
107 stream_complete) { 107 stream_complete) {
108 in_progress_ = false; 108 in_progress_ = false;
109 initial_span_ = 0; 109 initial_span_ = 0;
110 double_tap_mode_ = DOUBLE_TAP_MODE_NONE; 110 double_tap_mode_ = DOUBLE_TAP_MODE_NONE;
111 } 111 }
112 112
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 } 180 }
181 181
182 // Dispatch begin/end events as needed. 182 // Dispatch begin/end events as needed.
183 // If the configuration changes, notify the app to reset its current state by 183 // If the configuration changes, notify the app to reset its current state by
184 // beginning a fresh scale event stream. 184 // beginning a fresh scale event stream.
185 const bool was_in_progress = in_progress_; 185 const bool was_in_progress = in_progress_;
186 focus_x_ = focus_x; 186 focus_x_ = focus_x;
187 focus_y_ = focus_y; 187 focus_y_ = focus_y;
188 if (!InDoubleTapMode() && in_progress_ && 188 if (!InDoubleTapMode() && in_progress_ &&
189 (span < min_span_ || config_changed)) { 189 (span < min_span_ || config_changed)) {
190 listener_->OnScaleEnd(*this); 190 listener_->OnScaleEnd(*this, event);
191 in_progress_ = false; 191 in_progress_ = false;
192 initial_span_ = span; 192 initial_span_ = span;
193 double_tap_mode_ = DOUBLE_TAP_MODE_NONE; 193 double_tap_mode_ = DOUBLE_TAP_MODE_NONE;
194 } 194 }
195 if (config_changed) { 195 if (config_changed) {
196 prev_span_x_ = curr_span_x_ = span_x; 196 prev_span_x_ = curr_span_x_ = span_x;
197 prev_span_y_ = curr_span_y_ = span_y; 197 prev_span_y_ = curr_span_y_ = span_y;
198 initial_span_ = prev_span_ = curr_span_ = span; 198 initial_span_ = prev_span_ = curr_span_ = span;
199 } 199 }
200 200
201 const int min_span = InDoubleTapMode() ? span_slop_ : min_span_; 201 const int min_span = InDoubleTapMode() ? span_slop_ : min_span_;
202 if (!in_progress_ && span >= min_span && 202 if (!in_progress_ && span >= min_span &&
203 (was_in_progress || std::abs(span - initial_span_) > span_slop_)) { 203 (was_in_progress || std::abs(span - initial_span_) > span_slop_)) {
204 prev_span_x_ = curr_span_x_ = span_x; 204 prev_span_x_ = curr_span_x_ = span_x;
205 prev_span_y_ = curr_span_y_ = span_y; 205 prev_span_y_ = curr_span_y_ = span_y;
206 prev_span_ = curr_span_ = span; 206 prev_span_ = curr_span_ = span;
207 prev_time_ = curr_time_; 207 prev_time_ = curr_time_;
208 in_progress_ = listener_->OnScaleBegin(*this); 208 in_progress_ = listener_->OnScaleBegin(*this, event);
209 } 209 }
210 210
211 // Handle motion; focal point and span/scale factor are changing. 211 // Handle motion; focal point and span/scale factor are changing.
212 if (action == MotionEvent::ACTION_MOVE) { 212 if (action == MotionEvent::ACTION_MOVE) {
213 curr_span_x_ = span_x; 213 curr_span_x_ = span_x;
214 curr_span_y_ = span_y; 214 curr_span_y_ = span_y;
215 curr_span_ = span; 215 curr_span_ = span;
216 216
217 bool update_prev = true; 217 bool update_prev = true;
218 218
219 if (in_progress_) { 219 if (in_progress_) {
220 update_prev = listener_->OnScale(*this); 220 update_prev = listener_->OnScale(*this, event);
221 } 221 }
222 222
223 if (update_prev) { 223 if (update_prev) {
224 prev_span_x_ = curr_span_x_; 224 prev_span_x_ = curr_span_x_;
225 prev_span_y_ = curr_span_y_; 225 prev_span_y_ = curr_span_y_;
226 prev_span_ = curr_span_; 226 prev_span_ = curr_span_;
227 prev_time_ = curr_time_; 227 prev_time_ = curr_time_;
228 } 228 }
229 } 229 }
230 230
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 358
359 void ScaleGestureDetector::ClearTouchHistory() { 359 void ScaleGestureDetector::ClearTouchHistory() {
360 touch_upper_ = std::numeric_limits<float>::quiet_NaN(); 360 touch_upper_ = std::numeric_limits<float>::quiet_NaN();
361 touch_lower_ = std::numeric_limits<float>::quiet_NaN(); 361 touch_lower_ = std::numeric_limits<float>::quiet_NaN();
362 touch_history_last_accepted_ = std::numeric_limits<float>::quiet_NaN(); 362 touch_history_last_accepted_ = std::numeric_limits<float>::quiet_NaN();
363 touch_history_direction_ = 0; 363 touch_history_direction_ = 0;
364 touch_history_last_accepted_time_ = base::TimeTicks(); 364 touch_history_last_accepted_time_ = base::TimeTicks();
365 } 365 }
366 366
367 } // namespace ui 367 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/gesture_detection/scale_gesture_detector.h ('k') | ui/events/gesture_detection/touch_disposition_gesture_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698