Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(703)

Unified Diff: views/widget/root_view.cc

Issue 8364039: Initial views touchui GestureRecognizer support (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Reverted chrome_switches.cc changes and TOT sync up Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: views/widget/root_view.cc
diff --git a/views/widget/root_view.cc b/views/widget/root_view.cc
index a9cb2b349a48e5b402307b5477f5ea0a81e1e7cb..f4775db7a5de5fe898db22a37ccbfd1d3f9d9381 100644
--- a/views/widget/root_view.cc
+++ b/views/widget/root_view.cc
@@ -16,6 +16,7 @@
#include "views/focus/view_storage.h"
#include "views/layout/fill_layout.h"
#include "views/touchui/gesture_manager.h"
+#include "views/touchui/gesture_recognizer.h"
#include "views/widget/widget.h"
namespace views {
@@ -40,6 +41,8 @@ RootView::RootView(Widget* widget)
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),
focus_traversable_parent_view_(NULL) {
@@ -336,7 +339,7 @@ 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 (gesture_manager_->ProcessTouchEventForGesture(e, this, status))
+ if (DoGestureProcessing(e, status))
status = ui::TOUCH_STATUS_SYNTH_MOUSE;
if (status == ui::TOUCH_STATUS_END)
touch_pressed_handler_ = NULL;
@@ -375,7 +378,7 @@ ui::TouchStatus RootView::OnTouchEvent(const TouchEvent& event) {
if (status != ui::TOUCH_STATUS_START)
touch_pressed_handler_ = NULL;
- if (gesture_manager_->ProcessTouchEventForGesture(e, this, status))
+ if (DoGestureProcessing(e, status))
status = ui::TOUCH_STATUS_SYNTH_MOUSE;
return status;
}
@@ -384,11 +387,47 @@ ui::TouchStatus RootView::OnTouchEvent(const TouchEvent& event) {
touch_pressed_handler_ = NULL;
// Give the touch event to the gesture manager.
- if (gesture_manager_->ProcessTouchEventForGesture(e, this, status))
+ if (DoGestureProcessing(e, status))
status = ui::TOUCH_STATUS_SYNTH_MOUSE;
return status;
}
+ui::GestureStatus RootView::OnGestureEvent(const GestureEvent& event) {
+ GestureEvent e(event, this);
+ ui::GestureStatus status = ui::GESTURE_STATUS_UNKNOWN;
+
+ // Walk up the tree until we find a view that wants the gesture event.
+ for (gesture_handling_view_ = GetEventHandlerForPoint(e.location());
+ gesture_handling_view_ && (gesture_handling_view_ != this);
+ gesture_handling_view_ = gesture_handling_view_->parent()) {
+ if (!gesture_handling_view_->IsEnabled()) {
+ // Disabled views eat events but are treated as not handled by the
+ // the GestureManager.
+ return ui::GESTURE_STATUS_UNKNOWN;
+ }
+
+ // See if this view wants to handle the Gesture.
+ GestureEvent gesture_event(e, this, gesture_handling_view_);
+ status = gesture_handling_view_->ProcessGestureEvent(gesture_event);
+
+ // The view could have removed itself from the tree when handling
+ // OnGestureEvent(). So handle as per OnMousePressed. NB: we
+ // assume that the RootView itself cannot be so removed.
+ if (!gesture_handling_view_) return ui::GESTURE_STATUS_UNKNOWN;
+
+ // The gesture event wasn't processed. Go up the view hierarchy and
+ // dispatch the gesture event.
+ if (status == ui::GESTURE_STATUS_UNKNOWN) {
+ continue;
+ } else if (status == ui::GESTURE_STATUS_CONSUMED) {
+ return status;
+ } else {
+ return ui::GESTURE_STATUS_UNKNOWN;
+ }
+ }
+ return status;
+}
+
void RootView::SetMouseHandler(View *new_mh) {
// If we're clearing the mouse handler, clear explicit_mouse_handler_ as well.
explicit_mouse_handler_ = (new_mh != NULL);
@@ -412,6 +451,8 @@ void RootView::ViewHierarchyChanged(bool is_add, View* parent, View* child) {
mouse_move_handler_ = NULL;
if (touch_pressed_handler_ == child)
touch_pressed_handler_ = NULL;
+ if (gesture_handling_view_ == child)
+ gesture_handling_view_ = NULL;
}
}
@@ -451,5 +492,35 @@ 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
« views/views.gyp ('K') | « views/widget/root_view.h ('k') | views/widget/widget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698