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

Side by Side Diff: ui/aura/gestures/gesture_point.cc

Issue 9310031: Event smoothing in CrOS gesture recognizer. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Minor naming fixes, comments. Created 8 years, 10 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/aura/gestures/gesture_point.h" 5 #include "ui/aura/gestures/gesture_point.h"
6 6
7 #include "ui/aura/event.h" 7 #include "ui/aura/event.h"
8 #include "ui/base/events.h" 8 #include "ui/base/events.h"
9 9
10 namespace { 10 namespace {
11 11
12 // TODO(girard): Make these configurable in sync with this CL 12 // TODO(girard): Make these configurable in sync with this CL
13 // http://crbug.com/100773 13 // http://crbug.com/100773
14 const double kMaximumTouchDownDurationInSecondsForClick = 0.8; 14 const double kMaximumTouchDownDurationInSecondsForClick = 0.8;
15 const double kMinimumTouchDownDurationInSecondsForClick = 0.01; 15 const double kMinimumTouchDownDurationInSecondsForClick = 0.01;
16 const double kMaximumSecondsBetweenDoubleClick = 0.7; 16 const double kMaximumSecondsBetweenDoubleClick = 0.7;
17 const int kMaximumTouchMoveInPixelsForClick = 20; 17 const int kMaximumTouchMoveInPixelsForClick = 20;
18 const float kMinFlickSpeedSquared = 550.f * 550.f; 18 const float kMinFlickSpeedSquared = 550.f * 550.f;
19 const int kBufferedPoints = 10;
19 20
20 } // namespace aura 21 } // namespace
21 22
22 namespace aura { 23 namespace aura {
23 24
24 GesturePoint::GesturePoint() 25 GesturePoint::GesturePoint()
25 : first_touch_time_(0.0), 26 : first_touch_time_(0.0),
26 last_touch_time_(0.0), 27 last_touch_time_(0.0),
27 last_tap_time_(0.0), 28 last_tap_time_(0.0),
28 x_velocity_(0.0), 29 x_velocity_(0.0),
29 y_velocity_(0.0) { 30 y_velocity_(0.0),
31 velocity_calculator_(kBufferedPoints) {
30 } 32 }
31 33
32 void GesturePoint::Reset() { 34 void GesturePoint::Reset() {
33 first_touch_time_ = last_touch_time_ = 0.0; 35 first_touch_time_ = last_touch_time_ = 0.0;
34 x_velocity_ = y_velocity_ = 0.0; 36 x_velocity_ = y_velocity_ = 0.0;
35 } 37 }
36 38
37 void GesturePoint::UpdateValues(const TouchEvent& event, GestureState state) { 39 void GesturePoint::UpdateValues(const TouchEvent& event, GestureState state) {
40 const double event_timestamp_seconds = event.time_stamp().InSecondsF();
rjkroege 2012/02/02 15:58:37 if our compiler is doing the right thing with SSE,
38 if (state != GS_NO_GESTURE && event.type() == ui::ET_TOUCH_MOVED) { 41 if (state != GS_NO_GESTURE && event.type() == ui::ET_TOUCH_MOVED) {
39 double interval(event.time_stamp().InSecondsF() - last_touch_time_); 42 velocity_calculator_.PointSeen(event.x(),
rjkroege 2012/02/02 15:58:37 you need to move these over one char I think.
40 x_velocity_ = (event.x() - last_touch_position_.x()) / interval; 43 event.y(),
41 y_velocity_ = (event.y() - last_touch_position_.y()) / interval; 44 event_timestamp_seconds);
45 velocity_calculator_.Velocity(&x_velocity_, &y_velocity_);
42 } 46 }
43 47
44 last_touch_time_ = event.time_stamp().InSecondsF(); 48 last_touch_time_ = event_timestamp_seconds;
45 last_touch_position_ = event.location(); 49 last_touch_position_ = event.location();
46 50
47 if (state == GS_NO_GESTURE) { 51 if (state == GS_NO_GESTURE) {
48 first_touch_time_ = last_touch_time_; 52 first_touch_time_ = last_touch_time_;
49 first_touch_position_ = event.location(); 53 first_touch_position_ = event.location();
54 velocity_calculator_.ClearHistory();
55 velocity_calculator_.PointSeen(event.x(),
56 event.y(),
57 event_timestamp_seconds);
50 x_velocity_ = 0.0; 58 x_velocity_ = 0.0;
51 y_velocity_ = 0.0; 59 y_velocity_ = 0.0;
52 } 60 }
53 } 61 }
54 62
55 void GesturePoint::UpdateForTap() { 63 void GesturePoint::UpdateForTap() {
56 // Update the tap-position and time, and reset every other state. 64 // Update the tap-position and time, and reset every other state.
57 last_tap_time_ = last_touch_time_; 65 last_tap_time_ = last_touch_time_;
58 last_tap_position_ = last_touch_position_; 66 last_tap_position_ = last_touch_position_;
59 Reset(); 67 Reset();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 abs(event.y() - last_tap_position_.y()); 121 abs(event.y() - last_tap_position_.y());
114 return manhattanDistance < kMaximumTouchMoveInPixelsForClick; 122 return manhattanDistance < kMaximumTouchMoveInPixelsForClick;
115 } 123 }
116 124
117 bool GesturePoint::IsOverMinFlickSpeed() const { 125 bool GesturePoint::IsOverMinFlickSpeed() const {
118 return (x_velocity_ * x_velocity_ + y_velocity_ * y_velocity_) > 126 return (x_velocity_ * x_velocity_ + y_velocity_ * y_velocity_) >
119 kMinFlickSpeedSquared; 127 kMinFlickSpeedSquared;
120 } 128 }
121 129
122 } // namespace aura 130 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698