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

Unified Diff: ui/views/widget/root_view.cc

Issue 10479010: Gesture related changes for views: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix test and add some mores Created 8 years, 6 months 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
« no previous file with comments | « ui/views/widget/root_view.h ('k') | ui/views/widget/widget.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/widget/root_view.cc
diff --git a/ui/views/widget/root_view.cc b/ui/views/widget/root_view.cc
index f2025c65bac54b89daa23778b407134cb2192458..6b6c14b0c1383ed390a9e35e5339a05d9143be25 100644
--- a/ui/views/widget/root_view.cc
+++ b/ui/views/widget/root_view.cc
@@ -66,7 +66,7 @@ RootView::RootView(Widget* widget)
last_mouse_event_x_(-1),
last_mouse_event_y_(-1),
touch_pressed_handler_(NULL),
- gesture_handling_view_(NULL),
+ gesture_handler_(NULL),
ALLOW_THIS_IN_INITIALIZER_LIST(focus_search_(this, false, false)),
focus_traversable_parent_(NULL),
focus_traversable_parent_view_(NULL) {
@@ -300,16 +300,24 @@ void RootView::OnMouseReleased(const MouseEvent& event) {
}
void RootView::OnMouseCaptureLost() {
- if (mouse_pressed_handler_) {
+ // TODO: this likely needs to reset touch handler too.
+
+ if (mouse_pressed_handler_ || gesture_handler_) {
// Synthesize a release event for UpdateCursor.
- MouseEvent release_event(ui::ET_MOUSE_RELEASED, last_mouse_event_x_,
- last_mouse_event_y_, last_mouse_event_flags_);
- UpdateCursor(release_event);
+ if (mouse_pressed_handler_) {
+ MouseEvent release_event(ui::ET_MOUSE_RELEASED, last_mouse_event_x_,
+ last_mouse_event_y_, last_mouse_event_flags_);
+ UpdateCursor(release_event);
+ }
// We allow the view to delete us from OnMouseCaptureLost. As such,
// configure state such that we're done first, then call View.
View* mouse_pressed_handler = mouse_pressed_handler_;
+ View* gesture_handler = gesture_handler_;
SetMouseHandler(NULL);
- mouse_pressed_handler->OnMouseCaptureLost();
+ if (mouse_pressed_handler)
+ mouse_pressed_handler->OnMouseCaptureLost();
+ else
+ gesture_handler->OnMouseCaptureLost();
// WARNING: we may have been deleted.
}
}
@@ -374,6 +382,10 @@ bool RootView::OnMouseWheel(const MouseWheelEvent& event) {
}
ui::TouchStatus RootView::OnTouchEvent(const TouchEvent& event) {
+ // TODO: this looks all wrong. On a TOUCH_PRESSED we should figure out the
+ // view and target that view with all touches with the same id until the
+ // release (or keep it if captured).
+
TouchEvent e(event, this);
// If touch_pressed_handler_ is non null, we are currently processing
@@ -433,23 +445,33 @@ ui::GestureStatus RootView::OnGestureEvent(const GestureEvent& event) {
GestureEvent e(event, this);
ui::GestureStatus status = ui::GESTURE_STATUS_UNKNOWN;
+ if (gesture_handler_) {
+ // Allow |gesture_handler_| to delete this during processing.
+ View* handler = gesture_handler_;
+ GestureEvent handler_event(event, this, gesture_handler_);
+ // TODO: should only do this for the last touch id that goes up.
+ if (event.type() == ui::ET_GESTURE_TAP_UP)
+ gesture_handler_ = NULL;
+ return handler->OnGestureEvent(handler_event);
+ }
+
// 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()) {
+ for (gesture_handler_ = GetEventHandlerForPoint(e.location());
+ gesture_handler_ && (gesture_handler_ != this);
+ gesture_handler_ = gesture_handler_->parent()) {
+ if (!gesture_handler_->enabled()) {
// Disabled views eat events but are treated as not handled.
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);
+ GestureEvent gesture_event(e, this, gesture_handler_);
+ status = gesture_handler_->OnGestureEvent(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_)
+ if (!gesture_handler_)
return ui::GESTURE_STATUS_UNKNOWN;
// The gesture event wasn't processed. Go up the view hierarchy and
@@ -461,13 +483,17 @@ ui::GestureStatus RootView::OnGestureEvent(const GestureEvent& event) {
else
return ui::GESTURE_STATUS_UNKNOWN;
}
+
+ gesture_handler_ = NULL;
+
return status;
}
-void RootView::SetMouseHandler(View *new_mh) {
+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);
mouse_pressed_handler_ = new_mh;
+ gesture_handler_ = new_mh;
drag_info_.Reset();
}
@@ -492,8 +518,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;
+ if (gesture_handler_ == child)
+ gesture_handler_ = NULL;
}
}
« no previous file with comments | « ui/views/widget/root_view.h ('k') | ui/views/widget/widget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698