summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-19 19:29:47 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-19 19:29:47 +0000
commitda77c28d914f2bde774beaf1a60fb05750836d56 (patch)
treea5bec75353350201711dd63d742c378e94ad7772 /views
parent46db5eaeb15f0fbc9a24e43315c902f3038cc0fe (diff)
downloadchromium_src-da77c28d914f2bde774beaf1a60fb05750836d56.zip
chromium_src-da77c28d914f2bde774beaf1a60fb05750836d56.tar.gz
chromium_src-da77c28d914f2bde774beaf1a60fb05750836d56.tar.bz2
touch: Gesture manager receives the touch-sequence status.
OnTouchEvent now returns the status of the touch sequence, instead of a simple bool. The gesture manager can presumably make a better decision if this information is available to it. For more details: http://codereview.chromium.org/6347002/ BUG=none TEST=ViewTest.TouchEvent Review URL: http://codereview.chromium.org/6253005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71824 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/touchui/gesture_manager.cc6
-rw-r--r--views/touchui/gesture_manager.h10
-rw-r--r--views/view_unittest.cc21
-rw-r--r--views/widget/root_view.cc12
4 files changed, 28 insertions, 21 deletions
diff --git a/views/touchui/gesture_manager.cc b/views/touchui/gesture_manager.cc
index 05e0ced..424470c 100644
--- a/views/touchui/gesture_manager.cc
+++ b/views/touchui/gesture_manager.cc
@@ -22,9 +22,9 @@ GestureManager* GestureManager::GetInstance() {
bool GestureManager::ProcessTouchEventForGesture(const TouchEvent& event,
View* source,
- bool previouslyHandled) {
- if (previouslyHandled)
- return false;
+ View::TouchStatus status) {
+ if (status != View::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
diff --git a/views/touchui/gesture_manager.h b/views/touchui/gesture_manager.h
index f26aa98..492a4e6 100644
--- a/views/touchui/gesture_manager.h
+++ b/views/touchui/gesture_manager.h
@@ -7,12 +7,11 @@
#pragma once
#include "base/singleton.h"
+#include "views/view.h"
namespace views {
-class View;
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
@@ -25,17 +24,16 @@ class GestureManager {
static GestureManager* GetInstance();
- // TODO(sad): Use TouchStatus instead of bool for previouslyHandled.
// 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, handled
- // specifies if the event was actually handled explicitly by a view so that
+ // 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,
- bool previouslyHandled);
+ View::TouchStatus status);
// TODO(rjkroege): Write the remainder of this class.
// It will appear in a subsequent CL.
diff --git a/views/view_unittest.cc b/views/view_unittest.cc
index 87f9e6a..9035b9e 100644
--- a/views/view_unittest.cc
+++ b/views/view_unittest.cc
@@ -178,6 +178,7 @@ class TestView : public View {
// TouchEvent
int last_touch_event_type_;
bool last_touch_event_was_handled_;
+ bool in_touch_sequence_;
#endif
// Painting
@@ -201,7 +202,7 @@ class MockGestureManager : public GestureManager {
bool ProcessTouchEventForGesture(const TouchEvent& event,
View* source,
- bool previouslyHandled);
+ View::TouchStatus status);
MockGestureManager();
bool previously_handled_flag_;
@@ -414,14 +415,14 @@ TEST_F(ViewTest, MouseEvent) {
bool MockGestureManager::ProcessTouchEventForGesture(
const TouchEvent& event,
View* source,
- bool previouslyHandled) {
- if (previouslyHandled) {
+ View::TouchStatus status) {
+ if (status != View::TOUCH_STATUS_UNKNOWN) {
dispatched_synthetic_event_ = false;
return false;
}
last_touch_event_ = event.GetType();
last_view_ = source;
- previously_handled_flag_ = previouslyHandled;
+ previously_handled_flag_ = status != View::TOUCH_STATUS_UNKNOWN;
dispatched_synthetic_event_ = true;
return true;
}
@@ -432,6 +433,18 @@ MockGestureManager::MockGestureManager() {
View::TouchStatus TestView::OnTouchEvent(const TouchEvent& event) {
last_touch_event_type_ = event.GetType();
location_.SetPoint(event.x(), event.y());
+ if (!in_touch_sequence_) {
+ if (event.GetType() == Event::ET_TOUCH_PRESSED) {
+ in_touch_sequence_ = true;
+ return TOUCH_STATUS_START;
+ }
+ } else {
+ if (event.GetType() == Event::ET_TOUCH_RELEASED) {
+ in_touch_sequence_ = false;
+ return TOUCH_STATUS_END;
+ }
+ return TOUCH_STATUS_CONTINUE;
+ }
return last_touch_event_was_handled_ ? TOUCH_STATUS_CONTINUE :
TOUCH_STATUS_UNKNOWN;
}
diff --git a/views/widget/root_view.cc b/views/widget/root_view.cc
index a124e60..3106e33 100644
--- a/views/widget/root_view.cc
+++ b/views/widget/root_view.cc
@@ -315,13 +315,12 @@ View::TouchStatus RootView::OnTouchEvent(const TouchEvent& e) {
if (touch_pressed_handler_) {
TouchEvent touch_event(e, this, touch_pressed_handler_);
status = touch_pressed_handler_->ProcessTouchEvent(touch_event);
- gesture_manager_->ProcessTouchEventForGesture(e, this, true);
+ gesture_manager_->ProcessTouchEventForGesture(e, this, status);
if (status == TOUCH_STATUS_END)
touch_pressed_handler_ = NULL;
return status;
}
- bool handled = false;
// Walk up the tree until we find a view that wants the touch event.
for (touch_pressed_handler_ = GetViewForPoint(e.location());
touch_pressed_handler_ && (touch_pressed_handler_ != this);
@@ -329,7 +328,6 @@ View::TouchStatus RootView::OnTouchEvent(const TouchEvent& e) {
if (!touch_pressed_handler_->IsEnabled()) {
// Disabled views eat events but are treated as not handled by the
// the GestureManager.
- handled = false;
status = TOUCH_STATUS_UNKNOWN;
break;
}
@@ -343,8 +341,6 @@ View::TouchStatus RootView::OnTouchEvent(const TouchEvent& e) {
if (status != TOUCH_STATUS_START)
touch_pressed_handler_ = NULL;
- handled = status != TOUCH_STATUS_UNKNOWN;
-
// The view could have removed itself from the tree when handling
// OnTouchEvent(). So handle as per OnMousePressed. NB: we
// assume that the RootView itself cannot be so removed.
@@ -357,8 +353,8 @@ View::TouchStatus RootView::OnTouchEvent(const TouchEvent& e) {
// If the view handled the event, leave touch_pressed_handler_ set and
// return true, which will cause subsequent drag/release events to get
// forwarded to that view.
- if (handled) {
- gesture_manager_->ProcessTouchEventForGesture(e, this, handled);
+ if (status != TOUCH_STATUS_UNKNOWN) {
+ gesture_manager_->ProcessTouchEventForGesture(e, this, status);
return status;
}
}
@@ -367,7 +363,7 @@ View::TouchStatus RootView::OnTouchEvent(const TouchEvent& e) {
touch_pressed_handler_ = NULL;
// Give the touch event to the gesture manager.
- gesture_manager_->ProcessTouchEventForGesture(e, this, handled);
+ gesture_manager_->ProcessTouchEventForGesture(e, this, status);
return status;
}
#endif