summaryrefslogtreecommitdiffstats
path: root/ui/aura/gestures/gesture_point.cc
diff options
context:
space:
mode:
Diffstat (limited to 'ui/aura/gestures/gesture_point.cc')
-rw-r--r--ui/aura/gestures/gesture_point.cc30
1 files changed, 13 insertions, 17 deletions
diff --git a/ui/aura/gestures/gesture_point.cc b/ui/aura/gestures/gesture_point.cc
index 4d5b4d6..3402e56 100644
--- a/ui/aura/gestures/gesture_point.cc
+++ b/ui/aura/gestures/gesture_point.cc
@@ -4,7 +4,6 @@
#include "ui/aura/gestures/gesture_point.h"
-#include "base/basictypes.h"
#include "ui/aura/event.h"
#include "ui/base/events.h"
@@ -17,9 +16,8 @@ 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
+} // namespace aura
namespace aura {
@@ -27,21 +25,20 @@ GesturePoint::GesturePoint()
: first_touch_time_(0.0),
last_touch_time_(0.0),
last_tap_time_(0.0),
- velocity_calculator_(kBufferedPoints) {
+ x_velocity_(0.0),
+ y_velocity_(0.0) {
}
void GesturePoint::Reset() {
first_touch_time_ = last_touch_time_ = 0.0;
- velocity_calculator_.ClearHistory();
+ x_velocity_ = y_velocity_ = 0.0;
}
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) {
- velocity_calculator_.PointSeen(event.x(),
- event.y(),
- event_timestamp_microseconds);
+ 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;
}
last_touch_time_ = event.time_stamp().InSecondsF();
@@ -50,10 +47,8 @@ void GesturePoint::UpdateValues(const TouchEvent& event, GestureState state) {
if (state == GS_NO_GESTURE) {
first_touch_time_ = last_touch_time_;
first_touch_position_ = event.location();
- velocity_calculator_.ClearHistory();
- velocity_calculator_.PointSeen(event.x(),
- event.y(),
- event_timestamp_microseconds);
+ x_velocity_ = 0.0;
+ y_velocity_ = 0.0;
}
}
@@ -86,7 +81,7 @@ bool GesturePoint::IsInScrollWindow(const TouchEvent& event) const {
!IsInsideManhattanSquare(event);
}
-bool GesturePoint::IsInFlickWindow(const TouchEvent& event) {
+bool GesturePoint::IsInFlickWindow(const TouchEvent& event) const {
return IsOverMinFlickSpeed() && event.type() != ui::ET_TOUCH_CANCELLED;
}
@@ -119,8 +114,9 @@ bool GesturePoint::IsSecondClickInsideManhattanSquare(
return manhattanDistance < kMaximumTouchMoveInPixelsForClick;
}
-bool GesturePoint::IsOverMinFlickSpeed() {
- return velocity_calculator_.VelocitySquared() > kMinFlickSpeedSquared;
+bool GesturePoint::IsOverMinFlickSpeed() const {
+ return (x_velocity_ * x_velocity_ + y_velocity_ * y_velocity_) >
+ kMinFlickSpeedSquared;
}
} // namespace aura