Commit da77c28d authored by sadrul@chromium.org's avatar sadrul@chromium.org

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
parent 46db5eae
...@@ -22,9 +22,9 @@ GestureManager* GestureManager::GetInstance() { ...@@ -22,9 +22,9 @@ GestureManager* GestureManager::GetInstance() {
bool GestureManager::ProcessTouchEventForGesture(const TouchEvent& event, bool GestureManager::ProcessTouchEventForGesture(const TouchEvent& event,
View* source, View* source,
bool previouslyHandled) { View::TouchStatus status) {
if (previouslyHandled) if (status != View::TOUCH_STATUS_UNKNOWN)
return false; return false; // The event was consumed by a touch sequence.
// TODO(rjkroege): A realistic version of the GestureManager will // TODO(rjkroege): A realistic version of the GestureManager will
// appear in a subsequent CL. This interim version permits verifying that the // appear in a subsequent CL. This interim version permits verifying that the
......
...@@ -7,12 +7,11 @@ ...@@ -7,12 +7,11 @@
#pragma once #pragma once
#include "base/singleton.h" #include "base/singleton.h"
#include "views/view.h"
namespace views { namespace views {
class View;
class TouchEvent; class TouchEvent;
// A GestureManager singleton detects gestures occurring in the // A GestureManager singleton detects gestures occurring in the
// incoming feed of touch events across all of the RootViews in // incoming feed of touch events across all of the RootViews in
// the system. In response to a given touch event, the GestureManager // the system. In response to a given touch event, the GestureManager
...@@ -25,17 +24,16 @@ class GestureManager { ...@@ -25,17 +24,16 @@ class GestureManager {
static GestureManager* GetInstance(); static GestureManager* GetInstance();
// TODO(sad): Use TouchStatus instead of bool for previouslyHandled.
// Invoked for each touch event that could contribute to the current gesture. // 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 // Takes the event and the View that originated it and which will also
// be the target of any generated synthetic event. Finally, handled // be the target of any generated synthetic event. Finally, status
// specifies if the event was actually handled explicitly by a view so that // specifies if a touch sequence is in progress or not, so that the
// GestureManager state can correctly reflect events that are handled // GestureManager state can correctly reflect events that are handled
// already. // already.
// Returns true if the event resulted in firing a synthetic event. // Returns true if the event resulted in firing a synthetic event.
virtual bool ProcessTouchEventForGesture(const TouchEvent& event, virtual bool ProcessTouchEventForGesture(const TouchEvent& event,
View* source, View* source,
bool previouslyHandled); View::TouchStatus status);
// TODO(rjkroege): Write the remainder of this class. // TODO(rjkroege): Write the remainder of this class.
// It will appear in a subsequent CL. // It will appear in a subsequent CL.
......
...@@ -178,6 +178,7 @@ class TestView : public View { ...@@ -178,6 +178,7 @@ class TestView : public View {
// TouchEvent // TouchEvent
int last_touch_event_type_; int last_touch_event_type_;
bool last_touch_event_was_handled_; bool last_touch_event_was_handled_;
bool in_touch_sequence_;
#endif #endif
// Painting // Painting
...@@ -201,7 +202,7 @@ class MockGestureManager : public GestureManager { ...@@ -201,7 +202,7 @@ class MockGestureManager : public GestureManager {
bool ProcessTouchEventForGesture(const TouchEvent& event, bool ProcessTouchEventForGesture(const TouchEvent& event,
View* source, View* source,
bool previouslyHandled); View::TouchStatus status);
MockGestureManager(); MockGestureManager();
bool previously_handled_flag_; bool previously_handled_flag_;
...@@ -414,14 +415,14 @@ TEST_F(ViewTest, MouseEvent) { ...@@ -414,14 +415,14 @@ TEST_F(ViewTest, MouseEvent) {
bool MockGestureManager::ProcessTouchEventForGesture( bool MockGestureManager::ProcessTouchEventForGesture(
const TouchEvent& event, const TouchEvent& event,
View* source, View* source,
bool previouslyHandled) { View::TouchStatus status) {
if (previouslyHandled) { if (status != View::TOUCH_STATUS_UNKNOWN) {
dispatched_synthetic_event_ = false; dispatched_synthetic_event_ = false;
return false; return false;
} }
last_touch_event_ = event.GetType(); last_touch_event_ = event.GetType();
last_view_ = source; last_view_ = source;
previously_handled_flag_ = previouslyHandled; previously_handled_flag_ = status != View::TOUCH_STATUS_UNKNOWN;
dispatched_synthetic_event_ = true; dispatched_synthetic_event_ = true;
return true; return true;
} }
...@@ -432,6 +433,18 @@ MockGestureManager::MockGestureManager() { ...@@ -432,6 +433,18 @@ MockGestureManager::MockGestureManager() {
View::TouchStatus TestView::OnTouchEvent(const TouchEvent& event) { View::TouchStatus TestView::OnTouchEvent(const TouchEvent& event) {
last_touch_event_type_ = event.GetType(); last_touch_event_type_ = event.GetType();
location_.SetPoint(event.x(), event.y()); 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 : return last_touch_event_was_handled_ ? TOUCH_STATUS_CONTINUE :
TOUCH_STATUS_UNKNOWN; TOUCH_STATUS_UNKNOWN;
} }
......
...@@ -315,13 +315,12 @@ View::TouchStatus RootView::OnTouchEvent(const TouchEvent& e) { ...@@ -315,13 +315,12 @@ View::TouchStatus RootView::OnTouchEvent(const TouchEvent& e) {
if (touch_pressed_handler_) { if (touch_pressed_handler_) {
TouchEvent touch_event(e, this, touch_pressed_handler_); TouchEvent touch_event(e, this, touch_pressed_handler_);
status = touch_pressed_handler_->ProcessTouchEvent(touch_event); status = touch_pressed_handler_->ProcessTouchEvent(touch_event);
gesture_manager_->ProcessTouchEventForGesture(e, this, true); gesture_manager_->ProcessTouchEventForGesture(e, this, status);
if (status == TOUCH_STATUS_END) if (status == TOUCH_STATUS_END)
touch_pressed_handler_ = NULL; touch_pressed_handler_ = NULL;
return status; return status;
} }
bool handled = false;
// Walk up the tree until we find a view that wants the touch event. // Walk up the tree until we find a view that wants the touch event.
for (touch_pressed_handler_ = GetViewForPoint(e.location()); for (touch_pressed_handler_ = GetViewForPoint(e.location());
touch_pressed_handler_ && (touch_pressed_handler_ != this); touch_pressed_handler_ && (touch_pressed_handler_ != this);
...@@ -329,7 +328,6 @@ View::TouchStatus RootView::OnTouchEvent(const TouchEvent& e) { ...@@ -329,7 +328,6 @@ View::TouchStatus RootView::OnTouchEvent(const TouchEvent& e) {
if (!touch_pressed_handler_->IsEnabled()) { if (!touch_pressed_handler_->IsEnabled()) {
// Disabled views eat events but are treated as not handled by the // Disabled views eat events but are treated as not handled by the
// the GestureManager. // the GestureManager.
handled = false;
status = TOUCH_STATUS_UNKNOWN; status = TOUCH_STATUS_UNKNOWN;
break; break;
} }
...@@ -343,8 +341,6 @@ View::TouchStatus RootView::OnTouchEvent(const TouchEvent& e) { ...@@ -343,8 +341,6 @@ View::TouchStatus RootView::OnTouchEvent(const TouchEvent& e) {
if (status != TOUCH_STATUS_START) if (status != TOUCH_STATUS_START)
touch_pressed_handler_ = NULL; touch_pressed_handler_ = NULL;
handled = status != TOUCH_STATUS_UNKNOWN;
// The view could have removed itself from the tree when handling // The view could have removed itself from the tree when handling
// OnTouchEvent(). So handle as per OnMousePressed. NB: we // OnTouchEvent(). So handle as per OnMousePressed. NB: we
// assume that the RootView itself cannot be so removed. // assume that the RootView itself cannot be so removed.
...@@ -357,8 +353,8 @@ View::TouchStatus RootView::OnTouchEvent(const TouchEvent& e) { ...@@ -357,8 +353,8 @@ View::TouchStatus RootView::OnTouchEvent(const TouchEvent& e) {
// If the view handled the event, leave touch_pressed_handler_ set and // If the view handled the event, leave touch_pressed_handler_ set and
// return true, which will cause subsequent drag/release events to get // return true, which will cause subsequent drag/release events to get
// forwarded to that view. // forwarded to that view.
if (handled) { if (status != TOUCH_STATUS_UNKNOWN) {
gesture_manager_->ProcessTouchEventForGesture(e, this, handled); gesture_manager_->ProcessTouchEventForGesture(e, this, status);
return status; return status;
} }
} }
...@@ -367,7 +363,7 @@ View::TouchStatus RootView::OnTouchEvent(const TouchEvent& e) { ...@@ -367,7 +363,7 @@ View::TouchStatus RootView::OnTouchEvent(const TouchEvent& e) {
touch_pressed_handler_ = NULL; touch_pressed_handler_ = NULL;
// Give the touch event to the gesture manager. // Give the touch event to the gesture manager.
gesture_manager_->ProcessTouchEventForGesture(e, this, handled); gesture_manager_->ProcessTouchEventForGesture(e, this, status);
return status; return status;
} }
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment