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

Unified 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: Style tweaks, switch to scoped_array. Created 8 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: ui/aura/gestures/gesture_point.cc
diff --git a/ui/aura/gestures/gesture_point.cc b/ui/aura/gestures/gesture_point.cc
index 3402e56673331098a3d8e60233bda7736d52a91e..9cf23b9a18a377345557c651791d872822617b73 100644
--- a/ui/aura/gestures/gesture_point.cc
+++ b/ui/aura/gestures/gesture_point.cc
@@ -6,6 +6,7 @@
#include "ui/aura/event.h"
#include "ui/base/events.h"
+#include "base/basictypes.h"
sadrul 2012/02/02 22:31:10 sort alphabetically!
namespace {
@@ -16,8 +17,9 @@ const double kMinimumTouchDownDurationInSecondsForClick = 0.01;
const double kMaximumSecondsBetweenDoubleClick = 0.7;
const int kMaximumTouchMoveInPixelsForClick = 20;
const float kMinFlickSpeedSquared = 550.f * 550.f;
+const int kBufferedPoints = 10;
-} // namespace aura
+} // namespace
namespace aura {
@@ -25,20 +27,21 @@ GesturePoint::GesturePoint()
: first_touch_time_(0.0),
last_touch_time_(0.0),
last_tap_time_(0.0),
- x_velocity_(0.0),
- y_velocity_(0.0) {
+ velocity_calculator_(kBufferedPoints) {
}
void GesturePoint::Reset() {
first_touch_time_ = last_touch_time_ = 0.0;
- x_velocity_ = y_velocity_ = 0.0;
+ velocity_calculator_.ClearHistory();
}
void GesturePoint::UpdateValues(const TouchEvent& event, GestureState state) {
+ const int64 event_timestamp_microseconds =
+ event.time_stamp().InMicroseconds();
if (state != GS_NO_GESTURE && event.type() == ui::ET_TOUCH_MOVED) {
- double interval(event.time_stamp().InSecondsF() - last_touch_time_);
- x_velocity_ = (event.x() - last_touch_position_.x()) / interval;
- y_velocity_ = (event.y() - last_touch_position_.y()) / interval;
+ velocity_calculator_.PointSeen(event.x(),
+ event.y(),
+ event_timestamp_microseconds);
}
last_touch_time_ = event.time_stamp().InSecondsF();
@@ -47,8 +50,10 @@ void GesturePoint::UpdateValues(const TouchEvent& event, GestureState state) {
if (state == GS_NO_GESTURE) {
first_touch_time_ = last_touch_time_;
first_touch_position_ = event.location();
- x_velocity_ = 0.0;
- y_velocity_ = 0.0;
+ velocity_calculator_.ClearHistory();
+ velocity_calculator_.PointSeen(event.x(),
+ event.y(),
+ event_timestamp_microseconds);
}
}
@@ -81,7 +86,7 @@ bool GesturePoint::IsInScrollWindow(const TouchEvent& event) const {
!IsInsideManhattanSquare(event);
}
-bool GesturePoint::IsInFlickWindow(const TouchEvent& event) const {
+bool GesturePoint::IsInFlickWindow(const TouchEvent& event) {
return IsOverMinFlickSpeed() && event.type() != ui::ET_TOUCH_CANCELLED;
}
@@ -114,9 +119,8 @@ bool GesturePoint::IsSecondClickInsideManhattanSquare(
return manhattanDistance < kMaximumTouchMoveInPixelsForClick;
}
-bool GesturePoint::IsOverMinFlickSpeed() const {
- return (x_velocity_ * x_velocity_ + y_velocity_ * y_velocity_) >
- kMinFlickSpeedSquared;
+bool GesturePoint::IsOverMinFlickSpeed() {
+ return velocity_calculator_.VelocitySquared() > kMinFlickSpeedSquared;
}
} // namespace aura

Powered by Google App Engine
This is Rietveld 408576698