summaryrefslogtreecommitdiffstats
path: root/ui/views
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
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')
-rw-r--r--ui/views/events/event.cc28
-rw-r--r--ui/views/events/event.h19
-rw-r--r--ui/views/events/event_aura.cc14
-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
-rw-r--r--ui/views/view.h10
-rw-r--r--ui/views/view_unittest.cc371
-rw-r--r--ui/views/views.gyp4
-rw-r--r--ui/views/widget/native_widget_aura.cc4
-rw-r--r--ui/views/widget/root_view.cc47
-rw-r--r--ui/views/widget/root_view.h22
13 files changed, 80 insertions, 1017 deletions
diff --git a/ui/views/events/event.cc b/ui/views/events/event.cc
index e6c7a0d..a143392 100644
--- a/ui/views/events/event.cc
+++ b/ui/views/events/event.cc
@@ -205,25 +205,11 @@ const int MouseWheelEvent::kWheelDelta = 53;
////////////////////////////////////////////////////////////////////////////////
// GestureEvent, public:
-GestureEvent::GestureEvent(ui::EventType type,
- int x,
- int y,
- int flags,
- base::Time time_stamp,
- float delta_x,
- float delta_y)
- : LocatedEvent(type, gfx::Point(x, y), flags),
- delta_x_(delta_x),
- delta_y_(delta_y) {
- set_time_stamp(time_stamp);
-}
-
GestureEvent::GestureEvent(const GestureEvent& model, View* source,
View* target)
: LocatedEvent(model, source, target),
delta_x_(model.delta_x_),
delta_y_(model.delta_y_) {
- set_time_stamp(model.time_stamp());
}
////////////////////////////////////////////////////////////////////////////////
@@ -233,7 +219,19 @@ GestureEvent::GestureEvent(const GestureEvent& model, View* root)
: LocatedEvent(model, root),
delta_x_(model.delta_x_),
delta_y_(model.delta_y_) {
- set_time_stamp(model.time_stamp());
+}
+
+GestureEvent::GestureEvent(ui::EventType type, int x, int y, int flags)
+ : LocatedEvent(type, gfx::Point(x, y), flags),
+ delta_x_(0),
+ delta_y_(0) {
+}
+
+GestureEventForTest::GestureEventForTest(ui::EventType type,
+ int x,
+ int y,
+ int flags)
+ : GestureEvent(type, x, y, flags) {
}
} // namespace views
diff --git a/ui/views/events/event.h b/ui/views/events/event.h
index fcdb7d5..6e4e462 100644
--- a/ui/views/events/event.h
+++ b/ui/views/events/event.h
@@ -429,13 +429,7 @@ class VIEWS_EXPORT ScrollEvent : public MouseEvent {
////////////////////////////////////////////////////////////////////////////////
class VIEWS_EXPORT GestureEvent : public LocatedEvent {
public:
- GestureEvent(ui::EventType type,
- int x,
- int y,
- int flags,
- base::Time time_stamp,
- float delta_x,
- float delta_y);
+ explicit GestureEvent(const NativeEvent& native_event);
// Create a new GestureEvent which is identical to the provided model.
// If source / target views are provided, the model location will be converted
@@ -445,6 +439,9 @@ class VIEWS_EXPORT GestureEvent : public LocatedEvent {
float delta_x() const { return delta_x_; }
float delta_y() const { return delta_y_; }
+ protected:
+ GestureEvent(ui::EventType type, int x, int y, int flags);
+
private:
friend class internal::RootView;
@@ -456,6 +453,14 @@ class VIEWS_EXPORT GestureEvent : public LocatedEvent {
DISALLOW_COPY_AND_ASSIGN(GestureEvent);
};
+class VIEWS_EXPORT GestureEventForTest : public GestureEvent {
+ public:
+ GestureEventForTest(ui::EventType type, int x, int y, int flags);
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(GestureEventForTest);
+};
+
} // namespace views
#endif // UI_VIEWS_EVENTS_EVENT_H_
diff --git a/ui/views/events/event_aura.cc b/ui/views/events/event_aura.cc
index 9b3af83..610752d 100644
--- a/ui/views/events/event_aura.cc
+++ b/ui/views/events/event_aura.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// 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.
@@ -59,10 +59,22 @@ MouseWheelEvent::MouseWheelEvent(const NativeEvent& native_event)
offset_(ui::GetMouseWheelOffset(native_event->native_event())) {
}
+////////////////////////////////////////////////////////////////////////////////
+// ScrollEvent, public:
+
ScrollEvent::ScrollEvent(const NativeEvent& native_event)
: MouseEvent(native_event) {
CHECK(ui::GetScrollOffsets(
native_event->native_event(), &x_offset_, &y_offset_));
}
+////////////////////////////////////////////////////////////////////////////////
+// GestureEvent, public:
+
+GestureEvent::GestureEvent(const NativeEvent& event)
+ : LocatedEvent(event),
+ delta_x_(static_cast<aura::GestureEvent*>(event)->delta_x()),
+ delta_y_(static_cast<aura::GestureEvent*>(event)->delta_y()) {
+}
+
} // namespace views
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_
diff --git a/ui/views/view.h b/ui/views/view.h
index dfe1cc4..92cf372 100644
--- a/ui/views/view.h
+++ b/ui/views/view.h
@@ -582,7 +582,7 @@ class VIEWS_EXPORT View : public ui::LayerDelegate,
// does nothing. Override as needed.
virtual ui::TouchStatus OnTouchEvent(const TouchEvent& event);
- // This method is invoked for each GestureEvent recognized from GestureManager
+ // This method is invoked for each GestureEvent created by GestureRecognizer.
// Default implementation does nothing. Override as needed.
virtual ui::GestureStatus OnGestureEvent(const GestureEvent& event);
@@ -1257,12 +1257,12 @@ class VIEWS_EXPORT View : public ui::LayerDelegate,
bool ProcessMouseDragged(const MouseEvent& event, DragInfo* drop_info);
void ProcessMouseReleased(const MouseEvent& event);
- // RootView will invoke this with incoming TouchEvents. Returns the
- // the result of OnTouchEvent.
+ // RootView will invoke this with incoming TouchEvents. Returns the result
+ // of OnTouchEvent.
ui::TouchStatus ProcessTouchEvent(const TouchEvent& event);
- // GestureManager will invoke this with incoming GestureEvents. Returns the
- // the result of OnGestureEvent.
+ // RootView will invoke this with incoming GestureEvents. Returns the result
+ // of OnGestureEvent.
ui::GestureStatus ProcessGestureEvent(const GestureEvent& event);
// Accelerators --------------------------------------------------------------
diff --git a/ui/views/view_unittest.cc b/ui/views/view_unittest.cc
index 73f52e9..45e7dbd 100644
--- a/ui/views/view_unittest.cc
+++ b/ui/views/view_unittest.cc
@@ -29,8 +29,6 @@
#include "ui/views/focus/accelerator_handler.h"
#include "ui/views/focus/view_storage.h"
#include "ui/views/test/views_test_base.h"
-#include "ui/views/touchui/gesture_manager.h"
-#include "ui/views/touchui/gesture_recognizer.h"
#include "ui/views/view.h"
#include "ui/views/views_delegate.h"
#include "ui/views/widget/native_widget.h"
@@ -41,8 +39,9 @@
#include "ui/views/test/test_views_delegate.h"
#endif
#if defined(USE_AURA)
+#include "ui/aura/event.h"
#include "ui/aura/root_window.h"
-#include "ui/views/touchui/gesture_recognizer.h"
+#include "ui/aura/gestures/gesture_recognizer.h"
#endif
#if !defined(USE_WEBKIT_COMPOSITOR)
#include "ui/gfx/compositor/test/test_texture.h"
@@ -252,51 +251,6 @@ class TestView : public View {
std::map<ui::Accelerator, int> accelerator_count_map_;
};
-// Mock instance of the GestureManager for testing.
-class MockGestureManager : public GestureManager {
- public:
- // Reset all test state.
- void Reset() {
- last_touch_event_ = 0;
- last_view_ = NULL;
- previously_handled_flag_ = false;
- dispatched_synthetic_event_ = false;
- }
-
- bool ProcessTouchEventForGesture(const TouchEvent& event,
- View* source,
- ui::TouchStatus status);
- MockGestureManager();
-
- bool previously_handled_flag_;
- int last_touch_event_;
- View *last_view_;
- bool dispatched_synthetic_event_;
-
- DISALLOW_COPY_AND_ASSIGN(MockGestureManager);
-};
-
-// GestureRecognizer for testing.
-class TestGestureRecognizer : public GestureRecognizer {
- public:
- TestGestureRecognizer();
-
- // Reset all test state.
- void reset() {
- last_touch_event_ = 0;
- previously_handled_flag_ = false;
- }
-
- virtual Gestures* ProcessTouchEventForGesture(
- const TouchEvent& event,
- ui::TouchStatus status) OVERRIDE;
-
- bool previously_handled_flag_;
- int last_touch_event_;
-
- DISALLOW_COPY_AND_ASSIGN(TestGestureRecognizer);
-};
-
// A view subclass that ignores all touch events for testing purposes.
class TestViewIgnoreTouch : public TestView {
public:
@@ -314,23 +268,27 @@ class TestViewConsumeGesture : public TestView {
virtual ~TestViewConsumeGesture() {}
private:
- virtual ui::TouchStatus OnTouchEvent(const TouchEvent& event) OVERRIDE;
- virtual ui::GestureStatus OnGestureEvent(const GestureEvent& event) OVERRIDE;
+ virtual ui::GestureStatus OnGestureEvent(const GestureEvent& event) OVERRIDE {
+ last_gesture_event_type_ = event.type();
+ location_.SetPoint(event.x(), event.y());
+ return ui::GESTURE_STATUS_CONSUMED;
+ }
DISALLOW_COPY_AND_ASSIGN(TestViewConsumeGesture);
};
-// A view subclass that ignores all Gesture and touch events.
-class TestViewIgnoreTouchAndGesture: public TestView {
+// A view subclass that ignores all Gesture events.
+class TestViewIgnoreGesture: public TestView {
public:
- TestViewIgnoreTouchAndGesture() : TestView() {}
- virtual ~TestViewIgnoreTouchAndGesture() {}
+ TestViewIgnoreGesture() : TestView() {}
+ virtual ~TestViewIgnoreGesture() {}
private:
- virtual ui::TouchStatus OnTouchEvent(const TouchEvent& event) OVERRIDE;
- virtual ui::GestureStatus OnGestureEvent(const GestureEvent& event) OVERRIDE;
+ virtual ui::GestureStatus OnGestureEvent(const GestureEvent& event) OVERRIDE {
+ return ui::GESTURE_STATUS_UNKNOWN;
+ }
- DISALLOW_COPY_AND_ASSIGN(TestViewIgnoreTouchAndGesture);
+ DISALLOW_COPY_AND_ASSIGN(TestViewIgnoreGesture);
};
////////////////////////////////////////////////////////////////////////////////
@@ -440,24 +398,6 @@ TEST_F(ViewTest, MouseEvent) {
////////////////////////////////////////////////////////////////////////////////
// TouchEvent
////////////////////////////////////////////////////////////////////////////////
-bool MockGestureManager::ProcessTouchEventForGesture(
- const TouchEvent& event,
- View* source,
- ui::TouchStatus status) {
- if (status != ui::TOUCH_STATUS_UNKNOWN) {
- dispatched_synthetic_event_ = false;
- return false;
- }
- last_touch_event_ = event.type();
- last_view_ = source;
- previously_handled_flag_ = status != ui::TOUCH_STATUS_UNKNOWN;
- dispatched_synthetic_event_ = true;
- return true;
-}
-
-MockGestureManager::MockGestureManager() {
-}
-
ui::TouchStatus TestView::OnTouchEvent(const TouchEvent& event) {
last_touch_event_type_ = event.type();
location_.SetPoint(event.x(), event.y());
@@ -482,8 +422,6 @@ ui::TouchStatus TestViewIgnoreTouch::OnTouchEvent(const TouchEvent& event) {
}
TEST_F(ViewTest, TouchEvent) {
- MockGestureManager gm;
-
TestView* v1 = new TestView();
v1->SetBounds(0, 0, 300, 300);
@@ -501,7 +439,6 @@ TEST_F(ViewTest, TouchEvent) {
View* root = widget->GetRootView();
root->AddChildView(v1);
- static_cast<internal::RootView*>(root)->SetGestureManagerForTesting(&gm);
v1->AddChildView(v2);
v2->AddChildView(v3);
@@ -512,7 +449,6 @@ TEST_F(ViewTest, TouchEvent) {
// does.
v1->Reset();
v2->Reset();
- gm.Reset();
TouchEvent unhandled(ui::ET_TOUCH_MOVED,
400,
@@ -525,15 +461,9 @@ TEST_F(ViewTest, TouchEvent) {
EXPECT_EQ(v1->last_touch_event_type_, 0);
EXPECT_EQ(v2->last_touch_event_type_, 0);
- EXPECT_EQ(gm.previously_handled_flag_, false);
- EXPECT_EQ(gm.last_touch_event_, ui::ET_TOUCH_MOVED);
- EXPECT_EQ(gm.last_view_, root);
- EXPECT_EQ(gm.dispatched_synthetic_event_, true);
-
// Test press, drag, release touch sequence.
v1->Reset();
v2->Reset();
- gm.Reset();
TouchEvent pressed(ui::ET_TOUCH_PRESSED,
110,
@@ -550,11 +480,6 @@ TEST_F(ViewTest, TouchEvent) {
// Make sure v1 did not receive the event
EXPECT_EQ(v1->last_touch_event_type_, 0);
- // Since v2 handled the touch-event, the gesture manager should not handle it.
- EXPECT_EQ(gm.last_touch_event_, 0);
- EXPECT_EQ(NULL, gm.last_view_);
- EXPECT_EQ(gm.previously_handled_flag_, false);
-
// Drag event out of bounds. Should still go to v2
v1->Reset();
v2->Reset();
@@ -572,10 +497,6 @@ TEST_F(ViewTest, TouchEvent) {
// Make sure v1 did not receive the event
EXPECT_EQ(v1->last_touch_event_type_, 0);
- EXPECT_EQ(gm.last_touch_event_, 0);
- EXPECT_EQ(NULL, gm.last_view_);
- EXPECT_EQ(gm.previously_handled_flag_, false);
-
// Released event out of bounds. Should still go to v2
v1->Reset();
v2->Reset();
@@ -589,79 +510,24 @@ TEST_F(ViewTest, TouchEvent) {
// Make sure v1 did not receive the event
EXPECT_EQ(v1->last_touch_event_type_, 0);
- EXPECT_EQ(gm.last_touch_event_, 0);
- EXPECT_EQ(NULL, gm.last_view_);
- EXPECT_EQ(gm.previously_handled_flag_, false);
-
widget->CloseNow();
}
-////////////////////////////////////////////////////////////////////////////////
-// GestureEvent
-////////////////////////////////////////////////////////////////////////////////
-
-GestureRecognizer::Gestures* TestGestureRecognizer::ProcessTouchEventForGesture(
- const TouchEvent& event,
- ui::TouchStatus status) {
- if (status != ui::TOUCH_STATUS_UNKNOWN) {
- return NULL;
- }
- last_touch_event_ = event.type();
- previously_handled_flag_ = status != ui::TOUCH_STATUS_UNKNOWN;
- return GestureRecognizer::ProcessTouchEventForGesture(event, status);
-}
-
-TestGestureRecognizer::TestGestureRecognizer() {
-}
-
ui::GestureStatus TestView::OnGestureEvent(const GestureEvent& event) {
return ui::GESTURE_STATUS_UNKNOWN;
}
-// GestureConsumer view should ignore TouchEvent for testing purposes.
-ui::TouchStatus TestViewConsumeGesture::OnTouchEvent(
- const TouchEvent& event) {
- return ui::TOUCH_STATUS_UNKNOWN;
-}
-
-ui::GestureStatus TestViewConsumeGesture::OnGestureEvent(
- const GestureEvent& event) {
- last_gesture_event_type_ = event.type();
- location_.SetPoint(event.x(), event.y());
- return ui::GESTURE_STATUS_CONSUMED;
-}
-
-// IgnoreTouchAndGesture view should ignore touch and Gesture event for
-// testing purposes.
-ui::TouchStatus TestViewIgnoreTouchAndGesture::OnTouchEvent(
- const TouchEvent& event) {
- return ui::TOUCH_STATUS_UNKNOWN;
-}
-
-ui::GestureStatus TestViewIgnoreTouchAndGesture::OnGestureEvent(
- const GestureEvent& event) {
- return ui::GESTURE_STATUS_UNKNOWN;
-}
-
-#if defined(TOUCH_UI)
TEST_F(ViewTest, GestureEvent) {
- MockGestureManager gm;
- TestGestureRecognizer gr;
-
// Views hierarchy for non delivery of GestureEvent.
TestView* v1 = new TestViewConsumeGesture();
v1->SetBounds(0, 0, 300, 300);
- TestView* v2 = new TestView();
+ TestView* v2 = new TestViewConsumeGesture();
v2->SetBounds(100, 100, 100, 100);
- TestView* v3 = new TestViewConsumeGesture();
+ TestView* v3 = new TestViewIgnoreGesture();
v3->SetBounds(0, 0, 100, 100);
- // Views hierarchy for delivery of GestureEvent.
- TestView* v4 = new TestViewConsumeGesture();
- v4->SetBounds(200, 200, 100, 100);
-
scoped_ptr<Widget> widget(new Widget());
Widget::InitParams params(Widget::InitParams::TYPE_POPUP);
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
@@ -670,209 +536,38 @@ TEST_F(ViewTest, GestureEvent) {
View* root = widget->GetRootView();
root->AddChildView(v1);
- static_cast<internal::RootView*>(root)->SetGestureManagerForTesting(&gm);
- static_cast<internal::RootView*>(root)->SetGestureRecognizerForTesting(&gr);
v1->AddChildView(v2);
v2->AddChildView(v3);
- v1->AddChildView(v4);
-
- // |v3| completely obscures |v2|, but all the touch events on |v3| should
- // reach |v2| because |v3| doesn't process any touch events, hence no gesture
- // conversion take place.
- // Both |v4| and |v1| ignore touch events, hence |v4| should recieve gesture
- // events.
+ // |v3| completely obscures |v2|, but all the gesture events on |v3| should
+ // reach |v2| because |v3| doesn't process any gesture events. However, since
+ // |v2| does process gesture events, gesture events on |v3| or |v2| should not
+ // reach |v1|.
- // Make sure if none of the views handle the touch event, the gesture manager
- // does.
v1->Reset();
v2->Reset();
v3->Reset();
- v4->Reset();
- gr.reset();
- gm.Reset();
-
- TouchEvent unhandled(ui::ET_TOUCH_MOVED,
- 400,
- 400,
- 0, /* no flags */
- 0, /* first finger touch */
- 1.0, 0.0, 1.0, 0.0);
- root->OnTouchEvent(unhandled);
- EXPECT_EQ(v1->last_touch_event_type_, 0);
- EXPECT_EQ(v2->last_touch_event_type_, 0);
- EXPECT_EQ(v4->last_touch_event_type_, 0);
- EXPECT_EQ(v4->last_gesture_event_type_, 0);
-
- EXPECT_EQ(gr.previously_handled_flag_, false);
- EXPECT_EQ(gr.last_touch_event_, ui::ET_TOUCH_MOVED);
+ // Gesture on |v3|
+ GestureEventForTest g1(ui::ET_GESTURE_TAP, 110, 110, 0);
+ root->OnGestureEvent(g1);
+ EXPECT_EQ(ui::ET_GESTURE_TAP, v2->last_gesture_event_type_);
+ EXPECT_EQ(gfx::Point(10, 10), v2->location_);
+ EXPECT_EQ(ui::ET_UNKNOWN, v1->last_gesture_event_type_);
- // Test press, drag, release touch sequence.
v1->Reset();
v2->Reset();
v3->Reset();
- v4->Reset();
- gr.reset();
- gm.Reset();
-
- TouchEvent pressed(ui::ET_TOUCH_PRESSED,
- 110,
- 120,
- 0, /* no flags */
- 0, /* first finger touch */
- 1.0, 0.0, 1.0, 0.0);
- v2->last_touch_event_was_handled_ = true;
- root->OnTouchEvent(pressed);
- EXPECT_EQ(v2->last_touch_event_type_, ui::ET_TOUCH_PRESSED);
- EXPECT_EQ(v2->location_.x(), 10);
- EXPECT_EQ(v2->location_.y(), 20);
- // Make sure v1 did not receive the event
- EXPECT_EQ(v1->last_touch_event_type_, 0);
-
- // Since v2 handled the touch-event, the gesture recognizer should not
- // handle it.
- EXPECT_EQ(gr.last_touch_event_, 0);
- EXPECT_EQ(gr.previously_handled_flag_, false);
+ // Gesture on |v1|
+ GestureEventForTest g2(ui::ET_GESTURE_TAP, 80, 80, 0);
+ root->OnGestureEvent(g2);
+ EXPECT_EQ(ui::ET_GESTURE_TAP, v1->last_gesture_event_type_);
+ EXPECT_EQ(gfx::Point(80, 80), v1->location_);
+ EXPECT_EQ(ui::ET_UNKNOWN, v2->last_gesture_event_type_);
- // Drag event out of bounds. Should still go to v2
- v1->Reset();
- v2->Reset();
- TouchEvent dragged(ui::ET_TOUCH_MOVED,
- 50,
- 40,
- 0, /* no flags */
- 0, /* first finger touch */
- 1.0, 0.0, 1.0, 0.0);
- root->OnTouchEvent(dragged);
- EXPECT_EQ(v2->last_touch_event_type_, ui::ET_TOUCH_MOVED);
- EXPECT_EQ(v2->location_.x(), -50);
- EXPECT_EQ(v2->location_.y(), -60);
- // Make sure v1 did not receive the event
- EXPECT_EQ(v1->last_touch_event_type_, 0);
-
- EXPECT_EQ(gr.last_touch_event_, 0);
- EXPECT_EQ(gr.previously_handled_flag_, false);
-
- // Released event out of bounds. Should still go to v2
- v1->Reset();
- v2->Reset();
- TouchEvent released(ui::ET_TOUCH_RELEASED, 0, 0, 0, 0 /* first finger */,
- 1.0, 0.0, 1.0, 0.0);
- v2->last_touch_event_was_handled_ = true;
- root->OnTouchEvent(released);
- EXPECT_EQ(v2->last_touch_event_type_, ui::ET_TOUCH_RELEASED);
- EXPECT_EQ(v2->location_.x(), -100);
- EXPECT_EQ(v2->location_.y(), -100);
- // Make sure v1 did not receive the event
- EXPECT_EQ(v1->last_touch_event_type_, 0);
-
- EXPECT_EQ(gr.last_touch_event_, 0);
- EXPECT_EQ(gr.previously_handled_flag_, false);
-
- // Gesture event handling test.
- // 1) Test gesture type ui::ET_GESTURE_TAP_DOWN.
- v1->Reset();
- v4->Reset();
- gr.reset();
- gm.Reset();
-
- TouchEvent second_pressed(ui::ET_TOUCH_PRESSED,
- 210,
- 220,
- 0, /* no flags */
- 0, /* first finger touch */
- 1.0, 0.0, 1.0, 0.0);
- base::Time pressed_time = second_pressed.time_stamp();
- root->OnTouchEvent(second_pressed);
-
- // Since v1 and V4 didn't handled touch event, the gesture manager should
- // handle it.
- EXPECT_EQ(gr.last_touch_event_, ui::ET_TOUCH_PRESSED);
- EXPECT_EQ(gr.previously_handled_flag_, false);
-
- // Check v4 should receive gesture event but not v1.
- EXPECT_EQ(v1->last_touch_event_type_, 0);
- EXPECT_EQ(v4->last_touch_event_type_, 0);
- EXPECT_EQ(v4->last_gesture_event_type_, ui::ET_GESTURE_TAP_DOWN);
- EXPECT_EQ(v4->location_.x(), 10);
- EXPECT_EQ(v4->location_.y(), 20);
-
- // 2) Test gesture type ui::ET_GESTURE_TAP.
- v1->Reset();
- v4->Reset();
- gr.reset();
- gm.Reset();
-
- TouchEvent second_released(ui::ET_TOUCH_RELEASED,
- 210,
- 220,
- 0, /* no flags */
- 0, /* first finger touch */
- 1.0, 0.0, 1.0, 0.0);
-
- // Set touch time with-in click window.
- second_released.set_time_stamp(base::Time::FromDoubleT(
- pressed_time.ToDoubleT() + 0.7));
- root->OnTouchEvent(second_released);
-
- // Since v1 and V4 didn't handled touch event, the gesture manager should
- // handle it.
- EXPECT_EQ(gr.last_touch_event_, ui::ET_TOUCH_RELEASED);
- EXPECT_EQ(gr.previously_handled_flag_, false);
-
- // Check v4 should receive gesture event but not v1.
- EXPECT_EQ(v1->last_touch_event_type_, 0);
- EXPECT_EQ(v4->last_touch_event_type_, 0);
- EXPECT_EQ(v4->last_gesture_event_type_, ui::ET_GESTURE_TAP);
- EXPECT_EQ(v4->location_.x(), 10);
- EXPECT_EQ(v4->location_.y(), 20);
-
- // 3) Test Gesture to mouse conversion.
- // Views hierarchy for delivery of mouse event in absence of Touch and
- // Gesture handlers.
- TestView* v5 = new TestViewIgnoreTouchAndGesture();
- v5->SetBounds(0, 0, 300, 300);
-
- TestView* v6 = new TestViewIgnoreTouchAndGesture();
- v6->SetBounds(100, 100, 100, 100);
-
- root->AddChildView(v5);
- v5->AddChildView(v6);
-
- v5->Reset();
- v6->Reset();
- gr.reset();
- gm.Reset();
-
- TouchEvent third_pressed(ui::ET_TOUCH_PRESSED,
- 110,
- 120,
- 0, /* no flags */
- 0, /* first finger touch */
- 1.0, 0.0, 1.0, 0.0);
- root->OnTouchEvent(third_pressed);
-
- // Since v5 and V6 didn't handled touch and gesture event, gesture recognizer
- // and manager should recieve touch event.
- EXPECT_EQ(gr.last_touch_event_, ui::ET_TOUCH_PRESSED);
- EXPECT_EQ(gr.previously_handled_flag_, false);
- EXPECT_EQ(gm.previously_handled_flag_, false);
- EXPECT_EQ(gm.last_touch_event_, ui::ET_TOUCH_PRESSED);
- EXPECT_EQ(gm.last_view_, root);
- EXPECT_EQ(gm.dispatched_synthetic_event_, true);
-
- // Check v6 shouldn't recieve touch and gesture event but mouse event.
- EXPECT_EQ(v6->last_touch_event_type_, 0);
- EXPECT_EQ(v6->last_gesture_event_type_, 0);
-
- // Check v5 shouldn't recieve touch, gesture and mouse event.
- EXPECT_EQ(v5->last_touch_event_type_, 0);
- EXPECT_EQ(v5->last_gesture_event_type_, 0);
widget->CloseNow();
}
-#endif
////////////////////////////////////////////////////////////////////////////////
// Painting
diff --git a/ui/views/views.gyp b/ui/views/views.gyp
index 1bee26a..64171c6 100644
--- a/ui/views/views.gyp
+++ b/ui/views/views.gyp
@@ -312,10 +312,6 @@
'painter.h',
'repeat_controller.cc',
'repeat_controller.h',
- 'touchui/gesture_manager.cc',
- 'touchui/gesture_manager.h',
- 'touchui/gesture_recognizer.cc',
- 'touchui/gesture_recognizer.h',
'touchui/touch_selection_controller.cc',
'touchui/touch_selection_controller.h',
'view.cc',
diff --git a/ui/views/widget/native_widget_aura.cc b/ui/views/widget/native_widget_aura.cc
index f997344..13632fa 100644
--- a/ui/views/widget/native_widget_aura.cc
+++ b/ui/views/widget/native_widget_aura.cc
@@ -675,8 +675,8 @@ ui::TouchStatus NativeWidgetAura::OnTouchEvent(aura::TouchEvent* event) {
ui::GestureStatus NativeWidgetAura::OnGestureEvent(aura::GestureEvent* event) {
DCHECK(window_->IsVisible());
- // TODO(sad):
- return ui::GESTURE_STATUS_UNKNOWN;
+ GestureEvent gesture_event(event);
+ return delegate_->OnGestureEvent(gesture_event);
}
bool NativeWidgetAura::CanFocus() {
diff --git a/ui/views/widget/root_view.cc b/ui/views/widget/root_view.cc
index f6ac343..efb6361 100644
--- a/ui/views/widget/root_view.cc
+++ b/ui/views/widget/root_view.cc
@@ -15,8 +15,6 @@
#include "ui/gfx/compositor/layer.h"
#include "ui/views/focus/view_storage.h"
#include "ui/views/layout/fill_layout.h"
-#include "ui/views/touchui/gesture_manager.h"
-#include "ui/views/touchui/gesture_recognizer.h"
#include "ui/views/widget/widget.h"
namespace views {
@@ -39,9 +37,7 @@ RootView::RootView(Widget* widget)
last_mouse_event_flags_(0),
last_mouse_event_x_(-1),
last_mouse_event_y_(-1),
- gesture_manager_(GestureManager::GetInstance()),
touch_pressed_handler_(NULL),
- gesture_recognizer_(GestureRecognizer::GetInstance()),
gesture_handling_view_(NULL),
ALLOW_THIS_IN_INITIALIZER_LIST(focus_search_(this, false, false)),
focus_traversable_parent_(NULL),
@@ -340,8 +336,6 @@ ui::TouchStatus RootView::OnTouchEvent(const TouchEvent& event) {
if (touch_pressed_handler_) {
TouchEvent touch_event(e, this, touch_pressed_handler_);
status = touch_pressed_handler_->ProcessTouchEvent(touch_event);
- if (DoGestureProcessing(e, status))
- status = ui::TOUCH_STATUS_SYNTH_MOUSE;
if (status == ui::TOUCH_STATUS_END)
touch_pressed_handler_ = NULL;
return status;
@@ -352,8 +346,7 @@ ui::TouchStatus RootView::OnTouchEvent(const TouchEvent& event) {
touch_pressed_handler_ && (touch_pressed_handler_ != this);
touch_pressed_handler_ = touch_pressed_handler_->parent()) {
if (!touch_pressed_handler_->enabled()) {
- // Disabled views eat events but are treated as not handled by the
- // the GestureManager.
+ // Disabled views eat events but are treated as not handled.
status = ui::TOUCH_STATUS_UNKNOWN;
break;
}
@@ -379,17 +372,12 @@ ui::TouchStatus RootView::OnTouchEvent(const TouchEvent& event) {
if (status != ui::TOUCH_STATUS_START)
touch_pressed_handler_ = NULL;
- if (DoGestureProcessing(e, status))
- status = ui::TOUCH_STATUS_SYNTH_MOUSE;
return status;
}
// Reset touch_pressed_handler_ to indicate that no processing is occurring.
touch_pressed_handler_ = NULL;
- // Give the touch event to the gesture manager.
- if (gesture_manager_->ProcessTouchEventForGesture(e, this, status))
- status = ui::TOUCH_STATUS_SYNTH_MOUSE;
return status;
}
@@ -402,8 +390,7 @@ ui::GestureStatus RootView::OnGestureEvent(const GestureEvent& event) {
gesture_handling_view_ && (gesture_handling_view_ != this);
gesture_handling_view_ = gesture_handling_view_->parent()) {
if (!gesture_handling_view_->enabled()) {
- // Disabled views eat events but are treated as not handled by the
- // the GestureManager.
+ // Disabled views eat events but are treated as not handled.
return ui::GESTURE_STATUS_UNKNOWN;
}
@@ -498,35 +485,5 @@ void RootView::SetMouseLocationAndFlags(const MouseEvent& event) {
last_mouse_event_y_ = event.y();
}
-bool RootView::DoGestureProcessing(const TouchEvent& event,
- ui::TouchStatus status) {
- if (status != ui::TOUCH_STATUS_UNKNOWN)
- return false; // The event was consumed by a touch sequence.
-
- // Get the GestureEvent list processed from GestureRecognizer.
- scoped_ptr<GestureRecognizer::Gestures> gestures;
- gestures.reset(gesture_recognizer_->ProcessTouchEventForGesture(event,
- status));
- bool synthetic = true;
- for (unsigned int i = 0; i < gestures->size(); i++) {
- GestureEvent* event = gestures->at(i).get();
- GestureEvent e(*event, this);
- if (OnGestureEvent(e) == ui::GESTURE_STATUS_CONSUMED) {
- // All gesture events should be consumed.
- synthetic = false;
- } else {
- synthetic = true;
- break;
- }
- }
- if (synthetic) {
- // TODO(Gajen): This should be removed in future once all views are capable
- // of handling OnGestureEvent.
- return gesture_manager_->ProcessTouchEventForGesture(event, this,
- status);
- }
- return synthetic;
-}
-
} // namespace internal
} // namespace views
diff --git a/ui/views/widget/root_view.h b/ui/views/widget/root_view.h
index 2539676..7ae1316 100644
--- a/ui/views/widget/root_view.h
+++ b/ui/views/widget/root_view.h
@@ -20,8 +20,6 @@ enum TouchStatus;
namespace views {
class Widget;
-class GestureManager;
-class GestureRecognizer;
// This is a views-internal API and should not be used externally.
// Widget exposes this object as a View*.
@@ -70,12 +68,6 @@ class VIEWS_EXPORT RootView : public View, public FocusTraversable {
// it. Returns whether anyone consumed the event.
bool OnKeyEvent(const KeyEvent& event);
- // Provided only for testing:
- void SetGestureManagerForTesting(GestureManager* g) { gesture_manager_ = g; }
- void SetGestureRecognizerForTesting(GestureRecognizer* gr) {
- gesture_recognizer_ = gr;
- }
-
// Focus ---------------------------------------------------------------------
// Used to set the FocusTraversable parent after the view has been created
@@ -132,10 +124,6 @@ class VIEWS_EXPORT RootView : public View, public FocusTraversable {
friend class View;
friend class Widget;
- // Required so the GestureManager can call the Process* entry points
- // with synthetic events as necessary.
- friend class GestureManager;
-
// Input ---------------------------------------------------------------------
// Update the cursor given a mouse event. This is called by non mouse_move
@@ -150,10 +138,6 @@ class VIEWS_EXPORT RootView : public View, public FocusTraversable {
// be applied to the point prior to calling this).
void SetMouseLocationAndFlags(const MouseEvent& event);
- // Feeds touch event to GestureRecognizer.
- // Returns true if the event resulted in firing a synthetic event.
- bool DoGestureProcessing(const TouchEvent& event, ui::TouchStatus status);
-
//////////////////////////////////////////////////////////////////////////////
// Tree operations -----------------------------------------------------------
@@ -182,15 +166,9 @@ class VIEWS_EXPORT RootView : public View, public FocusTraversable {
int last_mouse_event_x_;
int last_mouse_event_y_;
- // The gesture_manager_ for this.
- GestureManager* gesture_manager_;
-
// The view currently handling touch events.
View* touch_pressed_handler_;
- // The gesture_recognizer_ for this.
- GestureRecognizer* gesture_recognizer_;
-
// The view currently handling gesture events.
View* gesture_handling_view_;