Chromium Code Reviews| 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/base/accessibility/accessible_view_state.h" | 11 #include "ui/base/accessibility/accessible_view_state.h" |
| 12 #include "ui/base/dragdrop/drag_drop_types.h" | 12 #include "ui/base/dragdrop/drag_drop_types.h" |
| 13 #include "ui/compositor/layer.h" | 13 #include "ui/compositor/layer.h" |
| 14 #include "ui/events/event.h" | 14 #include "ui/events/event.h" |
| 15 #include "ui/events/keycodes/keyboard_codes.h" | 15 #include "ui/events/keycodes/keyboard_codes.h" |
| 16 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
| 17 #include "ui/views/focus/view_storage.h" | 17 #include "ui/views/focus/view_storage.h" |
| 18 #include "ui/views/layout/fill_layout.h" | 18 #include "ui/views/layout/fill_layout.h" |
| 19 #include "ui/views/views_switches.h" | 19 #include "ui/views/views_switches.h" |
| 20 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
| 21 #include "ui/views/widget/widget_delegate.h" | 21 #include "ui/views/widget/widget_delegate.h" |
| 22 #include "ui/views/widget/widget_deletion_observer.h" | |
| 23 | 22 |
| 24 #if defined(USE_AURA) | 23 #if defined(USE_AURA) |
| 25 #include "ui/base/cursor/cursor.h" | 24 #include "ui/base/cursor/cursor.h" |
| 26 #endif | 25 #endif |
| 27 | 26 |
| 28 namespace views { | 27 namespace views { |
| 29 namespace internal { | 28 namespace internal { |
| 30 | 29 |
| 31 namespace { | 30 namespace { |
| 32 | 31 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 } | 216 } |
| 218 | 217 |
| 219 void RootView::DispatchGestureEvent(ui::GestureEvent* event) { | 218 void RootView::DispatchGestureEvent(ui::GestureEvent* event) { |
| 220 if (gesture_handler_) { | 219 if (gesture_handler_) { |
| 221 // |gesture_handler_| (or |scroll_gesture_handler_|) can be deleted during | 220 // |gesture_handler_| (or |scroll_gesture_handler_|) can be deleted during |
| 222 // processing. | 221 // processing. |
| 223 View* handler = scroll_gesture_handler_ && | 222 View* handler = scroll_gesture_handler_ && |
| 224 (event->IsScrollGestureEvent() || event->IsFlingScrollEvent()) ? | 223 (event->IsScrollGestureEvent() || event->IsFlingScrollEvent()) ? |
| 225 scroll_gesture_handler_ : gesture_handler_; | 224 scroll_gesture_handler_ : gesture_handler_; |
| 226 ui::GestureEvent handler_event(*event, static_cast<View*>(this), handler); | 225 ui::GestureEvent handler_event(*event, static_cast<View*>(this), handler); |
| 227 DispatchEventToTarget(handler, &handler_event); | 226 |
| 227 { | |
| 228 ui::EventDispatchDetails dispatch_details = | |
| 229 DispatchEventToTarget(handler, &handler_event); | |
| 230 if (dispatch_details.dispatcher_destroyed) | |
| 231 return; | |
| 232 } | |
|
sadrul
2014/02/19 18:32:34
The nested scope isn't necessary, is it?
pkotwicz
2014/02/19 20:14:11
Removed!
| |
| 228 | 233 |
| 229 if (event->type() == ui::ET_GESTURE_END && | 234 if (event->type() == ui::ET_GESTURE_END && |
| 230 event->details().touch_points() <= 1) { | 235 event->details().touch_points() <= 1) { |
| 231 // In case a drag was in progress, reset all the handlers. Otherwise, just | 236 // In case a drag was in progress, reset all the handlers. Otherwise, just |
| 232 // reset the gesture handler. | 237 // reset the gesture handler. |
| 233 if (gesture_handler_ == mouse_pressed_handler_) | 238 if (gesture_handler_ == mouse_pressed_handler_) |
| 234 SetMouseHandler(NULL); | 239 SetMouseHandler(NULL); |
| 235 else | 240 else |
| 236 gesture_handler_ = NULL; | 241 gesture_handler_ = NULL; |
| 237 } | 242 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 305 gesture_handler_ && (gesture_handler_ != this); | 310 gesture_handler_ && (gesture_handler_ != this); |
| 306 gesture_handler_ = gesture_handler_->parent()) { | 311 gesture_handler_ = gesture_handler_->parent()) { |
| 307 if (!gesture_handler_->enabled()) { | 312 if (!gesture_handler_->enabled()) { |
| 308 // Disabled views eat events but are treated as not handled. | 313 // Disabled views eat events but are treated as not handled. |
| 309 return; | 314 return; |
| 310 } | 315 } |
| 311 | 316 |
| 312 // See if this view wants to handle the Gesture. | 317 // See if this view wants to handle the Gesture. |
| 313 ui::GestureEvent gesture_event(*event, static_cast<View*>(this), | 318 ui::GestureEvent gesture_event(*event, static_cast<View*>(this), |
| 314 gesture_handler_); | 319 gesture_handler_); |
| 315 DispatchEventToTarget(gesture_handler_, &gesture_event); | 320 |
| 321 { | |
| 322 ui::EventDispatchDetails dispatch_details = | |
| 323 DispatchEventToTarget(gesture_handler_, &gesture_event); | |
| 324 if (dispatch_details.dispatcher_destroyed) | |
| 325 return; | |
| 326 } | |
| 316 | 327 |
| 317 // The view could have removed itself from the tree when handling | 328 // The view could have removed itself from the tree when handling |
| 318 // OnGestureEvent(). So handle as per OnMousePressed. NB: we | 329 // OnGestureEvent(). So handle as per OnMousePressed. NB: we |
| 319 // assume that the RootView itself cannot be so removed. | 330 // assume that the RootView itself cannot be so removed. |
| 320 if (!gesture_handler_) | 331 if (!gesture_handler_) |
| 321 return; | 332 return; |
| 322 | 333 |
| 323 if (gesture_event.handled()) { | 334 if (gesture_event.handled()) { |
| 324 if (gesture_event.type() == ui::ET_GESTURE_SCROLL_BEGIN) | 335 if (gesture_event.type() == ui::ET_GESTURE_SCROLL_BEGIN) |
| 325 scroll_gesture_handler_ = gesture_handler_; | 336 scroll_gesture_handler_ = gesture_handler_; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 441 ui::MouseEvent mouse_pressed_event(event, static_cast<View*>(this), | 452 ui::MouseEvent mouse_pressed_event(event, static_cast<View*>(this), |
| 442 mouse_pressed_handler_); | 453 mouse_pressed_handler_); |
| 443 | 454 |
| 444 // Remove the double-click flag if the handler is different than the | 455 // Remove the double-click flag if the handler is different than the |
| 445 // one which got the first click part of the double-click. | 456 // one which got the first click part of the double-click. |
| 446 if (mouse_pressed_handler_ != last_click_handler_) | 457 if (mouse_pressed_handler_ != last_click_handler_) |
| 447 mouse_pressed_event.set_flags(event.flags() & ~ui::EF_IS_DOUBLE_CLICK); | 458 mouse_pressed_event.set_flags(event.flags() & ~ui::EF_IS_DOUBLE_CLICK); |
| 448 | 459 |
| 449 drag_info_.Reset(); | 460 drag_info_.Reset(); |
| 450 { | 461 { |
| 451 WidgetDeletionObserver widget_deletion_observer(widget_); | 462 ui::EventDispatchDetails dispatch_details = |
| 452 DispatchEventToTarget(mouse_pressed_handler_, &mouse_pressed_event); | 463 DispatchEventToTarget(mouse_pressed_handler_, &mouse_pressed_event); |
| 453 if (!widget_deletion_observer.IsWidgetAlive()) | 464 if (dispatch_details.dispatcher_destroyed) |
| 454 return mouse_pressed_event.handled(); | 465 return mouse_pressed_event.handled(); |
| 455 } | 466 } |
| 456 | 467 |
| 457 // The view could have removed itself from the tree when handling | 468 // The view could have removed itself from the tree when handling |
| 458 // OnMousePressed(). In this case, the removal notification will have | 469 // OnMousePressed(). In this case, the removal notification will have |
| 459 // reset mouse_pressed_handler_ to NULL out from under us. Detect this | 470 // reset mouse_pressed_handler_ to NULL out from under us. Detect this |
| 460 // case and stop. (See comments in view.h.) | 471 // case and stop. (See comments in view.h.) |
| 461 // | 472 // |
| 462 // NOTE: Don't return true here, because we don't want the frame to | 473 // NOTE: Don't return true here, because we don't want the frame to |
| 463 // forward future events to us when there's no handler. | 474 // forward future events to us when there's no handler. |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 695 widget_->SetCursor(v->GetCursor(me)); | 706 widget_->SetCursor(v->GetCursor(me)); |
| 696 } | 707 } |
| 697 } | 708 } |
| 698 | 709 |
| 699 void RootView::SetMouseLocationAndFlags(const ui::MouseEvent& event) { | 710 void RootView::SetMouseLocationAndFlags(const ui::MouseEvent& event) { |
| 700 last_mouse_event_flags_ = event.flags(); | 711 last_mouse_event_flags_ = event.flags(); |
| 701 last_mouse_event_x_ = event.x(); | 712 last_mouse_event_x_ = event.x(); |
| 702 last_mouse_event_y_ = event.y(); | 713 last_mouse_event_y_ = event.y(); |
| 703 } | 714 } |
| 704 | 715 |
| 705 void RootView::DispatchEventToTarget(View* target, ui::Event* event) { | 716 ui::EventDispatchDetails RootView::DispatchEventToTarget(View* target, |
| 717 ui::Event* event) { | |
| 706 View* old_target = event_dispatch_target_; | 718 View* old_target = event_dispatch_target_; |
| 707 event_dispatch_target_ = target; | 719 event_dispatch_target_ = target; |
| 708 ui::EventDispatchDetails details = DispatchEvent(target, event); | 720 ui::EventDispatchDetails details = DispatchEvent(target, event); |
| 709 if (!details.dispatcher_destroyed) | 721 if (!details.dispatcher_destroyed) |
| 710 event_dispatch_target_ = old_target; | 722 event_dispatch_target_ = old_target; |
| 723 return details; | |
| 711 } | 724 } |
| 712 | 725 |
| 713 void RootView::NotifyEnterExitOfDescendant(const ui::MouseEvent& event, | 726 void RootView::NotifyEnterExitOfDescendant(const ui::MouseEvent& event, |
| 714 ui::EventType type, | 727 ui::EventType type, |
| 715 View* view, | 728 View* view, |
| 716 View* sibling) { | 729 View* sibling) { |
| 717 for (View* p = view->parent(); p; p = p->parent()) { | 730 for (View* p = view->parent(); p; p = p->parent()) { |
| 718 if (!p->notify_enter_exit_on_child()) | 731 if (!p->notify_enter_exit_on_child()) |
| 719 continue; | 732 continue; |
| 720 if (sibling && p->Contains(sibling)) | 733 if (sibling && p->Contains(sibling)) |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 739 return; | 752 return; |
| 740 } | 753 } |
| 741 } | 754 } |
| 742 | 755 |
| 743 bool RootView::CanDispatchToTarget(ui::EventTarget* target) { | 756 bool RootView::CanDispatchToTarget(ui::EventTarget* target) { |
| 744 return event_dispatch_target_ == target; | 757 return event_dispatch_target_ == target; |
| 745 } | 758 } |
| 746 | 759 |
| 747 } // namespace internal | 760 } // namespace internal |
| 748 } // namespace views | 761 } // namespace views |
| OLD | NEW |