summaryrefslogtreecommitdiffstats
path: root/ui/views/touchui
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-19 00:48:01 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-19 00:48:01 +0000
commit912b6f3be7f1e31b4107ecb8b572245d9f65ff47 (patch)
treed43a9f10d01316cc817cd7619f1561e0ed279e04 /ui/views/touchui
parent7d692835b4257b2621f969037f52e1dca67d833e (diff)
downloadchromium_src-912b6f3be7f1e31b4107ecb8b572245d9f65ff47.zip
chromium_src-912b6f3be7f1e31b4107ecb8b572245d9f65ff47.tar.gz
chromium_src-912b6f3be7f1e31b4107ecb8b572245d9f65ff47.tar.bz2
aura: Move GestureRecognizer from views into aura.
Remove deprecated GestureManager, and move the functional GestureRecognizer from views into aura. BUG=110227 TEST=views_unittests:GestureEvent, aura_unittests:GestureRecognizerTest Review URL: https://chromiumcodereview.appspot.com/9255019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118200 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views/touchui')
-rw-r--r--ui/views/touchui/gesture_manager.cc58
-rw-r--r--ui/views/touchui/gesture_manager.h56
-rw-r--r--ui/views/touchui/gesture_recognizer.cc287
-rw-r--r--ui/views/touchui/gesture_recognizer.h177
4 files changed, 0 insertions, 578 deletions
diff --git a/ui/views/touchui/gesture_manager.cc b/ui/views/touchui/gesture_manager.cc
deleted file mode 100644
index 4dd6b0a..0000000
--- a/ui/views/touchui/gesture_manager.cc
+++ /dev/null
@@ -1,58 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "ui/views/touchui/gesture_manager.h"
-
-#ifndef NDEBUG
-#include <ostream>
-#endif
-
-#include "base/logging.h"
-#include "ui/views/events/event.h"
-#include "ui/views/view.h"
-#include "ui/views/widget/widget.h"
-
-namespace views {
-
-GestureManager::~GestureManager() {
-}
-
-GestureManager* GestureManager::GetInstance() {
- return Singleton<GestureManager>::get();
-}
-
-bool GestureManager::ProcessTouchEventForGesture(const TouchEvent& event,
- View* source,
- ui::TouchStatus status) {
- if (status != ui::TOUCH_STATUS_UNKNOWN)
- return false; // The event was consumed by a touch sequence.
-
- // TODO(rjkroege): A realistic version of the GestureManager will
- // appear in a subsequent CL. This interim version permits verifying that the
- // event distribution code works by turning all touch inputs into
- // mouse approximations.
-
- // Conver the touch-event into a mouse-event. This mouse-event gets its
- // location information from the native-event, so it needs to convert the
- // coordinate to the target widget.
- MouseEvent mouseev(event);
- Widget* source_widget = source->GetWidget();
- Widget* top_widget = source_widget->GetTopLevelWidget();
- if (source_widget != top_widget && top_widget) {
- // This is necessary as TYPE_CHILD widget is still NativeWidgetGtk.
- // Fix this once TYPE_CHILD is switched to NativeWidgetViews.
- MouseEvent converted(mouseev,
- top_widget->GetRootView(),
- source_widget->GetRootView());
- source_widget->OnMouseEvent(mouseev);
- } else {
- source_widget->OnMouseEvent(mouseev);
- }
- return true;
-}
-
-GestureManager::GestureManager() {
-}
-
-} // namespace views
diff --git a/ui/views/touchui/gesture_manager.h b/ui/views/touchui/gesture_manager.h
deleted file mode 100644
index e5ec4b5..0000000
--- a/ui/views/touchui/gesture_manager.h
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef UI_VIEWS_TOUCHUI_GESTURE_MANAGER_H_
-#define UI_VIEWS_TOUCHUI_GESTURE_MANAGER_H_
-#pragma once
-
-#include "base/memory/singleton.h"
-#include "ui/views/view.h"
-
-namespace ui {
-enum TouchStatus;
-}
-
-namespace views {
-class TouchEvent;
-
-// A GestureManager singleton detects gestures occurring in the
-// incoming feed of touch events across all of the RootViews in
-// the system. In response to a given touch event, the GestureManager
-// updates its internal state and optionally dispatches synthetic
-// events to the invoking view.
-//
-class VIEWS_EXPORT GestureManager {
- public:
- virtual ~GestureManager();
-
- static GestureManager* GetInstance();
-
- // Invoked for each touch event that could contribute to the current gesture.
- // Takes the event and the View that originated it and which will also
- // be the target of any generated synthetic event. Finally, status
- // specifies if a touch sequence is in progress or not, so that the
- // GestureManager state can correctly reflect events that are handled
- // already.
- // Returns true if the event resulted in firing a synthetic event.
- virtual bool ProcessTouchEventForGesture(const TouchEvent& event,
- View* source,
- ui::TouchStatus status);
-
- // TODO(rjkroege): Write the remainder of this class.
- // It will appear in a subsequent CL.
-
- protected:
- GestureManager();
-
- private:
- friend struct DefaultSingletonTraits<GestureManager>;
-
- DISALLOW_COPY_AND_ASSIGN(GestureManager);
-};
-
-} // namespace views
-
-#endif // UI_VIEWS_TOUCHUI_GESTURE_MANAGER_H_
diff --git a/ui/views/touchui/gesture_recognizer.cc b/ui/views/touchui/gesture_recognizer.cc
deleted file mode 100644
index 112b222..0000000
--- a/ui/views/touchui/gesture_recognizer.cc
+++ /dev/null
@@ -1,287 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "ui/views/touchui/gesture_recognizer.h"
-
-#include "base/logging.h"
-#include "base/memory/scoped_ptr.h"
-#include "ui/views/events/event.h"
-
-namespace {
-// TODO(Gajen): Make these configurable in sync with this CL http://code.google.
-// com/p/chromium/issues/detail?id=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;
-
-} // namespace
-
-namespace views {
-
-////////////////////////////////////////////////////////////////////////////////
-// GestureRecognizer Public:
-
-GestureRecognizer::GestureRecognizer()
- : first_touch_time_(0.0),
- state_(GestureRecognizer::GS_NO_GESTURE),
- last_touch_time_(0.0),
- last_click_time_(0.0),
- x_velocity_(0.0),
- y_velocity_(0.0),
- flags_(0) {
-}
-
-GestureRecognizer::~GestureRecognizer() {
-}
-
-GestureRecognizer* GestureRecognizer::GetInstance() {
- return Singleton<GestureRecognizer>::get();
-}
-
-GestureRecognizer::Gestures* GestureRecognizer::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.identity(), 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 GestureRecognizer::Reset() {
- first_touch_time_ = 0.0;
- state_ = GestureRecognizer::GS_NO_GESTURE;
- last_touch_time_ = 0.0;
- last_touch_position_.SetPoint(0, 0);
- x_velocity_ = 0.0;
- y_velocity_ = 0.0;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// GestureRecognizer Private:
-
-// static
-GestureRecognizer::TouchState GestureRecognizer::TouchEventTypeToTouchState(
- ui::EventType type) {
- switch (type) {
- case ui::ET_TOUCH_RELEASED: return TS_RELEASED;
- case ui::ET_TOUCH_PRESSED: return TS_PRESSED;
- case ui::ET_TOUCH_MOVED: return TS_MOVED;
- case ui::ET_TOUCH_STATIONARY: return TS_STATIONARY;
- case ui::ET_TOUCH_CANCELLED: return TS_CANCELLED;
- default:
- VLOG(1) << "Unknown Touch Event type";
- }
- return TS_UNKNOWN;
-}
-
-unsigned int GestureRecognizer::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 GestureRecognizer::IsInClickTimeWindow() {
- double duration(last_touch_time_ - first_touch_time_);
- return duration >= kMinimumTouchDownDurationInSecondsForClick &&
- duration < kMaximumTouchDownDurationInSecondsForClick;
-}
-
-bool GestureRecognizer::IsInSecondClickTimeWindow() {
- double duration(last_touch_time_ - last_click_time_);
- return duration < kMaximumSecondsBetweenDoubleClick;
-}
-
-bool GestureRecognizer::IsInsideManhattanSquare(const TouchEvent& event) {
- int manhattanDistance = abs(event.x() - first_touch_position_.x()) +
- abs(event.y() - first_touch_position_.y());
- return manhattanDistance < kMaximumTouchMoveInPixelsForClick;
-}
-
-bool GestureRecognizer::IsSecondClickInsideManhattanSquare(
- const TouchEvent& event) {
- int manhattanDistance = abs(event.x() - last_click_position_.x()) +
- abs(event.y() - last_click_position_.y());
- return manhattanDistance < kMaximumTouchMoveInPixelsForClick;
-}
-
-bool GestureRecognizer::IsOverMinFlickSpeed() {
- return (x_velocity_ * x_velocity_ + y_velocity_ * y_velocity_) >
- kMinFlickSpeedSquared;
-}
-
-void GestureRecognizer::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 GestureRecognizer::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 GestureRecognizer::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 GestureRecognizer::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 GestureRecognizer::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 GestureRecognizer:: 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 GestureRecognizer::UpdateValues(const TouchEvent& event) {
- if (state_ != GS_NO_GESTURE && event.type() == ui::ET_TOUCH_MOVED) {
- double interval(event.time_stamp().ToDoubleT() - 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().ToDoubleT();
- 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 GestureRecognizer::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 GestureRecognizer::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 GestureRecognizer::InScroll(const TouchEvent& event, Gestures* gestures) {
- AppendScrollGestureUpdate(event, gestures);
- return true;
-}
-
-bool GestureRecognizer::NoGesture(const TouchEvent&, Gestures*) {
- Reset();
- return false;
-}
-
-bool GestureRecognizer::TouchDown(const TouchEvent& event, Gestures* gestures) {
- AppendTapDownGestureEvent(event, gestures);
- SetState(GS_PENDING_SYNTHETIC_CLICK);
- return false;
-}
-
-bool GestureRecognizer::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;
-}
-
-} // namespace views
diff --git a/ui/views/touchui/gesture_recognizer.h b/ui/views/touchui/gesture_recognizer.h
deleted file mode 100644
index 2eeca89..0000000
--- a/ui/views/touchui/gesture_recognizer.h
+++ /dev/null
@@ -1,177 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef UI_VIEWS_TOUCHUI_GESTURE_RECOGNIZER_H_
-#define UI_VIEWS_TOUCHUI_GESTURE_RECOGNIZER_H_
-#pragma once
-
-#include <map>
-#include <vector>
-
-#include "base/memory/linked_ptr.h"
-#include "base/memory/singleton.h"
-#include "ui/base/events.h"
-#include "ui/gfx/point.h"
-#include "ui/views/views_export.h"
-
-namespace views {
-class GestureManager;
-class TouchEvent;
-class GestureEvent;
-
-// A GestureRecognizer recognizes gestures from touch sequences.
-class VIEWS_EXPORT GestureRecognizer {
- public:
- // Gesture state.
- enum GestureState {
- GS_NO_GESTURE,
- GS_PENDING_SYNTHETIC_CLICK,
- GS_SCROLL,
- };
-
- // ui::EventType is mapped to TouchState so it can fit into 3 bits of
- // Signature.
- enum TouchState {
- TS_RELEASED,
- TS_PRESSED,
- TS_MOVED,
- TS_STATIONARY,
- TS_CANCELLED,
- TS_UNKNOWN,
- };
-
- // List of GestureEvent*.
- typedef std::vector<linked_ptr<GestureEvent> > Gestures;
-
- GestureRecognizer();
- virtual ~GestureRecognizer();
-
- static GestureRecognizer* GetInstance();
-
- // Invoked for each touch event that could contribute to the current gesture.
- // Returns list of zero or more GestureEvents identified after processing
- // TouchEvent.
- // Caller would be responsible for freeing up Gestures.
- virtual Gestures* ProcessTouchEventForGesture(const TouchEvent& event,
- ui::TouchStatus status);
-
- // Clears the GestureRecognizer to its initial state.
- virtual void Reset();
-
- // Accessor function.
- GestureState GetState() const { return state_; }
-
- private:
- friend struct DefaultSingletonTraits<GestureRecognizer>;
-
- // Gesture signature types for different values of combination (GestureState,
- // touch_id, ui::EventType, touch_handled), see GestureRecognizer::Signature()
- // for more info.
- //
- // Note: New addition of types should be placed as per their Signature value.
- enum GestureSignatureType {
- // For input combination (GS_NO_GESTURE, 0, ui::ET_TOUCH_PRESSED, false).
- GST_NO_GESTURE_FIRST_PRESSED = 0x00000003,
-
- // (GS_PENDING_SYNTHETIC_CLICK, 0, ui::ET_TOUCH_RELEASED, false).
- GST_PENDING_SYNTHETIC_CLICK_FIRST_RELEASED = 0x00020001,
-
- // (GS_PENDING_SYNTHETIC_CLICK, 0, ui::ET_TOUCH_MOVED, false).
- GST_PENDING_SYNTHETIC_CLICK_FIRST_MOVED = 0x00020005,
-
- // (GS_PENDING_SYNTHETIC_CLICK, 0, ui::ET_TOUCH_STATIONARY, false).
- GST_PENDING_SYNTHETIC_CLICK_FIRST_STATIONARY = 0x00020007,
-
- // (GS_PENDING_SYNTHETIC_CLICK, 0, ui::ET_TOUCH_CANCELLED, false).
- GST_PENDING_SYNTHETIC_CLICK_FIRST_CANCELLED = 0x00020009,
-
- // (GS_SCROLL, 0, ui::ET_TOUCH_RELEASED, false).
- GST_SCROLL_FIRST_RELEASED = 0x00040001,
-
- // (GS_SCROLL, 0, ui::ET_TOUCH_MOVED, false).
- GST_SCROLL_FIRST_MOVED = 0x00040005,
-
- // (GS_SCROLL, 0, ui::ET_TOUCH_CANCELLED, false).
- GST_SCROLL_FIRST_CANCELLED = 0x00040009,
- };
-
- // Get equivalent TouchState from EventType |type|.
- static TouchState TouchEventTypeToTouchState(ui::EventType type);
-
- // Builds a signature. Signatures are assembled by joining together
- // multiple bits.
- // 1 LSB bit so that the computed signature is always greater than 0
- // 3 bits for the |type|.
- // 1 bit for |touch_handled|
- // 12 bits for |touch_id|
- // 15 bits for the |gesture_state|.
- static unsigned int Signature(GestureState state,
- unsigned int touch_id, ui::EventType type,
- bool touch_handled);
-
- // Various statistical functions to manipulate gestures.
- bool IsInClickTimeWindow();
- bool IsInSecondClickTimeWindow();
- bool IsInsideManhattanSquare(const TouchEvent& event);
- bool IsSecondClickInsideManhattanSquare(const TouchEvent& event);
- bool IsOverMinFlickSpeed();
-
- // Functions to be called to add GestureEvents, after succesful recognition.
- void AppendTapDownGestureEvent(const TouchEvent& event, Gestures* gestures);
- void AppendClickGestureEvent(const TouchEvent& event, Gestures* gestures);
- void AppendDoubleClickGestureEvent(const TouchEvent& event,
- Gestures* gestures);
- void AppendScrollGestureBegin(const TouchEvent& event, Gestures* gestures);
- void AppendScrollGestureEnd(const TouchEvent& event,
- Gestures* gestures,
- float x_velocity, float y_velocity);
- void AppendScrollGestureUpdate(const TouchEvent& event, Gestures* gestures);
-
- void UpdateValues(const TouchEvent& event);
- void SetState(const GestureState state ) { state_ = state; }
-
- // Various GestureTransitionFunctions for a signature.
- // There is, 1:many mapping from GestureTransitionFunction to Signature
- // But a Signature have only one GestureTransitionFunction.
- bool Click(const TouchEvent& event, Gestures* gestures);
- bool InClickOrScroll(const TouchEvent& event, Gestures* gestures);
- bool InScroll(const TouchEvent& event, Gestures* gestures);
- bool NoGesture(const TouchEvent& event, Gestures* gestures);
- bool TouchDown(const TouchEvent& event, Gestures* gestures);
- bool ScrollEnd(const TouchEvent& event, Gestures* gestures);
-
- // Location of first touch event in a touch sequence.
- gfx::Point first_touch_position_;
-
- // Time of first touch event in a touch sequence.
- double first_touch_time_;
-
- // Current state of gesture recognizer.
- GestureState state_;
-
- // Time of current touch event in a touch sequence.
- double last_touch_time_;
-
- // Time of click gesture.
- double last_click_time_;
-
- // Location of click gesture.
- gfx::Point last_click_position_;
-
- // Location of current touch event in a touch sequence.
- gfx::Point last_touch_position_;
-
- // Velocity in x and y direction.
- float x_velocity_;
- float y_velocity_;
-
- // ui::EventFlags.
- int flags_;
-
- DISALLOW_COPY_AND_ASSIGN(GestureRecognizer);
-};
-
-} // namespace views
-
-#endif // UI_VIEWS_TOUCHUI_GESTURE_RECOGNIZER_H_