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

Side by Side Diff: ui/views/widget/root_view.cc

Issue 481433006: Support targeting for gestures in ViewTargeter (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: whitespace Created 6 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« ui/views/widget/root_view.h ('K') | « ui/views/widget/root_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/widget/root_view.h" 5 #include "ui/views/widget/root_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "ui/accessibility/ax_view_state.h" 11 #include "ui/accessibility/ax_view_state.h"
12 #include "ui/base/cursor/cursor.h" 12 #include "ui/base/cursor/cursor.h"
13 #include "ui/base/dragdrop/drag_drop_types.h" 13 #include "ui/base/dragdrop/drag_drop_types.h"
14 #include "ui/base/ui_base_switches_util.h" 14 #include "ui/base/ui_base_switches_util.h"
15 #include "ui/compositor/layer.h" 15 #include "ui/compositor/layer.h"
16 #include "ui/events/event.h" 16 #include "ui/events/event.h"
17 #include "ui/events/keycodes/keyboard_codes.h" 17 #include "ui/events/keycodes/keyboard_codes.h"
18 #include "ui/gfx/canvas.h" 18 #include "ui/gfx/canvas.h"
19 #include "ui/views/drag_controller.h" 19 #include "ui/views/drag_controller.h"
20 #include "ui/views/focus/view_storage.h" 20 #include "ui/views/focus/view_storage.h"
21 #include "ui/views/layout/fill_layout.h" 21 #include "ui/views/layout/fill_layout.h"
22 #include "ui/views/view_targeter.h" 22 #include "ui/views/view_targeter.h"
23 #include "ui/views/views_switches.h"
24 #include "ui/views/widget/widget.h" 23 #include "ui/views/widget/widget.h"
25 #include "ui/views/widget/widget_delegate.h" 24 #include "ui/views/widget/widget_delegate.h"
26 25
27 typedef ui::EventDispatchDetails DispatchDetails; 26 typedef ui::EventDispatchDetails DispatchDetails;
28 27
29 namespace views { 28 namespace views {
30 namespace internal { 29 namespace internal {
31 30
32 namespace { 31 namespace {
33 32
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 RootView::RootView(Widget* widget) 151 RootView::RootView(Widget* widget)
153 : widget_(widget), 152 : widget_(widget),
154 mouse_pressed_handler_(NULL), 153 mouse_pressed_handler_(NULL),
155 mouse_move_handler_(NULL), 154 mouse_move_handler_(NULL),
156 last_click_handler_(NULL), 155 last_click_handler_(NULL),
157 explicit_mouse_handler_(false), 156 explicit_mouse_handler_(false),
158 last_mouse_event_flags_(0), 157 last_mouse_event_flags_(0),
159 last_mouse_event_x_(-1), 158 last_mouse_event_x_(-1),
160 last_mouse_event_y_(-1), 159 last_mouse_event_y_(-1),
161 gesture_handler_(NULL), 160 gesture_handler_(NULL),
161 dispatch_to_gesture_handler_(false),
162 pre_dispatch_handler_(new internal::PreEventDispatchHandler(this)), 162 pre_dispatch_handler_(new internal::PreEventDispatchHandler(this)),
163 post_dispatch_handler_(new internal::PostEventDispatchHandler), 163 post_dispatch_handler_(new internal::PostEventDispatchHandler),
164 focus_search_(this, false, false), 164 focus_search_(this, false, false),
165 focus_traversable_parent_(NULL), 165 focus_traversable_parent_(NULL),
166 focus_traversable_parent_view_(NULL), 166 focus_traversable_parent_view_(NULL),
167 event_dispatch_target_(NULL), 167 event_dispatch_target_(NULL),
168 old_dispatch_target_(NULL) { 168 old_dispatch_target_(NULL) {
169 AddPreTargetHandler(pre_dispatch_handler_.get()); 169 AddPreTargetHandler(pre_dispatch_handler_.get());
170 AddPostTargetHandler(post_dispatch_handler_.get()); 170 AddPostTargetHandler(post_dispatch_handler_.get());
171 SetEventTargeter(scoped_ptr<ViewTargeter>(new ViewTargeter(this))); 171 SetEventTargeter(scoped_ptr<ViewTargeter>(new ViewTargeter(this)));
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 277
278 // Ignore subsequent gesture scroll events if no handler was set for a 278 // Ignore subsequent gesture scroll events if no handler was set for a
279 // ui::ET_GESTURE_SCROLL_BEGIN event. 279 // ui::ET_GESTURE_SCROLL_BEGIN event.
280 if (!gesture_handler_ && 280 if (!gesture_handler_ &&
281 (gesture_event->type() == ui::ET_GESTURE_SCROLL_UPDATE || 281 (gesture_event->type() == ui::ET_GESTURE_SCROLL_UPDATE ||
282 gesture_event->type() == ui::ET_GESTURE_SCROLL_END || 282 gesture_event->type() == ui::ET_GESTURE_SCROLL_END ||
283 gesture_event->type() == ui::ET_SCROLL_FLING_START)) { 283 gesture_event->type() == ui::ET_SCROLL_FLING_START)) {
284 return DispatchDetails(); 284 return DispatchDetails();
285 } 285 }
286 286
287 // If |gesture_handler_| is non-null (as a result of dispatching a previous
288 // gesture event), then |gesture_event| should be dispatched to
289 // |gesture_handler_|.
290 dispatch_to_gesture_handler_ = gesture_handler_ ? true : false;
291
287 DispatchGestureEvent(gesture_event); 292 DispatchGestureEvent(gesture_event);
288 return DispatchDetails(); 293 return DispatchDetails();
289 } 294 }
290 295
291 if (event->IsTouchEvent()) 296 if (event->IsTouchEvent())
292 NOTREACHED() << "Touch events should not be sent to RootView."; 297 NOTREACHED() << "Touch events should not be sent to RootView.";
293 298
294 if (event->IsMouseEvent()) 299 if (event->IsMouseEvent())
295 NOTREACHED() << "Should not be called with a MouseEvent."; 300 NOTREACHED() << "Should not be called with a MouseEvent.";
296 301
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 } 677 }
673 678
674 if (event->handled()) 679 if (event->handled())
675 return; 680 return;
676 681
677 if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN) { 682 if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN) {
678 // Some view started processing gesture events, however it does not 683 // Some view started processing gesture events, however it does not
679 // process scroll-gesture events. In such case, we allow the event to 684 // process scroll-gesture events. In such case, we allow the event to
680 // bubble up. |gesture_handler_| is changed to its nearest ancestor 685 // bubble up. |gesture_handler_| is changed to its nearest ancestor
681 // that handles scroll-gesture events. 686 // that handles scroll-gesture events.
682 for (gesture_handler_ = gesture_handler_->parent(); 687 gesture_handler_ = static_cast<View*>(
683 gesture_handler_ && gesture_handler_ != this; 688 targeter()->FindNextBestTarget(gesture_handler_, event));
684 gesture_handler_ = gesture_handler_->parent()) { 689 while (gesture_handler_ && gesture_handler_ != this) {
685 ui::GestureEvent gesture_event(*event, 690 ui::GestureEvent gesture_event(*event,
686 static_cast<View*>(this), 691 static_cast<View*>(this),
687 gesture_handler_); 692 gesture_handler_);
688 ui::EventDispatchDetails dispatch_details = 693 ui::EventDispatchDetails dispatch_details =
689 DispatchEvent(gesture_handler_, &gesture_event); 694 DispatchEvent(gesture_handler_, &gesture_event);
690 if (gesture_event.stopped_propagation()) { 695 if (gesture_event.stopped_propagation()) {
691 event->StopPropagation(); 696 event->StopPropagation();
692 return; 697 return;
693 } else if (gesture_event.handled()) { 698 } else if (gesture_event.handled()) {
694 event->SetHandled(); 699 event->SetHandled();
695 return; 700 return;
696 } else if (dispatch_details.dispatcher_destroyed || 701 } else if (dispatch_details.dispatcher_destroyed ||
697 dispatch_details.target_destroyed) { 702 dispatch_details.target_destroyed) {
698 return; 703 return;
699 } 704 }
705 gesture_handler_ = static_cast<View*>(
706 targeter()->FindNextBestTarget(gesture_handler_, event));
700 } 707 }
701 gesture_handler_ = NULL; 708 gesture_handler_ = NULL;
702 } 709 }
703 710
704 return; 711 return;
705 } 712 }
706 713
707 View* gesture_handler = NULL;
708 if (views::switches::IsRectBasedTargetingEnabled() &&
709 !event->details().bounding_box().IsEmpty()) {
710 // TODO(tdanderson): Pass in the bounding box to GetEventHandlerForRect()
711 // once crbug.com/313392 is resolved.
712 gfx::Rect touch_rect(event->details().bounding_box());
713 touch_rect.set_origin(event->location());
714 touch_rect.Offset(-touch_rect.width() / 2, -touch_rect.height() / 2);
715 gesture_handler = GetEventHandlerForRect(touch_rect);
716 } else {
717 gesture_handler = GetEventHandlerForPoint(event->location());
718 }
719
720 // Walk up the tree until we find a view that wants the gesture event. 714 // Walk up the tree until we find a view that wants the gesture event.
721 for (gesture_handler_ = gesture_handler; 715 gesture_handler_ =
722 gesture_handler_ && (gesture_handler_ != this); 716 static_cast<View*>(targeter()->FindTargetForEvent(this, event));
723 gesture_handler_ = gesture_handler_->parent()) { 717 while (gesture_handler_ && gesture_handler_ != this) {
724 // Disabled views are permitted to be targets of gesture events, but 718 // Disabled views are permitted to be targets of gesture events, but
725 // gesture events should never actually be dispatched to them. 719 // gesture events should never actually be dispatched to them.
726 if (!gesture_handler_->enabled()) { 720 if (!gesture_handler_->enabled()) {
727 event->SetHandled(); 721 event->SetHandled();
728 722
729 // Last ui::ET_GESTURE_END should not set the gesture_handler_. 723 // Last ui::ET_GESTURE_END should not set the gesture_handler_.
730 if (event->type() == ui::ET_GESTURE_END) { 724 if (event->type() == ui::ET_GESTURE_END) {
731 DCHECK_EQ(1, event->details().touch_points()); 725 DCHECK_EQ(1, event->details().touch_points());
732 gesture_handler_ = NULL; 726 gesture_handler_ = NULL;
733 } 727 }
(...skipping 24 matching lines...) Expand all
758 // Last ui::ET_GESTURE_END should not set the gesture_handler_. 752 // Last ui::ET_GESTURE_END should not set the gesture_handler_.
759 if (gesture_event.type() == ui::ET_GESTURE_END) { 753 if (gesture_event.type() == ui::ET_GESTURE_END) {
760 DCHECK_EQ(1, event->details().touch_points()); 754 DCHECK_EQ(1, event->details().touch_points());
761 gesture_handler_ = NULL; 755 gesture_handler_ = NULL;
762 } 756 }
763 return; 757 return;
764 } 758 }
765 759
766 // The gesture event wasn't processed. Go up the view hierarchy and 760 // The gesture event wasn't processed. Go up the view hierarchy and
767 // dispatch the gesture event. 761 // dispatch the gesture event.
762 gesture_handler_ = static_cast<View*>(
763 targeter()->FindNextBestTarget(gesture_handler_, event));
768 } 764 }
769 765
770 gesture_handler_ = NULL; 766 gesture_handler_ = NULL;
771 } 767 }
772 768
773 void RootView::UpdateCursor(const ui::MouseEvent& event) { 769 void RootView::UpdateCursor(const ui::MouseEvent& event) {
774 if (!(event.flags() & ui::EF_IS_NON_CLIENT)) { 770 if (!(event.flags() & ui::EF_IS_NON_CLIENT)) {
775 View* v = GetEventHandlerForPoint(event.location()); 771 View* v = GetEventHandlerForPoint(event.location());
776 ui::MouseEvent me(event, static_cast<View*>(this), v); 772 ui::MouseEvent me(event, static_cast<View*>(this), v);
777 widget_->SetCursor(v->GetCursor(me)); 773 widget_->SetCursor(v->GetCursor(me));
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 823
828 #ifndef NDEBUG 824 #ifndef NDEBUG
829 DCHECK(!event_dispatch_target_ || Contains(event_dispatch_target_)); 825 DCHECK(!event_dispatch_target_ || Contains(event_dispatch_target_));
830 #endif 826 #endif
831 827
832 return details; 828 return details;
833 } 829 }
834 830
835 } // namespace internal 831 } // namespace internal
836 } // namespace views 832 } // namespace views
OLDNEW
« ui/views/widget/root_view.h ('K') | « ui/views/widget/root_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698