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 ui::EventDispatchDetails dispatch_details = |
| 227 DispatchEventToTarget(handler, &handler_event); | |
| 228 if (dispatch_details.dispatcher_destroyed) | |
| 229 return; | |
| 228 | 230 |
| 229 if (event->type() == ui::ET_GESTURE_END && | 231 if (event->type() == ui::ET_GESTURE_END && |
| 230 event->details().touch_points() <= 1) { | 232 event->details().touch_points() <= 1) { |
| 231 // In case a drag was in progress, reset all the handlers. Otherwise, just | 233 // In case a drag was in progress, reset all the handlers. Otherwise, just |
| 232 // reset the gesture handler. | 234 // reset the gesture handler. |
| 233 if (gesture_handler_ == mouse_pressed_handler_) | 235 if (gesture_handler_ == mouse_pressed_handler_) |
| 234 SetMouseHandler(NULL); | 236 SetMouseHandler(NULL); |
| 235 else | 237 else |
| 236 gesture_handler_ = NULL; | 238 gesture_handler_ = NULL; |
| 237 } | 239 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 305 gesture_handler_ && (gesture_handler_ != this); | 307 gesture_handler_ && (gesture_handler_ != this); |
| 306 gesture_handler_ = gesture_handler_->parent()) { | 308 gesture_handler_ = gesture_handler_->parent()) { |
| 307 if (!gesture_handler_->enabled()) { | 309 if (!gesture_handler_->enabled()) { |
| 308 // Disabled views eat events but are treated as not handled. | 310 // Disabled views eat events but are treated as not handled. |
| 309 return; | 311 return; |
| 310 } | 312 } |
| 311 | 313 |
| 312 // See if this view wants to handle the Gesture. | 314 // See if this view wants to handle the Gesture. |
| 313 ui::GestureEvent gesture_event(*event, static_cast<View*>(this), | 315 ui::GestureEvent gesture_event(*event, static_cast<View*>(this), |
| 314 gesture_handler_); | 316 gesture_handler_); |
| 315 DispatchEventToTarget(gesture_handler_, &gesture_event); | 317 ui::EventDispatchDetails dispatch_details = |
| 318 DispatchEventToTarget(gesture_handler_, &gesture_event); | |
| 319 if (dispatch_details.dispatcher_destroyed) | |
| 320 return; | |
| 316 | 321 |
| 317 // The view could have removed itself from the tree when handling | 322 // The view could have removed itself from the tree when handling |
| 318 // OnGestureEvent(). So handle as per OnMousePressed. NB: we | 323 // OnGestureEvent(). So handle as per OnMousePressed. NB: we |
| 319 // assume that the RootView itself cannot be so removed. | 324 // assume that the RootView itself cannot be so removed. |
| 320 if (!gesture_handler_) | 325 if (!gesture_handler_) |
| 321 return; | 326 return; |
| 322 | 327 |
| 323 if (gesture_event.handled()) { | 328 if (gesture_event.handled()) { |
| 324 if (gesture_event.type() == ui::ET_GESTURE_SCROLL_BEGIN) | 329 if (gesture_event.type() == ui::ET_GESTURE_SCROLL_BEGIN) |
| 325 scroll_gesture_handler_ = gesture_handler_; | 330 scroll_gesture_handler_ = gesture_handler_; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 440 // See if this view wants to handle the mouse press. | 445 // See if this view wants to handle the mouse press. |
| 441 ui::MouseEvent mouse_pressed_event(event, static_cast<View*>(this), | 446 ui::MouseEvent mouse_pressed_event(event, static_cast<View*>(this), |
| 442 mouse_pressed_handler_); | 447 mouse_pressed_handler_); |
| 443 | 448 |
| 444 // Remove the double-click flag if the handler is different than the | 449 // Remove the double-click flag if the handler is different than the |
| 445 // one which got the first click part of the double-click. | 450 // one which got the first click part of the double-click. |
| 446 if (mouse_pressed_handler_ != last_click_handler_) | 451 if (mouse_pressed_handler_ != last_click_handler_) |
| 447 mouse_pressed_event.set_flags(event.flags() & ~ui::EF_IS_DOUBLE_CLICK); | 452 mouse_pressed_event.set_flags(event.flags() & ~ui::EF_IS_DOUBLE_CLICK); |
| 448 | 453 |
| 449 drag_info_.Reset(); | 454 drag_info_.Reset(); |
| 450 { | 455 ui::EventDispatchDetails dispatch_details = |
| 451 WidgetDeletionObserver widget_deletion_observer(widget_); | 456 DispatchEventToTarget(mouse_pressed_handler_, &mouse_pressed_event); |
| 452 DispatchEventToTarget(mouse_pressed_handler_, &mouse_pressed_event); | 457 if (dispatch_details.dispatcher_destroyed) |
| 453 if (!widget_deletion_observer.IsWidgetAlive()) | 458 return mouse_pressed_event.handled(); |
| 454 return mouse_pressed_event.handled(); | |
| 455 } | |
| 456 | 459 |
| 457 // The view could have removed itself from the tree when handling | 460 // The view could have removed itself from the tree when handling |
| 458 // OnMousePressed(). In this case, the removal notification will have | 461 // OnMousePressed(). In this case, the removal notification will have |
| 459 // reset mouse_pressed_handler_ to NULL out from under us. Detect this | 462 // reset mouse_pressed_handler_ to NULL out from under us. Detect this |
| 460 // case and stop. (See comments in view.h.) | 463 // case and stop. (See comments in view.h.) |
| 461 // | 464 // |
| 462 // NOTE: Don't return true here, because we don't want the frame to | 465 // 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. | 466 // forward future events to us when there's no handler. |
| 464 if (!mouse_pressed_handler_) | 467 if (!mouse_pressed_handler_) |
| 465 break; | 468 break; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 503 void RootView::OnMouseReleased(const ui::MouseEvent& event) { | 506 void RootView::OnMouseReleased(const ui::MouseEvent& event) { |
| 504 UpdateCursor(event); | 507 UpdateCursor(event); |
| 505 | 508 |
| 506 if (mouse_pressed_handler_) { | 509 if (mouse_pressed_handler_) { |
| 507 ui::MouseEvent mouse_released(event, static_cast<View*>(this), | 510 ui::MouseEvent mouse_released(event, static_cast<View*>(this), |
| 508 mouse_pressed_handler_); | 511 mouse_pressed_handler_); |
| 509 // We allow the view to delete us from the event dispatch callback. As such, | 512 // We allow the view to delete us from the event dispatch callback. As such, |
| 510 // configure state such that we're done first, then call View. | 513 // configure state such that we're done first, then call View. |
| 511 View* mouse_pressed_handler = mouse_pressed_handler_; | 514 View* mouse_pressed_handler = mouse_pressed_handler_; |
| 512 SetMouseHandler(NULL); | 515 SetMouseHandler(NULL); |
| 513 DispatchEventToTarget(mouse_pressed_handler, &mouse_released); | 516 DispatchEventToTarget(mouse_pressed_handler, &mouse_released); |
|
pkotwicz
2014/02/19 20:14:13
I did not make DispatchEventToTarget() have WARN_U
sadrul
2014/02/19 20:25:10
We should use the result here (like we do in RootW
| |
| 514 // WARNING: we may have been deleted. | 517 // WARNING: we may have been deleted. |
| 515 } | 518 } |
| 516 } | 519 } |
| 517 | 520 |
| 518 void RootView::OnMouseCaptureLost() { | 521 void RootView::OnMouseCaptureLost() { |
| 519 // TODO: this likely needs to reset touch handler too. | 522 // TODO: this likely needs to reset touch handler too. |
| 520 | 523 |
| 521 if (mouse_pressed_handler_ || gesture_handler_) { | 524 if (mouse_pressed_handler_ || gesture_handler_) { |
| 522 // Synthesize a release event for UpdateCursor. | 525 // Synthesize a release event for UpdateCursor. |
| 523 if (mouse_pressed_handler_) { | 526 if (mouse_pressed_handler_) { |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 695 widget_->SetCursor(v->GetCursor(me)); | 698 widget_->SetCursor(v->GetCursor(me)); |
| 696 } | 699 } |
| 697 } | 700 } |
| 698 | 701 |
| 699 void RootView::SetMouseLocationAndFlags(const ui::MouseEvent& event) { | 702 void RootView::SetMouseLocationAndFlags(const ui::MouseEvent& event) { |
| 700 last_mouse_event_flags_ = event.flags(); | 703 last_mouse_event_flags_ = event.flags(); |
| 701 last_mouse_event_x_ = event.x(); | 704 last_mouse_event_x_ = event.x(); |
| 702 last_mouse_event_y_ = event.y(); | 705 last_mouse_event_y_ = event.y(); |
| 703 } | 706 } |
| 704 | 707 |
| 705 void RootView::DispatchEventToTarget(View* target, ui::Event* event) { | 708 ui::EventDispatchDetails RootView::DispatchEventToTarget(View* target, |
| 709 ui::Event* event) { | |
| 706 View* old_target = event_dispatch_target_; | 710 View* old_target = event_dispatch_target_; |
| 707 event_dispatch_target_ = target; | 711 event_dispatch_target_ = target; |
| 708 ui::EventDispatchDetails details = DispatchEvent(target, event); | 712 ui::EventDispatchDetails details = DispatchEvent(target, event); |
| 709 if (!details.dispatcher_destroyed) | 713 if (!details.dispatcher_destroyed) |
| 710 event_dispatch_target_ = old_target; | 714 event_dispatch_target_ = old_target; |
| 715 return details; | |
| 711 } | 716 } |
| 712 | 717 |
| 713 void RootView::NotifyEnterExitOfDescendant(const ui::MouseEvent& event, | 718 void RootView::NotifyEnterExitOfDescendant(const ui::MouseEvent& event, |
| 714 ui::EventType type, | 719 ui::EventType type, |
| 715 View* view, | 720 View* view, |
| 716 View* sibling) { | 721 View* sibling) { |
| 717 for (View* p = view->parent(); p; p = p->parent()) { | 722 for (View* p = view->parent(); p; p = p->parent()) { |
| 718 if (!p->notify_enter_exit_on_child()) | 723 if (!p->notify_enter_exit_on_child()) |
| 719 continue; | 724 continue; |
| 720 if (sibling && p->Contains(sibling)) | 725 if (sibling && p->Contains(sibling)) |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 739 return; | 744 return; |
| 740 } | 745 } |
| 741 } | 746 } |
| 742 | 747 |
| 743 bool RootView::CanDispatchToTarget(ui::EventTarget* target) { | 748 bool RootView::CanDispatchToTarget(ui::EventTarget* target) { |
| 744 return event_dispatch_target_ == target; | 749 return event_dispatch_target_ == target; |
| 745 } | 750 } |
| 746 | 751 |
| 747 } // namespace internal | 752 } // namespace internal |
| 748 } // namespace views | 753 } // namespace views |
| OLD | NEW |