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

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: Time stored in microseconds. All velocity logic moved from GesturePoint to VelocityCalculator. 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 #include "base/basictypes.h"
9 10
10 namespace { 11 namespace {
11 12
12 // TODO(girard): Make these configurable in sync with this CL 13 // TODO(girard): Make these configurable in sync with this CL
13 // http://crbug.com/100773 14 // http://crbug.com/100773
14 const double kMaximumTouchDownDurationInSecondsForClick = 0.8; 15 const double kMaximumTouchDownDurationInSecondsForClick = 0.8;
15 const double kMinimumTouchDownDurationInSecondsForClick = 0.01; 16 const double kMinimumTouchDownDurationInSecondsForClick = 0.01;
16 const double kMaximumSecondsBetweenDoubleClick = 0.7; 17 const double kMaximumSecondsBetweenDoubleClick = 0.7;
17 const int kMaximumTouchMoveInPixelsForClick = 20; 18 const int kMaximumTouchMoveInPixelsForClick = 20;
18 const float kMinFlickSpeedSquared = 550.f * 550.f; 19 const float kMinFlickSpeedSquared = 550.f * 550.f;
20 const int kBufferedPoints = 10;
19 21
20 } // namespace aura 22 } // namespace
21 23
22 namespace aura { 24 namespace aura {
23 25
24 GesturePoint::GesturePoint() 26 GesturePoint::GesturePoint()
25 : first_touch_time_(0.0), 27 : first_touch_time_(0.0),
26 last_touch_time_(0.0), 28 last_touch_time_(0.0),
27 last_tap_time_(0.0), 29 last_tap_time_(0.0),
28 x_velocity_(0.0), 30 velocity_calculator_(kBufferedPoints) {
29 y_velocity_(0.0) {
30 } 31 }
31 32
32 void GesturePoint::Reset() { 33 void GesturePoint::Reset() {
33 first_touch_time_ = last_touch_time_ = 0.0; 34 first_touch_time_ = last_touch_time_ = 0.0;
34 x_velocity_ = y_velocity_ = 0.0; 35 velocity_calculator_.ClearHistory();
35 } 36 }
36 37
37 void GesturePoint::UpdateValues(const TouchEvent& event, GestureState state) { 38 void GesturePoint::UpdateValues(const TouchEvent& event, GestureState state) {
39 const int64 event_timestamp_microseconds =
40 event.time_stamp().InMicroseconds();
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(),
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_microseconds);
42 } 45 }
43 46
44 last_touch_time_ = event.time_stamp().InSecondsF(); 47 last_touch_time_ = event.time_stamp().InSecondsF();
45 last_touch_position_ = event.location(); 48 last_touch_position_ = event.location();
46 49
47 if (state == GS_NO_GESTURE) { 50 if (state == GS_NO_GESTURE) {
48 first_touch_time_ = last_touch_time_; 51 first_touch_time_ = last_touch_time_;
49 first_touch_position_ = event.location(); 52 first_touch_position_ = event.location();
50 x_velocity_ = 0.0; 53 velocity_calculator_.ClearHistory();
51 y_velocity_ = 0.0; 54 velocity_calculator_.PointSeen(event.x(),
55 event.y(),
56 event_timestamp_microseconds);
52 } 57 }
53 } 58 }
54 59
55 void GesturePoint::UpdateForTap() { 60 void GesturePoint::UpdateForTap() {
56 // Update the tap-position and time, and reset every other state. 61 // Update the tap-position and time, and reset every other state.
57 last_tap_time_ = last_touch_time_; 62 last_tap_time_ = last_touch_time_;
58 last_tap_position_ = last_touch_position_; 63 last_tap_position_ = last_touch_position_;
59 Reset(); 64 Reset();
60 } 65 }
61 66
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 } 113 }
109 114
110 bool GesturePoint::IsSecondClickInsideManhattanSquare( 115 bool GesturePoint::IsSecondClickInsideManhattanSquare(
111 const TouchEvent& event) const { 116 const TouchEvent& event) const {
112 int manhattanDistance = abs(event.x() - last_tap_position_.x()) + 117 int manhattanDistance = abs(event.x() - last_tap_position_.x()) +
113 abs(event.y() - last_tap_position_.y()); 118 abs(event.y() - last_tap_position_.y());
114 return manhattanDistance < kMaximumTouchMoveInPixelsForClick; 119 return manhattanDistance < kMaximumTouchMoveInPixelsForClick;
115 } 120 }
116 121
117 bool GesturePoint::IsOverMinFlickSpeed() const { 122 bool GesturePoint::IsOverMinFlickSpeed() const {
118 return (x_velocity_ * x_velocity_ + y_velocity_ * y_velocity_) > 123 return velocity_calculator_.VelocitySquared() > kMinFlickSpeedSquared;
119 kMinFlickSpeedSquared;
120 } 124 }
121 125
122 } // namespace aura 126 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698