[email protected] | e0d22e8 | 2012-01-04 00:46:57 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 87b0d82e | 2011-10-07 21:02:59 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | b65bdda | 2011-12-23 23:35:31 | [diff] [blame] | 5 | #include "ash/shell.h" |
[email protected] | 87b0d82e | 2011-10-07 21:02:59 | [diff] [blame] | 6 | |
[email protected] | f7eb89c | 2011-12-13 09:48:54 | [diff] [blame] | 7 | #include <algorithm> |
[email protected] | 0039db9 | 2012-05-09 04:11:45 | [diff] [blame] | 8 | #include <string> |
dcheng | cbf0d9d | 2015-12-27 22:49:23 | [diff] [blame] | 9 | #include <utility> |
[email protected] | f7eb89c | 2011-12-13 09:48:54 | [diff] [blame] | 10 | |
[email protected] | 60d677d | 2014-05-30 13:07:02 | [diff] [blame] | 11 | #include "ash/accelerators/accelerator_delegate.h" |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 12 | #include "ash/accelerators/magnifier_key_scroller.h" |
| 13 | #include "ash/accelerators/spoken_feedback_toggler.h" |
sky | 15ef0aa | 2017-01-20 18:55:59 | [diff] [blame] | 14 | #include "ash/app_list/app_list_delegate_impl.h" |
sky | 0702b27 | 2016-06-03 22:10:41 | [diff] [blame] | 15 | #include "ash/aura/wm_shell_aura.h" |
[email protected] | 55398d2 | 2013-10-10 19:49:20 | [diff] [blame] | 16 | #include "ash/autoclick/autoclick_controller.h" |
James Cook | 643b718 | 2017-03-05 22:02:58 | [diff] [blame] | 17 | #include "ash/common/accelerators/accelerator_controller.h" |
sky | 07a24d4 | 2017-03-09 23:57:30 | [diff] [blame] | 18 | #include "ash/common/accelerators/ash_focus_manager_factory.h" |
| 19 | #include "ash/common/accessibility_delegate.h" |
James Cook | 6316a55 | 2017-03-05 21:46:21 | [diff] [blame] | 20 | #include "ash/common/ash_constants.h" |
sky | 79fa3471 | 2017-03-20 23:46:47 | [diff] [blame] | 21 | #include "ash/common/cast_config_controller.h" |
sky | 07a24d4 | 2017-03-09 23:57:30 | [diff] [blame] | 22 | #include "ash/common/devtools/ash_devtools_css_agent.h" |
| 23 | #include "ash/common/devtools/ash_devtools_dom_agent.h" |
sky | 79fa3471 | 2017-03-20 23:46:47 | [diff] [blame] | 24 | #include "ash/common/focus_cycler.h" |
James Cook | 643b718 | 2017-03-05 22:02:58 | [diff] [blame] | 25 | #include "ash/common/frame/custom_frame_view_ash.h" |
James Cook | 6316a55 | 2017-03-05 21:46:21 | [diff] [blame] | 26 | #include "ash/common/gpu_support.h" |
| 27 | #include "ash/common/keyboard/keyboard_ui.h" |
| 28 | #include "ash/common/login_status.h" |
sky | 5ab1647 | 2017-03-21 19:35:08 | [diff] [blame] | 29 | #include "ash/common/media_controller.h" |
| 30 | #include "ash/common/new_window_controller.h" |
sky | 07a24d4 | 2017-03-09 23:57:30 | [diff] [blame] | 31 | #include "ash/common/palette_delegate.h" |
sky | 5ad143a | 2017-03-22 04:31:23 | [diff] [blame] | 32 | #include "ash/common/session/session_controller.h" |
James Cook | 6316a55 | 2017-03-05 21:46:21 | [diff] [blame] | 33 | #include "ash/common/session/session_state_delegate.h" |
sky | 5ad143a | 2017-03-22 04:31:23 | [diff] [blame] | 34 | #include "ash/common/shelf/shelf_controller.h" |
| 35 | #include "ash/common/shelf/shelf_delegate.h" |
| 36 | #include "ash/common/shelf/shelf_model.h" |
| 37 | #include "ash/common/shelf/shelf_window_watcher.h" |
James Cook | 643b718 | 2017-03-05 22:02:58 | [diff] [blame] | 38 | #include "ash/common/shelf/wm_shelf.h" |
James Cook | 6316a55 | 2017-03-05 21:46:21 | [diff] [blame] | 39 | #include "ash/common/shell_delegate.h" |
sky | 00c813f | 2017-03-08 22:48:55 | [diff] [blame] | 40 | #include "ash/common/shell_observer.h" |
sky | 5b45ed8 | 2017-03-27 02:54:23 | [diff] [blame^] | 41 | #include "ash/common/shutdown_controller.h" |
sky | 79fa3471 | 2017-03-20 23:46:47 | [diff] [blame] | 42 | #include "ash/common/system/brightness_control_delegate.h" |
James Cook | 6def4d9d | 2017-03-05 22:13:47 | [diff] [blame] | 43 | #include "ash/common/system/chromeos/bluetooth/bluetooth_notification_controller.h" |
jamescook | ac672433 | 2017-03-21 02:54:43 | [diff] [blame] | 44 | #include "ash/common/system/chromeos/bluetooth/tray_bluetooth_helper.h" |
sky | 79fa3471 | 2017-03-20 23:46:47 | [diff] [blame] | 45 | #include "ash/common/system/chromeos/brightness/brightness_controller_chromeos.h" |
| 46 | #include "ash/common/system/chromeos/keyboard_brightness_controller.h" |
James Cook | 6def4d9d | 2017-03-05 22:13:47 | [diff] [blame] | 47 | #include "ash/common/system/chromeos/network/sms_observer.h" |
sky | 5b45ed8 | 2017-03-27 02:54:23 | [diff] [blame^] | 48 | #include "ash/common/system/chromeos/network/vpn_list.h" |
James Cook | 6def4d9d | 2017-03-05 22:13:47 | [diff] [blame] | 49 | #include "ash/common/system/chromeos/power/power_status.h" |
sky | 79fa3471 | 2017-03-20 23:46:47 | [diff] [blame] | 50 | #include "ash/common/system/chromeos/session/logout_confirmation_controller.h" |
| 51 | #include "ash/common/system/keyboard_brightness_control_delegate.h" |
| 52 | #include "ash/common/system/locale/locale_notification_controller.h" |
James Cook | 6def4d9d | 2017-03-05 22:13:47 | [diff] [blame] | 53 | #include "ash/common/system/status_area_widget.h" |
sky | 07a24d4 | 2017-03-09 23:57:30 | [diff] [blame] | 54 | #include "ash/common/system/toast/toast_manager.h" |
sky | 79fa3471 | 2017-03-20 23:46:47 | [diff] [blame] | 55 | #include "ash/common/system/tray/system_tray_controller.h" |
James Cook | 6def4d9d | 2017-03-05 22:13:47 | [diff] [blame] | 56 | #include "ash/common/system/tray/system_tray_delegate.h" |
sky | 79fa3471 | 2017-03-20 23:46:47 | [diff] [blame] | 57 | #include "ash/common/system/tray/system_tray_notifier.h" |
sky | 07a24d4 | 2017-03-09 23:57:30 | [diff] [blame] | 58 | #include "ash/common/wallpaper/wallpaper_controller.h" |
James Cook | 6316a55 | 2017-03-05 21:46:21 | [diff] [blame] | 59 | #include "ash/common/wallpaper/wallpaper_delegate.h" |
James Cook | 643b718 | 2017-03-05 22:02:58 | [diff] [blame] | 60 | #include "ash/common/wm/container_finder.h" |
sky | 5ab1647 | 2017-03-21 19:35:08 | [diff] [blame] | 61 | #include "ash/common/wm/immersive_context_ash.h" |
James Cook | 643b718 | 2017-03-05 22:02:58 | [diff] [blame] | 62 | #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
| 63 | #include "ash/common/wm/maximize_mode/maximize_mode_window_manager.h" |
| 64 | #include "ash/common/wm/mru_window_tracker.h" |
sky | 5b45ed8 | 2017-03-27 02:54:23 | [diff] [blame^] | 65 | #include "ash/common/wm/overview/window_selector_controller.h" |
James Cook | 643b718 | 2017-03-05 22:02:58 | [diff] [blame] | 66 | #include "ash/common/wm/root_window_finder.h" |
| 67 | #include "ash/common/wm/system_modal_container_layout_manager.h" |
sky | 5b45ed8 | 2017-03-27 02:54:23 | [diff] [blame^] | 68 | #include "ash/common/wm/window_cycle_controller.h" |
James Cook | 643b718 | 2017-03-05 22:02:58 | [diff] [blame] | 69 | #include "ash/common/wm/window_positioner.h" |
| 70 | #include "ash/common/wm/workspace_controller.h" |
James Cook | 6316a55 | 2017-03-05 21:46:21 | [diff] [blame] | 71 | #include "ash/common/wm_shell.h" |
| 72 | #include "ash/common/wm_window.h" |
[email protected] | 87ec220 | 2014-02-06 06:24:27 | [diff] [blame] | 73 | #include "ash/display/cursor_window_controller.h" |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 74 | #include "ash/display/display_color_manager_chromeos.h" |
stevenjb | 537c5c3f | 2016-01-20 23:38:12 | [diff] [blame] | 75 | #include "ash/display/display_configuration_controller.h" |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 76 | #include "ash/display/display_error_observer_chromeos.h" |
[email protected] | 682990f | 2013-01-10 06:49:11 | [diff] [blame] | 77 | #include "ash/display/event_transformation_handler.h" |
[email protected] | 9154587 | 2012-11-21 13:58:27 | [diff] [blame] | 78 | #include "ash/display/mouse_cursor_event_filter.h" |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 79 | #include "ash/display/projecting_observer_chromeos.h" |
| 80 | #include "ash/display/resolution_notification_controller.h" |
rjkroege | 2c930540 | 2016-09-07 00:21:45 | [diff] [blame] | 81 | #include "ash/display/screen_ash.h" |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 82 | #include "ash/display/screen_orientation_controller_chromeos.h" |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 83 | #include "ash/display/screen_position_controller.h" |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 84 | #include "ash/display/shutdown_observer_chromeos.h" |
oshima | e281892 | 2015-07-28 01:18:52 | [diff] [blame] | 85 | #include "ash/display/window_tree_host_manager.h" |
[email protected] | f4c92b38 | 2012-08-28 00:59:59 | [diff] [blame] | 86 | #include "ash/drag_drop/drag_drop_controller.h" |
[email protected] | 59ccade | 2013-10-17 17:56:40 | [diff] [blame] | 87 | #include "ash/first_run/first_run_helper_impl.h" |
[email protected] | f4c92b38 | 2012-08-28 00:59:59 | [diff] [blame] | 88 | #include "ash/high_contrast/high_contrast_controller.h" |
oshima | 5e0fff8 | 2015-06-27 01:31:30 | [diff] [blame] | 89 | #include "ash/ime/input_method_event_handler.h" |
sammiequon | 203ae02 | 2016-09-18 17:23:42 | [diff] [blame] | 90 | #include "ash/laser/laser_pointer_controller.h" |
[email protected] | f4c92b38 | 2012-08-28 00:59:59 | [diff] [blame] | 91 | #include "ash/magnifier/magnification_controller.h" |
[email protected] | 77f7c13 | 2012-11-15 06:52:54 | [diff] [blame] | 92 | #include "ash/magnifier/partial_magnification_controller.h" |
jamescook | 8800b823 | 2016-10-19 12:46:27 | [diff] [blame] | 93 | #include "ash/public/cpp/shell_window_ids.h" |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 94 | #include "ash/root_window_controller.h" |
[email protected] | 1b4c747 | 2014-05-15 18:32:23 | [diff] [blame] | 95 | #include "ash/shell_init_params.h" |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 96 | #include "ash/sticky_keys/sticky_keys_controller.h" |
James Cook | 6def4d9d | 2017-03-05 22:13:47 | [diff] [blame] | 97 | #include "ash/system/chromeos/power/power_event_observer.h" |
| 98 | #include "ash/system/chromeos/power/video_activity_notifier.h" |
| 99 | #include "ash/system/chromeos/screen_layout_observer.h" |
kylechar | 55f0eaf2 | 2017-01-11 22:57:37 | [diff] [blame] | 100 | #include "ash/touch/ash_touch_transform_controller.h" |
oshima | 5a296e8 | 2016-04-29 01:32:27 | [diff] [blame] | 101 | #include "ash/utility/screenshot_controller.h" |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 102 | #include "ash/virtual_keyboard_controller.h" |
[email protected] | 39718b5 | 2012-12-03 17:24:56 | [diff] [blame] | 103 | #include "ash/wm/ash_focus_rules.h" |
[email protected] | c0ff034 | 2013-02-27 00:41:29 | [diff] [blame] | 104 | #include "ash/wm/ash_native_cursor_manager.h" |
[email protected] | 262f8bd | 2012-03-23 19:30:27 | [diff] [blame] | 105 | #include "ash/wm/event_client_impl.h" |
sky | b7b5409 | 2016-08-19 16:00:09 | [diff] [blame] | 106 | #include "ash/wm/immersive_handler_factory_ash.h" |
[email protected] | ab4f8c9 | 2013-05-30 19:07:47 | [diff] [blame] | 107 | #include "ash/wm/lock_state_controller.h" |
[email protected] | 9ae32df | 2012-07-26 03:25:18 | [diff] [blame] | 108 | #include "ash/wm/overlay_event_filter.h" |
sky | 6624a7af | 2016-05-27 18:47:49 | [diff] [blame] | 109 | #include "ash/wm/overview/scoped_overview_animation_settings_factory_aura.h" |
[email protected] | e0d22e8 | 2012-01-04 00:46:57 | [diff] [blame] | 110 | #include "ash/wm/power_button_controller.h" |
[email protected] | e4a181cc | 2012-03-17 02:20:57 | [diff] [blame] | 111 | #include "ash/wm/resize_shadow_controller.h" |
hidehiko | 6821ca4 | 2016-06-18 11:12:23 | [diff] [blame] | 112 | #include "ash/wm/screen_pinning_controller.h" |
[email protected] | 435b212e | 2012-04-05 19:43:37 | [diff] [blame] | 113 | #include "ash/wm/system_gesture_event_filter.h" |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 114 | #include "ash/wm/system_modal_container_event_filter.h" |
[email protected] | 3537d47 | 2014-01-15 05:45:31 | [diff] [blame] | 115 | #include "ash/wm/toplevel_window_event_handler.h" |
[email protected] | 9633a9d2 | 2012-01-21 16:40:58 | [diff] [blame] | 116 | #include "ash/wm/video_detector.h" |
[email protected] | b5756e2 | 2012-11-30 01:32:02 | [diff] [blame] | 117 | #include "ash/wm/window_animations.h" |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 118 | #include "ash/wm/window_properties.h" |
[email protected] | f4c92b38 | 2012-08-28 00:59:59 | [diff] [blame] | 119 | #include "ash/wm/window_util.h" |
[email protected] | f296be7 | 2011-10-11 15:40:00 | [diff] [blame] | 120 | #include "base/bind.h" |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 121 | #include "base/bind_helpers.h" |
jamescook | fda15900 | 2016-10-21 18:48:57 | [diff] [blame] | 122 | #include "base/command_line.h" |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 123 | #include "base/memory/ptr_util.h" |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 124 | #include "base/sys_info.h" |
tzik | 0dd58d4 | 2017-02-15 08:26:52 | [diff] [blame] | 125 | #include "base/threading/sequenced_worker_pool.h" |
primiano | 7182d7b | 2015-01-30 18:02:03 | [diff] [blame] | 126 | #include "base/trace_event/trace_event.h" |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 127 | #include "chromeos/audio/audio_a11y_controller.h" |
| 128 | #include "chromeos/chromeos_switches.h" |
| 129 | #include "chromeos/dbus/dbus_thread_manager.h" |
reveman | 2415898 | 2017-01-10 05:58:45 | [diff] [blame] | 130 | #include "chromeos/system/devicemode.h" |
sky | 07a24d4 | 2017-03-09 23:57:30 | [diff] [blame] | 131 | #include "components/ui_devtools/devtools_server.h" |
sky | b073203a | 2017-03-13 16:59:16 | [diff] [blame] | 132 | #include "services/preferences/public/cpp/pref_client_store.h" |
| 133 | #include "services/preferences/public/interfaces/preferences.mojom.h" |
derat | 94887a2 | 2017-01-20 18:17:25 | [diff] [blame] | 134 | #include "services/service_manager/public/cpp/connector.h" |
| 135 | #include "services/ui/public/interfaces/constants.mojom.h" |
sky | 7db5ccf | 2017-03-14 21:52:29 | [diff] [blame] | 136 | #include "ui/app_list/presenter/app_list.h" |
[email protected] | 2c45610 | 2011-12-26 06:26:34 | [diff] [blame] | 137 | #include "ui/aura/client/aura_constants.h" |
[email protected] | 8a45c97 | 2012-03-14 18:22:44 | [diff] [blame] | 138 | #include "ui/aura/env.h" |
[email protected] | 4bb1650 | 2011-12-06 14:44:58 | [diff] [blame] | 139 | #include "ui/aura/layout_manager.h" |
derat | 94887a2 | 2017-01-20 18:17:25 | [diff] [blame] | 140 | #include "ui/aura/mus/user_activity_forwarder.h" |
[email protected] | 87b0d82e | 2011-10-07 21:02:59 | [diff] [blame] | 141 | #include "ui/aura/window.h" |
[email protected] | fcc51c95 | 2014-02-21 21:31:26 | [diff] [blame] | 142 | #include "ui/aura/window_event_dispatcher.h" |
[email protected] | 2d481774 | 2012-12-17 20:16:18 | [diff] [blame] | 143 | #include "ui/base/ui_base_switches.h" |
derat | 2d4e62d | 2015-01-09 16:09:17 | [diff] [blame] | 144 | #include "ui/base/user_activity/user_activity_detector.h" |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 145 | #include "ui/chromeos/user_activity_power_manager_notifier.h" |
[email protected] | 116302fc | 2012-05-05 21:45:41 | [diff] [blame] | 146 | #include "ui/compositor/layer.h" |
| 147 | #include "ui/compositor/layer_animator.h" |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 148 | #include "ui/display/display.h" |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 149 | #include "ui/display/manager/chromeos/display_change_observer.h" |
| 150 | #include "ui/display/manager/chromeos/display_configurator.h" |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 151 | #include "ui/display/manager/display_manager.h" |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 152 | #include "ui/display/screen.h" |
[email protected] | 3e670aa | 2013-12-02 19:04:32 | [diff] [blame] | 153 | #include "ui/events/event_target_iterator.h" |
sky | 4ec2be8 | 2017-01-06 17:38:32 | [diff] [blame] | 154 | #include "ui/gfx/geometry/insets.h" |
[email protected] | 9ec0f45 | 2012-05-31 15:58:53 | [diff] [blame] | 155 | #include "ui/gfx/image/image_skia.h" |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 156 | #include "ui/keyboard/keyboard_controller.h" |
[email protected] | 608de6c | 2013-10-29 00:14:28 | [diff] [blame] | 157 | #include "ui/keyboard/keyboard_switches.h" |
[email protected] | f1d5c3a | 2013-04-23 17:42:56 | [diff] [blame] | 158 | #include "ui/keyboard/keyboard_util.h" |
[email protected] | d7f30a7 | 2013-10-05 05:09:41 | [diff] [blame] | 159 | #include "ui/views/corewm/tooltip_aura.h" |
[email protected] | a1b7a82 | 2013-02-23 19:08:04 | [diff] [blame] | 160 | #include "ui/views/corewm/tooltip_controller.h" |
sky | 07a24d4 | 2017-03-09 23:57:30 | [diff] [blame] | 161 | #include "ui/views/focus/focus_manager_factory.h" |
[email protected] | c13be0d | 2011-11-22 02:09:58 | [diff] [blame] | 162 | #include "ui/views/widget/native_widget_aura.h" |
| 163 | #include "ui/views/widget/widget.h" |
[email protected] | 60d677d | 2014-05-30 13:07:02 | [diff] [blame] | 164 | #include "ui/wm/core/accelerator_filter.h" |
[email protected] | ee3ed1077 | 2014-03-11 22:02:01 | [diff] [blame] | 165 | #include "ui/wm/core/compound_event_filter.h" |
| 166 | #include "ui/wm/core/focus_controller.h" |
[email protected] | ee3ed1077 | 2014-03-11 22:02:01 | [diff] [blame] | 167 | #include "ui/wm/core/shadow_controller.h" |
| 168 | #include "ui/wm/core/visibility_controller.h" |
| 169 | #include "ui/wm/core/window_modality_controller.h" |
[email protected] | 87b0d82e | 2011-10-07 21:02:59 | [diff] [blame] | 170 | |
oshima | e001c8c | 2016-04-13 23:49:04 | [diff] [blame] | 171 | #if defined(USE_X11) |
kylechar | 731f85f9 | 2016-12-01 20:50:46 | [diff] [blame] | 172 | #include "ui/display/manager/chromeos/x11/native_display_delegate_x11.h" |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 173 | #include "ui/gfx/x/x11_types.h" // nogncheck |
oshima | e001c8c | 2016-04-13 23:49:04 | [diff] [blame] | 174 | #endif |
| 175 | |
| 176 | #if defined(USE_OZONE) |
| 177 | #include "ui/display/types/native_display_delegate.h" |
| 178 | #include "ui/ozone/public/ozone_platform.h" |
| 179 | #endif |
[email protected] | 70b3e7d5 | 2012-06-02 22:12:25 | [diff] [blame] | 180 | |
[email protected] | 55f59335 | 2011-12-24 05:42:46 | [diff] [blame] | 181 | namespace ash { |
[email protected] | 87b0d82e | 2011-10-07 21:02:59 | [diff] [blame] | 182 | |
| 183 | namespace { |
[email protected] | 671a2ae | 2011-10-13 21:53:23 | [diff] [blame] | 184 | |
[email protected] | 615922f | 2012-02-07 02:41:15 | [diff] [blame] | 185 | using aura::Window; |
[email protected] | 3f02dc5 | 2011-10-21 19:36:45 | [diff] [blame] | 186 | using views::Widget; |
| 187 | |
[email protected] | b5756e2 | 2012-11-30 01:32:02 | [diff] [blame] | 188 | // A Corewm VisibilityController subclass that calls the Ash animation routine |
| 189 | // so we can pick up our extended animations. See ash/wm/window_animations.h. |
[email protected] | e319c7e | 2014-03-14 19:56:14 | [diff] [blame] | 190 | class AshVisibilityController : public ::wm::VisibilityController { |
[email protected] | b5756e2 | 2012-11-30 01:32:02 | [diff] [blame] | 191 | public: |
| 192 | AshVisibilityController() {} |
dcheng | 1f4538e | 2014-10-27 23:57:05 | [diff] [blame] | 193 | ~AshVisibilityController() override {} |
[email protected] | b5756e2 | 2012-11-30 01:32:02 | [diff] [blame] | 194 | |
| 195 | private: |
[email protected] | e319c7e | 2014-03-14 19:56:14 | [diff] [blame] | 196 | // Overridden from ::wm::VisibilityController: |
dcheng | 1f4538e | 2014-10-27 23:57:05 | [diff] [blame] | 197 | bool CallAnimateOnChildWindowVisibilityChanged(aura::Window* window, |
| 198 | bool visible) override { |
[email protected] | b5756e2 | 2012-11-30 01:32:02 | [diff] [blame] | 199 | return AnimateOnChildWindowVisibilityChanged(window, visible); |
| 200 | } |
| 201 | |
| 202 | DISALLOW_COPY_AND_ASSIGN(AshVisibilityController); |
| 203 | }; |
| 204 | |
[email protected] | 87b0d82e | 2011-10-07 21:02:59 | [diff] [blame] | 205 | } // namespace |
| 206 | |
[email protected] | cac10fc6 | 2011-10-07 23:22:56 | [diff] [blame] | 207 | // static |
achuith | 287b26e | 2015-09-03 17:49:18 | [diff] [blame] | 208 | Shell* Shell::instance_ = nullptr; |
[email protected] | 2b4cd30 | 2012-02-24 20:21:13 | [diff] [blame] | 209 | // static |
sky | 00f98a37 | 2017-01-11 06:03:49 | [diff] [blame] | 210 | aura::WindowTreeClient* Shell::window_tree_client_ = nullptr; |
| 211 | // static |
sky | a8b222f | 2017-01-12 15:47:13 | [diff] [blame] | 212 | aura::WindowManagerClient* Shell::window_manager_client_ = nullptr; |
| 213 | // static |
[email protected] | 9488d4d | 2012-02-29 18:32:37 | [diff] [blame] | 214 | bool Shell::initially_hide_cursor_ = false; |
[email protected] | 2b4cd30 | 2012-02-24 20:21:13 | [diff] [blame] | 215 | |
| 216 | //////////////////////////////////////////////////////////////////////////////// |
[email protected] | cac10fc6 | 2011-10-07 23:22:56 | [diff] [blame] | 217 | // Shell, public: |
| 218 | |
[email protected] | cac10fc6 | 2011-10-07 23:22:56 | [diff] [blame] | 219 | // static |
[email protected] | 1b4c747 | 2014-05-15 18:32:23 | [diff] [blame] | 220 | Shell* Shell::CreateInstance(const ShellInitParams& init_params) { |
[email protected] | 3266c2b9 | 2011-11-14 00:06:08 | [diff] [blame] | 221 | CHECK(!instance_); |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 222 | WmShell* wm_shell = init_params.wm_shell; |
| 223 | if (!wm_shell) |
sky | b073203a | 2017-03-13 16:59:16 | [diff] [blame] | 224 | wm_shell = new WmShellAura(); |
| 225 | instance_ = new Shell(base::WrapUnique<ShellDelegate>(init_params.delegate), |
| 226 | base::WrapUnique<WmShell>(wm_shell)); |
[email protected] | 1b4c747 | 2014-05-15 18:32:23 | [diff] [blame] | 227 | instance_->Init(init_params); |
[email protected] | 3266c2b9 | 2011-11-14 00:06:08 | [diff] [blame] | 228 | return instance_; |
| 229 | } |
| 230 | |
| 231 | // static |
sky | b073203a | 2017-03-13 16:59:16 | [diff] [blame] | 232 | Shell* Shell::Get() { |
oshima | 9eea82da | 2014-09-13 01:11:07 | [diff] [blame] | 233 | CHECK(instance_); |
[email protected] | cac10fc6 | 2011-10-07 23:22:56 | [diff] [blame] | 234 | return instance_; |
| 235 | } |
| 236 | |
[email protected] | 6377a00 | 2011-11-10 20:26:47 | [diff] [blame] | 237 | // static |
[email protected] | b3b7bcd | 2012-03-06 19:35:45 | [diff] [blame] | 238 | bool Shell::HasInstance() { |
| 239 | return !!instance_; |
| 240 | } |
| 241 | |
| 242 | // static |
[email protected] | ef589af | 2011-12-03 01:07:15 | [diff] [blame] | 243 | void Shell::DeleteInstance() { |
[email protected] | 6377a00 | 2011-11-10 20:26:47 | [diff] [blame] | 244 | delete instance_; |
[email protected] | 6377a00 | 2011-11-10 20:26:47 | [diff] [blame] | 245 | } |
| 246 | |
[email protected] | e73bd780 | 2012-02-17 20:10:34 | [diff] [blame] | 247 | // static |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 248 | RootWindowController* Shell::GetPrimaryRootWindowController() { |
oshima | 9eea82da | 2014-09-13 01:11:07 | [diff] [blame] | 249 | CHECK(HasInstance()); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 250 | return GetRootWindowController(GetPrimaryRootWindow()); |
[email protected] | be65be36 | 2012-06-15 07:38:23 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | // static |
| 254 | Shell::RootWindowControllerList Shell::GetAllRootWindowControllers() { |
oshima | 9eea82da | 2014-09-13 01:11:07 | [diff] [blame] | 255 | CHECK(HasInstance()); |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 256 | RootWindowControllerList root_window_controllers; |
| 257 | for (WmWindow* root_window : instance_->wm_shell_->GetAllRootWindows()) |
| 258 | root_window_controllers.push_back(root_window->GetRootWindowController()); |
| 259 | return root_window_controllers; |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | // static |
thanhph | c90f49ca | 2017-03-03 17:48:53 | [diff] [blame] | 263 | RootWindowController* Shell::GetRootWindowControllerWithDisplayId( |
| 264 | int64_t display_id) { |
| 265 | CHECK(HasInstance()); |
| 266 | WmWindow* root_window = |
| 267 | instance_->wm_shell_->GetRootWindowForDisplayId(display_id); |
| 268 | return root_window ? root_window->GetRootWindowController() : nullptr; |
| 269 | } |
| 270 | |
| 271 | // static |
[email protected] | bf9cdb36 | 2013-10-25 19:22:45 | [diff] [blame] | 272 | aura::Window* Shell::GetPrimaryRootWindow() { |
oshima | 9eea82da | 2014-09-13 01:11:07 | [diff] [blame] | 273 | CHECK(HasInstance()); |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 274 | return instance_->wm_shell_->GetPrimaryRootWindow()->aura_window(); |
[email protected] | e73bd780 | 2012-02-17 20:10:34 | [diff] [blame] | 275 | } |
| 276 | |
[email protected] | 7b0f750 | 2012-06-11 00:12:39 | [diff] [blame] | 277 | // static |
sky | 2734438 | 2017-03-08 21:30:32 | [diff] [blame] | 278 | aura::Window* Shell::GetRootWindowForNewWindows() { |
| 279 | CHECK(Shell::HasInstance()); |
| 280 | return WmWindow::GetAuraWindow(Shell::GetWmRootWindowForNewWindows()); |
[email protected] | a857dbe | 2012-05-30 22:10:14 | [diff] [blame] | 281 | } |
| 282 | |
[email protected] | 7b0f750 | 2012-06-11 00:12:39 | [diff] [blame] | 283 | // static |
sky | 2734438 | 2017-03-08 21:30:32 | [diff] [blame] | 284 | WmWindow* Shell::GetWmRootWindowForNewWindows() { |
| 285 | CHECK(Shell::HasInstance()); |
| 286 | Shell* shell = Shell::GetInstance(); |
| 287 | if (shell->scoped_root_window_for_new_windows_) |
| 288 | return shell->scoped_root_window_for_new_windows_; |
| 289 | return shell->root_window_for_new_windows_; |
mfomitchev | a1a8aa6 | 2016-05-03 16:23:26 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | // static |
[email protected] | c9390bd | 2013-11-08 20:33:13 | [diff] [blame] | 293 | aura::Window::Windows Shell::GetAllRootWindows() { |
oshima | 9eea82da | 2014-09-13 01:11:07 | [diff] [blame] | 294 | CHECK(HasInstance()); |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 295 | aura::Window::Windows windows; |
| 296 | for (WmWindow* window : instance_->wm_shell_->GetAllRootWindows()) |
| 297 | windows.push_back(window->aura_window()); |
| 298 | return windows; |
[email protected] | be65be36 | 2012-06-15 07:38:23 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | // static |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 302 | aura::Window* Shell::GetContainer(aura::Window* root_window, int container_id) { |
[email protected] | 7b0f750 | 2012-06-11 00:12:39 | [diff] [blame] | 303 | return root_window->GetChildById(container_id); |
| 304 | } |
| 305 | |
| 306 | // static |
[email protected] | bf9cdb36 | 2013-10-25 19:22:45 | [diff] [blame] | 307 | const aura::Window* Shell::GetContainer(const aura::Window* root_window, |
[email protected] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 308 | int container_id) { |
| 309 | return root_window->GetChildById(container_id); |
| 310 | } |
| 311 | |
[email protected] | 57b8bb35 | 2012-01-11 05:11:46 | [diff] [blame] | 312 | views::NonClientFrameView* Shell::CreateDefaultNonClientFrameView( |
| 313 | views::Widget* widget) { |
[email protected] | c73d133 | 2012-03-08 17:11:04 | [diff] [blame] | 314 | // Use translucent-style window frames for dialogs. |
[email protected] | 85501fe | 2013-10-18 10:15:27 | [diff] [blame] | 315 | return new CustomFrameViewAsh(widget); |
[email protected] | 57b8bb35 | 2012-01-11 05:11:46 | [diff] [blame] | 316 | } |
| 317 | |
[email protected] | 2e236a5 | 2012-06-27 22:21:47 | [diff] [blame] | 318 | void Shell::SetDisplayWorkAreaInsets(Window* contains, |
[email protected] | 8a45c97 | 2012-03-14 18:22:44 | [diff] [blame] | 319 | const gfx::Insets& insets) { |
sky | 92f5587f | 2017-02-16 19:13:07 | [diff] [blame] | 320 | wm_shell_->SetDisplayWorkAreaInsets(WmWindow::Get(contains), insets); |
[email protected] | 1a2145b | 2012-03-13 21:09:17 | [diff] [blame] | 321 | } |
| 322 | |
sky | e79274a | 2016-06-08 05:39:02 | [diff] [blame] | 323 | void Shell::OnLoginStateChanged(LoginStatus status) { |
sky | 00c813f | 2017-03-08 22:48:55 | [diff] [blame] | 324 | for (auto& observer : shell_observers_) |
ericwilligers | 5eff47d | 2016-10-17 19:19:18 | [diff] [blame] | 325 | observer.OnLoginStateChanged(status); |
[email protected] | 82d3954ae | 2012-04-20 09:02:22 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | void Shell::OnAppTerminating() { |
sky | 00c813f | 2017-03-08 22:48:55 | [diff] [blame] | 329 | for (auto& observer : shell_observers_) |
ericwilligers | 5eff47d | 2016-10-17 19:19:18 | [diff] [blame] | 330 | observer.OnAppTerminating(); |
[email protected] | 82d3954ae | 2012-04-20 09:02:22 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | void Shell::OnLockStateChanged(bool locked) { |
sky | 00c813f | 2017-03-08 22:48:55 | [diff] [blame] | 334 | for (auto& observer : shell_observers_) |
ericwilligers | 5eff47d | 2016-10-17 19:19:18 | [diff] [blame] | 335 | observer.OnLockStateChanged(locked); |
[email protected] | ae29814 | 2013-08-10 15:30:29 | [diff] [blame] | 336 | #ifndef NDEBUG |
| 337 | // Make sure that there is no system modal in Lock layer when unlocked. |
| 338 | if (!locked) { |
sky | e02e09e | 2017-03-09 22:54:23 | [diff] [blame] | 339 | aura::Window::Windows containers = wm::GetContainersFromAllRootWindows( |
| 340 | kShellWindowId_LockSystemModalContainer, GetPrimaryRootWindow()); |
| 341 | for (aura::Window* container : containers) |
| 342 | DCHECK(container->children().empty()); |
[email protected] | ae29814 | 2013-08-10 15:30:29 | [diff] [blame] | 343 | } |
| 344 | #endif |
[email protected] | 82d3954ae | 2012-04-20 09:02:22 | [diff] [blame] | 345 | } |
| 346 | |
[email protected] | 58868abf | 2014-01-17 23:45:33 | [diff] [blame] | 347 | void Shell::OnCastingSessionStartedOrStopped(bool started) { |
sky | 00c813f | 2017-03-08 22:48:55 | [diff] [blame] | 348 | for (auto& observer : shell_observers_) |
ericwilligers | 5eff47d | 2016-10-17 19:19:18 | [diff] [blame] | 349 | observer.OnCastingSessionStartedOrStopped(started); |
[email protected] | 58868abf | 2014-01-17 23:45:33 | [diff] [blame] | 350 | } |
| 351 | |
sky | 80556bc4 | 2016-06-07 22:46:13 | [diff] [blame] | 352 | void Shell::OnRootWindowAdded(WmWindow* root_window) { |
sky | 00c813f | 2017-03-08 22:48:55 | [diff] [blame] | 353 | for (auto& observer : shell_observers_) |
ericwilligers | 5eff47d | 2016-10-17 19:19:18 | [diff] [blame] | 354 | observer.OnRootWindowAdded(root_window); |
[email protected] | 0e3e7cb | 2014-04-12 05:18:25 | [diff] [blame] | 355 | } |
| 356 | |
[email protected] | 51f43811 | 2013-11-18 19:32:50 | [diff] [blame] | 357 | void Shell::CreateKeyboard() { |
[email protected] | 51f43811 | 2013-11-18 19:32:50 | [diff] [blame] | 358 | InitKeyboard(); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 359 | GetPrimaryRootWindowController()->ActivateKeyboard( |
| 360 | keyboard::KeyboardController::GetInstance()); |
[email protected] | 51f43811 | 2013-11-18 19:32:50 | [diff] [blame] | 361 | } |
| 362 | |
[email protected] | e1b299b | 2014-01-29 23:53:41 | [diff] [blame] | 363 | void Shell::DeactivateKeyboard() { |
jamescook | c3fbf095 | 2016-06-29 06:48:31 | [diff] [blame] | 364 | // TODO(jamescook): Move keyboard create and hide into WmShell. |
sky | 79fa3471 | 2017-03-20 23:46:47 | [diff] [blame] | 365 | keyboard_ui_->Hide(); |
[email protected] | a0b3fb88 | 2014-04-07 19:26:03 | [diff] [blame] | 366 | if (keyboard::KeyboardController::GetInstance()) { |
[email protected] | e1b299b | 2014-01-29 23:53:41 | [diff] [blame] | 367 | RootWindowControllerList controllers = GetAllRootWindowControllers(); |
| 368 | for (RootWindowControllerList::iterator iter = controllers.begin(); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 369 | iter != controllers.end(); ++iter) { |
[email protected] | a0b3fb88 | 2014-04-07 19:26:03 | [diff] [blame] | 370 | (*iter)->DeactivateKeyboard(keyboard::KeyboardController::GetInstance()); |
[email protected] | e1b299b | 2014-01-29 23:53:41 | [diff] [blame] | 371 | } |
| 372 | } |
achuith | 287b26e | 2015-09-03 17:49:18 | [diff] [blame] | 373 | keyboard::KeyboardController::ResetInstance(nullptr); |
[email protected] | e1b299b | 2014-01-29 23:53:41 | [diff] [blame] | 374 | } |
| 375 | |
[email protected] | da28585 | 2014-05-27 19:53:43 | [diff] [blame] | 376 | bool Shell::ShouldSaveDisplaySettings() { |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 377 | DCHECK(!wm_shell_->IsRunningInMash()); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 378 | return !( |
| 379 | screen_orientation_controller_->ignore_display_configuration_updates() || |
| 380 | resolution_notification_controller_->DoesNotificationTimeout()); |
[email protected] | da28585 | 2014-05-27 19:53:43 | [diff] [blame] | 381 | } |
[email protected] | da28585 | 2014-05-27 19:53:43 | [diff] [blame] | 382 | |
sky | 5ad143a | 2017-03-22 04:31:23 | [diff] [blame] | 383 | ShelfModel* Shell::shelf_model() { |
| 384 | return shelf_controller_->model(); |
| 385 | } |
| 386 | |
sky | 2734438 | 2017-03-08 21:30:32 | [diff] [blame] | 387 | aura::client::ActivationClient* Shell::activation_client() { |
| 388 | return focus_controller_.get(); |
| 389 | } |
| 390 | |
[email protected] | c758fbf | 2012-03-25 22:53:59 | [diff] [blame] | 391 | void Shell::UpdateShelfVisibility() { |
jamescook | b551aba | 2016-09-01 01:00:16 | [diff] [blame] | 392 | for (WmWindow* root : wm_shell_->GetAllRootWindows()) |
| 393 | root->GetRootWindowController()->GetShelf()->UpdateVisibilityState(); |
[email protected] | c758fbf | 2012-03-25 22:53:59 | [diff] [blame] | 394 | } |
| 395 | |
[email protected] | 88d7112 | 2012-10-18 07:11:01 | [diff] [blame] | 396 | WebNotificationTray* Shell::GetWebNotificationTray() { |
jamescook | 612205f | 2016-05-26 06:02:11 | [diff] [blame] | 397 | return GetPrimaryRootWindowController() |
jamescook | b551aba | 2016-09-01 01:00:16 | [diff] [blame] | 398 | ->GetStatusAreaWidget() |
jamescook | 612205f | 2016-05-26 06:02:11 | [diff] [blame] | 399 | ->web_notification_tray(); |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 400 | } |
| 401 | |
[email protected] | a0afeb1 | 2012-12-10 22:57:09 | [diff] [blame] | 402 | bool Shell::HasPrimaryStatusArea() { |
jamescook | b551aba | 2016-09-01 01:00:16 | [diff] [blame] | 403 | return !!GetPrimaryRootWindowController()->GetStatusAreaWidget(); |
[email protected] | 31f19e3 | 2012-10-30 22:31:23 | [diff] [blame] | 404 | } |
| 405 | |
[email protected] | a0afeb1 | 2012-12-10 22:57:09 | [diff] [blame] | 406 | SystemTray* Shell::GetPrimarySystemTray() { |
| 407 | return GetPrimaryRootWindowController()->GetSystemTray(); |
[email protected] | aa54218b | 2012-06-12 16:51:42 | [diff] [blame] | 408 | } |
| 409 | |
[email protected] | 2b8a9bb | 2013-07-01 22:43:40 | [diff] [blame] | 410 | void Shell::SetTouchHudProjectionEnabled(bool enabled) { |
| 411 | if (is_touch_hud_projection_enabled_ == enabled) |
| 412 | return; |
| 413 | |
[email protected] | 2b8a9bb | 2013-07-01 22:43:40 | [diff] [blame] | 414 | is_touch_hud_projection_enabled_ = enabled; |
sky | 00c813f | 2017-03-08 22:48:55 | [diff] [blame] | 415 | for (auto& observer : shell_observers_) |
ericwilligers | 5eff47d | 2016-10-17 19:19:18 | [diff] [blame] | 416 | observer.OnTouchHudProjectionToggled(enabled); |
[email protected] | 2b8a9bb | 2013-07-01 22:43:40 | [diff] [blame] | 417 | } |
| 418 | |
msw | a7e8a5f | 2016-03-01 04:15:06 | [diff] [blame] | 419 | FirstRunHelper* Shell::CreateFirstRunHelper() { |
| 420 | return new FirstRunHelperImpl; |
[email protected] | 59ccade | 2013-10-17 17:56:40 | [diff] [blame] | 421 | } |
[email protected] | 87ec220 | 2014-02-06 06:24:27 | [diff] [blame] | 422 | |
sky | 5ad143a | 2017-03-22 04:31:23 | [diff] [blame] | 423 | void Shell::CreateShelfView() { |
| 424 | // Must occur after SessionController creation and user login. |
| 425 | DCHECK(session_controller()); |
| 426 | DCHECK_GT(session_controller()->NumberOfLoggedInUsers(), 0); |
| 427 | CreateShelfDelegate(); |
| 428 | |
| 429 | for (WmWindow* root_window : wm_shell_->GetAllRootWindows()) |
| 430 | root_window->GetRootWindowController()->CreateShelfView(); |
| 431 | } |
| 432 | |
yawano | dc5533b3 | 2017-02-23 11:04:38 | [diff] [blame] | 433 | void Shell::SetLargeCursorSizeInDip(int large_cursor_size_in_dip) { |
| 434 | window_tree_host_manager_->cursor_window_controller() |
| 435 | ->SetLargeCursorSizeInDip(large_cursor_size_in_dip); |
| 436 | } |
| 437 | |
[email protected] | 87ec220 | 2014-02-06 06:24:27 | [diff] [blame] | 438 | void Shell::SetCursorCompositingEnabled(bool enabled) { |
oshima | e281892 | 2015-07-28 01:18:52 | [diff] [blame] | 439 | window_tree_host_manager_->cursor_window_controller() |
| 440 | ->SetCursorCompositingEnabled(enabled); |
[email protected] | 87ec220 | 2014-02-06 06:24:27 | [diff] [blame] | 441 | native_cursor_manager_->SetNativeCursorEnabled(!enabled); |
| 442 | } |
[email protected] | 59ccade | 2013-10-17 17:56:40 | [diff] [blame] | 443 | |
[email protected] | f946670 | 2012-09-17 16:35:27 | [diff] [blame] | 444 | void Shell::DoInitialWorkspaceAnimation() { |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 445 | return GetPrimaryRootWindowController() |
| 446 | ->workspace_controller() |
| 447 | ->DoInitialAnimation(); |
[email protected] | f946670 | 2012-09-17 16:35:27 | [diff] [blame] | 448 | } |
| 449 | |
sky | 00c813f | 2017-03-08 22:48:55 | [diff] [blame] | 450 | void Shell::AddShellObserver(ShellObserver* observer) { |
| 451 | shell_observers_.AddObserver(observer); |
| 452 | } |
| 453 | |
| 454 | void Shell::RemoveShellObserver(ShellObserver* observer) { |
| 455 | shell_observers_.RemoveObserver(observer); |
| 456 | } |
| 457 | |
sky | 7db5ccf | 2017-03-14 21:52:29 | [diff] [blame] | 458 | void Shell::ShowAppList() { |
| 459 | // Show the app list on the default display for new windows. |
| 460 | app_list_->Show( |
| 461 | GetWmRootWindowForNewWindows()->GetDisplayNearestWindow().id()); |
| 462 | } |
| 463 | |
| 464 | void Shell::DismissAppList() { |
| 465 | app_list_->Dismiss(); |
| 466 | } |
| 467 | |
| 468 | void Shell::ToggleAppList() { |
| 469 | // Toggle the app list on the default display for new windows. |
| 470 | app_list_->ToggleAppList( |
| 471 | GetWmRootWindowForNewWindows()->GetDisplayNearestWindow().id()); |
| 472 | } |
| 473 | |
| 474 | bool Shell::IsAppListVisible() const { |
| 475 | return app_list_->IsVisible(); |
| 476 | } |
| 477 | |
| 478 | bool Shell::GetAppListTargetVisibility() const { |
| 479 | return app_list_->GetTargetVisibility(); |
| 480 | } |
| 481 | |
sky | 5ad143a | 2017-03-22 04:31:23 | [diff] [blame] | 482 | void Shell::UpdateAfterLoginStatusChange(LoginStatus status) { |
| 483 | for (WmWindow* root_window : wm_shell_->GetAllRootWindows()) { |
| 484 | root_window->GetRootWindowController()->UpdateAfterLoginStatusChange( |
| 485 | status); |
| 486 | } |
| 487 | } |
| 488 | |
sky | 00c813f | 2017-03-08 22:48:55 | [diff] [blame] | 489 | void Shell::NotifyMaximizeModeStarted() { |
| 490 | for (auto& observer : shell_observers_) |
| 491 | observer.OnMaximizeModeStarted(); |
| 492 | } |
| 493 | |
| 494 | void Shell::NotifyMaximizeModeEnding() { |
| 495 | for (auto& observer : shell_observers_) |
| 496 | observer.OnMaximizeModeEnding(); |
| 497 | } |
| 498 | |
| 499 | void Shell::NotifyMaximizeModeEnded() { |
| 500 | for (auto& observer : shell_observers_) |
| 501 | observer.OnMaximizeModeEnded(); |
| 502 | } |
| 503 | |
| 504 | void Shell::NotifyOverviewModeStarting() { |
| 505 | for (auto& observer : shell_observers_) |
| 506 | observer.OnOverviewModeStarting(); |
| 507 | } |
| 508 | |
| 509 | void Shell::NotifyOverviewModeEnded() { |
| 510 | for (auto& observer : shell_observers_) |
| 511 | observer.OnOverviewModeEnded(); |
| 512 | } |
| 513 | |
| 514 | void Shell::NotifyFullscreenStateChanged(bool is_fullscreen, |
| 515 | WmWindow* root_window) { |
| 516 | for (auto& observer : shell_observers_) |
| 517 | observer.OnFullscreenStateChanged(is_fullscreen, root_window); |
| 518 | } |
| 519 | |
| 520 | void Shell::NotifyPinnedStateChanged(WmWindow* pinned_window) { |
| 521 | for (auto& observer : shell_observers_) |
| 522 | observer.OnPinnedStateChanged(pinned_window); |
| 523 | } |
| 524 | |
xiyuan | 3816018 | 2017-03-14 22:50:13 | [diff] [blame] | 525 | void Shell::NotifyVirtualKeyboardActivated(bool activated, |
| 526 | WmWindow* root_window) { |
sky | 00c813f | 2017-03-08 22:48:55 | [diff] [blame] | 527 | for (auto& observer : shell_observers_) |
xiyuan | 3816018 | 2017-03-14 22:50:13 | [diff] [blame] | 528 | observer.OnVirtualKeyboardStateChanged(activated, root_window); |
sky | 00c813f | 2017-03-08 22:48:55 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | void Shell::NotifyShelfCreatedForRootWindow(WmWindow* root_window) { |
| 532 | for (auto& observer : shell_observers_) |
| 533 | observer.OnShelfCreatedForRootWindow(root_window); |
| 534 | } |
| 535 | |
| 536 | void Shell::NotifyShelfAlignmentChanged(WmWindow* root_window) { |
| 537 | for (auto& observer : shell_observers_) |
| 538 | observer.OnShelfAlignmentChanged(root_window); |
| 539 | } |
| 540 | |
| 541 | void Shell::NotifyShelfAutoHideBehaviorChanged(WmWindow* root_window) { |
| 542 | for (auto& observer : shell_observers_) |
| 543 | observer.OnShelfAutoHideBehaviorChanged(root_window); |
| 544 | } |
| 545 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 546 | //////////////////////////////////////////////////////////////////////////////// |
| 547 | // Shell, private: |
| 548 | |
sky | b073203a | 2017-03-13 16:59:16 | [diff] [blame] | 549 | Shell::Shell(std::unique_ptr<ShellDelegate> shell_delegate, |
| 550 | std::unique_ptr<WmShell> wm_shell) |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 551 | : wm_shell_(std::move(wm_shell)), |
sky | 79fa3471 | 2017-03-20 23:46:47 | [diff] [blame] | 552 | brightness_control_delegate_( |
| 553 | base::MakeUnique<system::BrightnessControllerChromeos>()), |
| 554 | cast_config_(base::MakeUnique<CastConfigController>()), |
| 555 | focus_cycler_(base::MakeUnique<FocusCycler>()), |
sky | 5ab1647 | 2017-03-21 19:35:08 | [diff] [blame] | 556 | immersive_context_(base::MakeUnique<ImmersiveContextAsh>()), |
sky | 79fa3471 | 2017-03-20 23:46:47 | [diff] [blame] | 557 | keyboard_brightness_control_delegate_( |
| 558 | base::MakeUnique<KeyboardBrightnessController>()), |
| 559 | locale_notification_controller_( |
| 560 | base::MakeUnique<LocaleNotificationController>()), |
sky | 5ab1647 | 2017-03-21 19:35:08 | [diff] [blame] | 561 | media_controller_(base::MakeUnique<MediaController>()), |
| 562 | new_window_controller_(base::MakeUnique<NewWindowController>()), |
sky | 5ad143a | 2017-03-22 04:31:23 | [diff] [blame] | 563 | session_controller_(base::MakeUnique<SessionController>()), |
| 564 | shelf_controller_(base::MakeUnique<ShelfController>()), |
sky | b073203a | 2017-03-13 16:59:16 | [diff] [blame] | 565 | shell_delegate_(std::move(shell_delegate)), |
sky | 5b45ed8 | 2017-03-27 02:54:23 | [diff] [blame^] | 566 | shutdown_controller_(base::MakeUnique<ShutdownController>()), |
sky | 79fa3471 | 2017-03-20 23:46:47 | [diff] [blame] | 567 | system_tray_controller_(base::MakeUnique<SystemTrayController>()), |
sky | 5b45ed8 | 2017-03-27 02:54:23 | [diff] [blame^] | 568 | system_tray_notifier_(base::MakeUnique<SystemTrayNotifier>()), |
| 569 | vpn_list_(base::MakeUnique<VpnList>()), |
| 570 | window_cycle_controller_(base::MakeUnique<WindowCycleController>()), |
| 571 | window_selector_controller_(base::MakeUnique<WindowSelectorController>()), |
sky | 7db5ccf | 2017-03-14 21:52:29 | [diff] [blame] | 572 | app_list_(base::MakeUnique<app_list::AppList>()), |
yusukes | 1168eda | 2016-04-27 07:52:08 | [diff] [blame] | 573 | link_handler_model_factory_(nullptr), |
jamescook | ac672433 | 2017-03-21 02:54:43 | [diff] [blame] | 574 | tray_bluetooth_helper_(base::MakeUnique<TrayBluetoothHelper>()), |
kylechar | 7a067ec | 2017-01-07 01:16:28 | [diff] [blame] | 575 | display_configurator_(new display::DisplayConfigurator()), |
sadrul | 7a8785e | 2016-02-12 21:54:35 | [diff] [blame] | 576 | native_cursor_manager_(nullptr), |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 577 | simulate_modal_window_open_for_testing_(false), |
msw | 3f439af | 2016-09-08 22:35:26 | [diff] [blame] | 578 | is_touch_hud_projection_enabled_(false) { |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 579 | // TODO(sky): better refactor cash/mash dependencies. Perhaps put all cash |
| 580 | // state on WmShellAura. http://crbug.com/671246. |
| 581 | |
| 582 | if (!wm_shell_->IsRunningInMash()) { |
sky | b073203a | 2017-03-13 16:59:16 | [diff] [blame] | 583 | gpu_support_.reset(shell_delegate_->CreateGPUSupport()); |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 584 | display_manager_.reset(ScreenAsh::CreateDisplayManager()); |
| 585 | window_tree_host_manager_.reset(new WindowTreeHostManager); |
| 586 | user_metrics_recorder_.reset(new UserMetricsRecorder); |
| 587 | } |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 588 | |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 589 | PowerStatus::Initialize(); |
sky | 5ad143a | 2017-03-22 04:31:23 | [diff] [blame] | 590 | |
| 591 | session_controller_->AddSessionStateObserver(this); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | Shell::~Shell() { |
| 595 | TRACE_EVENT0("shutdown", "ash::Shell::Destructor"); |
| 596 | |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 597 | const bool is_mash = wm_shell_->IsRunningInMash(); |
| 598 | |
| 599 | if (!is_mash) |
| 600 | user_metrics_recorder_->OnShellShuttingDown(); |
bruthig | c24d11f | 2015-06-09 21:30:03 | [diff] [blame] | 601 | |
sky | b073203a | 2017-03-13 16:59:16 | [diff] [blame] | 602 | shell_delegate_->PreShutdown(); |
[email protected] | 050e7718 | 2014-03-25 15:29:16 | [diff] [blame] | 603 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 604 | // Remove the focus from any window. This will prevent overhead and side |
| 605 | // effects (e.g. crashes) from changing focus during shutdown. |
| 606 | // See bug crbug.com/134502. |
achuith | 287b26e | 2015-09-03 17:49:18 | [diff] [blame] | 607 | aura::client::GetFocusClient(GetPrimaryRootWindow())->FocusWindow(nullptr); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 608 | |
| 609 | // Please keep in same order as in Init() because it's easy to miss one. |
| 610 | if (window_modality_controller_) |
| 611 | window_modality_controller_.reset(); |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 612 | if (!is_mash) { |
| 613 | RemovePreTargetHandler( |
| 614 | window_tree_host_manager_->input_method_event_handler()); |
| 615 | } |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 616 | |
[email protected] | e4ea5236 | 2014-02-15 03:21:06 | [diff] [blame] | 617 | RemovePreTargetHandler(magnifier_key_scroll_handler_.get()); |
| 618 | magnifier_key_scroll_handler_.reset(); |
| 619 | |
| 620 | RemovePreTargetHandler(speech_feedback_handler_.get()); |
| 621 | speech_feedback_handler_.reset(); |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 622 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 623 | RemovePreTargetHandler(overlay_filter_.get()); |
[email protected] | 3537d47 | 2014-01-15 05:45:31 | [diff] [blame] | 624 | RemovePreTargetHandler(accelerator_filter_.get()); |
| 625 | RemovePreTargetHandler(event_transformation_handler_.get()); |
| 626 | RemovePreTargetHandler(toplevel_window_event_handler_.get()); |
| 627 | RemovePostTargetHandler(toplevel_window_event_handler_.get()); |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 628 | if (!is_mash) { |
| 629 | RemovePreTargetHandler(system_gesture_filter_.get()); |
| 630 | RemovePreTargetHandler(mouse_cursor_filter_.get()); |
| 631 | } |
hariank | 0dd03dd | 2016-07-14 23:47:33 | [diff] [blame] | 632 | RemovePreTargetHandler(modality_filter_.get()); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 633 | |
| 634 | // TooltipController is deleted with the Shell so removing its references. |
| 635 | RemovePreTargetHandler(tooltip_controller_.get()); |
| 636 | |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 637 | screen_orientation_controller_.reset(); |
yiyix | a68ade51 | 2016-09-01 17:38:13 | [diff] [blame] | 638 | screen_layout_observer_.reset(); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 639 | |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 640 | // Destroy the virtual keyboard controller before the maximize mode controller |
| 641 | // since the latters destructor triggers events that the former is listening |
| 642 | // to but no longer cares about. |
rsadam | bbaf2c8 | 2015-01-07 17:54:13 | [diff] [blame] | 643 | virtual_keyboard_controller_.reset(); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 644 | |
[email protected] | 2a57beb5 | 2014-06-09 20:02:26 | [diff] [blame] | 645 | // Destroy maximize mode controller early on since it has some observers which |
[email protected] | 5ed2b64 | 2014-03-04 00:06:57 | [diff] [blame] | 646 | // need to be removed. |
sky | 5ab1647 | 2017-03-21 19:35:08 | [diff] [blame] | 647 | maximize_mode_controller_.reset(); |
[email protected] | 5ed2b64 | 2014-03-04 00:06:57 | [diff] [blame] | 648 | |
jdufault | 551152e | 2016-01-27 19:48:43 | [diff] [blame] | 649 | // Destroy the keyboard before closing the shelf, since it will invoke a shelf |
| 650 | // layout. |
| 651 | DeactivateKeyboard(); |
| 652 | |
sky | 07a24d4 | 2017-03-09 23:57:30 | [diff] [blame] | 653 | toast_manager_.reset(); |
yoshiki | 32f5163 | 2016-03-24 01:24:43 | [diff] [blame] | 654 | |
jdufault | 551152e | 2016-01-27 19:48:43 | [diff] [blame] | 655 | // Destroy SystemTrayDelegate before destroying the status area(s). Make sure |
| 656 | // to deinitialize the shelf first, as it is initialized after the delegate. |
jamescook | b551aba | 2016-09-01 01:00:16 | [diff] [blame] | 657 | for (WmWindow* root : wm_shell_->GetAllRootWindows()) |
| 658 | root->GetRootWindowController()->GetShelf()->ShutdownShelfWidget(); |
jamescook | ac672433 | 2017-03-21 02:54:43 | [diff] [blame] | 659 | tray_bluetooth_helper_.reset(); |
sky | 79fa3471 | 2017-03-20 23:46:47 | [diff] [blame] | 660 | DeleteSystemTrayDelegate(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 661 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 662 | // Drag-and-drop must be canceled prior to close all windows. |
| 663 | drag_drop_controller_.reset(); |
| 664 | |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 665 | // Controllers who have WindowObserver added must be deleted |
| 666 | // before |window_tree_host_manager_| is deleted. |
[email protected] | 8c9d12a | 2013-12-06 18:39:03 | [diff] [blame] | 667 | |
[email protected] | 8c9d12a | 2013-12-06 18:39:03 | [diff] [blame] | 668 | // VideoActivityNotifier must be deleted before |video_detector_| is |
| 669 | // deleted because it's observing video activity through |
derat | 83b76139 | 2016-07-11 16:44:44 | [diff] [blame] | 670 | // VideoDetector::Observer interface. |
[email protected] | 8c9d12a | 2013-12-06 18:39:03 | [diff] [blame] | 671 | video_activity_notifier_.reset(); |
[email protected] | 8c9d12a | 2013-12-06 18:39:03 | [diff] [blame] | 672 | video_detector_.reset(); |
[email protected] | 0e3e7cb | 2014-04-12 05:18:25 | [diff] [blame] | 673 | high_contrast_controller_.reset(); |
[email protected] | 8c9d12a | 2013-12-06 18:39:03 | [diff] [blame] | 674 | |
| 675 | shadow_controller_.reset(); |
| 676 | resize_shadow_controller_.reset(); |
| 677 | |
sky | 37f0dd1 | 2016-07-19 18:00:59 | [diff] [blame] | 678 | // Has to happen before ~MruWindowTracker. |
sky | 5b45ed8 | 2017-03-27 02:54:23 | [diff] [blame^] | 679 | window_cycle_controller_.reset(); |
| 680 | window_selector_controller_.reset(); |
[email protected] | 8c9d12a | 2013-12-06 18:39:03 | [diff] [blame] | 681 | |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 682 | CloseAllRootWindowChildWindows(); |
| 683 | |
afakhry | 5815939 | 2015-05-22 02:45:52 | [diff] [blame] | 684 | // MruWindowTracker must be destroyed after all windows have been deleted to |
| 685 | // avoid a possible crash when Shell is destroyed from a non-normal shutdown |
| 686 | // path. (crbug.com/485438). |
sky | 5ab1647 | 2017-03-21 19:35:08 | [diff] [blame] | 687 | mru_window_tracker_.reset(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 688 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 689 | // These need a valid Shell instance to clean up properly, so explicitly |
| 690 | // delete them before invalidating the instance. |
| 691 | // Alphabetical. TODO(oshima): sort. |
| 692 | magnification_controller_.reset(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 693 | tooltip_controller_.reset(); |
| 694 | event_client_.reset(); |
[email protected] | 3537d47 | 2014-01-15 05:45:31 | [diff] [blame] | 695 | toplevel_window_event_handler_.reset(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 696 | visibility_controller_.reset(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 697 | |
| 698 | power_button_controller_.reset(); |
| 699 | lock_state_controller_.reset(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 700 | |
hidehiko | 6821ca4 | 2016-06-18 11:12:23 | [diff] [blame] | 701 | screen_pinning_controller_.reset(); |
| 702 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 703 | resolution_notification_controller_.reset(); |
oshima | 5a296e8 | 2016-04-29 01:32:27 | [diff] [blame] | 704 | screenshot_controller_.reset(); |
[email protected] | 8ab613cf | 2014-05-12 09:39:49 | [diff] [blame] | 705 | mouse_cursor_filter_.reset(); |
hariank | 0dd03dd | 2016-07-14 23:47:33 | [diff] [blame] | 706 | modality_filter_.reset(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 707 | |
[email protected] | 03122891a | 2014-05-13 23:56:49 | [diff] [blame] | 708 | touch_transformer_controller_.reset(); |
warx | 533c8f6 | 2016-04-12 01:19:43 | [diff] [blame] | 709 | audio_a11y_controller_.reset(); |
sammiequon | 203ae02 | 2016-09-18 17:23:42 | [diff] [blame] | 710 | laser_pointer_controller_.reset(); |
| 711 | partial_magnification_controller_.reset(); |
warx | 533c8f6 | 2016-04-12 01:19:43 | [diff] [blame] | 712 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 713 | // This also deletes all RootWindows. Note that we invoke Shutdown() on |
oshima | e281892 | 2015-07-28 01:18:52 | [diff] [blame] | 714 | // WindowTreeHostManager before resetting |window_tree_host_manager_|, since |
| 715 | // destruction |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 716 | // of its owned RootWindowControllers relies on the value. |
rjkroege | 2c930540 | 2016-09-07 00:21:45 | [diff] [blame] | 717 | ScreenAsh::CreateScreenForShutdown(); |
stevenjb | 537c5c3f | 2016-01-20 23:38:12 | [diff] [blame] | 718 | display_configuration_controller_.reset(); |
dtseng | 4ae0a88 | 2016-04-15 21:39:27 | [diff] [blame] | 719 | |
sky | 15ef0aa | 2017-01-20 18:55:59 | [diff] [blame] | 720 | // AppListDelegateImpl depends upon AppList. |
| 721 | app_list_delegate_impl_.reset(); |
| 722 | |
sky | 07a24d4 | 2017-03-09 23:57:30 | [diff] [blame] | 723 | // These members access Shell in their destructors. |
| 724 | wallpaper_controller_.reset(); |
| 725 | accessibility_delegate_.reset(); |
| 726 | |
| 727 | // Balances the Install() in Initialize(). |
| 728 | views::FocusManagerFactory::Install(nullptr); |
| 729 | |
sky | 5ad143a | 2017-03-22 04:31:23 | [diff] [blame] | 730 | // ShelfWindowWatcher has window observers and a pointer to the shelf model. |
| 731 | shelf_window_watcher_.reset(); |
| 732 | |
| 733 | // ShelfItemDelegate subclasses it owns have complex cleanup to run (e.g. ARC |
| 734 | // shelf items in Chrome) so explicitly shutdown early. |
| 735 | shelf_model()->DestroyItemDelegates(); |
| 736 | |
| 737 | // Must be destroyed before FocusController. |
| 738 | shelf_delegate_.reset(); |
| 739 | |
| 740 | // Removes itself as an observer of |pref_store_|. |
| 741 | shelf_controller_.reset(); |
| 742 | |
jamescook | 428f986f | 2016-07-15 19:13:25 | [diff] [blame] | 743 | wm_shell_->Shutdown(); |
sky | 5ad143a | 2017-03-22 04:31:23 | [diff] [blame] | 744 | |
sky | 2734438 | 2017-03-08 21:30:32 | [diff] [blame] | 745 | // Depends on |focus_controller_|, so must be destroyed before. |
oshima | e281892 | 2015-07-28 01:18:52 | [diff] [blame] | 746 | window_tree_host_manager_.reset(); |
sky | 2734438 | 2017-03-08 21:30:32 | [diff] [blame] | 747 | focus_controller_->RemoveObserver(this); |
| 748 | focus_controller_.reset(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 749 | screen_position_controller_.reset(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 750 | |
robert.bradford | ab05249 | 2015-05-06 11:09:56 | [diff] [blame] | 751 | display_color_manager_.reset(); |
[email protected] | 7bc49bd | 2014-01-22 09:30:34 | [diff] [blame] | 752 | if (display_change_observer_) |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 753 | display_configurator_->RemoveObserver(display_change_observer_.get()); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 754 | if (display_error_observer_) |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 755 | display_configurator_->RemoveObserver(display_error_observer_.get()); |
jdufault | 88fb7665 | 2015-04-30 22:36:43 | [diff] [blame] | 756 | if (projecting_observer_) { |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 757 | display_configurator_->RemoveObserver(projecting_observer_.get()); |
sky | 00c813f | 2017-03-08 22:48:55 | [diff] [blame] | 758 | RemoveShellObserver(projecting_observer_.get()); |
jdufault | 88fb7665 | 2015-04-30 22:36:43 | [diff] [blame] | 759 | } |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 760 | display_change_observer_.reset(); |
kylechar | 98748a5 | 2016-12-03 01:33:22 | [diff] [blame] | 761 | shutdown_observer_.reset(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 762 | |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 763 | PowerStatus::Shutdown(); |
pneubeck | 8be1f542 | 2014-10-09 16:46:18 | [diff] [blame] | 764 | |
| 765 | // Ensure that DBusThreadManager outlives this Shell. |
| 766 | DCHECK(chromeos::DBusThreadManager::IsInitialized()); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 767 | |
sky | 88bd4be6 | 2016-06-09 17:34:41 | [diff] [blame] | 768 | // Needs to happen right before |instance_| is reset. |
| 769 | wm_shell_.reset(); |
sky | 5ad143a | 2017-03-22 04:31:23 | [diff] [blame] | 770 | session_controller_->RemoveSessionStateObserver(this); |
sky | b073203a | 2017-03-13 16:59:16 | [diff] [blame] | 771 | wallpaper_delegate_.reset(); |
| 772 | pref_store_ = nullptr; |
| 773 | shell_delegate_.reset(); |
sky | 88bd4be6 | 2016-06-09 17:34:41 | [diff] [blame] | 774 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 775 | DCHECK(instance_ == this); |
achuith | 287b26e | 2015-09-03 17:49:18 | [diff] [blame] | 776 | instance_ = nullptr; |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 777 | } |
| 778 | |
[email protected] | 1b4c747 | 2014-05-15 18:32:23 | [diff] [blame] | 779 | void Shell::Init(const ShellInitParams& init_params) { |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 780 | const bool is_mash = wm_shell_->IsRunningInMash(); |
| 781 | |
sky | 07a24d4 | 2017-03-09 23:57:30 | [diff] [blame] | 782 | blocking_pool_ = init_params.blocking_pool; |
| 783 | |
sky | b073203a | 2017-03-13 16:59:16 | [diff] [blame] | 784 | wallpaper_delegate_ = shell_delegate_->CreateWallpaperDelegate(); |
| 785 | |
| 786 | // Can be null in tests. |
| 787 | if (shell_delegate_->GetShellConnector()) { |
| 788 | prefs::mojom::PreferencesServiceFactoryPtr pref_factory_ptr; |
| 789 | shell_delegate_->GetShellConnector()->BindInterface( |
| 790 | prefs::mojom::kServiceName, &pref_factory_ptr); |
| 791 | pref_store_ = new preferences::PrefClientStore(std::move(pref_factory_ptr)); |
| 792 | } |
| 793 | |
sky | 07a24d4 | 2017-03-09 23:57:30 | [diff] [blame] | 794 | // Some delegates access WmShell during their construction. Create them here |
| 795 | // instead of the WmShell constructor. |
sky | b073203a | 2017-03-13 16:59:16 | [diff] [blame] | 796 | accessibility_delegate_.reset(shell_delegate_->CreateAccessibilityDelegate()); |
| 797 | palette_delegate_ = shell_delegate_->CreatePaletteDelegate(); |
sky | 07a24d4 | 2017-03-09 23:57:30 | [diff] [blame] | 798 | toast_manager_ = base::MakeUnique<ToastManager>(); |
| 799 | |
sky | 07a24d4 | 2017-03-09 23:57:30 | [diff] [blame] | 800 | // Install the custom factory early on so that views::FocusManagers for Tray, |
| 801 | // Shelf, and WallPaper could be created by the factory. |
| 802 | views::FocusManagerFactory::Install(new AshFocusManagerFactory); |
| 803 | |
| 804 | wallpaper_controller_ = base::MakeUnique<WallpaperController>(blocking_pool_); |
| 805 | |
| 806 | // Start devtools server |
| 807 | devtools_server_ = ui::devtools::UiDevToolsServer::Create(nullptr); |
| 808 | if (devtools_server_) { |
| 809 | auto dom_backend = base::MakeUnique<devtools::AshDevToolsDOMAgent>(); |
| 810 | auto css_backend = |
| 811 | base::MakeUnique<devtools::AshDevToolsCSSAgent>(dom_backend.get()); |
| 812 | auto devtools_client = base::MakeUnique<ui::devtools::UiDevToolsClient>( |
| 813 | "Ash", devtools_server_.get()); |
| 814 | devtools_client->AddAgent(std::move(dom_backend)); |
| 815 | devtools_client->AddAgent(std::move(css_backend)); |
| 816 | devtools_server_->AttachClient(std::move(devtools_client)); |
| 817 | } |
jamescook | 3daef41 | 2016-07-14 23:53:30 | [diff] [blame] | 818 | |
sky | 15ef0aa | 2017-01-20 18:55:59 | [diff] [blame] | 819 | if (is_mash) |
| 820 | app_list_delegate_impl_ = base::MakeUnique<AppListDelegateImpl>(); |
| 821 | |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 822 | // TODO(sky): move creation to WmShell. |
| 823 | if (!is_mash) |
| 824 | immersive_handler_factory_ = base::MakeUnique<ImmersiveHandlerFactoryAsh>(); |
sky | b7b5409 | 2016-08-19 16:00:09 | [diff] [blame] | 825 | |
sky | 6624a7af | 2016-05-27 18:47:49 | [diff] [blame] | 826 | scoped_overview_animation_settings_factory_.reset( |
| 827 | new ScopedOverviewAnimationSettingsFactoryAura); |
sky | 5ab1647 | 2017-03-21 19:35:08 | [diff] [blame] | 828 | window_positioner_ = base::MakeUnique<WindowPositioner>(); |
sky | 984c189 | 2016-04-20 00:00:34 | [diff] [blame] | 829 | |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 830 | if (!is_mash) { |
| 831 | native_cursor_manager_ = new AshNativeCursorManager; |
| 832 | cursor_manager_.reset( |
| 833 | new CursorManager(base::WrapUnique(native_cursor_manager_))); |
| 834 | } |
sky | fee520c | 2016-02-11 19:57:46 | [diff] [blame] | 835 | |
sky | b073203a | 2017-03-13 16:59:16 | [diff] [blame] | 836 | shell_delegate_->PreInit(); |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 837 | bool display_initialized = true; |
| 838 | if (!is_mash) { |
| 839 | display_initialized = display_manager_->InitFromCommandLine(); |
stevenjb | 537c5c3f | 2016-01-20 23:38:12 | [diff] [blame] | 840 | |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 841 | display_configuration_controller_.reset(new DisplayConfigurationController( |
| 842 | display_manager_.get(), window_tree_host_manager_.get())); |
stevenjb | 537c5c3f | 2016-01-20 23:38:12 | [diff] [blame] | 843 | |
oshima | e001c8c | 2016-04-13 23:49:04 | [diff] [blame] | 844 | #if defined(USE_OZONE) |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 845 | display_configurator_->Init( |
| 846 | ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate(), |
| 847 | !gpu_support_->IsPanelFittingDisabled()); |
oshima | e001c8c | 2016-04-13 23:49:04 | [diff] [blame] | 848 | #elif defined(USE_X11) |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 849 | display_configurator_->Init( |
| 850 | base::MakeUnique<display::NativeDisplayDelegateX11>(), |
| 851 | !gpu_support_->IsPanelFittingDisabled()); |
oshima | e001c8c | 2016-04-13 23:49:04 | [diff] [blame] | 852 | #endif |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 853 | } |
[email protected] | 0249a653 | 2013-10-31 06:53:34 | [diff] [blame] | 854 | |
pneubeck | 8be1f542 | 2014-10-09 16:46:18 | [diff] [blame] | 855 | // The DBusThreadManager must outlive this Shell. See the DCHECK in ~Shell. |
| 856 | chromeos::DBusThreadManager* dbus_thread_manager = |
| 857 | chromeos::DBusThreadManager::Get(); |
| 858 | projecting_observer_.reset( |
| 859 | new ProjectingObserver(dbus_thread_manager->GetPowerManagerClient())); |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 860 | display_configurator_->AddObserver(projecting_observer_.get()); |
sky | 00c813f | 2017-03-08 22:48:55 | [diff] [blame] | 861 | AddShellObserver(projecting_observer_.get()); |
[email protected] | 72bce52 | 2014-02-10 21:11:26 | [diff] [blame] | 862 | |
reveman | 2415898 | 2017-01-10 05:58:45 | [diff] [blame] | 863 | if (!display_initialized && chromeos::IsRunningAsSystemCompositor()) { |
kylechar | f2e4e41 | 2016-12-04 04:21:35 | [diff] [blame] | 864 | display_change_observer_ = base::MakeUnique<display::DisplayChangeObserver>( |
kylechar | 98748a5 | 2016-12-03 01:33:22 | [diff] [blame] | 865 | display_configurator_.get(), display_manager_.get()); |
| 866 | |
| 867 | shutdown_observer_ = |
| 868 | base::MakeUnique<ShutdownObserver>(display_configurator_.get()); |
| 869 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 870 | // Register |display_change_observer_| first so that the rest of |
| 871 | // observer gets invoked after the root windows are configured. |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 872 | display_configurator_->AddObserver(display_change_observer_.get()); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 873 | display_error_observer_.reset(new DisplayErrorObserver()); |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 874 | display_configurator_->AddObserver(display_error_observer_.get()); |
| 875 | display_configurator_->set_state_controller(display_change_observer_.get()); |
| 876 | display_configurator_->set_mirroring_controller(display_manager_.get()); |
| 877 | display_configurator_->ForceInitialConfigure( |
jamescook | fda15900 | 2016-10-21 18:48:57 | [diff] [blame] | 878 | base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 879 | chromeos::switches::kFirstExecAfterBoot) |
| 880 | ? kChromeOsBootColor |
| 881 | : 0); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 882 | display_initialized = true; |
| 883 | } |
msw | 3f439af | 2016-09-08 22:35:26 | [diff] [blame] | 884 | display_color_manager_.reset(new DisplayColorManager( |
| 885 | display_configurator_.get(), init_params.blocking_pool)); |
stevenjb | 537c5c3f | 2016-01-20 23:38:12 | [diff] [blame] | 886 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 887 | if (!display_initialized) |
[email protected] | 0249a653 | 2013-10-31 06:53:34 | [diff] [blame] | 888 | display_manager_->InitDefaultDisplay(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 889 | |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 890 | if (!is_mash) { |
| 891 | display_manager_->RefreshFontParams(); |
[email protected] | 68d6080e | 2014-08-21 23:06:32 | [diff] [blame] | 892 | |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 893 | aura::Env::GetInstance()->set_context_factory(init_params.context_factory); |
| 894 | aura::Env::GetInstance()->set_context_factory_private( |
| 895 | init_params.context_factory_private); |
| 896 | } |
[email protected] | ecca62b | 2013-10-09 16:18:53 | [diff] [blame] | 897 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 898 | // The WindowModalityController needs to be at the front of the input event |
| 899 | // pretarget handler list to ensure that it processes input events when modal |
| 900 | // windows are active. |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 901 | window_modality_controller_.reset(new ::wm::WindowModalityController(this)); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 902 | |
[email protected] | e319c7e | 2014-03-14 19:56:14 | [diff] [blame] | 903 | env_filter_.reset(new ::wm::CompoundEventFilter); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 904 | AddPreTargetHandler(env_filter_.get()); |
| 905 | |
sky | 2734438 | 2017-03-08 21:30:32 | [diff] [blame] | 906 | // FocusController takes ownership of AshFocusRules. |
| 907 | focus_controller_ = |
| 908 | base::MakeUnique<::wm::FocusController>(new wm::AshFocusRules()); |
| 909 | focus_controller_->AddObserver(this); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 910 | |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 911 | screen_position_controller_.reset(new ScreenPositionController); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 912 | |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 913 | wm_shell_->CreatePrimaryHost(); |
sky | 2734438 | 2017-03-08 21:30:32 | [diff] [blame] | 914 | root_window_for_new_windows_ = WmWindow::Get(GetPrimaryRootWindow()); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 915 | |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 916 | if (!is_mash) { |
| 917 | resolution_notification_controller_.reset( |
| 918 | new ResolutionNotificationController); |
| 919 | } |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 920 | |
derat | c6250a0 | 2017-01-25 05:51:53 | [diff] [blame] | 921 | if (cursor_manager_) { |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 922 | cursor_manager_->SetDisplay( |
| 923 | display::Screen::GetScreen()->GetPrimaryDisplay()); |
derat | c6250a0 | 2017-01-25 05:51:53 | [diff] [blame] | 924 | } |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 925 | |
sky | 81a2d79 | 2017-03-17 19:14:39 | [diff] [blame] | 926 | accelerator_controller_ = wm_shell_->CreateAcceleratorController(); |
sky | 5ab1647 | 2017-03-21 19:35:08 | [diff] [blame] | 927 | maximize_mode_controller_ = base::MakeUnique<MaximizeModeController>(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 928 | |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 929 | if (!is_mash) { |
| 930 | AddPreTargetHandler( |
| 931 | window_tree_host_manager_->input_method_event_handler()); |
| 932 | } |
oshima | 5e0fff8 | 2015-06-27 01:31:30 | [diff] [blame] | 933 | |
spang | e9b5127 | 2014-12-11 01:20:10 | [diff] [blame] | 934 | magnifier_key_scroll_handler_ = MagnifierKeyScroller::CreateHandler(); |
[email protected] | e4ea5236 | 2014-02-15 03:21:06 | [diff] [blame] | 935 | AddPreTargetHandler(magnifier_key_scroll_handler_.get()); |
spang | e9b5127 | 2014-12-11 01:20:10 | [diff] [blame] | 936 | speech_feedback_handler_ = SpokenFeedbackToggler::CreateHandler(); |
[email protected] | e4ea5236 | 2014-02-15 03:21:06 | [diff] [blame] | 937 | AddPreTargetHandler(speech_feedback_handler_.get()); |
[email protected] | 3dff2ef | 2014-02-09 22:50:39 | [diff] [blame] | 938 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 939 | // The order in which event filters are added is significant. |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 940 | |
derat | 2d4e62d | 2015-01-09 16:09:17 | [diff] [blame] | 941 | // ui::UserActivityDetector passes events to observers, so let them get |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 942 | // rewritten first. |
derat | 2d4e62d | 2015-01-09 16:09:17 | [diff] [blame] | 943 | user_activity_detector_.reset(new ui::UserActivityDetector); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 944 | |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 945 | overlay_filter_.reset(new OverlayEventFilter); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 946 | AddPreTargetHandler(overlay_filter_.get()); |
sky | 00c813f | 2017-03-08 22:48:55 | [diff] [blame] | 947 | AddShellObserver(overlay_filter_.get()); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 948 | |
[email protected] | 60d677d | 2014-05-30 13:07:02 | [diff] [blame] | 949 | accelerator_filter_.reset(new ::wm::AcceleratorFilter( |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 950 | std::unique_ptr<::wm::AcceleratorDelegate>(new AcceleratorDelegate), |
sky | 81a2d79 | 2017-03-17 19:14:39 | [diff] [blame] | 951 | accelerator_controller_->accelerator_history())); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 952 | AddPreTargetHandler(accelerator_filter_.get()); |
| 953 | |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 954 | event_transformation_handler_.reset(new EventTransformationHandler); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 955 | AddPreTargetHandler(event_transformation_handler_.get()); |
| 956 | |
sky | cf67ed5a | 2016-05-23 19:38:39 | [diff] [blame] | 957 | toplevel_window_event_handler_.reset( |
sky | 0702b27 | 2016-06-03 22:10:41 | [diff] [blame] | 958 | new ToplevelWindowEventHandler(wm_shell_.get())); |
[email protected] | 3537d47 | 2014-01-15 05:45:31 | [diff] [blame] | 959 | |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 960 | if (!is_mash) { |
| 961 | system_gesture_filter_.reset(new SystemGestureEventFilter); |
| 962 | AddPreTargetHandler(system_gesture_filter_.get()); |
| 963 | } |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 964 | |
[email protected] | 354520b | 2014-06-21 04:31:01 | [diff] [blame] | 965 | sticky_keys_controller_.reset(new StickyKeysController); |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 966 | if (!is_mash) { |
| 967 | screen_pinning_controller_.reset( |
| 968 | new ScreenPinningController(window_tree_host_manager_.get())); |
| 969 | } |
[email protected] | 354520b | 2014-06-21 04:31:01 | [diff] [blame] | 970 | |
jamescook | d9f152f | 2016-11-15 00:53:08 | [diff] [blame] | 971 | lock_state_controller_ = |
sky | 5b45ed8 | 2017-03-27 02:54:23 | [diff] [blame^] | 972 | base::MakeUnique<LockStateController>(shutdown_controller_.get()); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 973 | power_button_controller_.reset( |
| 974 | new PowerButtonController(lock_state_controller_.get())); |
[email protected] | 685442f3 | 2014-02-28 10:40:06 | [diff] [blame] | 975 | // Pass the initial display state to PowerButtonController. |
| 976 | power_button_controller_->OnDisplayModeChanged( |
[email protected] | bcec7fb6 | 2014-04-08 20:59:09 | [diff] [blame] | 977 | display_configurator_->cached_displays()); |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 978 | |
sky | 00c813f | 2017-03-08 22:48:55 | [diff] [blame] | 979 | AddShellObserver(lock_state_controller_.get()); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 980 | |
derat | 94887a2 | 2017-01-20 18:17:25 | [diff] [blame] | 981 | // The connector is unavailable in some tests. |
sky | b073203a | 2017-03-13 16:59:16 | [diff] [blame] | 982 | if (is_mash && shell_delegate_->GetShellConnector()) { |
derat | 94887a2 | 2017-01-20 18:17:25 | [diff] [blame] | 983 | ui::mojom::UserActivityMonitorPtr user_activity_monitor; |
sky | b073203a | 2017-03-13 16:59:16 | [diff] [blame] | 984 | shell_delegate_->GetShellConnector()->BindInterface(ui::mojom::kServiceName, |
| 985 | &user_activity_monitor); |
derat | 94887a2 | 2017-01-20 18:17:25 | [diff] [blame] | 986 | user_activity_forwarder_ = base::MakeUnique<aura::UserActivityForwarder>( |
| 987 | std::move(user_activity_monitor), user_activity_detector_.get()); |
| 988 | } |
| 989 | |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 990 | drag_drop_controller_.reset(new DragDropController); |
oshima | 5a296e8 | 2016-04-29 01:32:27 | [diff] [blame] | 991 | // |screenshot_controller_| needs to be created (and prepended as a |
mukai | 19274bdd | 2015-02-24 22:37:48 | [diff] [blame] | 992 | // pre-target handler) at this point, because |mouse_cursor_filter_| needs to |
oshima | 5a296e8 | 2016-04-29 01:32:27 | [diff] [blame] | 993 | // process mouse events prior to screenshot session. |
mukai | 19274bdd | 2015-02-24 22:37:48 | [diff] [blame] | 994 | // See http://crbug.com/459214 |
oshima | 5a296e8 | 2016-04-29 01:32:27 | [diff] [blame] | 995 | screenshot_controller_.reset(new ScreenshotController()); |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 996 | if (!is_mash) { |
| 997 | mouse_cursor_filter_.reset(new MouseCursorEventFilter()); |
| 998 | PrependPreTargetHandler(mouse_cursor_filter_.get()); |
| 999 | } |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 1000 | |
| 1001 | // Create Controllers that may need root window. |
| 1002 | // TODO(oshima): Move as many controllers before creating |
| 1003 | // RootWindowController as possible. |
| 1004 | visibility_controller_.reset(new AshVisibilityController); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 1005 | |
sammiequon | 203ae02 | 2016-09-18 17:23:42 | [diff] [blame] | 1006 | laser_pointer_controller_.reset(new LaserPointerController()); |
| 1007 | partial_magnification_controller_.reset(new PartialMagnificationController()); |
sammiequon | 203ae02 | 2016-09-18 17:23:42 | [diff] [blame] | 1008 | |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 1009 | magnification_controller_.reset(MagnificationController::CreateInstance()); |
sky | 5ab1647 | 2017-03-21 19:35:08 | [diff] [blame] | 1010 | mru_window_tracker_ = base::MakeUnique<MruWindowTracker>(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 1011 | |
[email protected] | 55398d2 | 2013-10-10 19:49:20 | [diff] [blame] | 1012 | autoclick_controller_.reset(AutoclickController::CreateInstance()); |
| 1013 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 1014 | high_contrast_controller_.reset(new HighContrastController); |
| 1015 | video_detector_.reset(new VideoDetector); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 1016 | |
oshima | ebbe6377 | 2015-02-19 18:41:32 | [diff] [blame] | 1017 | tooltip_controller_.reset(new views::corewm::TooltipController( |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 1018 | std::unique_ptr<views::corewm::Tooltip>(new views::corewm::TooltipAura))); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 1019 | AddPreTargetHandler(tooltip_controller_.get()); |
| 1020 | |
hariank | 0dd03dd | 2016-07-14 23:47:33 | [diff] [blame] | 1021 | modality_filter_.reset(new SystemModalContainerEventFilter(this)); |
| 1022 | AddPreTargetHandler(modality_filter_.get()); |
| 1023 | |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 1024 | event_client_.reset(new EventClientImpl); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 1025 | |
sky | b073203a | 2017-03-13 16:59:16 | [diff] [blame] | 1026 | session_state_delegate_.reset(shell_delegate_->CreateSessionStateDelegate()); |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 1027 | // Must occur after Shell has installed its early pre-target handlers (for |
| 1028 | // example, WindowModalityController). |
jamescook | 0a9d02e | 2016-08-23 00:20:05 | [diff] [blame] | 1029 | wm_shell_->CreatePointerWatcherAdapter(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 1030 | |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 1031 | resize_shadow_controller_.reset(new ResizeShadowController()); |
sky | 2734438 | 2017-03-08 21:30:32 | [diff] [blame] | 1032 | shadow_controller_.reset(new ::wm::ShadowController(focus_controller_.get())); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 1033 | |
sky | 79fa3471 | 2017-03-20 23:46:47 | [diff] [blame] | 1034 | SetSystemTrayDelegate( |
sky | b073203a | 2017-03-13 16:59:16 | [diff] [blame] | 1035 | base::WrapUnique(shell_delegate_->CreateSystemTrayDelegate())); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 1036 | |
jamescook | ac672433 | 2017-03-21 02:54:43 | [diff] [blame] | 1037 | // May trigger initialization of the Bluetooth adapter. |
| 1038 | tray_bluetooth_helper_->Initialize(); |
| 1039 | |
kylechar | 55f0eaf2 | 2017-01-11 22:57:37 | [diff] [blame] | 1040 | // Create AshTouchTransformController before |
oshima | e281892 | 2015-07-28 01:18:52 | [diff] [blame] | 1041 | // WindowTreeHostManager::InitDisplays() |
kylechar | 55f0eaf2 | 2017-01-11 22:57:37 | [diff] [blame] | 1042 | // since AshTouchTransformController listens on |
oshima | e281892 | 2015-07-28 01:18:52 | [diff] [blame] | 1043 | // WindowTreeHostManager::Observer::OnDisplaysInitialized(). |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 1044 | if (!is_mash) { |
| 1045 | touch_transformer_controller_.reset(new AshTouchTransformController( |
| 1046 | display_configurator_.get(), display_manager_.get())); |
| 1047 | } |
[email protected] | 03122891a | 2014-05-13 23:56:49 | [diff] [blame] | 1048 | |
sky | 79fa3471 | 2017-03-20 23:46:47 | [diff] [blame] | 1049 | keyboard_ui_ = wm_shell_->CreateKeyboardUI(); |
sky | fee520c | 2016-02-11 19:57:46 | [diff] [blame] | 1050 | |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 1051 | wm_shell_->InitHosts(init_params); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 1052 | |
rsadam | 9172bc8a | 2014-10-29 23:37:38 | [diff] [blame] | 1053 | // Needs to be created after InitDisplays() since it may cause the virtual |
| 1054 | // keyboard to be deployed. |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 1055 | if (!is_mash) |
| 1056 | virtual_keyboard_controller_.reset(new VirtualKeyboardController); |
rsadam | 9172bc8a | 2014-10-29 23:37:38 | [diff] [blame] | 1057 | |
warx | 533c8f6 | 2016-04-12 01:19:43 | [diff] [blame] | 1058 | audio_a11y_controller_.reset(new chromeos::AudioA11yController); |
warx | 533c8f6 | 2016-04-12 01:19:43 | [diff] [blame] | 1059 | |
msw | 0e91d93 | 2016-08-25 22:34:09 | [diff] [blame] | 1060 | // Initialize the wallpaper after the RootWindowController has been created, |
| 1061 | // otherwise the widget will not paint when restoring after a browser crash. |
| 1062 | // Also, initialize after display initialization to ensure correct sizing. |
sky | b073203a | 2017-03-13 16:59:16 | [diff] [blame] | 1063 | wallpaper_delegate_->InitializeWallpaper(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 1064 | |
sadrul | 7a8785e | 2016-02-12 21:54:35 | [diff] [blame] | 1065 | if (cursor_manager_) { |
| 1066 | if (initially_hide_cursor_) |
| 1067 | cursor_manager_->HideCursor(); |
| 1068 | cursor_manager_->SetCursor(ui::kCursorPointer); |
| 1069 | } |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 1070 | |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 1071 | power_event_observer_.reset(new PowerEventObserver()); |
[email protected] | ded58fd | 2013-10-09 07:56:55 | [diff] [blame] | 1072 | user_activity_notifier_.reset( |
[email protected] | b0fa701 | 2014-04-16 12:50:57 | [diff] [blame] | 1073 | new ui::UserActivityPowerManagerNotifier(user_activity_detector_.get())); |
[email protected] | ded58fd | 2013-10-09 07:56:55 | [diff] [blame] | 1074 | video_activity_notifier_.reset( |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 1075 | new VideoActivityNotifier(video_detector_.get())); |
| 1076 | bluetooth_notification_controller_.reset(new BluetoothNotificationController); |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 1077 | if (!is_mash) { |
| 1078 | screen_orientation_controller_.reset(new ScreenOrientationController()); |
| 1079 | screen_layout_observer_.reset(new ScreenLayoutObserver()); |
| 1080 | } |
yiyix | 90cfee2 | 2017-02-16 05:38:18 | [diff] [blame] | 1081 | sms_observer_.reset(new SmsObserver()); |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 1082 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 1083 | // The compositor thread and main message loop have to be running in |
| 1084 | // order to create mirror window. Run it after the main message loop |
| 1085 | // is started. |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 1086 | if (!is_mash) |
| 1087 | display_manager_->CreateMirrorWindowAsyncIfAny(); |
bruthig | c24d11f | 2015-06-09 21:30:03 | [diff] [blame] | 1088 | |
sky | 00c813f | 2017-03-08 22:48:55 | [diff] [blame] | 1089 | for (auto& observer : shell_observers_) |
ericwilligers | 5eff47d | 2016-10-17 19:19:18 | [diff] [blame] | 1090 | observer.OnShellInitialized(); |
phweiss | 0bf64c5 | 2015-11-17 12:56:18 | [diff] [blame] | 1091 | |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 1092 | if (!is_mash) |
| 1093 | user_metrics_recorder_->OnShellInitialized(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 1094 | } |
| 1095 | |
[email protected] | 51f43811 | 2013-11-18 19:32:50 | [diff] [blame] | 1096 | void Shell::InitKeyboard() { |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 1097 | if (keyboard::IsKeyboardEnabled()) { |
[email protected] | a0b3fb88 | 2014-04-07 19:26:03 | [diff] [blame] | 1098 | if (keyboard::KeyboardController::GetInstance()) { |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 1099 | RootWindowControllerList controllers = GetAllRootWindowControllers(); |
| 1100 | for (RootWindowControllerList::iterator iter = controllers.begin(); |
| 1101 | iter != controllers.end(); ++iter) { |
[email protected] | a0b3fb88 | 2014-04-07 19:26:03 | [diff] [blame] | 1102 | (*iter)->DeactivateKeyboard( |
| 1103 | keyboard::KeyboardController::GetInstance()); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 1104 | } |
| 1105 | } |
[email protected] | a0b3fb88 | 2014-04-07 19:26:03 | [diff] [blame] | 1106 | keyboard::KeyboardController::ResetInstance( |
sky | b073203a | 2017-03-13 16:59:16 | [diff] [blame] | 1107 | new keyboard::KeyboardController(shell_delegate_->CreateKeyboardUI(), |
| 1108 | virtual_keyboard_controller_.get())); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 1109 | } |
| 1110 | } |
| 1111 | |
[email protected] | 41baaed | 2013-11-09 04:18:26 | [diff] [blame] | 1112 | void Shell::InitRootWindow(aura::Window* root_window) { |
sky | 2734438 | 2017-03-08 21:30:32 | [diff] [blame] | 1113 | DCHECK(focus_controller_); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 1114 | DCHECK(visibility_controller_.get()); |
| 1115 | DCHECK(drag_drop_controller_.get()); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 1116 | |
sky | 2734438 | 2017-03-08 21:30:32 | [diff] [blame] | 1117 | aura::client::SetFocusClient(root_window, focus_controller_.get()); |
| 1118 | aura::client::SetActivationClient(root_window, focus_controller_.get()); |
| 1119 | root_window->AddPreTargetHandler(focus_controller_.get()); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 1120 | aura::client::SetVisibilityClient(root_window, visibility_controller_.get()); |
| 1121 | aura::client::SetDragDropClient(root_window, drag_drop_controller_.get()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 1122 | aura::client::SetScreenPositionClient(root_window, |
| 1123 | screen_position_controller_.get()); |
sadrul | 7a8785e | 2016-02-12 21:54:35 | [diff] [blame] | 1124 | aura::client::SetCursorClient(root_window, cursor_manager_.get()); |
[email protected] | 54a37cdc | 2012-07-25 19:16:01 | [diff] [blame] | 1125 | aura::client::SetTooltipClient(root_window, tooltip_controller_.get()); |
[email protected] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 1126 | aura::client::SetEventClient(root_window, event_client_.get()); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 1127 | |
[email protected] | 3537d47 | 2014-01-15 05:45:31 | [diff] [blame] | 1128 | aura::client::SetWindowMoveClient(root_window, |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 1129 | toplevel_window_event_handler_.get()); |
[email protected] | 3537d47 | 2014-01-15 05:45:31 | [diff] [blame] | 1130 | root_window->AddPreTargetHandler(toplevel_window_event_handler_.get()); |
| 1131 | root_window->AddPostTargetHandler(toplevel_window_event_handler_.get()); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 1132 | } |
| 1133 | |
sky | 79fa3471 | 2017-03-20 23:46:47 | [diff] [blame] | 1134 | void Shell::SetSystemTrayDelegate( |
| 1135 | std::unique_ptr<SystemTrayDelegate> delegate) { |
| 1136 | DCHECK(delegate); |
| 1137 | system_tray_delegate_ = std::move(delegate); |
| 1138 | system_tray_delegate_->Initialize(); |
| 1139 | // Accesses WmShell in its constructor. |
| 1140 | logout_confirmation_controller_.reset(new LogoutConfirmationController( |
| 1141 | base::Bind(&SystemTrayController::SignOut, |
| 1142 | base::Unretained(system_tray_controller_.get())))); |
| 1143 | } |
| 1144 | |
| 1145 | void Shell::DeleteSystemTrayDelegate() { |
| 1146 | DCHECK(system_tray_delegate_); |
| 1147 | // Accesses WmShell in its destructor. |
| 1148 | logout_confirmation_controller_.reset(); |
| 1149 | system_tray_delegate_.reset(); |
| 1150 | } |
| 1151 | |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 1152 | void Shell::CloseAllRootWindowChildWindows() { |
| 1153 | for (WmWindow* wm_root_window : wm_shell_->GetAllRootWindows()) { |
| 1154 | aura::Window* root_window = wm_root_window->aura_window(); |
| 1155 | RootWindowController* controller = GetRootWindowController(root_window); |
| 1156 | if (controller) { |
| 1157 | controller->CloseChildWindows(); |
| 1158 | } else { |
| 1159 | while (!root_window->children().empty()) { |
| 1160 | aura::Window* child = root_window->children()[0]; |
| 1161 | delete child; |
| 1162 | } |
| 1163 | } |
| 1164 | } |
| 1165 | } |
| 1166 | |
sky | 5ad143a | 2017-03-22 04:31:23 | [diff] [blame] | 1167 | void Shell::CreateShelfDelegate() { |
| 1168 | // May be called multiple times as shelves are created and destroyed. |
| 1169 | if (shelf_delegate_) |
| 1170 | return; |
| 1171 | // Must occur after SessionController creation and user login because |
| 1172 | // Chrome's implementation of ShelfDelegate assumes it can get information |
| 1173 | // about multi-profile login state. |
| 1174 | DCHECK(session_controller()); |
| 1175 | DCHECK_GT(session_controller()->NumberOfLoggedInUsers(), 0); |
| 1176 | shelf_delegate_.reset(shell_delegate_->CreateShelfDelegate(shelf_model())); |
| 1177 | shelf_window_watcher_ = base::MakeUnique<ShelfWindowWatcher>(shelf_model()); |
| 1178 | } |
| 1179 | |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 1180 | bool Shell::CanWindowReceiveEvents(aura::Window* window) { |
| 1181 | RootWindowControllerList controllers = GetAllRootWindowControllers(); |
oshima | 9a61ecf | 2016-06-18 10:43:05 | [diff] [blame] | 1182 | for (RootWindowController* controller : controllers) { |
| 1183 | if (controller->CanWindowReceiveEvents(window)) |
[email protected] | 602022b | 2014-03-31 17:07:31 | [diff] [blame] | 1184 | return true; |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 1185 | } |
| 1186 | return false; |
| 1187 | } |
| 1188 | |
[email protected] | 049cf34b | 2012-12-07 17:15:48 | [diff] [blame] | 1189 | //////////////////////////////////////////////////////////////////////////////// |
| 1190 | // Shell, ui::EventTarget overrides: |
| 1191 | |
[email protected] | 869f635 | 2012-12-06 20:47:17 | [diff] [blame] | 1192 | bool Shell::CanAcceptEvent(const ui::Event& event) { |
[email protected] | 5097e69 | 2012-10-30 22:08:41 | [diff] [blame] | 1193 | return true; |
| 1194 | } |
| 1195 | |
| 1196 | ui::EventTarget* Shell::GetParentTarget() { |
[email protected] | ff027885 | 2013-11-05 22:35:48 | [diff] [blame] | 1197 | return aura::Env::GetInstance(); |
[email protected] | 5097e69 | 2012-10-30 22:08:41 | [diff] [blame] | 1198 | } |
| 1199 | |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 1200 | std::unique_ptr<ui::EventTargetIterator> Shell::GetChildIterator() const { |
| 1201 | return std::unique_ptr<ui::EventTargetIterator>(); |
[email protected] | 3e670aa | 2013-12-02 19:04:32 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | ui::EventTargeter* Shell::GetEventTargeter() { |
| 1205 | NOTREACHED(); |
achuith | 287b26e | 2015-09-03 17:49:18 | [diff] [blame] | 1206 | return nullptr; |
[email protected] | 3e670aa | 2013-12-02 19:04:32 | [diff] [blame] | 1207 | } |
| 1208 | |
sky | 2734438 | 2017-03-08 21:30:32 | [diff] [blame] | 1209 | void Shell::OnWindowActivated( |
| 1210 | aura::client::ActivationChangeObserver::ActivationReason reason, |
| 1211 | aura::Window* gained_active, |
| 1212 | aura::Window* lost_active) { |
| 1213 | WmWindow* gained_active_wm = WmWindow::Get(gained_active); |
| 1214 | if (gained_active_wm) |
| 1215 | root_window_for_new_windows_ = gained_active_wm->GetRootWindow(); |
| 1216 | } |
| 1217 | |
sky | 5ad143a | 2017-03-22 04:31:23 | [diff] [blame] | 1218 | void Shell::SessionStateChanged(session_manager::SessionState state) { |
| 1219 | // Create the shelf when a session becomes active. It's safe to do this |
| 1220 | // multiple times (e.g. initial login vs. multiprofile add session). |
| 1221 | if (state == session_manager::SessionState::ACTIVE) { |
| 1222 | CreateShelfView(); |
| 1223 | |
| 1224 | if (!wm_shell_->IsRunningInMash()) { |
| 1225 | // Recreate the keyboard after initial login and after multiprofile login. |
| 1226 | CreateKeyboard(); |
| 1227 | } |
| 1228 | } |
| 1229 | |
| 1230 | // Only trigger an update in mash because with classic ash chrome calls |
| 1231 | // UpdateAfterLoginStatusChange() directly. |
| 1232 | if (wm_shell_->IsRunningInMash()) { |
| 1233 | // TODO(jamescook): Should this call Shell::OnLoginStatusChanged() too? |
| 1234 | UpdateAfterLoginStatusChange(session_controller_->GetLoginStatus()); |
| 1235 | } |
| 1236 | } |
| 1237 | |
[email protected] | 55f59335 | 2011-12-24 05:42:46 | [diff] [blame] | 1238 | } // namespace ash |