| 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_) |
| 446 SetMouseHandler(nullptr); |
| 445 ui::EventDispatchDetails dispatch_details = | 447 ui::EventDispatchDetails dispatch_details = |
| 446 DispatchEvent(mouse_pressed_handler, &mouse_released); | 448 DispatchEvent(mouse_pressed_handler, &mouse_released); |
| 447 if (dispatch_details.dispatcher_destroyed) | 449 if (dispatch_details.dispatcher_destroyed) |
| 448 return; | 450 return; |
| 449 } | 451 } |
| 450 } | 452 } |
| 451 | 453 |
| 452 void RootView::OnMouseCaptureLost() { | 454 void RootView::OnMouseCaptureLost() { |
| 453 // TODO: this likely needs to reset touch handler too. | 455 // TODO: this likely needs to reset touch handler too. |
| 454 | 456 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 DispatchEvent(v, const_cast<ui::MouseWheelEvent*>(&event)); | 587 DispatchEvent(v, const_cast<ui::MouseWheelEvent*>(&event)); |
| 586 if (dispatch_details.dispatcher_destroyed || | 588 if (dispatch_details.dispatcher_destroyed || |
| 587 dispatch_details.target_destroyed) { | 589 dispatch_details.target_destroyed) { |
| 588 return event.handled(); | 590 return event.handled(); |
| 589 } | 591 } |
| 590 } | 592 } |
| 591 return event.handled(); | 593 return event.handled(); |
| 592 } | 594 } |
| 593 | 595 |
| 594 void RootView::SetMouseHandler(View* new_mh) { | 596 void RootView::SetMouseHandler(View* new_mh) { |
| 595 // If we're clearing the mouse handler, clear explicit_mouse_handler_ as well. | 597 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 } | 598 } |
| 601 | 599 |
| 602 void RootView::GetAccessibleState(ui::AXViewState* state) { | 600 void RootView::GetAccessibleState(ui::AXViewState* state) { |
| 603 state->name = widget_->widget_delegate()->GetAccessibleWindowTitle(); | 601 state->name = widget_->widget_delegate()->GetAccessibleWindowTitle(); |
| 604 state->role = widget_->widget_delegate()->GetAccessibleWindowRole(); | 602 state->role = widget_->widget_delegate()->GetAccessibleWindowRole(); |
| 605 } | 603 } |
| 606 | 604 |
| 607 void RootView::UpdateParentLayer() { | 605 void RootView::UpdateParentLayer() { |
| 608 if (layer()) | 606 if (layer()) |
| 609 ReparentLayer(gfx::Vector2d(GetMirroredX(), y()), widget_->GetLayer()); | 607 ReparentLayer(gfx::Vector2d(GetMirroredX(), y()), widget_->GetLayer()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 629 old_dispatch_target_ = NULL; | 627 old_dispatch_target_ = NULL; |
| 630 } | 628 } |
| 631 } | 629 } |
| 632 | 630 |
| 633 void RootView::VisibilityChanged(View* /*starting_from*/, bool is_visible) { | 631 void RootView::VisibilityChanged(View* /*starting_from*/, bool is_visible) { |
| 634 if (!is_visible) { | 632 if (!is_visible) { |
| 635 // When the root view is being hidden (e.g. when widget is minimized) | 633 // 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 | 634 // handlers are reset, so that after it is reshown, events are not captured |
| 637 // by old handlers. | 635 // by old handlers. |
| 638 explicit_mouse_handler_ = false; | 636 explicit_mouse_handler_ = false; |
| 637 clear_mouse_handler_on_release_ = true; |
| 639 mouse_pressed_handler_ = NULL; | 638 mouse_pressed_handler_ = NULL; |
| 640 mouse_move_handler_ = NULL; | 639 mouse_move_handler_ = NULL; |
| 641 gesture_handler_ = NULL; | 640 gesture_handler_ = NULL; |
| 642 event_dispatch_target_ = NULL; | 641 event_dispatch_target_ = NULL; |
| 643 old_dispatch_target_ = NULL; | 642 old_dispatch_target_ = NULL; |
| 644 } | 643 } |
| 645 } | 644 } |
| 646 | 645 |
| 647 void RootView::OnPaint(gfx::Canvas* canvas) { | 646 void RootView::OnPaint(gfx::Canvas* canvas) { |
| 648 if (!layer() || !layer()->fills_bounds_opaquely()) | 647 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); | 697 MouseEnterExitEvent notify_event(event, type); |
| 699 ui::EventDispatchDetails dispatch_details = DispatchEvent(p, ¬ify_event); | 698 ui::EventDispatchDetails dispatch_details = DispatchEvent(p, ¬ify_event); |
| 700 if (dispatch_details.dispatcher_destroyed || | 699 if (dispatch_details.dispatcher_destroyed || |
| 701 dispatch_details.target_destroyed) { | 700 dispatch_details.target_destroyed) { |
| 702 return dispatch_details; | 701 return dispatch_details; |
| 703 } | 702 } |
| 704 } | 703 } |
| 705 return ui::EventDispatchDetails(); | 704 return ui::EventDispatchDetails(); |
| 706 } | 705 } |
| 707 | 706 |
| 707 void RootView::SetMouseHandler(View* new_mh, bool clear_on_release) { |
| 708 // If we're clearing the mouse handler, clear explicit_mouse_handler_ as well. |
| 709 explicit_mouse_handler_ = (new_mh != nullptr); |
| 710 clear_mouse_handler_on_release_ = clear_on_release; |
| 711 mouse_pressed_handler_ = new_mh; |
| 712 gesture_handler_ = new_mh; |
| 713 drag_info_.Reset(); |
| 714 } |
| 715 |
| 708 bool RootView::CanDispatchToTarget(ui::EventTarget* target) { | 716 bool RootView::CanDispatchToTarget(ui::EventTarget* target) { |
| 709 return event_dispatch_target_ == target; | 717 return event_dispatch_target_ == target; |
| 710 } | 718 } |
| 711 | 719 |
| 712 ui::EventDispatchDetails RootView::PreDispatchEvent(ui::EventTarget* target, | 720 ui::EventDispatchDetails RootView::PreDispatchEvent(ui::EventTarget* target, |
| 713 ui::Event* event) { | 721 ui::Event* event) { |
| 714 View* view = static_cast<View*>(target); | 722 View* view = static_cast<View*>(target); |
| 715 if (event->IsGestureEvent()) { | 723 if (event->IsGestureEvent()) { |
| 716 // Update |gesture_handler_| to indicate which View is currently handling | 724 // Update |gesture_handler_| to indicate which View is currently handling |
| 717 // gesture events. | 725 // gesture events. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 | 764 |
| 757 #ifndef NDEBUG | 765 #ifndef NDEBUG |
| 758 DCHECK(!event_dispatch_target_ || Contains(event_dispatch_target_)); | 766 DCHECK(!event_dispatch_target_ || Contains(event_dispatch_target_)); |
| 759 #endif | 767 #endif |
| 760 | 768 |
| 761 return details; | 769 return details; |
| 762 } | 770 } |
| 763 | 771 |
| 764 } // namespace internal | 772 } // namespace internal |
| 765 } // namespace views | 773 } // namespace views |
| OLD | NEW |