| 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" | 23 #include "ui/views/widget/root_view_targeter.h" |
| 24 #include "ui/views/widget/widget.h" | 24 #include "ui/views/widget/widget.h" |
| 25 #include "ui/views/widget/widget_delegate.h" | 25 #include "ui/views/widget/widget_delegate.h" |
| 26 | 26 |
| 27 typedef ui::EventDispatchDetails DispatchDetails; | 27 typedef ui::EventDispatchDetails DispatchDetails; |
| 28 | 28 |
| 29 namespace views { | 29 namespace views { |
| 30 namespace internal { | 30 namespace internal { |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 RootView::RootView(Widget* widget) | 152 RootView::RootView(Widget* widget) |
| 153 : widget_(widget), | 153 : widget_(widget), |
| 154 mouse_pressed_handler_(NULL), | 154 mouse_pressed_handler_(NULL), |
| 155 mouse_move_handler_(NULL), | 155 mouse_move_handler_(NULL), |
| 156 last_click_handler_(NULL), | 156 last_click_handler_(NULL), |
| 157 explicit_mouse_handler_(false), | 157 explicit_mouse_handler_(false), |
| 158 last_mouse_event_flags_(0), | 158 last_mouse_event_flags_(0), |
| 159 last_mouse_event_x_(-1), | 159 last_mouse_event_x_(-1), |
| 160 last_mouse_event_y_(-1), | 160 last_mouse_event_y_(-1), |
| 161 gesture_handler_(NULL), | 161 gesture_handler_(NULL), |
| 162 allow_gesture_event_retargeting_(true), |
| 162 pre_dispatch_handler_(new internal::PreEventDispatchHandler(this)), | 163 pre_dispatch_handler_(new internal::PreEventDispatchHandler(this)), |
| 163 post_dispatch_handler_(new internal::PostEventDispatchHandler), | 164 post_dispatch_handler_(new internal::PostEventDispatchHandler), |
| 164 focus_search_(this, false, false), | 165 focus_search_(this, false, false), |
| 165 focus_traversable_parent_(NULL), | 166 focus_traversable_parent_(NULL), |
| 166 focus_traversable_parent_view_(NULL), | 167 focus_traversable_parent_view_(NULL), |
| 167 event_dispatch_target_(NULL), | 168 event_dispatch_target_(NULL), |
| 168 old_dispatch_target_(NULL) { | 169 old_dispatch_target_(NULL) { |
| 169 AddPreTargetHandler(pre_dispatch_handler_.get()); | 170 AddPreTargetHandler(pre_dispatch_handler_.get()); |
| 170 AddPostTargetHandler(post_dispatch_handler_.get()); | 171 AddPostTargetHandler(post_dispatch_handler_.get()); |
| 171 SetEventTargeter(scoped_ptr<ViewTargeter>(new ViewTargeter(this))); | 172 SetEventTargeter(scoped_ptr<ViewTargeter>(new RootViewTargeter(this, this))); |
| 172 } | 173 } |
| 173 | 174 |
| 174 RootView::~RootView() { | 175 RootView::~RootView() { |
| 175 // If we have children remove them explicitly so to make sure a remove | 176 // If we have children remove them explicitly so to make sure a remove |
| 176 // notification is sent for each one of them. | 177 // notification is sent for each one of them. |
| 177 if (has_children()) | 178 if (has_children()) |
| 178 RemoveAllChildViews(true); | 179 RemoveAllChildViews(true); |
| 179 } | 180 } |
| 180 | 181 |
| 181 // Tree operations ------------------------------------------------------------- | 182 // Tree operations ------------------------------------------------------------- |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 | 278 |
| 278 // Ignore subsequent gesture scroll events if no handler was set for a | 279 // Ignore subsequent gesture scroll events if no handler was set for a |
| 279 // ui::ET_GESTURE_SCROLL_BEGIN event. | 280 // ui::ET_GESTURE_SCROLL_BEGIN event. |
| 280 if (!gesture_handler_ && | 281 if (!gesture_handler_ && |
| 281 (gesture_event->type() == ui::ET_GESTURE_SCROLL_UPDATE || | 282 (gesture_event->type() == ui::ET_GESTURE_SCROLL_UPDATE || |
| 282 gesture_event->type() == ui::ET_GESTURE_SCROLL_END || | 283 gesture_event->type() == ui::ET_GESTURE_SCROLL_END || |
| 283 gesture_event->type() == ui::ET_SCROLL_FLING_START)) { | 284 gesture_event->type() == ui::ET_SCROLL_FLING_START)) { |
| 284 return DispatchDetails(); | 285 return DispatchDetails(); |
| 285 } | 286 } |
| 286 | 287 |
| 288 // If |gesture_handler_| is non-null (as a result of dispatching a previous |
| 289 // gesture event), then |gesture_event| should be dispatched only to |
| 290 // |gesture_handler_|. |
| 291 allow_gesture_event_retargeting_ = gesture_handler_ ? false : true; |
| 292 |
| 287 DispatchGestureEvent(gesture_event); | 293 DispatchGestureEvent(gesture_event); |
| 288 return DispatchDetails(); | 294 return DispatchDetails(); |
| 289 } | 295 } |
| 290 | 296 |
| 291 if (event->IsTouchEvent()) | 297 if (event->IsTouchEvent()) |
| 292 NOTREACHED() << "Touch events should not be sent to RootView."; | 298 NOTREACHED() << "Touch events should not be sent to RootView."; |
| 293 | 299 |
| 294 if (event->IsMouseEvent()) | 300 if (event->IsMouseEvent()) |
| 295 NOTREACHED() << "Should not be called with a MouseEvent."; | 301 NOTREACHED() << "Should not be called with a MouseEvent."; |
| 296 | 302 |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 } | 678 } |
| 673 | 679 |
| 674 if (event->handled()) | 680 if (event->handled()) |
| 675 return; | 681 return; |
| 676 | 682 |
| 677 if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN) { | 683 if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN) { |
| 678 // Some view started processing gesture events, however it does not | 684 // Some view started processing gesture events, however it does not |
| 679 // process scroll-gesture events. In such case, we allow the event to | 685 // process scroll-gesture events. In such case, we allow the event to |
| 680 // bubble up. |gesture_handler_| is changed to its nearest ancestor | 686 // bubble up. |gesture_handler_| is changed to its nearest ancestor |
| 681 // that handles scroll-gesture events. | 687 // that handles scroll-gesture events. |
| 682 for (gesture_handler_ = gesture_handler_->parent(); | 688 gesture_handler_ = static_cast<View*>( |
| 683 gesture_handler_ && gesture_handler_ != this; | 689 targeter()->FindNextBestTarget(gesture_handler_, event)); |
| 684 gesture_handler_ = gesture_handler_->parent()) { | 690 while (gesture_handler_ && gesture_handler_ != this) { |
| 685 ui::GestureEvent gesture_event(*event, | 691 ui::GestureEvent gesture_event(*event, |
| 686 static_cast<View*>(this), | 692 static_cast<View*>(this), |
| 687 gesture_handler_); | 693 gesture_handler_); |
| 688 ui::EventDispatchDetails dispatch_details = | 694 ui::EventDispatchDetails dispatch_details = |
| 689 DispatchEvent(gesture_handler_, &gesture_event); | 695 DispatchEvent(gesture_handler_, &gesture_event); |
| 690 if (gesture_event.stopped_propagation()) { | 696 if (gesture_event.stopped_propagation()) { |
| 691 event->StopPropagation(); | 697 event->StopPropagation(); |
| 692 return; | 698 return; |
| 693 } else if (gesture_event.handled()) { | 699 } else if (gesture_event.handled()) { |
| 694 event->SetHandled(); | 700 event->SetHandled(); |
| 695 return; | 701 return; |
| 696 } else if (dispatch_details.dispatcher_destroyed || | 702 } else if (dispatch_details.dispatcher_destroyed || |
| 697 dispatch_details.target_destroyed) { | 703 dispatch_details.target_destroyed) { |
| 698 return; | 704 return; |
| 699 } | 705 } |
| 706 gesture_handler_ = static_cast<View*>( |
| 707 targeter()->FindNextBestTarget(gesture_handler_, event)); |
| 700 } | 708 } |
| 701 gesture_handler_ = NULL; | 709 gesture_handler_ = NULL; |
| 702 } | 710 } |
| 703 | 711 |
| 704 return; | 712 return; |
| 705 } | 713 } |
| 706 | 714 |
| 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. | 715 // Walk up the tree until we find a view that wants the gesture event. |
| 721 for (gesture_handler_ = gesture_handler; | 716 gesture_handler_ = |
| 722 gesture_handler_ && (gesture_handler_ != this); | 717 static_cast<View*>(targeter()->FindTargetForEvent(this, event)); |
| 723 gesture_handler_ = gesture_handler_->parent()) { | 718 while (gesture_handler_ && gesture_handler_ != this) { |
| 724 // Disabled views are permitted to be targets of gesture events, but | 719 // Disabled views are permitted to be targets of gesture events, but |
| 725 // gesture events should never actually be dispatched to them. | 720 // gesture events should never actually be dispatched to them. |
| 726 if (!gesture_handler_->enabled()) { | 721 if (!gesture_handler_->enabled()) { |
| 727 event->SetHandled(); | 722 event->SetHandled(); |
| 728 | 723 |
| 729 // Last ui::ET_GESTURE_END should not set the gesture_handler_. | 724 // Last ui::ET_GESTURE_END should not set the gesture_handler_. |
| 730 if (event->type() == ui::ET_GESTURE_END) { | 725 if (event->type() == ui::ET_GESTURE_END) { |
| 731 DCHECK_EQ(1, event->details().touch_points()); | 726 DCHECK_EQ(1, event->details().touch_points()); |
| 732 gesture_handler_ = NULL; | 727 gesture_handler_ = NULL; |
| 733 } | 728 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 758 // Last ui::ET_GESTURE_END should not set the gesture_handler_. | 753 // Last ui::ET_GESTURE_END should not set the gesture_handler_. |
| 759 if (gesture_event.type() == ui::ET_GESTURE_END) { | 754 if (gesture_event.type() == ui::ET_GESTURE_END) { |
| 760 DCHECK_EQ(1, event->details().touch_points()); | 755 DCHECK_EQ(1, event->details().touch_points()); |
| 761 gesture_handler_ = NULL; | 756 gesture_handler_ = NULL; |
| 762 } | 757 } |
| 763 return; | 758 return; |
| 764 } | 759 } |
| 765 | 760 |
| 766 // The gesture event wasn't processed. Go up the view hierarchy and | 761 // The gesture event wasn't processed. Go up the view hierarchy and |
| 767 // dispatch the gesture event. | 762 // dispatch the gesture event. |
| 763 gesture_handler_ = static_cast<View*>( |
| 764 targeter()->FindNextBestTarget(gesture_handler_, event)); |
| 768 } | 765 } |
| 769 | 766 |
| 770 gesture_handler_ = NULL; | 767 gesture_handler_ = NULL; |
| 771 } | 768 } |
| 772 | 769 |
| 773 void RootView::UpdateCursor(const ui::MouseEvent& event) { | 770 void RootView::UpdateCursor(const ui::MouseEvent& event) { |
| 774 if (!(event.flags() & ui::EF_IS_NON_CLIENT)) { | 771 if (!(event.flags() & ui::EF_IS_NON_CLIENT)) { |
| 775 View* v = GetEventHandlerForPoint(event.location()); | 772 View* v = GetEventHandlerForPoint(event.location()); |
| 776 ui::MouseEvent me(event, static_cast<View*>(this), v); | 773 ui::MouseEvent me(event, static_cast<View*>(this), v); |
| 777 widget_->SetCursor(v->GetCursor(me)); | 774 widget_->SetCursor(v->GetCursor(me)); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 | 824 |
| 828 #ifndef NDEBUG | 825 #ifndef NDEBUG |
| 829 DCHECK(!event_dispatch_target_ || Contains(event_dispatch_target_)); | 826 DCHECK(!event_dispatch_target_ || Contains(event_dispatch_target_)); |
| 830 #endif | 827 #endif |
| 831 | 828 |
| 832 return details; | 829 return details; |
| 833 } | 830 } |
| 834 | 831 |
| 835 } // namespace internal | 832 } // namespace internal |
| 836 } // namespace views | 833 } // namespace views |
| OLD | NEW |