| Index: ui/views/widget/root_view.cc
|
| diff --git a/ui/views/widget/root_view.cc b/ui/views/widget/root_view.cc
|
| index c4978ca365c68809e163ea91b783934169c2c729..a8f4ef6ffc7c07efd5dffbea7f7476733c160c4e 100644
|
| --- a/ui/views/widget/root_view.cc
|
| +++ b/ui/views/widget/root_view.cc
|
| @@ -16,6 +16,7 @@
|
| #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 {
|
| @@ -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) {
|
| @@ -337,7 +340,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;
|
| @@ -376,7 +379,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;
|
| }
|
| @@ -390,6 +393,42 @@ ui::TouchStatus RootView::OnTouchEvent(const TouchEvent& event) {
|
| 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_->enabled()) {
|
| + // 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);
|
| @@ -418,6 +457,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;
|
| }
|
| }
|
|
|
| @@ -457,5 +498,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
|
|
|