diff options
author | rjkroege@google.com <rjkroege@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-08 14:06:10 +0000 |
---|---|---|
committer | rjkroege@google.com <rjkroege@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-08 14:06:10 +0000 |
commit | ad84c8f53a2973e4d752de9fe8c52e3268a867e1 (patch) | |
tree | cb330cc04d3b0dd3a93eca847e367d794310653c /views/widget | |
parent | 2229e8264e786f5265bf5c0a6265d5aa3dfaf713 (diff) | |
download | chromium_src-ad84c8f53a2973e4d752de9fe8c52e3268a867e1.zip chromium_src-ad84c8f53a2973e4d752de9fe8c52e3268a867e1.tar.gz chromium_src-ad84c8f53a2973e4d752de9fe8c52e3268a867e1.tar.bz2 |
Added entry points to view/View to dispatch and process TouchEvents.
This change is part of a series of changes to bring TouchEvent
processing to views.
BUG=na
TESTED=compiled with and without touchui
Review URL: http://codereview.chromium.org/3192002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58823 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/widget')
-rw-r--r-- | views/widget/root_view.cc | 65 | ||||
-rw-r--r-- | views/widget/root_view.h | 29 |
2 files changed, 92 insertions, 2 deletions
diff --git a/views/widget/root_view.cc b/views/widget/root_view.cc index 20464cc..8b8f896 100644 --- a/views/widget/root_view.cc +++ b/views/widget/root_view.cc @@ -16,6 +16,10 @@ #include "views/widget/widget.h" #include "views/window/window.h" +#if defined(TOUCH_UI) +#include "views/touchui/gesture_manager.h" +#endif + #if defined(OS_LINUX) #include "views/widget/widget_gtk.h" #endif // defined(OS_LINUX) @@ -76,6 +80,11 @@ RootView::RootView(Widget* widget) focus_traversable_parent_(NULL), focus_traversable_parent_view_(NULL), drag_view_(NULL) +#if defined(TOUCH_UI) + , + gesture_manager_(GestureManager::Get()), + touch_pressed_handler_(NULL) +#endif #ifndef NDEBUG , is_processing_paint_(false) @@ -289,6 +298,62 @@ void RootView::SetFocusOnMousePressed(bool f) { focus_on_mouse_pressed_ = f; } +#if defined(TOUCH_UI) +bool RootView::OnTouchEvent(const TouchEvent& e) { + // If touch_pressed_handler_ is non null, we are currently processing + // a touch down on the screen situation. In that case we send the + // event to touch_pressed_handler_ + + if (touch_pressed_handler_) { + TouchEvent touch_event(e, this, touch_pressed_handler_); + touch_pressed_handler_->ProcessTouchEvent(touch_event); + gesture_manager_->ProcessTouchEventForGesture(e, this, true); + return true; + } + + 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); + touch_pressed_handler_ = touch_pressed_handler_->GetParent()) { + if (!touch_pressed_handler_->IsEnabled()) { + // Disabled views eat events but are treated as not handled by the + // the GestureManager. + handled = false; + break; + } + + // See if this view wants to handle the touch + TouchEvent touch_event(e, this, touch_pressed_handler_); + handled = touch_pressed_handler_->ProcessTouchEvent(touch_event); + + // 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. + // + // NOTE: Don't return true here, because we don't want the frame to + // forward future events to us when there's no handler. + if (!touch_pressed_handler_) + break; + + // 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); + return true; + } + } + + // Reset touch_pressed_handler_ to indicate that no processing is occurring. + touch_pressed_handler_ = NULL; + + // Give the touch event to the gesture manager. + gesture_manager_->ProcessTouchEventForGesture(e, this, handled); + return handled; +} +#endif + bool RootView::OnMousePressed(const MouseEvent& e) { // This function does not normally handle non-client messages except for // non-client double-clicks. Actually, all double-clicks are special as the diff --git a/views/widget/root_view.h b/views/widget/root_view.h index c749bc8..91c1672 100644 --- a/views/widget/root_view.h +++ b/views/widget/root_view.h @@ -22,6 +22,10 @@ namespace views { class PaintTask; class Widget; +#if defined(TOUCH_UI) +class GestureManager; +#endif + ///////////////////////////////////////////////////////////////////////////// // // RootView class @@ -93,6 +97,9 @@ class RootView : public View, virtual void OnMouseReleased(const MouseEvent& e, bool canceled); virtual void OnMouseMoved(const MouseEvent& e); virtual void SetMouseHandler(View* new_mouse_handler); +#if defined(TOUCH_UI) + virtual bool OnTouchEvent(const TouchEvent& e); +#endif // Invoked By the Widget if the mouse drag is interrupted by // the system. Invokes OnMouseReleased with a value of true for canceled. @@ -175,6 +182,12 @@ class RootView : public View, // Accessibility accessors/mutators, overridden from View. virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); +#if defined(TOUCH_UI) && defined(UNIT_TEST) + // For unit testing purposes, we use this method to set a mock + // GestureManager + void SetGestureManager(GestureManager* g) { gesture_manager_ = g; } +#endif + protected: // Overridden to properly reset our event propagation member @@ -189,6 +202,12 @@ class RootView : public View, friend class View; friend class PaintTask; +#if defined(TOUCH_UI) + // Required so the GestureManager can call the Process* entry points + // with synthetic events as necessary. + friend class GestureManager; +#endif + RootView(); // Convert a point to our current mouse handler. Returns false if the @@ -321,14 +340,20 @@ class RootView : public View, // view the drag started from. View* drag_view_; +#if defined(TOUCH_UI) + // The gesture_manager_ for this. + GestureManager* gesture_manager_; + + // The view currently handling touch events. + View *touch_pressed_handler_; +#endif + #ifndef NDEBUG // True if we're currently processing paint. bool is_processing_paint_; #endif - DISALLOW_COPY_AND_ASSIGN(RootView); }; - } // namespace views #endif // VIEWS_WIDGET_ROOT_VIEW_H_ |