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 "ash/shell.h" | 5 #include "ash/shell.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "ash/accelerators/accelerator_controller.h" | 11 #include "ash/accelerators/accelerator_controller.h" |
12 #include "ash/accelerators/accelerator_delegate.h" | 12 #include "ash/accelerators/accelerator_delegate.h" |
13 #include "ash/accelerators/focus_manager_factory.h" | 13 #include "ash/accelerators/focus_manager_factory.h" |
14 #include "ash/aura/wm_shell_aura.h" | 14 #include "ash/aura/wm_shell_aura.h" |
15 #include "ash/aura/wm_window_aura.h" | 15 #include "ash/aura/wm_window_aura.h" |
16 #include "ash/autoclick/autoclick_controller.h" | 16 #include "ash/autoclick/autoclick_controller.h" |
17 #include "ash/common/ash_switches.h" | 17 #include "ash/common/ash_switches.h" |
18 #include "ash/common/gpu_support.h" | 18 #include "ash/common/gpu_support.h" |
19 #include "ash/common/keyboard/keyboard_ui.h" | 19 #include "ash/common/keyboard/keyboard_ui.h" |
20 #include "ash/common/login_status.h" | 20 #include "ash/common/login_status.h" |
21 #include "ash/common/pointer_watcher_delegate.h" | 21 #include "ash/common/pointer_watcher_delegate.h" |
22 #include "ash/common/session/session_state_delegate.h" | 22 #include "ash/common/session/session_state_delegate.h" |
23 #include "ash/common/shelf/app_list_shelf_item_delegate.h" | |
23 #include "ash/common/shelf/shelf_item_delegate.h" | 24 #include "ash/common/shelf/shelf_item_delegate.h" |
24 #include "ash/common/shelf/shelf_item_delegate_manager.h" | 25 #include "ash/common/shelf/shelf_item_delegate_manager.h" |
25 #include "ash/common/shelf/shelf_model.h" | 26 #include "ash/common/shelf/shelf_model.h" |
26 #include "ash/common/shell_delegate.h" | 27 #include "ash/common/shell_delegate.h" |
27 #include "ash/common/shell_window_ids.h" | 28 #include "ash/common/shell_window_ids.h" |
28 #include "ash/common/system/locale/locale_notification_controller.h" | 29 #include "ash/common/system/locale/locale_notification_controller.h" |
29 #include "ash/common/system/status_area_widget.h" | 30 #include "ash/common/system/status_area_widget.h" |
30 #include "ash/common/system/toast/toast_manager.h" | 31 #include "ash/common/system/toast/toast_manager.h" |
31 #include "ash/common/system/tray/system_tray_delegate.h" | 32 #include "ash/common/system/tray/system_tray_delegate.h" |
32 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | 33 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
(...skipping 16 matching lines...) Expand all Loading... | |
49 #include "ash/first_run/first_run_helper_impl.h" | 50 #include "ash/first_run/first_run_helper_impl.h" |
50 #include "ash/frame/custom_frame_view_ash.h" | 51 #include "ash/frame/custom_frame_view_ash.h" |
51 #include "ash/high_contrast/high_contrast_controller.h" | 52 #include "ash/high_contrast/high_contrast_controller.h" |
52 #include "ash/host/ash_window_tree_host_init_params.h" | 53 #include "ash/host/ash_window_tree_host_init_params.h" |
53 #include "ash/ime/input_method_event_handler.h" | 54 #include "ash/ime/input_method_event_handler.h" |
54 #include "ash/keyboard_uma_event_filter.h" | 55 #include "ash/keyboard_uma_event_filter.h" |
55 #include "ash/magnifier/magnification_controller.h" | 56 #include "ash/magnifier/magnification_controller.h" |
56 #include "ash/magnifier/partial_magnification_controller.h" | 57 #include "ash/magnifier/partial_magnification_controller.h" |
57 #include "ash/new_window_delegate.h" | 58 #include "ash/new_window_delegate.h" |
58 #include "ash/root_window_controller.h" | 59 #include "ash/root_window_controller.h" |
59 #include "ash/shelf/app_list_shelf_item_delegate.h" | |
60 #include "ash/shelf/shelf.h" | 60 #include "ash/shelf/shelf.h" |
61 #include "ash/shelf/shelf_delegate.h" | 61 #include "ash/shelf/shelf_delegate.h" |
62 #include "ash/shelf/shelf_widget.h" | 62 #include "ash/shelf/shelf_widget.h" |
63 #include "ash/shelf/shelf_window_watcher.h" | 63 #include "ash/shelf/shelf_window_watcher.h" |
64 #include "ash/shell_factory.h" | 64 #include "ash/shell_factory.h" |
65 #include "ash/shell_init_params.h" | 65 #include "ash/shell_init_params.h" |
66 #include "ash/utility/screenshot_controller.h" | 66 #include "ash/utility/screenshot_controller.h" |
67 #include "ash/wm/ash_focus_rules.h" | 67 #include "ash/wm/ash_focus_rules.h" |
68 #include "ash/wm/ash_native_cursor_manager.h" | 68 #include "ash/wm/ash_native_cursor_manager.h" |
69 #include "ash/wm/event_client_impl.h" | 69 #include "ash/wm/event_client_impl.h" |
70 #include "ash/wm/lock_state_controller.h" | 70 #include "ash/wm/lock_state_controller.h" |
71 #include "ash/wm/overlay_event_filter.h" | 71 #include "ash/wm/overlay_event_filter.h" |
72 #include "ash/wm/overview/scoped_overview_animation_settings_factory_aura.h" | 72 #include "ash/wm/overview/scoped_overview_animation_settings_factory_aura.h" |
73 #include "ash/wm/power_button_controller.h" | 73 #include "ash/wm/power_button_controller.h" |
74 #include "ash/wm/resize_shadow_controller.h" | 74 #include "ash/wm/resize_shadow_controller.h" |
75 #include "ash/wm/screen_pinning_controller.h" | 75 #include "ash/wm/screen_pinning_controller.h" |
76 #include "ash/wm/system_gesture_event_filter.h" | 76 #include "ash/wm/system_gesture_event_filter.h" |
77 #include "ash/wm/system_modal_container_event_filter.h" | 77 #include "ash/wm/system_modal_container_event_filter.h" |
78 #include "ash/wm/system_modal_container_layout_manager.h" | 78 #include "ash/wm/system_modal_container_layout_manager.h" |
79 #include "ash/wm/toplevel_window_event_handler.h" | 79 #include "ash/wm/toplevel_window_event_handler.h" |
80 #include "ash/wm/video_detector.h" | 80 #include "ash/wm/video_detector.h" |
81 #include "ash/wm/window_animations.h" | 81 #include "ash/wm/window_animations.h" |
82 #include "ash/wm/window_properties.h" | 82 #include "ash/wm/window_properties.h" |
83 #include "ash/wm/window_util.h" | 83 #include "ash/wm/window_util.h" |
84 #include "ash/wm/workspace_controller.h" | 84 #include "ash/wm/workspace_controller.h" |
85 #include "base/bind.h" | 85 #include "base/bind.h" |
86 #include "base/memory/ptr_util.h" | 86 #include "base/memory/ptr_util.h" |
87 #include "base/trace_event/trace_event.h" | 87 #include "base/trace_event/trace_event.h" |
88 #include "ui/app_list/presenter/app_list_presenter.h" | |
89 #include "ui/aura/client/aura_constants.h" | 88 #include "ui/aura/client/aura_constants.h" |
90 #include "ui/aura/env.h" | 89 #include "ui/aura/env.h" |
91 #include "ui/aura/layout_manager.h" | 90 #include "ui/aura/layout_manager.h" |
92 #include "ui/aura/window.h" | 91 #include "ui/aura/window.h" |
93 #include "ui/aura/window_event_dispatcher.h" | 92 #include "ui/aura/window_event_dispatcher.h" |
94 #include "ui/base/ui_base_switches.h" | 93 #include "ui/base/ui_base_switches.h" |
95 #include "ui/base/user_activity/user_activity_detector.h" | 94 #include "ui/base/user_activity/user_activity_detector.h" |
96 #include "ui/compositor/layer.h" | 95 #include "ui/compositor/layer.h" |
97 #include "ui/compositor/layer_animator.h" | 96 #include "ui/compositor/layer_animator.h" |
98 #include "ui/display/display.h" | 97 #include "ui/display/display.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 #endif | 152 #endif |
154 #endif // defined(OS_CHROMEOS) | 153 #endif // defined(OS_CHROMEOS) |
155 | 154 |
156 namespace ash { | 155 namespace ash { |
157 | 156 |
158 namespace { | 157 namespace { |
159 | 158 |
160 using aura::Window; | 159 using aura::Window; |
161 using views::Widget; | 160 using views::Widget; |
162 | 161 |
163 // Returns the display id corresponding to window, or |GetTargetDisplayId()| | |
164 // if |window| is null. | |
165 int64_t GetDisplayIdForWindow(aura::Window* window) { | |
166 if (!window) | |
167 return Shell::GetTargetDisplayId(); | |
168 return display::Screen::GetScreen()->GetDisplayNearestWindow(window).id(); | |
169 } | |
170 | |
171 // A Corewm VisibilityController subclass that calls the Ash animation routine | 162 // A Corewm VisibilityController subclass that calls the Ash animation routine |
172 // so we can pick up our extended animations. See ash/wm/window_animations.h. | 163 // so we can pick up our extended animations. See ash/wm/window_animations.h. |
173 class AshVisibilityController : public ::wm::VisibilityController { | 164 class AshVisibilityController : public ::wm::VisibilityController { |
174 public: | 165 public: |
175 AshVisibilityController() {} | 166 AshVisibilityController() {} |
176 ~AshVisibilityController() override {} | 167 ~AshVisibilityController() override {} |
177 | 168 |
178 private: | 169 private: |
179 // Overridden from ::wm::VisibilityController: | 170 // Overridden from ::wm::VisibilityController: |
180 bool CallAnimateOnChildWindowVisibilityChanged(aura::Window* window, | 171 bool CallAnimateOnChildWindowVisibilityChanged(aura::Window* window, |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
308 // No context menus when screen is locked. | 299 // No context menus when screen is locked. |
309 if (session_state_delegate_->IsScreenLocked()) | 300 if (session_state_delegate_->IsScreenLocked()) |
310 return; | 301 return; |
311 | 302 |
312 aura::Window* root = WmWindowAura::GetAuraWindow( | 303 aura::Window* root = WmWindowAura::GetAuraWindow( |
313 wm::GetRootWindowMatching(gfx::Rect(location_in_screen, gfx::Size()))); | 304 wm::GetRootWindowMatching(gfx::Rect(location_in_screen, gfx::Size()))); |
314 GetRootWindowController(root)->ShowContextMenu(location_in_screen, | 305 GetRootWindowController(root)->ShowContextMenu(location_in_screen, |
315 source_type); | 306 source_type); |
316 } | 307 } |
317 | 308 |
318 void Shell::ShowAppList(aura::Window* window) { | |
319 // If the context window is not given, show it on the target root window. | |
320 wm_shell_->delegate()->GetAppListPresenter()->Show( | |
321 GetDisplayIdForWindow(window)); | |
322 } | |
323 | |
324 void Shell::DismissAppList() { | |
325 wm_shell_->delegate()->GetAppListPresenter()->Dismiss(); | |
326 } | |
327 | |
328 void Shell::ToggleAppList(aura::Window* window) { | |
329 // If the context window is not given, show it on the target root window. | |
330 wm_shell_->delegate()->GetAppListPresenter()->ToggleAppList( | |
331 GetDisplayIdForWindow(window)); | |
332 } | |
333 | |
334 bool Shell::IsApplistVisible() const { | |
335 return wm_shell_->delegate()->GetAppListPresenter()->IsVisible(); | |
336 } | |
337 | |
338 bool Shell::GetAppListTargetVisibility() const { | |
339 return wm_shell_->delegate()->GetAppListPresenter()->GetTargetVisibility(); | |
340 } | |
341 | |
342 views::NonClientFrameView* Shell::CreateDefaultNonClientFrameView( | 309 views::NonClientFrameView* Shell::CreateDefaultNonClientFrameView( |
343 views::Widget* widget) { | 310 views::Widget* widget) { |
344 // Use translucent-style window frames for dialogs. | 311 // Use translucent-style window frames for dialogs. |
345 return new CustomFrameViewAsh(widget); | 312 return new CustomFrameViewAsh(widget); |
346 } | 313 } |
347 | 314 |
348 void Shell::SetDisplayWorkAreaInsets(Window* contains, | 315 void Shell::SetDisplayWorkAreaInsets(Window* contains, |
349 const gfx::Insets& insets) { | 316 const gfx::Insets& insets) { |
350 if (!window_tree_host_manager_->UpdateWorkAreaOfDisplayNearestWindow( | 317 if (!window_tree_host_manager_->UpdateWorkAreaOfDisplayNearestWindow( |
351 contains, insets)) { | 318 contains, insets)) { |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
532 ShelfWidget* shelf = GetPrimaryRootWindowController()->shelf_widget(); | 499 ShelfWidget* shelf = GetPrimaryRootWindowController()->shelf_widget(); |
533 return shelf && shelf->status_area_widget(); | 500 return shelf && shelf->status_area_widget(); |
534 } | 501 } |
535 | 502 |
536 SystemTray* Shell::GetPrimarySystemTray() { | 503 SystemTray* Shell::GetPrimarySystemTray() { |
537 return GetPrimaryRootWindowController()->GetSystemTray(); | 504 return GetPrimaryRootWindowController()->GetSystemTray(); |
538 } | 505 } |
539 | 506 |
540 ShelfDelegate* Shell::GetShelfDelegate() { | 507 ShelfDelegate* Shell::GetShelfDelegate() { |
541 if (!shelf_delegate_) { | 508 if (!shelf_delegate_) { |
509 ShelfModel* shelf_model = wm_shell_->shelf_model(); | |
542 // Creates ShelfItemDelegateManager before ShelfDelegate. | 510 // Creates ShelfItemDelegateManager before ShelfDelegate. |
511 // TODO(jamescook): Move this into WmShell. | |
543 shelf_item_delegate_manager_.reset( | 512 shelf_item_delegate_manager_.reset( |
544 new ShelfItemDelegateManager(shelf_model_.get())); | 513 new ShelfItemDelegateManager(shelf_model)); |
545 | 514 |
546 shelf_delegate_.reset( | 515 shelf_delegate_.reset( |
547 wm_shell_->delegate()->CreateShelfDelegate(shelf_model_.get())); | 516 wm_shell_->delegate()->CreateShelfDelegate(shelf_model)); |
548 std::unique_ptr<ShelfItemDelegate> controller(new AppListShelfItemDelegate); | 517 std::unique_ptr<ShelfItemDelegate> controller(new AppListShelfItemDelegate); |
msw
2016/07/20 17:33:50
future: This should probably happen in shelf_view.
James Cook
2016/07/20 18:35:39
Acknowledged.
| |
549 | 518 |
550 // Finding the shelf model's location of the app list and setting its | 519 // Finding the shelf model's location of the app list and setting its |
551 // ShelfItemDelegate. | 520 // ShelfItemDelegate. |
552 int app_list_index = shelf_model_->GetItemIndexForType(TYPE_APP_LIST); | 521 int app_list_index = shelf_model->GetItemIndexForType(TYPE_APP_LIST); |
553 DCHECK_GE(app_list_index, 0); | 522 DCHECK_GE(app_list_index, 0); |
554 ShelfID app_list_id = shelf_model_->items()[app_list_index].id; | 523 ShelfID app_list_id = shelf_model->items()[app_list_index].id; |
555 DCHECK(app_list_id); | 524 DCHECK(app_list_id); |
556 shelf_item_delegate_manager_->SetShelfItemDelegate(app_list_id, | 525 shelf_item_delegate_manager_->SetShelfItemDelegate(app_list_id, |
557 std::move(controller)); | 526 std::move(controller)); |
558 shelf_window_watcher_.reset(new ShelfWindowWatcher( | 527 shelf_window_watcher_.reset(new ShelfWindowWatcher( |
559 shelf_model_.get(), shelf_item_delegate_manager_.get())); | 528 shelf_model, shelf_item_delegate_manager_.get())); |
560 } | 529 } |
561 return shelf_delegate_.get(); | 530 return shelf_delegate_.get(); |
562 } | 531 } |
563 | 532 |
564 void Shell::SetTouchHudProjectionEnabled(bool enabled) { | 533 void Shell::SetTouchHudProjectionEnabled(bool enabled) { |
565 if (is_touch_hud_projection_enabled_ == enabled) | 534 if (is_touch_hud_projection_enabled_ == enabled) |
566 return; | 535 return; |
567 | 536 |
568 is_touch_hud_projection_enabled_ = enabled; | 537 is_touch_hud_projection_enabled_ = enabled; |
569 FOR_EACH_OBSERVER(ShellObserver, *wm_shell_->shell_observers(), | 538 FOR_EACH_OBSERVER(ShellObserver, *wm_shell_->shell_observers(), |
(...skipping 18 matching lines...) Expand all Loading... | |
588 ->DoInitialAnimation(); | 557 ->DoInitialAnimation(); |
589 } | 558 } |
590 | 559 |
591 //////////////////////////////////////////////////////////////////////////////// | 560 //////////////////////////////////////////////////////////////////////////////// |
592 // Shell, private: | 561 // Shell, private: |
593 | 562 |
594 Shell::Shell(ShellDelegate* delegate, base::SequencedWorkerPool* blocking_pool) | 563 Shell::Shell(ShellDelegate* delegate, base::SequencedWorkerPool* blocking_pool) |
595 : wm_shell_(new WmShellAura(base::WrapUnique(delegate))), | 564 : wm_shell_(new WmShellAura(base::WrapUnique(delegate))), |
596 target_root_window_(nullptr), | 565 target_root_window_(nullptr), |
597 scoped_target_root_window_(nullptr), | 566 scoped_target_root_window_(nullptr), |
598 shelf_model_(new ShelfModel), | |
599 link_handler_model_factory_(nullptr), | 567 link_handler_model_factory_(nullptr), |
600 activation_client_(nullptr), | 568 activation_client_(nullptr), |
601 #if defined(OS_CHROMEOS) | 569 #if defined(OS_CHROMEOS) |
602 display_configurator_(new ui::DisplayConfigurator()), | 570 display_configurator_(new ui::DisplayConfigurator()), |
603 #endif // defined(OS_CHROMEOS) | 571 #endif // defined(OS_CHROMEOS) |
604 native_cursor_manager_(nullptr), | 572 native_cursor_manager_(nullptr), |
605 simulate_modal_window_open_for_testing_(false), | 573 simulate_modal_window_open_for_testing_(false), |
606 is_touch_hud_projection_enabled_(false), | 574 is_touch_hud_projection_enabled_(false), |
607 blocking_pool_(blocking_pool) { | 575 blocking_pool_(blocking_pool) { |
608 DCHECK(aura::Env::GetInstanceDontCreate()); | 576 DCHECK(aura::Env::GetInstanceDontCreate()); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
699 video_detector_.reset(); | 667 video_detector_.reset(); |
700 high_contrast_controller_.reset(); | 668 high_contrast_controller_.reset(); |
701 | 669 |
702 shadow_controller_.reset(); | 670 shadow_controller_.reset(); |
703 resize_shadow_controller_.reset(); | 671 resize_shadow_controller_.reset(); |
704 | 672 |
705 // Has to happen before ~MruWindowTracker. | 673 // Has to happen before ~MruWindowTracker. |
706 wm_shell_->DeleteWindowCycleController(); | 674 wm_shell_->DeleteWindowCycleController(); |
707 wm_shell_->DeleteWindowSelectorController(); | 675 wm_shell_->DeleteWindowSelectorController(); |
708 | 676 |
709 // |shelf_window_watcher_| has a weak pointer to |shelf_Model_| | 677 // |shelf_window_watcher_| has a weak pointer to the shelf model and has |
710 // and has window observers. | 678 // window observers. |
711 shelf_window_watcher_.reset(); | 679 shelf_window_watcher_.reset(); |
712 | 680 |
713 // Destroy all child windows including widgets. | 681 // Destroy all child windows including widgets. |
714 window_tree_host_manager_->CloseChildWindows(); | 682 window_tree_host_manager_->CloseChildWindows(); |
715 // MruWindowTracker must be destroyed after all windows have been deleted to | 683 // MruWindowTracker must be destroyed after all windows have been deleted to |
716 // avoid a possible crash when Shell is destroyed from a non-normal shutdown | 684 // avoid a possible crash when Shell is destroyed from a non-normal shutdown |
717 // path. (crbug.com/485438). | 685 // path. (crbug.com/485438). |
718 wm_shell_->DeleteMruWindowTracker(); | 686 wm_shell_->DeleteMruWindowTracker(); |
719 | 687 |
720 // Chrome implementation of shelf delegate depends on FocusClient, | 688 // Chrome implementation of shelf delegate depends on FocusClient, |
721 // so must be deleted before |focus_client_| (below). | 689 // so must be deleted before |focus_client_| (below). |
722 shelf_delegate_.reset(); | 690 shelf_delegate_.reset(); |
723 | 691 |
724 // These need a valid Shell instance to clean up properly, so explicitly | 692 // These need a valid Shell instance to clean up properly, so explicitly |
725 // delete them before invalidating the instance. | 693 // delete them before invalidating the instance. |
726 // Alphabetical. TODO(oshima): sort. | 694 // Alphabetical. TODO(oshima): sort. |
727 magnification_controller_.reset(); | 695 magnification_controller_.reset(); |
728 partial_magnification_controller_.reset(); | 696 partial_magnification_controller_.reset(); |
729 tooltip_controller_.reset(); | 697 tooltip_controller_.reset(); |
730 event_client_.reset(); | 698 event_client_.reset(); |
731 toplevel_window_event_handler_.reset(); | 699 toplevel_window_event_handler_.reset(); |
732 visibility_controller_.reset(); | 700 visibility_controller_.reset(); |
733 // |shelf_item_delegate_manager_| observes |shelf_model_|. It must be | 701 // |shelf_item_delegate_manager_| observes the shelf model. |
734 // destroyed before |shelf_model_| is destroyed. | |
735 shelf_item_delegate_manager_.reset(); | 702 shelf_item_delegate_manager_.reset(); |
736 shelf_model_.reset(); | |
737 | 703 |
738 power_button_controller_.reset(); | 704 power_button_controller_.reset(); |
739 lock_state_controller_.reset(); | 705 lock_state_controller_.reset(); |
740 | 706 |
741 screen_pinning_controller_.reset(); | 707 screen_pinning_controller_.reset(); |
742 | 708 |
743 #if defined(OS_CHROMEOS) | 709 #if defined(OS_CHROMEOS) |
744 resolution_notification_controller_.reset(); | 710 resolution_notification_controller_.reset(); |
745 #endif | 711 #endif |
746 desktop_background_controller_.reset(); | 712 desktop_background_controller_.reset(); |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1162 | 1128 |
1163 void Shell::OnWindowActivated( | 1129 void Shell::OnWindowActivated( |
1164 aura::client::ActivationChangeObserver::ActivationReason reason, | 1130 aura::client::ActivationChangeObserver::ActivationReason reason, |
1165 aura::Window* gained_active, | 1131 aura::Window* gained_active, |
1166 aura::Window* lost_active) { | 1132 aura::Window* lost_active) { |
1167 if (gained_active) | 1133 if (gained_active) |
1168 target_root_window_ = gained_active->GetRootWindow(); | 1134 target_root_window_ = gained_active->GetRootWindow(); |
1169 } | 1135 } |
1170 | 1136 |
1171 } // namespace ash | 1137 } // namespace ash |
OLD | NEW |