Chromium Code Reviews| Index: views/widget/root_view.cc |
| diff --git a/views/widget/root_view.cc b/views/widget/root_view.cc |
| index 878e236bfa7bcde41a3e8a02b5a6c04c05536e86..a9755f0259fa4bc1b60801a26edd24c95981239c 100644 |
| --- a/views/widget/root_view.cc |
| +++ b/views/widget/root_view.cc |
| @@ -6,8 +6,10 @@ |
| #include <algorithm> |
| +#include "base/command_line.h" |
| #include "base/logging.h" |
| #include "base/message_loop.h" |
| +#include "chrome/common/chrome_switches.h" |
|
Ian Vollick
2011/11/08 20:07:54
views/ is not allowed to depend on chrome/, so you
Gajen
2011/11/10 15:52:55
Deprecated, as no longer required in new Design.
|
| #include "ui/base/accessibility/accessible_view_state.h" |
| #include "ui/base/dragdrop/drag_drop_types.h" |
| #include "ui/base/keycodes/keyboard_codes.h" |
| @@ -38,11 +40,18 @@ RootView::RootView(Widget* widget) |
| last_mouse_event_flags_(0), |
| last_mouse_event_x_(-1), |
| last_mouse_event_y_(-1), |
| - gesture_manager_(GestureManager::GetInstance()), |
| + gesture_manager_(NULL), |
| touch_pressed_handler_(NULL), |
| + gesture_handling_view_(NULL), |
| ALLOW_THIS_IN_INITIALIZER_LIST(focus_search_(this, false, false)), |
| focus_traversable_parent_(NULL), |
| focus_traversable_parent_view_(NULL) { |
| + // TODO(Gajen): Refactor gesture recognizer integration with new approach |
| + // proposed in http://codereview.chromium.org/8364039/. |
| + if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableGesture)) |
| + gesture_manager_ = GestureRecognizer::GetInstance(); |
| + else |
| + gesture_manager_ = GestureManager::GetInstance(); |
| } |
| RootView::~RootView() { |
| @@ -400,6 +409,52 @@ void RootView::GetAccessibleState(ui::AccessibleViewState* state) { |
| state->role = ui::AccessibilityTypes::ROLE_APPLICATION; |
| } |
| +bool RootView::ForwardGestureEvents(GestureRecognizer::Gestures* gestures) { |
| + scoped_ptr<GestureRecognizer::Gestures> events; |
| + events.reset(gestures); |
| + bool return_value = false; |
| + for (unsigned int i = 0; i < events->size(); i++) { |
| + GestureEvent* event = gestures->at(i).GetGestureEvent(); |
| + 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. |
| + status = ui::GESTURE_STATUS_UNKNOWN; |
| + break; |
| + } |
| + |
| + // 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_) |
| + break; |
| + |
| + // 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_value = true; |
| + } else { |
| + return_value = false; |
| + } |
| + } |
| + if (!return_value) return false; |
| + } |
| + return return_value; |
| +} |
| + |
| //////////////////////////////////////////////////////////////////////////////// |
| // RootView, protected: |
| @@ -413,6 +468,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; |
| } |
| } |