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

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: Fixes for clang chromium-style-check. 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
« no previous file with comments | « ui/aura/gestures/gesture_point.h ('k') | ui/aura/gestures/gesture_sequence.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/basictypes.h"
7 #include "ui/aura/event.h" 8 #include "ui/aura/event.h"
8 #include "ui/base/events.h" 9 #include "ui/base/events.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
33 GesturePoint::~GesturePoint() {}
34
32 void GesturePoint::Reset() { 35 void GesturePoint::Reset() {
33 first_touch_time_ = last_touch_time_ = 0.0; 36 first_touch_time_ = last_touch_time_ = 0.0;
34 x_velocity_ = y_velocity_ = 0.0; 37 velocity_calculator_.ClearHistory();
35 } 38 }
36 39
37 void GesturePoint::UpdateValues(const TouchEvent& event, GestureState state) { 40 void GesturePoint::UpdateValues(const TouchEvent& event, GestureState state) {
41 const int64 event_timestamp_microseconds =
42 event.time_stamp().InMicroseconds();
38 if (state != GS_NO_GESTURE && event.type() == ui::ET_TOUCH_MOVED) { 43 if (state != GS_NO_GESTURE && event.type() == ui::ET_TOUCH_MOVED) {
39 double interval(event.time_stamp().InSecondsF() - last_touch_time_); 44 velocity_calculator_.PointSeen(event.x(),
40 x_velocity_ = (event.x() - last_touch_position_.x()) / interval; 45 event.y(),
41 y_velocity_ = (event.y() - last_touch_position_.y()) / interval; 46 event_timestamp_microseconds);
42 } 47 }
43 48
44 last_touch_time_ = event.time_stamp().InSecondsF(); 49 last_touch_time_ = event.time_stamp().InSecondsF();
45 last_touch_position_ = event.location(); 50 last_touch_position_ = event.location();
46 51
47 if (state == GS_NO_GESTURE) { 52 if (state == GS_NO_GESTURE) {
48 first_touch_time_ = last_touch_time_; 53 first_touch_time_ = last_touch_time_;
49 first_touch_position_ = event.location(); 54 first_touch_position_ = event.location();
50 x_velocity_ = 0.0; 55 velocity_calculator_.ClearHistory();
51 y_velocity_ = 0.0; 56 velocity_calculator_.PointSeen(event.x(),
57 event.y(),
58 event_timestamp_microseconds);
52 } 59 }
53 } 60 }
54 61
55 void GesturePoint::UpdateForTap() { 62 void GesturePoint::UpdateForTap() {
56 // Update the tap-position and time, and reset every other state. 63 // Update the tap-position and time, and reset every other state.
57 last_tap_time_ = last_touch_time_; 64 last_tap_time_ = last_touch_time_;
58 last_tap_position_ = last_touch_position_; 65 last_tap_position_ = last_touch_position_;
59 Reset(); 66 Reset();
60 } 67 }
61 68
(...skipping 12 matching lines...) Expand all
74 bool GesturePoint::IsInDoubleClickWindow(const TouchEvent& event) const { 81 bool GesturePoint::IsInDoubleClickWindow(const TouchEvent& event) const {
75 return IsInSecondClickTimeWindow() && 82 return IsInSecondClickTimeWindow() &&
76 IsSecondClickInsideManhattanSquare(event); 83 IsSecondClickInsideManhattanSquare(event);
77 } 84 }
78 85
79 bool GesturePoint::IsInScrollWindow(const TouchEvent& event) const { 86 bool GesturePoint::IsInScrollWindow(const TouchEvent& event) const {
80 return event.type() == ui::ET_TOUCH_MOVED && 87 return event.type() == ui::ET_TOUCH_MOVED &&
81 !IsInsideManhattanSquare(event); 88 !IsInsideManhattanSquare(event);
82 } 89 }
83 90
84 bool GesturePoint::IsInFlickWindow(const TouchEvent& event) const { 91 bool GesturePoint::IsInFlickWindow(const TouchEvent& event) {
85 return IsOverMinFlickSpeed() && event.type() != ui::ET_TOUCH_CANCELLED; 92 return IsOverMinFlickSpeed() && event.type() != ui::ET_TOUCH_CANCELLED;
86 } 93 }
87 94
88 bool GesturePoint::DidScroll(const TouchEvent& event) const { 95 bool GesturePoint::DidScroll(const TouchEvent& event) const {
89 return abs(last_touch_position_.x() - first_touch_position_.x()) > 0 || 96 return abs(last_touch_position_.x() - first_touch_position_.x()) > 0 ||
90 abs(last_touch_position_.y() - first_touch_position_.y()) > 0; 97 abs(last_touch_position_.y() - first_touch_position_.y()) > 0;
91 } 98 }
92 99
93 bool GesturePoint::IsInClickTimeWindow() const { 100 bool GesturePoint::IsInClickTimeWindow() const {
94 double duration = last_touch_time_ - first_touch_time_; 101 double duration = last_touch_time_ - first_touch_time_;
(...skipping 12 matching lines...) Expand all
107 return manhattanDistance < kMaximumTouchMoveInPixelsForClick; 114 return manhattanDistance < kMaximumTouchMoveInPixelsForClick;
108 } 115 }
109 116
110 bool GesturePoint::IsSecondClickInsideManhattanSquare( 117 bool GesturePoint::IsSecondClickInsideManhattanSquare(
111 const TouchEvent& event) const { 118 const TouchEvent& event) const {
112 int manhattanDistance = abs(event.x() - last_tap_position_.x()) + 119 int manhattanDistance = abs(event.x() - last_tap_position_.x()) +
113 abs(event.y() - last_tap_position_.y()); 120 abs(event.y() - last_tap_position_.y());
114 return manhattanDistance < kMaximumTouchMoveInPixelsForClick; 121 return manhattanDistance < kMaximumTouchMoveInPixelsForClick;
115 } 122 }
116 123
117 bool GesturePoint::IsOverMinFlickSpeed() const { 124 bool GesturePoint::IsOverMinFlickSpeed() {
118 return (x_velocity_ * x_velocity_ + y_velocity_ * y_velocity_) > 125 return velocity_calculator_.VelocitySquared() > kMinFlickSpeedSquared;
119 kMinFlickSpeedSquared;
120 } 126 }
121 127
122 } // namespace aura 128 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/gestures/gesture_point.h ('k') | ui/aura/gestures/gesture_sequence.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698