OLD | NEW |
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 Loading... |
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 Loading... |
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 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 } else if (handler_event.handled()) { | 671 } else if (handler_event.handled()) { |
667 event->SetHandled(); | 672 event->SetHandled(); |
668 return; | 673 return; |
669 } | 674 } |
670 | 675 |
671 if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN) { | 676 if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN) { |
672 // Some view started processing gesture events, however it does not | 677 // Some view started processing gesture events, however it does not |
673 // process scroll-gesture events. In such case, we allow the event to | 678 // process scroll-gesture events. In such case, we allow the event to |
674 // bubble up. |gesture_handler_| is changed to its nearest ancestor | 679 // bubble up. |gesture_handler_| is changed to its nearest ancestor |
675 // that handles scroll-gesture events. | 680 // that handles scroll-gesture events. |
676 for (gesture_handler_ = gesture_handler_->parent(); | 681 gesture_handler_ = static_cast<View*>( |
677 gesture_handler_ && gesture_handler_ != this; | 682 targeter()->FindNextBestTarget(gesture_handler_, event)); |
678 gesture_handler_ = gesture_handler_->parent()) { | 683 while (gesture_handler_ && gesture_handler_ != this) { |
679 ui::GestureEvent gesture_event(*event, | 684 ui::GestureEvent gesture_event(*event, |
680 static_cast<View*>(this), | 685 static_cast<View*>(this), |
681 gesture_handler_); | 686 gesture_handler_); |
682 ui::EventDispatchDetails dispatch_details = | 687 ui::EventDispatchDetails dispatch_details = |
683 DispatchEvent(gesture_handler_, &gesture_event); | 688 DispatchEvent(gesture_handler_, &gesture_event); |
684 if (gesture_event.stopped_propagation()) { | 689 if (gesture_event.stopped_propagation()) { |
685 event->StopPropagation(); | 690 event->StopPropagation(); |
686 return; | 691 return; |
687 } else if (gesture_event.handled()) { | 692 } else if (gesture_event.handled()) { |
688 event->SetHandled(); | 693 event->SetHandled(); |
689 return; | 694 return; |
690 } else if (dispatch_details.dispatcher_destroyed || | 695 } else if (dispatch_details.dispatcher_destroyed || |
691 dispatch_details.target_destroyed) { | 696 dispatch_details.target_destroyed) { |
692 return; | 697 return; |
693 } | 698 } |
| 699 gesture_handler_ = static_cast<View*>( |
| 700 targeter()->FindNextBestTarget(gesture_handler_, event)); |
694 } | 701 } |
695 gesture_handler_ = NULL; | 702 gesture_handler_ = NULL; |
696 } | 703 } |
697 | 704 |
698 return; | 705 return; |
699 } | 706 } |
700 | 707 |
701 View* gesture_handler = NULL; | |
702 if (views::switches::IsRectBasedTargetingEnabled() && | |
703 !event->details().bounding_box().IsEmpty()) { | |
704 // TODO(tdanderson): Pass in the bounding box to GetEventHandlerForRect() | |
705 // once crbug.com/313392 is resolved. | |
706 gfx::Rect touch_rect(event->details().bounding_box()); | |
707 touch_rect.set_origin(event->location()); | |
708 touch_rect.Offset(-touch_rect.width() / 2, -touch_rect.height() / 2); | |
709 gesture_handler = GetEventHandlerForRect(touch_rect); | |
710 } else { | |
711 gesture_handler = GetEventHandlerForPoint(event->location()); | |
712 } | |
713 | |
714 // Walk up the tree until we find a view that wants the gesture event. | 708 // Walk up the tree until we find a view that wants the gesture event. |
715 for (gesture_handler_ = gesture_handler; | 709 gesture_handler_ = |
716 gesture_handler_ && (gesture_handler_ != this); | 710 static_cast<View*>(targeter()->FindTargetForEvent(this, event)); |
717 gesture_handler_ = gesture_handler_->parent()) { | 711 while (gesture_handler_ && gesture_handler_ != this) { |
718 // Disabled views eat events but are treated as not handled. | 712 // Disabled views eat events but are treated as not handled. |
719 if (!gesture_handler_->enabled()) | 713 if (!gesture_handler_->enabled()) |
720 return; | 714 return; |
721 | 715 |
722 // See if this view wants to handle the Gesture. | 716 // See if this view wants to handle the Gesture. |
723 ui::GestureEvent gesture_event(*event, | 717 ui::GestureEvent gesture_event(*event, |
724 static_cast<View*>(this), | 718 static_cast<View*>(this), |
725 gesture_handler_); | 719 gesture_handler_); |
726 ui::EventDispatchDetails dispatch_details = | 720 ui::EventDispatchDetails dispatch_details = |
727 DispatchEvent(gesture_handler_, &gesture_event); | 721 DispatchEvent(gesture_handler_, &gesture_event); |
(...skipping 14 matching lines...) Expand all Loading... |
742 // Last ui::ET_GESTURE_END should not set the gesture_handler_. | 736 // Last ui::ET_GESTURE_END should not set the gesture_handler_. |
743 if (gesture_event.type() == ui::ET_GESTURE_END) { | 737 if (gesture_event.type() == ui::ET_GESTURE_END) { |
744 DCHECK_EQ(1, event->details().touch_points()); | 738 DCHECK_EQ(1, event->details().touch_points()); |
745 gesture_handler_ = NULL; | 739 gesture_handler_ = NULL; |
746 } | 740 } |
747 return; | 741 return; |
748 } | 742 } |
749 | 743 |
750 // The gesture event wasn't processed. Go up the view hierarchy and | 744 // The gesture event wasn't processed. Go up the view hierarchy and |
751 // dispatch the gesture event. | 745 // dispatch the gesture event. |
| 746 gesture_handler_ = static_cast<View*>( |
| 747 targeter()->FindNextBestTarget(gesture_handler_, event)); |
752 } | 748 } |
753 | 749 |
754 gesture_handler_ = NULL; | 750 gesture_handler_ = NULL; |
755 } | 751 } |
756 | 752 |
757 void RootView::UpdateCursor(const ui::MouseEvent& event) { | 753 void RootView::UpdateCursor(const ui::MouseEvent& event) { |
758 if (!(event.flags() & ui::EF_IS_NON_CLIENT)) { | 754 if (!(event.flags() & ui::EF_IS_NON_CLIENT)) { |
759 View* v = GetEventHandlerForPoint(event.location()); | 755 View* v = GetEventHandlerForPoint(event.location()); |
760 ui::MouseEvent me(event, static_cast<View*>(this), v); | 756 ui::MouseEvent me(event, static_cast<View*>(this), v); |
761 widget_->SetCursor(v->GetCursor(me)); | 757 widget_->SetCursor(v->GetCursor(me)); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 | 807 |
812 #ifndef NDEBUG | 808 #ifndef NDEBUG |
813 DCHECK(!event_dispatch_target_ || Contains(event_dispatch_target_)); | 809 DCHECK(!event_dispatch_target_ || Contains(event_dispatch_target_)); |
814 #endif | 810 #endif |
815 | 811 |
816 return details; | 812 return details; |
817 } | 813 } |
818 | 814 |
819 } // namespace internal | 815 } // namespace internal |
820 } // namespace views | 816 } // namespace views |
OLD | NEW |