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

Unified Diff: ui/aura/gestures/gesture_recognizer_aura.cc

Issue 9104021: aura: Update GestureRecognizer to be able to process multi-point gestures. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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_recognizer_aura.cc
diff --git a/ui/aura/gestures/gesture_recognizer_aura.cc b/ui/aura/gestures/gesture_recognizer_aura.cc
index 7b8b528e13b8ff6bbdf4f214ba88bef609d89f29..ec681b397663bfdc9d6b6a7340a5e662f6979a67 100644
--- a/ui/aura/gestures/gesture_recognizer_aura.cc
+++ b/ui/aura/gestures/gesture_recognizer_aura.cc
@@ -8,17 +8,10 @@
#include "base/memory/scoped_ptr.h"
#include "base/time.h"
#include "ui/aura/event.h"
+#include "ui/aura/gestures/gesture_sequence.h"
#include "ui/base/events.h"
namespace {
-// TODO(girard): Make these configurable in sync with this CL
-// http://crbug.com/100773
-const double kMaximumTouchDownDurationInSecondsForClick = 0.8;
-const double kMinimumTouchDownDurationInSecondsForClick = 0.01;
-const double kMaximumSecondsBetweenDoubleClick = 0.7;
-const int kMaximumTouchMoveInPixelsForClick = 20;
-const float kMinFlickSpeedSquared = 550.f * 550.f;
-
// This is used to pop a std::queue when returning from a function.
class ScopedPop {
public:
@@ -39,274 +32,6 @@ class ScopedPop {
namespace aura {
-namespace {
-
-// Get equivalent TouchState from EventType |type|.
-GestureSequence::TouchState TouchEventTypeToTouchState(ui::EventType type) {
- switch (type) {
- case ui::ET_TOUCH_RELEASED:
- return GestureSequence::TS_RELEASED;
- case ui::ET_TOUCH_PRESSED:
- return GestureSequence::TS_PRESSED;
- case ui::ET_TOUCH_MOVED:
- return GestureSequence::TS_MOVED;
- case ui::ET_TOUCH_STATIONARY:
- return GestureSequence::TS_STATIONARY;
- case ui::ET_TOUCH_CANCELLED:
- return GestureSequence::TS_CANCELLED;
- default:
- VLOG(1) << "Unknown Touch Event type";
- }
- return GestureSequence::TS_UNKNOWN;
-}
-
-} // namespace
-
-////////////////////////////////////////////////////////////////////////////////
-// GestureSequence Public:
-
-GestureSequence::GestureSequence()
- : first_touch_time_(0.0),
- state_(GestureSequence::GS_NO_GESTURE),
- last_touch_time_(0.0),
- last_click_time_(0.0),
- x_velocity_(0.0),
- y_velocity_(0.0),
- flags_(0) {
-}
-
-GestureSequence::~GestureSequence() {
-}
-
-GestureSequence::Gestures* GestureSequence::ProcessTouchEventForGesture(
- const TouchEvent& event,
- ui::TouchStatus status) {
- if (status != ui::TOUCH_STATUS_UNKNOWN)
- return NULL; // The event was consumed by a touch sequence.
-
- scoped_ptr<Gestures> gestures(new Gestures());
- UpdateValues(event);
- switch (Signature(state_, event.touch_id(), event.type(), false)) {
- case GST_NO_GESTURE_FIRST_PRESSED:
- TouchDown(event, gestures.get());
- break;
- case GST_PENDING_SYNTHETIC_CLICK_FIRST_RELEASED:
- Click(event, gestures.get());
- break;
- case GST_PENDING_SYNTHETIC_CLICK_FIRST_MOVED:
- case GST_PENDING_SYNTHETIC_CLICK_FIRST_STATIONARY:
- InClickOrScroll(event, gestures.get());
- break;
- case GST_PENDING_SYNTHETIC_CLICK_FIRST_CANCELLED:
- NoGesture(event, gestures.get());
- break;
- case GST_SCROLL_FIRST_MOVED:
- InScroll(event, gestures.get());
- break;
- case GST_SCROLL_FIRST_RELEASED:
- case GST_SCROLL_FIRST_CANCELLED:
- ScrollEnd(event, gestures.get());
- break;
- }
- return gestures.release();
-}
-
-void GestureSequence::Reset() {
- first_touch_time_ = 0.0;
- state_ = GestureSequence::GS_NO_GESTURE;
- last_touch_time_ = 0.0;
- last_touch_position_.SetPoint(0, 0);
- x_velocity_ = 0.0;
- y_velocity_ = 0.0;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// GestureSequence Private:
-
-unsigned int GestureSequence::Signature(GestureState gesture_state,
- unsigned int touch_id,
- ui::EventType type,
- bool touch_handled) {
- CHECK((touch_id & 0xfff) == touch_id);
- TouchState touch_state = TouchEventTypeToTouchState(type);
- return 1 + ((touch_state & 0x7) << 1 | (touch_handled ? 1 << 4 : 0) |
- ((touch_id & 0xfff) << 5) | (gesture_state << 17));
-}
-
-bool GestureSequence::IsInClickTimeWindow() {
- double duration(last_touch_time_ - first_touch_time_);
- return duration >= kMinimumTouchDownDurationInSecondsForClick &&
- duration < kMaximumTouchDownDurationInSecondsForClick;
-}
-
-bool GestureSequence::IsInSecondClickTimeWindow() {
- double duration(last_touch_time_ - last_click_time_);
- return duration < kMaximumSecondsBetweenDoubleClick;
-}
-
-bool GestureSequence::IsInsideManhattanSquare(const TouchEvent& event) {
- int manhattanDistance = abs(event.x() - first_touch_position_.x()) +
- abs(event.y() - first_touch_position_.y());
- return manhattanDistance < kMaximumTouchMoveInPixelsForClick;
-}
-
-bool GestureSequence::IsSecondClickInsideManhattanSquare(
- const TouchEvent& event) {
- int manhattanDistance = abs(event.x() - last_click_position_.x()) +
- abs(event.y() - last_click_position_.y());
- return manhattanDistance < kMaximumTouchMoveInPixelsForClick;
-}
-
-bool GestureSequence::IsOverMinFlickSpeed() {
- return (x_velocity_ * x_velocity_ + y_velocity_ * y_velocity_) >
- kMinFlickSpeedSquared;
-}
-
-void GestureSequence::AppendTapDownGestureEvent(const TouchEvent& event,
- Gestures* gestures) {
- gestures->push_back(linked_ptr<GestureEvent>(new GestureEvent(
- ui::ET_GESTURE_TAP_DOWN,
- first_touch_position_.x(),
- first_touch_position_.y(),
- event.flags(),
- base::Time::FromDoubleT(last_touch_time_),
- 0.f, 0.f)));
-}
-
-void GestureSequence::AppendClickGestureEvent(const TouchEvent& event,
- Gestures* gestures) {
- gestures->push_back(linked_ptr<GestureEvent>(new GestureEvent(
- ui::ET_GESTURE_TAP,
- first_touch_position_.x(),
- first_touch_position_.y(),
- event.flags(),
- base::Time::FromDoubleT(last_touch_time_),
- 0.f, 0.f)));
-}
-
-void GestureSequence::AppendDoubleClickGestureEvent(const TouchEvent& event,
- Gestures* gestures) {
- gestures->push_back(linked_ptr<GestureEvent>(new GestureEvent(
- ui::ET_GESTURE_DOUBLE_TAP,
- first_touch_position_.x(),
- first_touch_position_.y(),
- event.flags(),
- base::Time::FromDoubleT(last_touch_time_),
- 0.f, 0.f)));
-}
-
-void GestureSequence::AppendScrollGestureBegin(const TouchEvent& event,
- Gestures* gestures) {
- gestures->push_back(linked_ptr<GestureEvent>(new GestureEvent(
- ui::ET_GESTURE_SCROLL_BEGIN,
- event.x(),
- event.y(),
- event.flags(),
- base::Time::FromDoubleT(last_touch_time_),
- 0.f, 0.f)));
-}
-
-void GestureSequence::AppendScrollGestureEnd(const TouchEvent& event,
- Gestures* gestures,
- float x_velocity,
- float y_velocity) {
- gestures->push_back(linked_ptr<GestureEvent>(new GestureEvent(
- ui::ET_GESTURE_SCROLL_END,
- event.x(),
- event.y(),
- event.flags(),
- base::Time::FromDoubleT(last_touch_time_),
- x_velocity, y_velocity)));
-}
-
-void GestureSequence:: AppendScrollGestureUpdate(const TouchEvent& event,
- Gestures* gestures) {
- float delta_x(event.x() - first_touch_position_.x());
- float delta_y(event.y() - first_touch_position_.y());
-
- gestures->push_back(linked_ptr<GestureEvent>(new GestureEvent(
- ui::ET_GESTURE_SCROLL_UPDATE,
- event.x(),
- event.y(),
- event.flags(),
- base::Time::FromDoubleT(last_touch_time_),
- delta_x, delta_y)));
-
- first_touch_position_ = event.location();
-}
-
-void GestureSequence::UpdateValues(const TouchEvent& event) {
- 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;
- }
- last_touch_time_ = event.time_stamp().InSecondsF();
- last_touch_position_ = event.location();
- if (state_ == GS_NO_GESTURE) {
- first_touch_time_ = last_touch_time_;
- first_touch_position_ = event.location();
- x_velocity_ = 0.0;
- y_velocity_ = 0.0;
- }
-}
-
-bool GestureSequence::Click(const TouchEvent& event, Gestures* gestures) {
- bool gesture_added = false;
- if (IsInClickTimeWindow() && IsInsideManhattanSquare(event)) {
- gesture_added = true;
- AppendClickGestureEvent(event, gestures);
- if (IsInSecondClickTimeWindow() &&
- IsSecondClickInsideManhattanSquare(event))
- AppendDoubleClickGestureEvent(event, gestures);
- last_click_time_ = last_touch_time_;
- last_click_position_ = last_touch_position_;
- }
- Reset();
- return gesture_added;
-}
-
-bool GestureSequence::InClickOrScroll(const TouchEvent& event,
- Gestures* gestures) {
- if (IsInClickTimeWindow() && IsInsideManhattanSquare(event)) {
- SetState(GS_PENDING_SYNTHETIC_CLICK);
- return false;
- }
- if (event.type() == ui::ET_TOUCH_MOVED && !IsInsideManhattanSquare(event)) {
- AppendScrollGestureBegin(event, gestures);
- AppendScrollGestureUpdate(event, gestures);
- SetState(GS_SCROLL);
- return true;
- }
- return false;
-}
-
-bool GestureSequence::InScroll(const TouchEvent& event, Gestures* gestures) {
- AppendScrollGestureUpdate(event, gestures);
- return true;
-}
-
-bool GestureSequence::NoGesture(const TouchEvent&, Gestures*) {
- Reset();
- return false;
-}
-
-bool GestureSequence::TouchDown(const TouchEvent& event, Gestures* gestures) {
- AppendTapDownGestureEvent(event, gestures);
- SetState(GS_PENDING_SYNTHETIC_CLICK);
- return false;
-}
-
-bool GestureSequence::ScrollEnd(const TouchEvent& event, Gestures* gestures) {
- if (IsOverMinFlickSpeed() && event.type() != ui::ET_TOUCH_CANCELLED)
- AppendScrollGestureEnd(event, gestures, x_velocity_, y_velocity_);
- else
- AppendScrollGestureEnd(event, gestures, 0.f, 0.f);
- SetState(GS_NO_GESTURE);
- Reset();
- return false;
-}
-
////////////////////////////////////////////////////////////////////////////////
// GestureRecognizerAura, public:
@@ -317,6 +42,9 @@ GestureRecognizerAura::GestureRecognizerAura()
GestureRecognizerAura::~GestureRecognizerAura() {
}
+////////////////////////////////////////////////////////////////////////////////
+// GestureRecognizerAura, private:
+
GestureSequence::Gestures* GestureRecognizerAura::ProcessTouchEventForGesture(
const TouchEvent& event,
ui::TouchStatus status) {

Powered by Google App Engine
This is Rietveld 408576698