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

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

Issue 12207092: views: Dispatch key, touch, scroll and gesture events using the EventDispatch interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tot-merge-before-land Created 7 years, 10 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') | no next file » | 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 02a772ef4bb8a722aff5af3f2679c672a1668dfc..01d8b0209c8981735238ea1000c5e9ff8d21c94f 100644
--- a/ui/views/widget/root_view.cc
+++ b/ui/views/widget/root_view.cc
@@ -71,7 +71,8 @@ RootView::RootView(Widget* widget)
scroll_gesture_handler_(NULL),
ALLOW_THIS_IN_INITIALIZER_LIST(focus_search_(this, false, false)),
focus_traversable_parent_(NULL),
- focus_traversable_parent_view_(NULL) {
+ focus_traversable_parent_view_(NULL),
+ event_dispatch_target_(NULL) {
}
RootView::~RootView() {
@@ -112,8 +113,6 @@ void RootView::NotifyNativeViewHierarchyChanged(bool attached,
// Input -----------------------------------------------------------------------
void RootView::DispatchKeyEvent(ui::KeyEvent* event) {
- bool consumed = false;
-
View* v = NULL;
if (GetFocusManager()) // NULL in unittests.
v = GetFocusManager()->GetFocusedView();
@@ -125,19 +124,15 @@ void RootView::DispatchKeyEvent(ui::KeyEvent* event) {
event->StopPropagation();
return;
}
- for (; v && v != this && !consumed; v = v->parent()) {
- consumed = (event->type() == ui::ET_KEY_PRESSED) ?
- v->OnKeyPressed(*event) : v->OnKeyReleased(*event);
- }
- if (consumed)
- event->StopPropagation();
+ for (; v && v != this && !event->handled(); v = v->parent())
+ DispatchEventToTarget(v, event);
}
void RootView::DispatchScrollEvent(ui::ScrollEvent* event) {
for (View* v = GetEventHandlerForPoint(event->location());
v && v != this && !event->stopped_propagation(); v = v->parent()) {
- v->OnScrollEvent(event);
+ DispatchEventToTarget(v, event);
}
if (event->handled() || event->type() != ui::ET_SCROLL)
@@ -177,7 +172,7 @@ void RootView::DispatchTouchEvent(ui::TouchEvent* event) {
if (touch_pressed_handler_) {
ui::TouchEvent touch_event(*event, static_cast<View*>(this),
touch_pressed_handler_);
- touch_pressed_handler_->ProcessTouchEvent(&touch_event);
+ DispatchEventToTarget(touch_pressed_handler_, &touch_event);
if (touch_event.handled())
event->SetHandled();
if (touch_event.stopped_propagation())
@@ -197,7 +192,7 @@ void RootView::DispatchTouchEvent(ui::TouchEvent* event) {
// See if this view wants to handle the touch
ui::TouchEvent touch_event(*event, static_cast<View*>(this),
touch_pressed_handler_);
- touch_pressed_handler_->ProcessTouchEvent(&touch_event);
+ DispatchEventToTarget(touch_pressed_handler_, &touch_event);
if (touch_event.handled())
event->SetHandled();
if (touch_event.stopped_propagation())
@@ -236,7 +231,7 @@ void RootView::DispatchGestureEvent(ui::GestureEvent* event) {
(event->IsScrollGestureEvent() || event->IsFlingScrollEvent()) ?
scroll_gesture_handler_ : gesture_handler_;
ui::GestureEvent handler_event(*event, static_cast<View*>(this), handler);
- handler->ProcessGestureEvent(&handler_event);
+ DispatchEventToTarget(handler, &handler_event);
if (event->type() == ui::ET_GESTURE_END &&
event->details().touch_points() <= 1) {
@@ -273,7 +268,7 @@ void RootView::DispatchGestureEvent(ui::GestureEvent* event) {
scroll_gesture_handler_ = scroll_gesture_handler_->parent()) {
ui::GestureEvent gesture_event(*event, static_cast<View*>(this),
scroll_gesture_handler_);
- scroll_gesture_handler_->ProcessGestureEvent(&gesture_event);
+ DispatchEventToTarget(scroll_gesture_handler_, &gesture_event);
if (gesture_event.stopped_propagation()) {
event->StopPropagation();
return;
@@ -311,7 +306,7 @@ void RootView::DispatchGestureEvent(ui::GestureEvent* event) {
// See if this view wants to handle the Gesture.
ui::GestureEvent gesture_event(*event, static_cast<View*>(this),
gesture_handler_);
- gesture_handler_->ProcessGestureEvent(&gesture_event);
+ DispatchEventToTarget(gesture_handler_, &gesture_event);
// The view could have removed itself from the tree when handling
// OnGestureEvent(). So handle as per OnMousePressed. NB: we
@@ -632,6 +627,8 @@ void RootView::ViewHierarchyChanged(bool is_add, View* parent, View* child) {
gesture_handler_ = NULL;
if (scroll_gesture_handler_ == child)
scroll_gesture_handler_ = NULL;
+ if (event_dispatch_target_ == child)
+ event_dispatch_target_ = NULL;
}
}
@@ -673,5 +670,16 @@ void RootView::SetMouseLocationAndFlags(const ui::MouseEvent& event) {
last_mouse_event_y_ = event.y();
}
+void RootView::DispatchEventToTarget(View* target, ui::Event* event) {
+ View* old_target = event_dispatch_target_;
+ event_dispatch_target_ = target;
+ if (DispatchEvent(target, event))
+ event_dispatch_target_ = old_target;
+}
+
+bool RootView::CanDispatchToTarget(ui::EventTarget* target) {
+ return event_dispatch_target_ == target;
+}
+
} // namespace internal
} // namespace views
« no previous file with comments | « ui/views/widget/root_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698