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() {
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
......
......@@ -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.
......
......@@ -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;
}
......
......@@ -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
......
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