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/macros.h" | 10 #include "base/macros.h" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 // RootView, public: | 150 // RootView, public: |
| 151 | 151 |
| 152 // Creation and lifetime ------------------------------------------------------- | 152 // Creation and lifetime ------------------------------------------------------- |
| 153 | 153 |
| 154 RootView::RootView(Widget* widget) | 154 RootView::RootView(Widget* widget) |
| 155 : widget_(widget), | 155 : widget_(widget), |
| 156 mouse_pressed_handler_(NULL), | 156 mouse_pressed_handler_(NULL), |
| 157 mouse_move_handler_(NULL), | 157 mouse_move_handler_(NULL), |
| 158 last_click_handler_(NULL), | 158 last_click_handler_(NULL), |
| 159 explicit_mouse_handler_(false), | 159 explicit_mouse_handler_(false), |
| 160 clear_mouse_handler_on_release_(true), | |
| 160 last_mouse_event_flags_(0), | 161 last_mouse_event_flags_(0), |
| 161 last_mouse_event_x_(-1), | 162 last_mouse_event_x_(-1), |
| 162 last_mouse_event_y_(-1), | 163 last_mouse_event_y_(-1), |
| 163 gesture_handler_(NULL), | 164 gesture_handler_(NULL), |
| 164 gesture_handler_set_before_processing_(false), | 165 gesture_handler_set_before_processing_(false), |
| 165 pre_dispatch_handler_(new internal::PreEventDispatchHandler(this)), | 166 pre_dispatch_handler_(new internal::PreEventDispatchHandler(this)), |
| 166 post_dispatch_handler_(new internal::PostEventDispatchHandler), | 167 post_dispatch_handler_(new internal::PostEventDispatchHandler), |
| 167 focus_search_(this, false, false), | 168 focus_search_(this, false, false), |
| 168 focus_traversable_parent_(NULL), | 169 focus_traversable_parent_(NULL), |
| 169 focus_traversable_parent_view_(NULL), | 170 focus_traversable_parent_view_(NULL), |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 434 | 435 |
| 435 void RootView::OnMouseReleased(const ui::MouseEvent& event) { | 436 void RootView::OnMouseReleased(const ui::MouseEvent& event) { |
| 436 UpdateCursor(event); | 437 UpdateCursor(event); |
| 437 | 438 |
| 438 if (mouse_pressed_handler_) { | 439 if (mouse_pressed_handler_) { |
| 439 ui::MouseEvent mouse_released(event, static_cast<View*>(this), | 440 ui::MouseEvent mouse_released(event, static_cast<View*>(this), |
| 440 mouse_pressed_handler_); | 441 mouse_pressed_handler_); |
| 441 // We allow the view to delete us from the event dispatch callback. As such, | 442 // We allow the view to delete us from the event dispatch callback. As such, |
| 442 // configure state such that we're done first, then call View. | 443 // configure state such that we're done first, then call View. |
| 443 View* mouse_pressed_handler = mouse_pressed_handler_; | 444 View* mouse_pressed_handler = mouse_pressed_handler_; |
| 444 SetMouseHandler(NULL); | 445 if (clear_mouse_handler_on_release_) { |
|
sky
2016/04/11 15:25:45
nit: no {}
| |
| 446 SetMouseHandler(nullptr); | |
| 447 } | |
| 445 ui::EventDispatchDetails dispatch_details = | 448 ui::EventDispatchDetails dispatch_details = |
| 446 DispatchEvent(mouse_pressed_handler, &mouse_released); | 449 DispatchEvent(mouse_pressed_handler, &mouse_released); |
| 447 if (dispatch_details.dispatcher_destroyed) | 450 if (dispatch_details.dispatcher_destroyed) |
| 448 return; | 451 return; |
| 449 } | 452 } |
| 450 } | 453 } |
| 451 | 454 |
| 452 void RootView::OnMouseCaptureLost() { | 455 void RootView::OnMouseCaptureLost() { |
| 453 // TODO: this likely needs to reset touch handler too. | 456 // TODO: this likely needs to reset touch handler too. |
| 454 | 457 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 585 DispatchEvent(v, const_cast<ui::MouseWheelEvent*>(&event)); | 588 DispatchEvent(v, const_cast<ui::MouseWheelEvent*>(&event)); |
| 586 if (dispatch_details.dispatcher_destroyed || | 589 if (dispatch_details.dispatcher_destroyed || |
| 587 dispatch_details.target_destroyed) { | 590 dispatch_details.target_destroyed) { |
| 588 return event.handled(); | 591 return event.handled(); |
| 589 } | 592 } |
| 590 } | 593 } |
| 591 return event.handled(); | 594 return event.handled(); |
| 592 } | 595 } |
| 593 | 596 |
| 594 void RootView::SetMouseHandler(View* new_mh) { | 597 void RootView::SetMouseHandler(View* new_mh) { |
| 595 // If we're clearing the mouse handler, clear explicit_mouse_handler_ as well. | 598 SetMouseHandler(new_mh, true /* clear_on_release */); |
| 596 explicit_mouse_handler_ = (new_mh != NULL); | |
| 597 mouse_pressed_handler_ = new_mh; | |
| 598 gesture_handler_ = new_mh; | |
| 599 drag_info_.Reset(); | |
| 600 } | 599 } |
| 601 | 600 |
| 602 void RootView::GetAccessibleState(ui::AXViewState* state) { | 601 void RootView::GetAccessibleState(ui::AXViewState* state) { |
| 603 state->name = widget_->widget_delegate()->GetAccessibleWindowTitle(); | 602 state->name = widget_->widget_delegate()->GetAccessibleWindowTitle(); |
| 604 state->role = widget_->widget_delegate()->GetAccessibleWindowRole(); | 603 state->role = widget_->widget_delegate()->GetAccessibleWindowRole(); |
| 605 } | 604 } |
| 606 | 605 |
| 607 void RootView::UpdateParentLayer() { | 606 void RootView::UpdateParentLayer() { |
| 608 if (layer()) | 607 if (layer()) |
| 609 ReparentLayer(gfx::Vector2d(GetMirroredX(), y()), widget_->GetLayer()); | 608 ReparentLayer(gfx::Vector2d(GetMirroredX(), y()), widget_->GetLayer()); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 629 old_dispatch_target_ = NULL; | 628 old_dispatch_target_ = NULL; |
| 630 } | 629 } |
| 631 } | 630 } |
| 632 | 631 |
| 633 void RootView::VisibilityChanged(View* /*starting_from*/, bool is_visible) { | 632 void RootView::VisibilityChanged(View* /*starting_from*/, bool is_visible) { |
| 634 if (!is_visible) { | 633 if (!is_visible) { |
| 635 // When the root view is being hidden (e.g. when widget is minimized) | 634 // When the root view is being hidden (e.g. when widget is minimized) |
| 636 // handlers are reset, so that after it is reshown, events are not captured | 635 // handlers are reset, so that after it is reshown, events are not captured |
| 637 // by old handlers. | 636 // by old handlers. |
| 638 explicit_mouse_handler_ = false; | 637 explicit_mouse_handler_ = false; |
| 638 clear_mouse_handler_on_release_ = true; | |
| 639 mouse_pressed_handler_ = NULL; | 639 mouse_pressed_handler_ = NULL; |
| 640 mouse_move_handler_ = NULL; | 640 mouse_move_handler_ = NULL; |
| 641 gesture_handler_ = NULL; | 641 gesture_handler_ = NULL; |
| 642 event_dispatch_target_ = NULL; | 642 event_dispatch_target_ = NULL; |
| 643 old_dispatch_target_ = NULL; | 643 old_dispatch_target_ = NULL; |
| 644 } | 644 } |
| 645 } | 645 } |
| 646 | 646 |
| 647 void RootView::OnPaint(gfx::Canvas* canvas) { | 647 void RootView::OnPaint(gfx::Canvas* canvas) { |
| 648 if (!layer() || !layer()->fills_bounds_opaquely()) | 648 if (!layer() || !layer()->fills_bounds_opaquely()) |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 698 MouseEnterExitEvent notify_event(event, type); | 698 MouseEnterExitEvent notify_event(event, type); |
| 699 ui::EventDispatchDetails dispatch_details = DispatchEvent(p, ¬ify_event); | 699 ui::EventDispatchDetails dispatch_details = DispatchEvent(p, ¬ify_event); |
| 700 if (dispatch_details.dispatcher_destroyed || | 700 if (dispatch_details.dispatcher_destroyed || |
| 701 dispatch_details.target_destroyed) { | 701 dispatch_details.target_destroyed) { |
| 702 return dispatch_details; | 702 return dispatch_details; |
| 703 } | 703 } |
| 704 } | 704 } |
| 705 return ui::EventDispatchDetails(); | 705 return ui::EventDispatchDetails(); |
| 706 } | 706 } |
| 707 | 707 |
| 708 void RootView::SetMouseHandler(View* new_mh, bool clear_on_release) { | |
| 709 // If we're clearing the mouse handler, clear explicit_mouse_handler_ as well. | |
| 710 explicit_mouse_handler_ = (new_mh != nullptr); | |
| 711 clear_mouse_handler_on_release_ = clear_on_release; | |
| 712 mouse_pressed_handler_ = new_mh; | |
| 713 gesture_handler_ = new_mh; | |
| 714 drag_info_.Reset(); | |
| 715 } | |
| 716 | |
| 708 bool RootView::CanDispatchToTarget(ui::EventTarget* target) { | 717 bool RootView::CanDispatchToTarget(ui::EventTarget* target) { |
| 709 return event_dispatch_target_ == target; | 718 return event_dispatch_target_ == target; |
| 710 } | 719 } |
| 711 | 720 |
| 712 ui::EventDispatchDetails RootView::PreDispatchEvent(ui::EventTarget* target, | 721 ui::EventDispatchDetails RootView::PreDispatchEvent(ui::EventTarget* target, |
| 713 ui::Event* event) { | 722 ui::Event* event) { |
| 714 View* view = static_cast<View*>(target); | 723 View* view = static_cast<View*>(target); |
| 715 if (event->IsGestureEvent()) { | 724 if (event->IsGestureEvent()) { |
| 716 // Update |gesture_handler_| to indicate which View is currently handling | 725 // Update |gesture_handler_| to indicate which View is currently handling |
| 717 // gesture events. | 726 // gesture events. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 756 | 765 |
| 757 #ifndef NDEBUG | 766 #ifndef NDEBUG |
| 758 DCHECK(!event_dispatch_target_ || Contains(event_dispatch_target_)); | 767 DCHECK(!event_dispatch_target_ || Contains(event_dispatch_target_)); |
| 759 #endif | 768 #endif |
| 760 | 769 |
| 761 return details; | 770 return details; |
| 762 } | 771 } |
| 763 | 772 |
| 764 } // namespace internal | 773 } // namespace internal |
| 765 } // namespace views | 774 } // namespace views |
| OLD | NEW |