[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> |
Mitsuru Oshima | 04b54d0 | 2017-10-09 14:22:45 | [diff] [blame] | 8 | #include <memory> |
[email protected] | 0039db9 | 2012-05-09 04:11:45 | [diff] [blame] | 9 | #include <string> |
dcheng | cbf0d9d | 2015-12-27 22:49:23 | [diff] [blame] | 10 | #include <utility> |
[email protected] | f7eb89c | 2011-12-13 09:48:54 | [diff] [blame] | 11 | |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 12 | #include "ash/accelerators/accelerator_controller.h" |
[email protected] | 60d677d | 2014-05-30 13:07:02 | [diff] [blame] | 13 | #include "ash/accelerators/accelerator_delegate.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 14 | #include "ash/accelerators/ash_focus_manager_factory.h" |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 15 | #include "ash/accelerators/magnifier_key_scroller.h" |
| 16 | #include "ash/accelerators/spoken_feedback_toggler.h" |
James Cook | ec14495 | 2017-09-01 00:05:16 | [diff] [blame] | 17 | #include "ash/accessibility/accessibility_controller.h" |
James Cook | 37b7d10 | 2017-10-06 04:35:19 | [diff] [blame] | 18 | #include "ash/accessibility/accessibility_delegate.h" |
sky | 15ef0aa | 2017-01-20 18:55:59 | [diff] [blame] | 19 | #include "ash/app_list/app_list_delegate_impl.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 20 | #include "ash/ash_constants.h" |
[email protected] | 55398d2 | 2013-10-10 19:49:20 | [diff] [blame] | 21 | #include "ash/autoclick/autoclick_controller.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 22 | #include "ash/cast_config_controller.h" |
Scott Violet | d64dac1 | 2017-06-02 21:50:08 | [diff] [blame] | 23 | #include "ash/display/ash_display_controller.h" |
[email protected] | 87ec220 | 2014-02-06 06:24:27 | [diff] [blame] | 24 | #include "ash/display/cursor_window_controller.h" |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 25 | #include "ash/display/display_color_manager_chromeos.h" |
stevenjb | 537c5c3f | 2016-01-20 23:38:12 | [diff] [blame] | 26 | #include "ash/display/display_configuration_controller.h" |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 27 | #include "ash/display/display_error_observer_chromeos.h" |
Steven Bennetts | 7683e34 | 2018-01-02 21:29:52 | [diff] [blame] | 28 | #include "ash/display/display_shutdown_observer.h" |
[email protected] | 682990f | 2013-01-10 06:49:11 | [diff] [blame] | 29 | #include "ash/display/event_transformation_handler.h" |
[email protected] | 9154587 | 2012-11-21 13:58:27 | [diff] [blame] | 30 | #include "ash/display/mouse_cursor_event_filter.h" |
Qiang Xu | d77a90c | 2018-02-20 19:43:29 | [diff] [blame] | 31 | #include "ash/display/persistent_window_controller.h" |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 32 | #include "ash/display/projecting_observer_chromeos.h" |
| 33 | #include "ash/display/resolution_notification_controller.h" |
rjkroege | 2c930540 | 2016-09-07 00:21:45 | [diff] [blame] | 34 | #include "ash/display/screen_ash.h" |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 35 | #include "ash/display/screen_orientation_controller_chromeos.h" |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 36 | #include "ash/display/screen_position_controller.h" |
oshima | e281892 | 2015-07-28 01:18:52 | [diff] [blame] | 37 | #include "ash/display/window_tree_host_manager.h" |
[email protected] | f4c92b38 | 2012-08-28 00:59:59 | [diff] [blame] | 38 | #include "ash/drag_drop/drag_drop_controller.h" |
[email protected] | 59ccade | 2013-10-17 17:56:40 | [diff] [blame] | 39 | #include "ash/first_run/first_run_helper_impl.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 40 | #include "ash/focus_cycler.h" |
| 41 | #include "ash/frame/custom_frame_view_ash.h" |
[email protected] | f4c92b38 | 2012-08-28 00:59:59 | [diff] [blame] | 42 | #include "ash/high_contrast/high_contrast_controller.h" |
Vladislav Kaznacheev | 6d6aaff | 2017-07-22 04:06:32 | [diff] [blame] | 43 | #include "ash/highlighter/highlighter_controller.h" |
Scott Violet | 596bb4634 | 2017-06-21 14:43:13 | [diff] [blame] | 44 | #include "ash/host/ash_window_tree_host_init_params.h" |
James Cook | bb02673 | 2017-06-09 23:01:55 | [diff] [blame] | 45 | #include "ash/ime/ime_controller.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 46 | #include "ash/keyboard/keyboard_ui.h" |
sammiequon | 203ae02 | 2016-09-18 17:23:42 | [diff] [blame] | 47 | #include "ash/laser/laser_pointer_controller.h" |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 48 | #include "ash/login/login_screen_controller.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 49 | #include "ash/login_status.h" |
Ahmed Fakhry | 4bf3f74 | 2018-02-06 17:33:36 | [diff] [blame] | 50 | #include "ash/magnifier/docked_magnifier_controller.h" |
[email protected] | f4c92b38 | 2012-08-28 00:59:59 | [diff] [blame] | 51 | #include "ash/magnifier/magnification_controller.h" |
[email protected] | 77f7c13 | 2012-11-15 06:52:54 | [diff] [blame] | 52 | #include "ash/magnifier/partial_magnification_controller.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 53 | #include "ash/media_controller.h" |
Evan Stade | e9974e2 | 2017-09-23 00:02:26 | [diff] [blame] | 54 | #include "ash/message_center/message_center_controller.h" |
Scott Violet | 3c554ae | 2017-12-13 02:25:41 | [diff] [blame] | 55 | #include "ash/metrics/time_to_first_present_recorder.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 56 | #include "ash/new_window_controller.h" |
Vladislav Kaznacheev | 92edf62e | 2017-10-13 22:08:01 | [diff] [blame] | 57 | #include "ash/note_taking_controller.h" |
Ahmed Fakhry | 4af48e4 | 2018-02-28 17:45:38 | [diff] [blame^] | 58 | #include "ash/public/cpp/ash_features.h" |
Evan Stade | 7d0e823 | 2017-10-04 02:01:36 | [diff] [blame] | 59 | #include "ash/public/cpp/ash_switches.h" |
sky | 494c6cbd | 2017-03-27 20:57:48 | [diff] [blame] | 60 | #include "ash/public/cpp/config.h" |
msw | 109806d | 2017-06-02 20:11:57 | [diff] [blame] | 61 | #include "ash/public/cpp/shelf_model.h" |
jamescook | 8800b823 | 2016-10-19 12:46:27 | [diff] [blame] | 62 | #include "ash/public/cpp/shell_window_ids.h" |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 63 | #include "ash/root_window_controller.h" |
James Cook | 5e9d340 | 2017-11-01 00:20:12 | [diff] [blame] | 64 | #include "ash/screenshot_delegate.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 65 | #include "ash/session/session_controller.h" |
James Cook | 840177e | 2017-05-25 02:20:01 | [diff] [blame] | 66 | #include "ash/shelf/shelf.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 67 | #include "ash/shelf/shelf_controller.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 68 | #include "ash/shelf/shelf_window_watcher.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 69 | #include "ash/shell_delegate.h" |
[email protected] | 1b4c747 | 2014-05-15 18:32:23 | [diff] [blame] | 70 | #include "ash/shell_init_params.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 71 | #include "ash/shell_observer.h" |
sky | 11cf8db9 | 2017-04-10 23:38:08 | [diff] [blame] | 72 | #include "ash/shell_port.h" |
Scott Violet | 22a7b921 | 2017-07-20 19:05:19 | [diff] [blame] | 73 | #include "ash/shell_port_classic.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 74 | #include "ash/shutdown_controller.h" |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 75 | #include "ash/sticky_keys/sticky_keys_controller.h" |
James Cook | a35a1e2 | 2017-04-08 02:33:08 | [diff] [blame] | 76 | #include "ash/system/bluetooth/bluetooth_notification_controller.h" |
Sonny Sasaka | 55f69fc | 2017-08-28 21:29:37 | [diff] [blame] | 77 | #include "ash/system/bluetooth/bluetooth_power_controller.h" |
James Cook | a35a1e2 | 2017-04-08 02:33:08 | [diff] [blame] | 78 | #include "ash/system/bluetooth/tray_bluetooth_helper.h" |
| 79 | #include "ash/system/brightness/brightness_controller_chromeos.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 80 | #include "ash/system/brightness_control_delegate.h" |
Lann Martin | b999140 | 2017-06-23 22:25:08 | [diff] [blame] | 81 | #include "ash/system/keyboard_brightness/keyboard_brightness_controller.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 82 | #include "ash/system/keyboard_brightness_control_delegate.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 83 | #include "ash/system/locale/locale_notification_controller.h" |
James Cook | a35a1e2 | 2017-04-08 02:33:08 | [diff] [blame] | 84 | #include "ash/system/network/sms_observer.h" |
| 85 | #include "ash/system/network/vpn_list.h" |
afakhry | e4fae85 | 2017-05-09 18:49:06 | [diff] [blame] | 86 | #include "ash/system/night_light/night_light_controller.h" |
Sammie Quon | 4d7dba6 | 2017-08-03 23:18:17 | [diff] [blame] | 87 | #include "ash/system/palette/palette_tray.h" |
Sammie Quon | 6c4e2b1f | 2017-10-13 16:54:18 | [diff] [blame] | 88 | #include "ash/system/palette/palette_welcome_bubble.h" |
Toni Barzic | 9d0c82f4 | 2017-12-06 00:53:52 | [diff] [blame] | 89 | #include "ash/system/power/backlights_forced_off_setter.h" |
Sammie Quon | 95c6a1c | 2017-09-12 19:16:55 | [diff] [blame] | 90 | #include "ash/system/power/peripheral_battery_notifier.h" |
Qiang Xu | 0a86020f | 2017-10-12 08:34:54 | [diff] [blame] | 91 | #include "ash/system/power/power_button_controller.h" |
James Cook | a35a1e2 | 2017-04-08 02:33:08 | [diff] [blame] | 92 | #include "ash/system/power/power_event_observer.h" |
| 93 | #include "ash/system/power/power_status.h" |
| 94 | #include "ash/system/power/video_activity_notifier.h" |
| 95 | #include "ash/system/screen_layout_observer.h" |
James Cook | dc04112 | 2017-08-01 14:03:22 | [diff] [blame] | 96 | #include "ash/system/session/logout_button_tray.h" |
James Cook | a35a1e2 | 2017-04-08 02:33:08 | [diff] [blame] | 97 | #include "ash/system/session/logout_confirmation_controller.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 98 | #include "ash/system/status_area_widget.h" |
| 99 | #include "ash/system/toast/toast_manager.h" |
| 100 | #include "ash/system/tray/system_tray_controller.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 101 | #include "ash/system/tray/system_tray_notifier.h" |
James Cook | 9807235 | 2017-08-07 18:00:07 | [diff] [blame] | 102 | #include "ash/system/tray_caps_lock.h" |
kylechar | 55f0eaf2 | 2017-01-11 22:57:37 | [diff] [blame] | 103 | #include "ash/touch/ash_touch_transform_controller.h" |
Qiang Xu | f1400a36 | 2017-09-14 02:28:30 | [diff] [blame] | 104 | #include "ash/touch/touch_devices_controller.h" |
tbarzic | c78da1ff9 | 2017-05-08 20:46:15 | [diff] [blame] | 105 | #include "ash/tray_action/tray_action.h" |
oshima | 5a296e8 | 2016-04-29 01:32:27 | [diff] [blame] | 106 | #include "ash/utility/screenshot_controller.h" |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 107 | #include "ash/virtual_keyboard_controller.h" |
Yue Li | a33960a | 2017-11-01 22:06:07 | [diff] [blame] | 108 | #include "ash/voice_interaction/voice_interaction_controller.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 109 | #include "ash/wallpaper/wallpaper_controller.h" |
[email protected] | 39718b5 | 2012-12-03 17:24:56 | [diff] [blame] | 110 | #include "ash/wm/ash_focus_rules.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 111 | #include "ash/wm/container_finder.h" |
[email protected] | 262f8bd | 2012-03-23 19:30:27 | [diff] [blame] | 112 | #include "ash/wm/event_client_impl.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 113 | #include "ash/wm/immersive_context_ash.h" |
sky | b7b5409 | 2016-08-19 16:00:09 | [diff] [blame] | 114 | #include "ash/wm/immersive_handler_factory_ash.h" |
[email protected] | ab4f8c9 | 2013-05-30 19:07:47 | [diff] [blame] | 115 | #include "ash/wm/lock_state_controller.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 116 | #include "ash/wm/mru_window_tracker.h" |
erg | 36cfb95 | 2017-06-21 19:41:45 | [diff] [blame] | 117 | #include "ash/wm/native_cursor_manager_ash_classic.h" |
| 118 | #include "ash/wm/native_cursor_manager_ash_mus.h" |
[email protected] | 9ae32df | 2012-07-26 03:25:18 | [diff] [blame] | 119 | #include "ash/wm/overlay_event_filter.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 120 | #include "ash/wm/overview/window_selector_controller.h" |
[email protected] | e4a181cc | 2012-03-17 02:20:57 | [diff] [blame] | 121 | #include "ash/wm/resize_shadow_controller.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 122 | #include "ash/wm/root_window_finder.h" |
hidehiko | 6821ca4 | 2016-06-18 11:12:23 | [diff] [blame] | 123 | #include "ash/wm/screen_pinning_controller.h" |
xdai | d491376 | 2017-07-06 00:17:22 | [diff] [blame] | 124 | #include "ash/wm/splitview/split_view_controller.h" |
[email protected] | 435b212e | 2012-04-05 19:43:37 | [diff] [blame] | 125 | #include "ash/wm/system_gesture_event_filter.h" |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 126 | #include "ash/wm/system_modal_container_event_filter.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 127 | #include "ash/wm/system_modal_container_layout_manager.h" |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 128 | #include "ash/wm/tablet_mode/tablet_mode_controller.h" |
| 129 | #include "ash/wm/tablet_mode/tablet_mode_window_manager.h" |
[email protected] | 3537d47 | 2014-01-15 05:45:31 | [diff] [blame] | 130 | #include "ash/wm/toplevel_window_event_handler.h" |
[email protected] | 9633a9d2 | 2012-01-21 16:40:58 | [diff] [blame] | 131 | #include "ash/wm/video_detector.h" |
[email protected] | b5756e2 | 2012-11-30 01:32:02 | [diff] [blame] | 132 | #include "ash/wm/window_animations.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 133 | #include "ash/wm/window_cycle_controller.h" |
| 134 | #include "ash/wm/window_positioner.h" |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 135 | #include "ash/wm/window_properties.h" |
[email protected] | f4c92b38 | 2012-08-28 00:59:59 | [diff] [blame] | 136 | #include "ash/wm/window_util.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 137 | #include "ash/wm/workspace_controller.h" |
[email protected] | f296be7 | 2011-10-11 15:40:00 | [diff] [blame] | 138 | #include "base/bind.h" |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 139 | #include "base/bind_helpers.h" |
jamescook | fda15900 | 2016-10-21 18:48:57 | [diff] [blame] | 140 | #include "base/command_line.h" |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 141 | #include "base/memory/ptr_util.h" |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 142 | #include "base/sys_info.h" |
primiano | 7182d7b | 2015-01-30 18:02:03 | [diff] [blame] | 143 | #include "base/trace_event/trace_event.h" |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 144 | #include "chromeos/chromeos_switches.h" |
reveman | 2415898 | 2017-01-10 05:58:45 | [diff] [blame] | 145 | #include "chromeos/system/devicemode.h" |
tibell | b93c729b | 2017-03-30 00:45:09 | [diff] [blame] | 146 | #include "components/prefs/pref_registry_simple.h" |
| 147 | #include "components/prefs/pref_service.h" |
Saman Sami | 3fb310d | 2017-11-09 16:51:54 | [diff] [blame] | 148 | #include "components/viz/host/host_frame_sink_manager.h" |
Ken Rockot | 388ba4fc | 2018-02-10 17:23:41 | [diff] [blame] | 149 | #include "mash/public/mojom/launchable.mojom.h" |
tibell | b93c729b | 2017-03-30 00:45:09 | [diff] [blame] | 150 | #include "services/preferences/public/cpp/pref_service_factory.h" |
Ken Rockot | f7f533e | 2018-02-11 02:21:33 | [diff] [blame] | 151 | #include "services/preferences/public/mojom/preferences.mojom.h" |
derat | 94887a2 | 2017-01-20 18:17:25 | [diff] [blame] | 152 | #include "services/service_manager/public/cpp/connector.h" |
| 153 | #include "services/ui/public/interfaces/constants.mojom.h" |
sky | 7db5ccf | 2017-03-14 21:52:29 | [diff] [blame] | 154 | #include "ui/app_list/presenter/app_list.h" |
[email protected] | 2c45610 | 2011-12-26 06:26:34 | [diff] [blame] | 155 | #include "ui/aura/client/aura_constants.h" |
[email protected] | 8a45c97 | 2012-03-14 18:22:44 | [diff] [blame] | 156 | #include "ui/aura/env.h" |
[email protected] | 4bb1650 | 2011-12-06 14:44:58 | [diff] [blame] | 157 | #include "ui/aura/layout_manager.h" |
sky | 6861271 | 2017-04-27 04:45:04 | [diff] [blame] | 158 | #include "ui/aura/mus/focus_synchronizer.h" |
derat | 94887a2 | 2017-01-20 18:17:25 | [diff] [blame] | 159 | #include "ui/aura/mus/user_activity_forwarder.h" |
sky | 6861271 | 2017-04-27 04:45:04 | [diff] [blame] | 160 | #include "ui/aura/mus/window_tree_client.h" |
[email protected] | 87b0d82e | 2011-10-07 21:02:59 | [diff] [blame] | 161 | #include "ui/aura/window.h" |
[email protected] | fcc51c95 | 2014-02-21 21:31:26 | [diff] [blame] | 162 | #include "ui/aura/window_event_dispatcher.h" |
[email protected] | 2d481774 | 2012-12-17 20:16:18 | [diff] [blame] | 163 | #include "ui/base/ui_base_switches.h" |
derat | 2d4e62d | 2015-01-09 16:09:17 | [diff] [blame] | 164 | #include "ui/base/user_activity/user_activity_detector.h" |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 165 | #include "ui/chromeos/user_activity_power_manager_notifier.h" |
[email protected] | 116302fc | 2012-05-05 21:45:41 | [diff] [blame] | 166 | #include "ui/compositor/layer.h" |
| 167 | #include "ui/compositor/layer_animator.h" |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 168 | #include "ui/display/display.h" |
sky | 2f68b6f | 2017-05-21 16:08:39 | [diff] [blame] | 169 | #include "ui/display/manager/chromeos/default_touch_transform_setter.h" |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 170 | #include "ui/display/manager/chromeos/display_change_observer.h" |
| 171 | #include "ui/display/manager/chromeos/display_configurator.h" |
sky | 7265b1cc | 2017-05-22 23:11:03 | [diff] [blame] | 172 | #include "ui/display/manager/chromeos/touch_transform_setter.h" |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 173 | #include "ui/display/manager/display_manager.h" |
kylechar | 7e4f46f | 2017-10-31 23:26:57 | [diff] [blame] | 174 | #include "ui/display/mojo/dev_display_controller.mojom.h" |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 175 | #include "ui/display/screen.h" |
sky | cfaad89 | 2017-04-28 20:52:58 | [diff] [blame] | 176 | #include "ui/display/types/native_display_delegate.h" |
[email protected] | 3e670aa | 2013-12-02 19:04:32 | [diff] [blame] | 177 | #include "ui/events/event_target_iterator.h" |
sky | 4ec2be8 | 2017-01-06 17:38:32 | [diff] [blame] | 178 | #include "ui/gfx/geometry/insets.h" |
[email protected] | 9ec0f45 | 2012-05-31 15:58:53 | [diff] [blame] | 179 | #include "ui/gfx/image/image_skia.h" |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 180 | #include "ui/keyboard/keyboard_controller.h" |
[email protected] | 608de6c | 2013-10-29 00:14:28 | [diff] [blame] | 181 | #include "ui/keyboard/keyboard_switches.h" |
yhanada | 8909a54 | 2017-07-11 10:06:19 | [diff] [blame] | 182 | #include "ui/keyboard/keyboard_ui.h" |
[email protected] | f1d5c3a | 2013-04-23 17:42:56 | [diff] [blame] | 183 | #include "ui/keyboard/keyboard_util.h" |
[email protected] | d7f30a7 | 2013-10-05 05:09:41 | [diff] [blame] | 184 | #include "ui/views/corewm/tooltip_aura.h" |
[email protected] | a1b7a82 | 2013-02-23 19:08:04 | [diff] [blame] | 185 | #include "ui/views/corewm/tooltip_controller.h" |
sky | 07a24d4 | 2017-03-09 23:57:30 | [diff] [blame] | 186 | #include "ui/views/focus/focus_manager_factory.h" |
[email protected] | c13be0d | 2011-11-22 02:09:58 | [diff] [blame] | 187 | #include "ui/views/widget/native_widget_aura.h" |
| 188 | #include "ui/views/widget/widget.h" |
[email protected] | 60d677d | 2014-05-30 13:07:02 | [diff] [blame] | 189 | #include "ui/wm/core/accelerator_filter.h" |
[email protected] | ee3ed1077 | 2014-03-11 22:02:01 | [diff] [blame] | 190 | #include "ui/wm/core/compound_event_filter.h" |
| 191 | #include "ui/wm/core/focus_controller.h" |
[email protected] | ee3ed1077 | 2014-03-11 22:02:01 | [diff] [blame] | 192 | #include "ui/wm/core/shadow_controller.h" |
| 193 | #include "ui/wm/core/visibility_controller.h" |
| 194 | #include "ui/wm/core/window_modality_controller.h" |
[email protected] | 87b0d82e | 2011-10-07 21:02:59 | [diff] [blame] | 195 | |
[email protected] | 55f59335 | 2011-12-24 05:42:46 | [diff] [blame] | 196 | namespace ash { |
[email protected] | 87b0d82e | 2011-10-07 21:02:59 | [diff] [blame] | 197 | |
| 198 | namespace { |
[email protected] | 671a2ae | 2011-10-13 21:53:23 | [diff] [blame] | 199 | |
[email protected] | 615922f | 2012-02-07 02:41:15 | [diff] [blame] | 200 | using aura::Window; |
[email protected] | 3f02dc5 | 2011-10-21 19:36:45 | [diff] [blame] | 201 | using views::Widget; |
| 202 | |
jamescook | 518dccbd | 2017-05-18 04:57:07 | [diff] [blame] | 203 | bool g_is_browser_process_with_mash = false; |
| 204 | |
[email protected] | b5756e2 | 2012-11-30 01:32:02 | [diff] [blame] | 205 | // A Corewm VisibilityController subclass that calls the Ash animation routine |
| 206 | // 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] | 207 | class AshVisibilityController : public ::wm::VisibilityController { |
[email protected] | b5756e2 | 2012-11-30 01:32:02 | [diff] [blame] | 208 | public: |
Chris Watkins | c24daf6 | 2017-11-28 03:43:09 | [diff] [blame] | 209 | AshVisibilityController() = default; |
| 210 | ~AshVisibilityController() override = default; |
[email protected] | b5756e2 | 2012-11-30 01:32:02 | [diff] [blame] | 211 | |
| 212 | private: |
[email protected] | e319c7e | 2014-03-14 19:56:14 | [diff] [blame] | 213 | // Overridden from ::wm::VisibilityController: |
dcheng | 1f4538e | 2014-10-27 23:57:05 | [diff] [blame] | 214 | bool CallAnimateOnChildWindowVisibilityChanged(aura::Window* window, |
| 215 | bool visible) override { |
[email protected] | b5756e2 | 2012-11-30 01:32:02 | [diff] [blame] | 216 | return AnimateOnChildWindowVisibilityChanged(window, visible); |
| 217 | } |
| 218 | |
| 219 | DISALLOW_COPY_AND_ASSIGN(AshVisibilityController); |
| 220 | }; |
| 221 | |
[email protected] | 87b0d82e | 2011-10-07 21:02:59 | [diff] [blame] | 222 | } // namespace |
| 223 | |
[email protected] | cac10fc6 | 2011-10-07 23:22:56 | [diff] [blame] | 224 | // static |
achuith | 287b26e | 2015-09-03 17:49:18 | [diff] [blame] | 225 | Shell* Shell::instance_ = nullptr; |
[email protected] | 2b4cd30 | 2012-02-24 20:21:13 | [diff] [blame] | 226 | // static |
sky | 00f98a37 | 2017-01-11 06:03:49 | [diff] [blame] | 227 | aura::WindowTreeClient* Shell::window_tree_client_ = nullptr; |
| 228 | // static |
sky | a8b222f | 2017-01-12 15:47:13 | [diff] [blame] | 229 | aura::WindowManagerClient* Shell::window_manager_client_ = nullptr; |
[email protected] | 2b4cd30 | 2012-02-24 20:21:13 | [diff] [blame] | 230 | |
| 231 | //////////////////////////////////////////////////////////////////////////////// |
[email protected] | cac10fc6 | 2011-10-07 23:22:56 | [diff] [blame] | 232 | // Shell, public: |
| 233 | |
[email protected] | cac10fc6 | 2011-10-07 23:22:56 | [diff] [blame] | 234 | // static |
Scott Violet | c8a1c6c | 2017-11-29 23:17:36 | [diff] [blame] | 235 | Shell* Shell::CreateInstance(ShellInitParams init_params) { |
[email protected] | 3266c2b9 | 2011-11-14 00:06:08 | [diff] [blame] | 236 | CHECK(!instance_); |
Scott Violet | c8a1c6c | 2017-11-29 23:17:36 | [diff] [blame] | 237 | instance_ = new Shell(std::move(init_params.delegate), |
| 238 | std::move(init_params.shell_port)); |
| 239 | instance_->Init(init_params.context_factory, |
| 240 | init_params.context_factory_private); |
[email protected] | 3266c2b9 | 2011-11-14 00:06:08 | [diff] [blame] | 241 | return instance_; |
| 242 | } |
| 243 | |
| 244 | // static |
sky | b073203a | 2017-03-13 16:59:16 | [diff] [blame] | 245 | Shell* Shell::Get() { |
jamescook | 518dccbd | 2017-05-18 04:57:07 | [diff] [blame] | 246 | CHECK(!g_is_browser_process_with_mash) // Implies null |instance_|. |
| 247 | << "Ash is running in its own process so Shell::Get() will return null. " |
| 248 | "The browser process must use the mojo interfaces in //ash/public to " |
| 249 | "access ash. See ash/README.md for details."; |
oshima | 9eea82da | 2014-09-13 01:11:07 | [diff] [blame] | 250 | CHECK(instance_); |
[email protected] | cac10fc6 | 2011-10-07 23:22:56 | [diff] [blame] | 251 | return instance_; |
| 252 | } |
| 253 | |
[email protected] | 6377a00 | 2011-11-10 20:26:47 | [diff] [blame] | 254 | // static |
[email protected] | b3b7bcd | 2012-03-06 19:35:45 | [diff] [blame] | 255 | bool Shell::HasInstance() { |
| 256 | return !!instance_; |
| 257 | } |
| 258 | |
| 259 | // static |
[email protected] | ef589af | 2011-12-03 01:07:15 | [diff] [blame] | 260 | void Shell::DeleteInstance() { |
[email protected] | 6377a00 | 2011-11-10 20:26:47 | [diff] [blame] | 261 | delete instance_; |
[email protected] | 6377a00 | 2011-11-10 20:26:47 | [diff] [blame] | 262 | } |
| 263 | |
[email protected] | e73bd780 | 2012-02-17 20:10:34 | [diff] [blame] | 264 | // static |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 265 | RootWindowController* Shell::GetPrimaryRootWindowController() { |
oshima | 9eea82da | 2014-09-13 01:11:07 | [diff] [blame] | 266 | CHECK(HasInstance()); |
msw | 257a6a23 | 2017-06-01 01:46:30 | [diff] [blame] | 267 | return RootWindowController::ForWindow(GetPrimaryRootWindow()); |
[email protected] | be65be36 | 2012-06-15 07:38:23 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | // static |
| 271 | Shell::RootWindowControllerList Shell::GetAllRootWindowControllers() { |
oshima | 9eea82da | 2014-09-13 01:11:07 | [diff] [blame] | 272 | CHECK(HasInstance()); |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 273 | RootWindowControllerList root_window_controllers; |
msw | 257a6a23 | 2017-06-01 01:46:30 | [diff] [blame] | 274 | for (aura::Window* root : GetAllRootWindows()) |
| 275 | root_window_controllers.push_back(RootWindowController::ForWindow(root)); |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 276 | return root_window_controllers; |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | // static |
thanhph | c90f49ca | 2017-03-03 17:48:53 | [diff] [blame] | 280 | RootWindowController* Shell::GetRootWindowControllerWithDisplayId( |
| 281 | int64_t display_id) { |
| 282 | CHECK(HasInstance()); |
Scott Violet | 596bb4634 | 2017-06-21 14:43:13 | [diff] [blame] | 283 | aura::Window* root = GetRootWindowForDisplayId(display_id); |
msw | 257a6a23 | 2017-06-01 01:46:30 | [diff] [blame] | 284 | return root ? RootWindowController::ForWindow(root) : nullptr; |
thanhph | c90f49ca | 2017-03-03 17:48:53 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | // static |
Scott Violet | 596bb4634 | 2017-06-21 14:43:13 | [diff] [blame] | 288 | aura::Window* Shell::GetRootWindowForDisplayId(int64_t display_id) { |
| 289 | CHECK(HasInstance()); |
| 290 | return instance_->window_tree_host_manager_->GetRootWindowForDisplayId( |
| 291 | display_id); |
| 292 | } |
| 293 | |
| 294 | // static |
[email protected] | bf9cdb36 | 2013-10-25 19:22:45 | [diff] [blame] | 295 | aura::Window* Shell::GetPrimaryRootWindow() { |
oshima | 9eea82da | 2014-09-13 01:11:07 | [diff] [blame] | 296 | CHECK(HasInstance()); |
Scott Violet | 596bb4634 | 2017-06-21 14:43:13 | [diff] [blame] | 297 | return instance_->window_tree_host_manager_->GetPrimaryRootWindow(); |
[email protected] | e73bd780 | 2012-02-17 20:10:34 | [diff] [blame] | 298 | } |
| 299 | |
[email protected] | 7b0f750 | 2012-06-11 00:12:39 | [diff] [blame] | 300 | // static |
sky | 2734438 | 2017-03-08 21:30:32 | [diff] [blame] | 301 | aura::Window* Shell::GetRootWindowForNewWindows() { |
| 302 | CHECK(Shell::HasInstance()); |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 303 | Shell* shell = Shell::Get(); |
sky | 2734438 | 2017-03-08 21:30:32 | [diff] [blame] | 304 | if (shell->scoped_root_window_for_new_windows_) |
| 305 | return shell->scoped_root_window_for_new_windows_; |
| 306 | return shell->root_window_for_new_windows_; |
mfomitchev | a1a8aa6 | 2016-05-03 16:23:26 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | // static |
[email protected] | c9390bd | 2013-11-08 20:33:13 | [diff] [blame] | 310 | aura::Window::Windows Shell::GetAllRootWindows() { |
oshima | 9eea82da | 2014-09-13 01:11:07 | [diff] [blame] | 311 | CHECK(HasInstance()); |
Scott Violet | 596bb4634 | 2017-06-21 14:43:13 | [diff] [blame] | 312 | return instance_->window_tree_host_manager_->GetAllRootWindows(); |
[email protected] | be65be36 | 2012-06-15 07:38:23 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | // static |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 316 | aura::Window* Shell::GetContainer(aura::Window* root_window, int container_id) { |
[email protected] | 7b0f750 | 2012-06-11 00:12:39 | [diff] [blame] | 317 | return root_window->GetChildById(container_id); |
| 318 | } |
| 319 | |
| 320 | // static |
[email protected] | bf9cdb36 | 2013-10-25 19:22:45 | [diff] [blame] | 321 | const aura::Window* Shell::GetContainer(const aura::Window* root_window, |
[email protected] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 322 | int container_id) { |
| 323 | return root_window->GetChildById(container_id); |
| 324 | } |
| 325 | |
sky | 494c6cbd | 2017-03-27 20:57:48 | [diff] [blame] | 326 | // static |
James Cook | 7b7c6a5 | 2018-01-04 23:40:03 | [diff] [blame] | 327 | int Shell::GetOpenSystemModalWindowContainerId() { |
| 328 | // The test boolean is not static to avoid leaking state between tests. |
| 329 | if (Get()->simulate_modal_window_open_for_test_) |
| 330 | return kShellWindowId_SystemModalContainer; |
| 331 | |
| 332 | // Traverse all system modal containers, and find its direct child window |
| 333 | // with "SystemModal" setting, and visible. |
| 334 | // Note: LockSystemModalContainer is more restrictive, so make it preferable |
| 335 | // to SystemModalCotainer. |
| 336 | constexpr int modal_window_ids[] = {kShellWindowId_LockSystemModalContainer, |
| 337 | kShellWindowId_SystemModalContainer}; |
| 338 | for (aura::Window* root : Shell::GetAllRootWindows()) { |
| 339 | for (int modal_window_id : modal_window_ids) { |
| 340 | aura::Window* system_modal = root->GetChildById(modal_window_id); |
| 341 | if (!system_modal) |
| 342 | continue; |
| 343 | for (const aura::Window* child : system_modal->children()) { |
| 344 | if (child->GetProperty(aura::client::kModalKey) == |
| 345 | ui::MODAL_TYPE_SYSTEM && |
| 346 | child->layer()->GetTargetVisibility()) { |
| 347 | return modal_window_id; |
| 348 | } |
| 349 | } |
| 350 | } |
| 351 | } |
| 352 | return -1; |
| 353 | } |
| 354 | |
| 355 | // static |
| 356 | bool Shell::IsSystemModalWindowOpen() { |
| 357 | return GetOpenSystemModalWindowContainerId() >= 0; |
| 358 | } |
| 359 | |
| 360 | // static |
jamescook | 0dfe563 | 2017-04-05 18:49:02 | [diff] [blame] | 361 | Config Shell::GetAshConfig() { |
sky | 11cf8db9 | 2017-04-10 23:38:08 | [diff] [blame] | 362 | return Get()->shell_port_->GetAshConfig(); |
sky | 494c6cbd | 2017-03-27 20:57:48 | [diff] [blame] | 363 | } |
| 364 | |
moshayedi | c229a52 | 2017-05-05 18:14:26 | [diff] [blame] | 365 | // static |
| 366 | bool Shell::ShouldUseIMEService() { |
| 367 | return Shell::GetAshConfig() == Config::MASH || |
| 368 | (Shell::GetAshConfig() == Config::MUS && |
| 369 | base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 370 | switches::kUseIMEService)); |
| 371 | } |
| 372 | |
afakhry | e4fae85 | 2017-05-09 18:49:06 | [diff] [blame] | 373 | // static |
Wenzhao Zang | 56c29293 | 2017-08-02 04:58:34 | [diff] [blame] | 374 | void Shell::RegisterLocalStatePrefs(PrefRegistrySimple* registry) { |
Sammie Quon | 4d7dba6 | 2017-08-03 23:18:17 | [diff] [blame] | 375 | PaletteTray::RegisterLocalStatePrefs(registry); |
Wenzhao Zang | 56c29293 | 2017-08-02 04:58:34 | [diff] [blame] | 376 | WallpaperController::RegisterLocalStatePrefs(registry); |
Sonny Sasaka | 55f69fc | 2017-08-28 21:29:37 | [diff] [blame] | 377 | BluetoothPowerController::RegisterLocalStatePrefs(registry); |
Wenzhao Zang | 56c29293 | 2017-08-02 04:58:34 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | // static |
James Cook | ec14495 | 2017-09-01 00:05:16 | [diff] [blame] | 381 | void Shell::RegisterProfilePrefs(PrefRegistrySimple* registry, bool for_test) { |
| 382 | AccessibilityController::RegisterProfilePrefs(registry, for_test); |
Sonny Sasaka | 55f69fc | 2017-08-28 21:29:37 | [diff] [blame] | 383 | BluetoothPowerController::RegisterProfilePrefs(registry); |
Ahmed Fakhry | 4bf3f74 | 2018-02-06 17:33:36 | [diff] [blame] | 384 | DockedMagnifierController::RegisterProfilePrefs(registry); |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 385 | LoginScreenController::RegisterProfilePrefs(registry, for_test); |
Sammie Quon | 6c4e2b1f | 2017-10-13 16:54:18 | [diff] [blame] | 386 | LogoutButtonTray::RegisterProfilePrefs(registry); |
| 387 | NightLightController::RegisterProfilePrefs(registry); |
Vladislav Kaznacheev | fefa6bd | 2017-10-14 00:25:24 | [diff] [blame] | 388 | PaletteTray::RegisterProfilePrefs(registry); |
Sammie Quon | 6c4e2b1f | 2017-10-13 16:54:18 | [diff] [blame] | 389 | PaletteWelcomeBubble::RegisterProfilePrefs(registry); |
| 390 | ShelfController::RegisterProfilePrefs(registry); |
Qiang Xu | f1400a36 | 2017-09-14 02:28:30 | [diff] [blame] | 391 | TouchDevicesController::RegisterProfilePrefs(registry); |
Sammie Quon | 6c4e2b1f | 2017-10-13 16:54:18 | [diff] [blame] | 392 | TrayCapsLock::RegisterProfilePrefs(registry, for_test); |
afakhry | e4fae85 | 2017-05-09 18:49:06 | [diff] [blame] | 393 | } |
| 394 | |
[email protected] | 57b8bb35 | 2012-01-11 05:11:46 | [diff] [blame] | 395 | views::NonClientFrameView* Shell::CreateDefaultNonClientFrameView( |
| 396 | views::Widget* widget) { |
[email protected] | c73d133 | 2012-03-08 17:11:04 | [diff] [blame] | 397 | // Use translucent-style window frames for dialogs. |
[email protected] | 85501fe | 2013-10-18 10:15:27 | [diff] [blame] | 398 | return new CustomFrameViewAsh(widget); |
[email protected] | 57b8bb35 | 2012-01-11 05:11:46 | [diff] [blame] | 399 | } |
| 400 | |
[email protected] | 2e236a5 | 2012-06-27 22:21:47 | [diff] [blame] | 401 | void Shell::SetDisplayWorkAreaInsets(Window* contains, |
[email protected] | 8a45c97 | 2012-03-14 18:22:44 | [diff] [blame] | 402 | const gfx::Insets& insets) { |
Scott Violet | 596bb4634 | 2017-06-21 14:43:13 | [diff] [blame] | 403 | window_tree_host_manager_->UpdateWorkAreaOfDisplayNearestWindow(contains, |
| 404 | insets); |
[email protected] | 1a2145b | 2012-03-13 21:09:17 | [diff] [blame] | 405 | } |
| 406 | |
[email protected] | 58868abf | 2014-01-17 23:45:33 | [diff] [blame] | 407 | void Shell::OnCastingSessionStartedOrStopped(bool started) { |
sky | 00c813f | 2017-03-08 22:48:55 | [diff] [blame] | 408 | for (auto& observer : shell_observers_) |
ericwilligers | 5eff47d | 2016-10-17 19:19:18 | [diff] [blame] | 409 | observer.OnCastingSessionStartedOrStopped(started); |
[email protected] | 58868abf | 2014-01-17 23:45:33 | [diff] [blame] | 410 | } |
| 411 | |
varkha | c71444e5 | 2017-05-25 22:51:34 | [diff] [blame] | 412 | void Shell::OnRootWindowAdded(aura::Window* root_window) { |
sky | 00c813f | 2017-03-08 22:48:55 | [diff] [blame] | 413 | for (auto& observer : shell_observers_) |
ericwilligers | 5eff47d | 2016-10-17 19:19:18 | [diff] [blame] | 414 | observer.OnRootWindowAdded(root_window); |
[email protected] | 0e3e7cb | 2014-04-12 05:18:25 | [diff] [blame] | 415 | } |
| 416 | |
[email protected] | 51f43811 | 2013-11-18 19:32:50 | [diff] [blame] | 417 | void Shell::CreateKeyboard() { |
Keigo Oka | e82281a | 2017-06-14 13:59:14 | [diff] [blame] | 418 | if (keyboard::IsKeyboardEnabled()) { |
| 419 | if (keyboard::KeyboardController::GetInstance()) { |
| 420 | RootWindowControllerList controllers = GetAllRootWindowControllers(); |
| 421 | for (RootWindowControllerList::iterator iter = controllers.begin(); |
| 422 | iter != controllers.end(); ++iter) { |
| 423 | (*iter)->DeactivateKeyboard( |
| 424 | keyboard::KeyboardController::GetInstance()); |
| 425 | } |
| 426 | } |
| 427 | keyboard::KeyboardController::ResetInstance( |
| 428 | new keyboard::KeyboardController(shell_delegate_->CreateKeyboardUI(), |
| 429 | virtual_keyboard_controller_.get())); |
| 430 | for (auto& observer : shell_observers_) |
| 431 | observer.OnKeyboardControllerCreated(); |
| 432 | } |
| 433 | |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 434 | GetPrimaryRootWindowController()->ActivateKeyboard( |
| 435 | keyboard::KeyboardController::GetInstance()); |
[email protected] | 51f43811 | 2013-11-18 19:32:50 | [diff] [blame] | 436 | } |
| 437 | |
Keigo Oka | c7617a4 | 2017-06-14 11:33:24 | [diff] [blame] | 438 | void Shell::DestroyKeyboard() { |
sky | 11cf8db9 | 2017-04-10 23:38:08 | [diff] [blame] | 439 | // TODO(jamescook): Move keyboard create and hide into ShellPort. |
sky | 79fa3471 | 2017-03-20 23:46:47 | [diff] [blame] | 440 | keyboard_ui_->Hide(); |
[email protected] | a0b3fb88 | 2014-04-07 19:26:03 | [diff] [blame] | 441 | if (keyboard::KeyboardController::GetInstance()) { |
[email protected] | e1b299b | 2014-01-29 23:53:41 | [diff] [blame] | 442 | RootWindowControllerList controllers = GetAllRootWindowControllers(); |
| 443 | for (RootWindowControllerList::iterator iter = controllers.begin(); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 444 | iter != controllers.end(); ++iter) { |
[email protected] | a0b3fb88 | 2014-04-07 19:26:03 | [diff] [blame] | 445 | (*iter)->DeactivateKeyboard(keyboard::KeyboardController::GetInstance()); |
[email protected] | e1b299b | 2014-01-29 23:53:41 | [diff] [blame] | 446 | } |
| 447 | } |
achuith | 287b26e | 2015-09-03 17:49:18 | [diff] [blame] | 448 | keyboard::KeyboardController::ResetInstance(nullptr); |
[email protected] | e1b299b | 2014-01-29 23:53:41 | [diff] [blame] | 449 | } |
| 450 | |
[email protected] | da28585 | 2014-05-27 19:53:43 | [diff] [blame] | 451 | bool Shell::ShouldSaveDisplaySettings() { |
Steven Bennetts | 7614ab5 | 2018-01-12 20:48:17 | [diff] [blame] | 452 | // This function is only called from Chrome, hence the DCHECK for not-MASH. |
| 453 | DCHECK(GetAshConfig() != Config::MASH); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 454 | return !( |
| 455 | screen_orientation_controller_->ignore_display_configuration_updates() || |
| 456 | resolution_notification_controller_->DoesNotificationTimeout()); |
[email protected] | da28585 | 2014-05-27 19:53:43 | [diff] [blame] | 457 | } |
[email protected] | da28585 | 2014-05-27 19:53:43 | [diff] [blame] | 458 | |
Ahmed Fakhry | 4bf3f74 | 2018-02-06 17:33:36 | [diff] [blame] | 459 | DockedMagnifierController* Shell::docked_magnifier_controller() { |
Ahmed Fakhry | 4af48e4 | 2018-02-28 17:45:38 | [diff] [blame^] | 460 | DCHECK(features::IsDockedMagnifierEnabled()); |
Ahmed Fakhry | 4bf3f74 | 2018-02-06 17:33:36 | [diff] [blame] | 461 | return docked_magnifier_controller_.get(); |
| 462 | } |
| 463 | |
afakhry | 9e0a18b3 | 2017-06-05 19:23:14 | [diff] [blame] | 464 | NightLightController* Shell::night_light_controller() { |
Evan Stade | 48768f4 | 2017-10-10 05:23:30 | [diff] [blame] | 465 | DCHECK(switches::IsNightLightEnabled()); |
afakhry | 9e0a18b3 | 2017-06-05 19:23:14 | [diff] [blame] | 466 | return night_light_controller_.get(); |
| 467 | } |
| 468 | |
sky | 5ad143a | 2017-03-22 04:31:23 | [diff] [blame] | 469 | ShelfModel* Shell::shelf_model() { |
| 470 | return shelf_controller_->model(); |
| 471 | } |
| 472 | |
Thiago Farina | 3b086a0 | 2017-05-30 22:32:50 | [diff] [blame] | 473 | ::wm::ActivationClient* Shell::activation_client() { |
sky | 2734438 | 2017-03-08 21:30:32 | [diff] [blame] | 474 | return focus_controller_.get(); |
| 475 | } |
| 476 | |
[email protected] | c758fbf | 2012-03-25 22:53:59 | [diff] [blame] | 477 | void Shell::UpdateShelfVisibility() { |
msw | 257a6a23 | 2017-06-01 01:46:30 | [diff] [blame] | 478 | for (aura::Window* root : GetAllRootWindows()) |
| 479 | Shelf::ForWindow(root)->UpdateVisibilityState(); |
[email protected] | c758fbf | 2012-03-25 22:53:59 | [diff] [blame] | 480 | } |
| 481 | |
Wenzhao Zang | 44240fb | 2017-07-13 01:36:54 | [diff] [blame] | 482 | PrefService* Shell::GetLocalStatePrefService() const { |
Sam McNally | a853cd8 | 2017-08-30 01:55:10 | [diff] [blame] | 483 | return local_state_.get(); |
Wenzhao Zang | 44240fb | 2017-07-13 01:36:54 | [diff] [blame] | 484 | } |
| 485 | |
[email protected] | 88d7112 | 2012-10-18 07:11:01 | [diff] [blame] | 486 | WebNotificationTray* Shell::GetWebNotificationTray() { |
jamescook | 612205f | 2016-05-26 06:02:11 | [diff] [blame] | 487 | return GetPrimaryRootWindowController() |
jamescook | b551aba | 2016-09-01 01:00:16 | [diff] [blame] | 488 | ->GetStatusAreaWidget() |
jamescook | 612205f | 2016-05-26 06:02:11 | [diff] [blame] | 489 | ->web_notification_tray(); |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 490 | } |
| 491 | |
[email protected] | a0afeb1 | 2012-12-10 22:57:09 | [diff] [blame] | 492 | bool Shell::HasPrimaryStatusArea() { |
jamescook | b551aba | 2016-09-01 01:00:16 | [diff] [blame] | 493 | return !!GetPrimaryRootWindowController()->GetStatusAreaWidget(); |
[email protected] | 31f19e3 | 2012-10-30 22:31:23 | [diff] [blame] | 494 | } |
| 495 | |
[email protected] | a0afeb1 | 2012-12-10 22:57:09 | [diff] [blame] | 496 | SystemTray* Shell::GetPrimarySystemTray() { |
| 497 | return GetPrimaryRootWindowController()->GetSystemTray(); |
[email protected] | aa54218b | 2012-06-12 16:51:42 | [diff] [blame] | 498 | } |
| 499 | |
msw | a7e8a5f | 2016-03-01 04:15:06 | [diff] [blame] | 500 | FirstRunHelper* Shell::CreateFirstRunHelper() { |
| 501 | return new FirstRunHelperImpl; |
[email protected] | 59ccade | 2013-10-17 17:56:40 | [diff] [blame] | 502 | } |
[email protected] | 87ec220 | 2014-02-06 06:24:27 | [diff] [blame] | 503 | |
yawano | dc5533b3 | 2017-02-23 11:04:38 | [diff] [blame] | 504 | void Shell::SetLargeCursorSizeInDip(int large_cursor_size_in_dip) { |
| 505 | window_tree_host_manager_->cursor_window_controller() |
| 506 | ->SetLargeCursorSizeInDip(large_cursor_size_in_dip); |
| 507 | } |
| 508 | |
Weidong Guo | d07448f | 2017-10-18 03:35:18 | [diff] [blame] | 509 | void Shell::UpdateCursorCompositingEnabled() { |
| 510 | SetCursorCompositingEnabled( |
| 511 | window_tree_host_manager_->cursor_window_controller() |
| 512 | ->ShouldEnableCursorCompositing()); |
| 513 | } |
| 514 | |
[email protected] | 87ec220 | 2014-02-06 06:24:27 | [diff] [blame] | 515 | void Shell::SetCursorCompositingEnabled(bool enabled) { |
erg | 36cfb95 | 2017-06-21 19:41:45 | [diff] [blame] | 516 | if (GetAshConfig() != Config::MASH) { |
| 517 | // TODO: needs to work in mash. http://crbug.com/705592. |
Weidong Guo | 7dfd148 | 2017-11-08 05:56:28 | [diff] [blame] | 518 | CursorWindowController* cursor_window_controller = |
| 519 | window_tree_host_manager_->cursor_window_controller(); |
| 520 | |
| 521 | if (cursor_window_controller->is_cursor_compositing_enabled() == enabled) |
| 522 | return; |
| 523 | cursor_window_controller->SetCursorCompositingEnabled(enabled); |
sky | 494c6cbd | 2017-03-27 20:57:48 | [diff] [blame] | 524 | native_cursor_manager_->SetNativeCursorEnabled(!enabled); |
| 525 | } |
[email protected] | 87ec220 | 2014-02-06 06:24:27 | [diff] [blame] | 526 | } |
[email protected] | 59ccade | 2013-10-17 17:56:40 | [diff] [blame] | 527 | |
[email protected] | f946670 | 2012-09-17 16:35:27 | [diff] [blame] | 528 | void Shell::DoInitialWorkspaceAnimation() { |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 529 | return GetPrimaryRootWindowController() |
| 530 | ->workspace_controller() |
| 531 | ->DoInitialAnimation(); |
[email protected] | f946670 | 2012-09-17 16:35:27 | [diff] [blame] | 532 | } |
| 533 | |
xdai | d491376 | 2017-07-06 00:17:22 | [diff] [blame] | 534 | bool Shell::IsSplitViewModeActive() const { |
| 535 | return split_view_controller_->IsSplitViewModeActive(); |
| 536 | } |
| 537 | |
sky | 00c813f | 2017-03-08 22:48:55 | [diff] [blame] | 538 | void Shell::AddShellObserver(ShellObserver* observer) { |
| 539 | shell_observers_.AddObserver(observer); |
| 540 | } |
| 541 | |
| 542 | void Shell::RemoveShellObserver(ShellObserver* observer) { |
| 543 | shell_observers_.RemoveObserver(observer); |
| 544 | } |
| 545 | |
sky | 5ad143a | 2017-03-22 04:31:23 | [diff] [blame] | 546 | void Shell::UpdateAfterLoginStatusChange(LoginStatus status) { |
varkha | 5967963 | 2017-06-01 00:42:05 | [diff] [blame] | 547 | for (auto* root_window_controller : GetAllRootWindowControllers()) |
| 548 | root_window_controller->UpdateAfterLoginStatusChange(status); |
sky | 5ad143a | 2017-03-22 04:31:23 | [diff] [blame] | 549 | } |
| 550 | |
sky | 00c813f | 2017-03-08 22:48:55 | [diff] [blame] | 551 | void Shell::NotifyOverviewModeStarting() { |
| 552 | for (auto& observer : shell_observers_) |
| 553 | observer.OnOverviewModeStarting(); |
| 554 | } |
| 555 | |
Xiaoqian Dai | fb4698ed | 2018-02-23 20:11:06 | [diff] [blame] | 556 | void Shell::NotifyOverviewModeEnding() { |
| 557 | for (auto& observer : shell_observers_) |
| 558 | observer.OnOverviewModeEnding(); |
| 559 | } |
| 560 | |
sky | 00c813f | 2017-03-08 22:48:55 | [diff] [blame] | 561 | void Shell::NotifyOverviewModeEnded() { |
| 562 | for (auto& observer : shell_observers_) |
| 563 | observer.OnOverviewModeEnded(); |
| 564 | } |
| 565 | |
xdai | d491376 | 2017-07-06 00:17:22 | [diff] [blame] | 566 | void Shell::NotifySplitViewModeStarting() { |
| 567 | for (auto& observer : shell_observers_) |
| 568 | observer.OnSplitViewModeStarting(); |
| 569 | } |
| 570 | |
| 571 | void Shell::NotifySplitViewModeEnded() { |
| 572 | for (auto& observer : shell_observers_) |
| 573 | observer.OnSplitViewModeEnded(); |
| 574 | } |
| 575 | |
sky | 00c813f | 2017-03-08 22:48:55 | [diff] [blame] | 576 | void Shell::NotifyFullscreenStateChanged(bool is_fullscreen, |
varkha | c71444e5 | 2017-05-25 22:51:34 | [diff] [blame] | 577 | aura::Window* root_window) { |
sky | 00c813f | 2017-03-08 22:48:55 | [diff] [blame] | 578 | for (auto& observer : shell_observers_) |
| 579 | observer.OnFullscreenStateChanged(is_fullscreen, root_window); |
| 580 | } |
| 581 | |
varkha | 19d7e6c5 | 2017-05-25 21:15:30 | [diff] [blame] | 582 | void Shell::NotifyPinnedStateChanged(aura::Window* pinned_window) { |
sky | 00c813f | 2017-03-08 22:48:55 | [diff] [blame] | 583 | for (auto& observer : shell_observers_) |
| 584 | observer.OnPinnedStateChanged(pinned_window); |
| 585 | } |
| 586 | |
xiyuan | 3816018 | 2017-03-14 22:50:13 | [diff] [blame] | 587 | void Shell::NotifyVirtualKeyboardActivated(bool activated, |
sky | 97f9a743 | 2017-05-09 05:14:31 | [diff] [blame] | 588 | aura::Window* root_window) { |
sky | 00c813f | 2017-03-08 22:48:55 | [diff] [blame] | 589 | for (auto& observer : shell_observers_) |
xiyuan | 3816018 | 2017-03-14 22:50:13 | [diff] [blame] | 590 | observer.OnVirtualKeyboardStateChanged(activated, root_window); |
sky | 00c813f | 2017-03-08 22:48:55 | [diff] [blame] | 591 | } |
| 592 | |
varkha | 6b016b0f | 2017-05-26 16:14:18 | [diff] [blame] | 593 | void Shell::NotifyShelfCreatedForRootWindow(aura::Window* root_window) { |
sky | 00c813f | 2017-03-08 22:48:55 | [diff] [blame] | 594 | for (auto& observer : shell_observers_) |
| 595 | observer.OnShelfCreatedForRootWindow(root_window); |
| 596 | } |
| 597 | |
varkha | 6b016b0f | 2017-05-26 16:14:18 | [diff] [blame] | 598 | void Shell::NotifyShelfAlignmentChanged(aura::Window* root_window) { |
sky | 00c813f | 2017-03-08 22:48:55 | [diff] [blame] | 599 | for (auto& observer : shell_observers_) |
| 600 | observer.OnShelfAlignmentChanged(root_window); |
| 601 | } |
| 602 | |
varkha | 6b016b0f | 2017-05-26 16:14:18 | [diff] [blame] | 603 | void Shell::NotifyShelfAutoHideBehaviorChanged(aura::Window* root_window) { |
sky | 00c813f | 2017-03-08 22:48:55 | [diff] [blame] | 604 | for (auto& observer : shell_observers_) |
| 605 | observer.OnShelfAutoHideBehaviorChanged(root_window); |
| 606 | } |
| 607 | |
jamescook | 518dccbd | 2017-05-18 04:57:07 | [diff] [blame] | 608 | // static |
| 609 | void Shell::SetIsBrowserProcessWithMash() { |
| 610 | g_is_browser_process_with_mash = true; |
| 611 | } |
| 612 | |
muyuanli | d766f2e | 2017-06-26 20:17:19 | [diff] [blame] | 613 | void Shell::NotifyAppListVisibilityChanged(bool visible, |
| 614 | aura::Window* root_window) { |
newcomer | 2febb983 | 2017-06-12 17:00:23 | [diff] [blame] | 615 | for (auto& observer : shell_observers_) |
| 616 | observer.OnAppListVisibilityChanged(visible, root_window); |
| 617 | } |
| 618 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 619 | //////////////////////////////////////////////////////////////////////////////// |
| 620 | // Shell, private: |
| 621 | |
sky | b073203a | 2017-03-13 16:59:16 | [diff] [blame] | 622 | Shell::Shell(std::unique_ptr<ShellDelegate> shell_delegate, |
sky | 11cf8db9 | 2017-04-10 23:38:08 | [diff] [blame] | 623 | std::unique_ptr<ShellPort> shell_port) |
| 624 | : shell_port_(std::move(shell_port)), |
Mitsuru Oshima | 04b54d0 | 2017-10-09 14:22:45 | [diff] [blame] | 625 | ash_display_controller_(std::make_unique<AshDisplayController>()), |
sky | 79fa3471 | 2017-03-20 23:46:47 | [diff] [blame] | 626 | brightness_control_delegate_( |
Mitsuru Oshima | 04b54d0 | 2017-10-09 14:22:45 | [diff] [blame] | 627 | std::make_unique<system::BrightnessControllerChromeos>()), |
| 628 | cast_config_(std::make_unique<CastConfigController>()), |
| 629 | focus_cycler_(std::make_unique<FocusCycler>()), |
| 630 | ime_controller_(std::make_unique<ImeController>()), |
| 631 | immersive_context_(std::make_unique<ImmersiveContextAsh>()), |
sky | 79fa3471 | 2017-03-20 23:46:47 | [diff] [blame] | 632 | keyboard_brightness_control_delegate_( |
Mitsuru Oshima | 04b54d0 | 2017-10-09 14:22:45 | [diff] [blame] | 633 | std::make_unique<KeyboardBrightnessController>()), |
sky | 79fa3471 | 2017-03-20 23:46:47 | [diff] [blame] | 634 | locale_notification_controller_( |
Mitsuru Oshima | 04b54d0 | 2017-10-09 14:22:45 | [diff] [blame] | 635 | std::make_unique<LocaleNotificationController>()), |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 636 | login_screen_controller_(std::make_unique<LoginScreenController>()), |
Mitsuru Oshima | 04b54d0 | 2017-10-09 14:22:45 | [diff] [blame] | 637 | media_controller_(std::make_unique<MediaController>()), |
| 638 | new_window_controller_(std::make_unique<NewWindowController>()), |
| 639 | session_controller_(std::make_unique<SessionController>( |
Sam McNally | f4dab61 | 2017-08-16 03:06:33 | [diff] [blame] | 640 | shell_delegate->GetShellConnector())), |
Vladislav Kaznacheev | 92edf62e | 2017-10-13 22:08:01 | [diff] [blame] | 641 | note_taking_controller_(std::make_unique<NoteTakingController>()), |
sky | b073203a | 2017-03-13 16:59:16 | [diff] [blame] | 642 | shell_delegate_(std::move(shell_delegate)), |
Mitsuru Oshima | 04b54d0 | 2017-10-09 14:22:45 | [diff] [blame] | 643 | shutdown_controller_(std::make_unique<ShutdownController>()), |
| 644 | system_tray_controller_(std::make_unique<SystemTrayController>()), |
| 645 | system_tray_notifier_(std::make_unique<SystemTrayNotifier>()), |
Mitsuru Oshima | 04b54d0 | 2017-10-09 14:22:45 | [diff] [blame] | 646 | vpn_list_(std::make_unique<VpnList>()), |
| 647 | window_cycle_controller_(std::make_unique<WindowCycleController>()), |
| 648 | window_selector_controller_(std::make_unique<WindowSelectorController>()), |
| 649 | app_list_(std::make_unique<app_list::AppList>()), |
| 650 | tray_bluetooth_helper_(std::make_unique<TrayBluetoothHelper>()), |
kylechar | 7a067ec | 2017-01-07 01:16:28 | [diff] [blame] | 651 | display_configurator_(new display::DisplayConfigurator()), |
sadrul | 7a8785e | 2016-02-12 21:54:35 | [diff] [blame] | 652 | native_cursor_manager_(nullptr), |
Sam McNally | e36abbc | 2017-07-20 01:04:28 | [diff] [blame] | 653 | weak_factory_(this) { |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 654 | // TODO(sky): better refactor cash/mash dependencies. Perhaps put all cash |
sky | 11cf8db9 | 2017-04-10 23:38:08 | [diff] [blame] | 655 | // state on ShellPortClassic. http://crbug.com/671246. |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 656 | |
Scott Violet | 596bb4634 | 2017-06-21 14:43:13 | [diff] [blame] | 657 | display_manager_.reset(ScreenAsh::CreateDisplayManager()); |
Mitsuru Oshima | 04b54d0 | 2017-10-09 14:22:45 | [diff] [blame] | 658 | window_tree_host_manager_ = std::make_unique<WindowTreeHostManager>(); |
| 659 | user_metrics_recorder_ = std::make_unique<UserMetricsRecorder>(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 660 | |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 661 | PowerStatus::Initialize(); |
sky | 5ad143a | 2017-03-22 04:31:23 | [diff] [blame] | 662 | |
Xiyuan Xia | 22b1a6c | 2017-04-18 22:46:01 | [diff] [blame] | 663 | session_controller_->AddObserver(this); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | Shell::~Shell() { |
| 667 | TRACE_EVENT0("shutdown", "ash::Shell::Destructor"); |
| 668 | |
sky | 11cf8db9 | 2017-04-10 23:38:08 | [diff] [blame] | 669 | const Config config = shell_port_->GetAshConfig(); |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 670 | |
Scott Violet | 41562d1c | 2017-06-26 15:15:48 | [diff] [blame] | 671 | user_metrics_recorder_->OnShellShuttingDown(); |
bruthig | c24d11f | 2015-06-09 21:30:03 | [diff] [blame] | 672 | |
Steven Bennetts | 7614ab5 | 2018-01-12 20:48:17 | [diff] [blame] | 673 | shell_delegate_->PreShutdown(); |
[email protected] | 050e7718 | 2014-03-25 15:29:16 | [diff] [blame] | 674 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 675 | // Remove the focus from any window. This will prevent overhead and side |
| 676 | // effects (e.g. crashes) from changing focus during shutdown. |
| 677 | // See bug crbug.com/134502. |
achuith | 287b26e | 2015-09-03 17:49:18 | [diff] [blame] | 678 | aura::client::GetFocusClient(GetPrimaryRootWindow())->FocusWindow(nullptr); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 679 | |
xdai | d491376 | 2017-07-06 00:17:22 | [diff] [blame] | 680 | // Please keep in reverse order as in Init() because it's easy to miss one. |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 681 | if (window_modality_controller_) |
| 682 | window_modality_controller_.reset(); |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 683 | |
[email protected] | e4ea5236 | 2014-02-15 03:21:06 | [diff] [blame] | 684 | RemovePreTargetHandler(magnifier_key_scroll_handler_.get()); |
| 685 | magnifier_key_scroll_handler_.reset(); |
| 686 | |
| 687 | RemovePreTargetHandler(speech_feedback_handler_.get()); |
| 688 | speech_feedback_handler_.reset(); |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 689 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 690 | RemovePreTargetHandler(overlay_filter_.get()); |
Xiyuan Xia | 22b1a6c | 2017-04-18 22:46:01 | [diff] [blame] | 691 | overlay_filter_.reset(); |
| 692 | |
[email protected] | 3537d47 | 2014-01-15 05:45:31 | [diff] [blame] | 693 | RemovePreTargetHandler(accelerator_filter_.get()); |
| 694 | RemovePreTargetHandler(event_transformation_handler_.get()); |
| 695 | RemovePreTargetHandler(toplevel_window_event_handler_.get()); |
| 696 | RemovePostTargetHandler(toplevel_window_event_handler_.get()); |
Scott Violet | 596bb4634 | 2017-06-21 14:43:13 | [diff] [blame] | 697 | RemovePreTargetHandler(system_gesture_filter_.get()); |
| 698 | RemovePreTargetHandler(mouse_cursor_filter_.get()); |
hariank | 0dd03dd | 2016-07-14 23:47:33 | [diff] [blame] | 699 | RemovePreTargetHandler(modality_filter_.get()); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 700 | |
| 701 | // TooltipController is deleted with the Shell so removing its references. |
| 702 | RemovePreTargetHandler(tooltip_controller_.get()); |
| 703 | |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 704 | screen_orientation_controller_.reset(); |
yiyix | a68ade51 | 2016-09-01 17:38:13 | [diff] [blame] | 705 | screen_layout_observer_.reset(); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 706 | |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 707 | // Destroy the virtual keyboard controller before the tablet mode controller |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 708 | // since the latters destructor triggers events that the former is listening |
| 709 | // to but no longer cares about. |
rsadam | bbaf2c8 | 2015-01-07 17:54:13 | [diff] [blame] | 710 | virtual_keyboard_controller_.reset(); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 711 | |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 712 | // Destroy tablet mode controller early on since it has some observers which |
[email protected] | 5ed2b64 | 2014-03-04 00:06:57 | [diff] [blame] | 713 | // need to be removed. |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 714 | tablet_mode_controller_.reset(); |
[email protected] | 5ed2b64 | 2014-03-04 00:06:57 | [diff] [blame] | 715 | |
jdufault | 551152e | 2016-01-27 19:48:43 | [diff] [blame] | 716 | // Destroy the keyboard before closing the shelf, since it will invoke a shelf |
| 717 | // layout. |
Keigo Oka | c7617a4 | 2017-06-14 11:33:24 | [diff] [blame] | 718 | DestroyKeyboard(); |
jdufault | 551152e | 2016-01-27 19:48:43 | [diff] [blame] | 719 | |
sky | 07a24d4 | 2017-03-09 23:57:30 | [diff] [blame] | 720 | toast_manager_.reset(); |
yoshiki | 32f5163 | 2016-03-24 01:24:43 | [diff] [blame] | 721 | |
msw | 257a6a23 | 2017-06-01 01:46:30 | [diff] [blame] | 722 | for (aura::Window* root : GetAllRootWindows()) |
| 723 | Shelf::ForWindow(root)->ShutdownShelfWidget(); |
jamescook | ac672433 | 2017-03-21 02:54:43 | [diff] [blame] | 724 | tray_bluetooth_helper_.reset(); |
James Cook | b50959e2 | 2017-08-10 20:24:38 | [diff] [blame] | 725 | |
| 726 | // Accesses root window containers. |
| 727 | logout_confirmation_controller_.reset(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 728 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 729 | // Drag-and-drop must be canceled prior to close all windows. |
| 730 | drag_drop_controller_.reset(); |
| 731 | |
Xiyuan Xia | 22b1a6c | 2017-04-18 22:46:01 | [diff] [blame] | 732 | // Controllers who have WindowObserver added must be deleted |
| 733 | // before |window_tree_host_manager_| is deleted. |
[email protected] | 8c9d12a | 2013-12-06 18:39:03 | [diff] [blame] | 734 | |
Qiang Xu | d77a90c | 2018-02-20 19:43:29 | [diff] [blame] | 735 | persistent_window_controller_.reset(); |
| 736 | |
[email protected] | 8c9d12a | 2013-12-06 18:39:03 | [diff] [blame] | 737 | // VideoActivityNotifier must be deleted before |video_detector_| is |
| 738 | // deleted because it's observing video activity through |
derat | 83b76139 | 2016-07-11 16:44:44 | [diff] [blame] | 739 | // VideoDetector::Observer interface. |
[email protected] | 8c9d12a | 2013-12-06 18:39:03 | [diff] [blame] | 740 | video_activity_notifier_.reset(); |
[email protected] | 8c9d12a | 2013-12-06 18:39:03 | [diff] [blame] | 741 | video_detector_.reset(); |
[email protected] | 0e3e7cb | 2014-04-12 05:18:25 | [diff] [blame] | 742 | high_contrast_controller_.reset(); |
[email protected] | 8c9d12a | 2013-12-06 18:39:03 | [diff] [blame] | 743 | |
| 744 | shadow_controller_.reset(); |
| 745 | resize_shadow_controller_.reset(); |
| 746 | |
sky | 37f0dd1 | 2016-07-19 18:00:59 | [diff] [blame] | 747 | // Has to happen before ~MruWindowTracker. |
sky | 5b45ed8 | 2017-03-27 02:54:23 | [diff] [blame] | 748 | window_cycle_controller_.reset(); |
| 749 | window_selector_controller_.reset(); |
[email protected] | 8c9d12a | 2013-12-06 18:39:03 | [diff] [blame] | 750 | |
xdai | 7a8867cd | 2017-08-25 23:10:16 | [diff] [blame] | 751 | // |split_view_controller_| needs to be deleted after |
| 752 | // |window_selector_controller_|. |
| 753 | split_view_controller_.reset(); |
| 754 | |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 755 | CloseAllRootWindowChildWindows(); |
| 756 | |
afakhry | 5815939 | 2015-05-22 02:45:52 | [diff] [blame] | 757 | // MruWindowTracker must be destroyed after all windows have been deleted to |
| 758 | // avoid a possible crash when Shell is destroyed from a non-normal shutdown |
| 759 | // path. (crbug.com/485438). |
sky | 5ab1647 | 2017-03-21 19:35:08 | [diff] [blame] | 760 | mru_window_tracker_.reset(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 761 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 762 | // These need a valid Shell instance to clean up properly, so explicitly |
| 763 | // delete them before invalidating the instance. |
| 764 | // Alphabetical. TODO(oshima): sort. |
| 765 | magnification_controller_.reset(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 766 | tooltip_controller_.reset(); |
| 767 | event_client_.reset(); |
[email protected] | 3537d47 | 2014-01-15 05:45:31 | [diff] [blame] | 768 | toplevel_window_event_handler_.reset(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 769 | visibility_controller_.reset(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 770 | |
Toni Barzic | 85ae39e | 2017-12-07 05:50:18 | [diff] [blame] | 771 | tray_action_.reset(); |
| 772 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 773 | power_button_controller_.reset(); |
| 774 | lock_state_controller_.reset(); |
Toni Barzic | 9d0c82f4 | 2017-12-06 00:53:52 | [diff] [blame] | 775 | backlights_forced_off_setter_.reset(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 776 | |
hidehiko | 6821ca4 | 2016-06-18 11:12:23 | [diff] [blame] | 777 | screen_pinning_controller_.reset(); |
| 778 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 779 | resolution_notification_controller_.reset(); |
oshima | 5a296e8 | 2016-04-29 01:32:27 | [diff] [blame] | 780 | screenshot_controller_.reset(); |
[email protected] | 8ab613cf | 2014-05-12 09:39:49 | [diff] [blame] | 781 | mouse_cursor_filter_.reset(); |
hariank | 0dd03dd | 2016-07-14 23:47:33 | [diff] [blame] | 782 | modality_filter_.reset(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 783 | |
[email protected] | 03122891a | 2014-05-13 23:56:49 | [diff] [blame] | 784 | touch_transformer_controller_.reset(); |
sammiequon | 203ae02 | 2016-09-18 17:23:42 | [diff] [blame] | 785 | laser_pointer_controller_.reset(); |
| 786 | partial_magnification_controller_.reset(); |
Vladislav Kaznacheev | 6d6aaff | 2017-07-22 04:06:32 | [diff] [blame] | 787 | highlighter_controller_.reset(); |
Yue Li | a33960a | 2017-11-01 22:06:07 | [diff] [blame] | 788 | voice_interaction_controller_.reset(); |
warx | 533c8f6 | 2016-04-12 01:19:43 | [diff] [blame] | 789 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 790 | // This also deletes all RootWindows. Note that we invoke Shutdown() on |
oshima | e281892 | 2015-07-28 01:18:52 | [diff] [blame] | 791 | // WindowTreeHostManager before resetting |window_tree_host_manager_|, since |
msw | 257a6a23 | 2017-06-01 01:46:30 | [diff] [blame] | 792 | // destruction of its owned RootWindowControllers relies on the value. |
rjkroege | 2c930540 | 2016-09-07 00:21:45 | [diff] [blame] | 793 | ScreenAsh::CreateScreenForShutdown(); |
stevenjb | 537c5c3f | 2016-01-20 23:38:12 | [diff] [blame] | 794 | display_configuration_controller_.reset(); |
dtseng | 4ae0a88 | 2016-04-15 21:39:27 | [diff] [blame] | 795 | |
sky | 15ef0aa | 2017-01-20 18:55:59 | [diff] [blame] | 796 | // AppListDelegateImpl depends upon AppList. |
| 797 | app_list_delegate_impl_.reset(); |
| 798 | |
sky | 07a24d4 | 2017-03-09 23:57:30 | [diff] [blame] | 799 | // These members access Shell in their destructors. |
| 800 | wallpaper_controller_.reset(); |
James Cook | ec14495 | 2017-09-01 00:05:16 | [diff] [blame] | 801 | accessibility_controller_.reset(); |
sky | 07a24d4 | 2017-03-09 23:57:30 | [diff] [blame] | 802 | accessibility_delegate_.reset(); |
Evan Stade | 4d07c42 | 2017-09-01 21:51:51 | [diff] [blame] | 803 | message_center_controller_.reset(); |
sky | 07a24d4 | 2017-03-09 23:57:30 | [diff] [blame] | 804 | |
| 805 | // Balances the Install() in Initialize(). |
| 806 | views::FocusManagerFactory::Install(nullptr); |
| 807 | |
sky | 5ad143a | 2017-03-22 04:31:23 | [diff] [blame] | 808 | // ShelfWindowWatcher has window observers and a pointer to the shelf model. |
| 809 | shelf_window_watcher_.reset(); |
| 810 | |
tibell | b93c729b | 2017-03-30 00:45:09 | [diff] [blame] | 811 | // Removes itself as an observer of |pref_service_|. |
sky | 5ad143a | 2017-03-22 04:31:23 | [diff] [blame] | 812 | shelf_controller_.reset(); |
| 813 | |
Ahmed Fakhry | e96051f | 2017-12-12 17:42:17 | [diff] [blame] | 814 | // NightLightController depends on the PrefService as well as the window tree |
| 815 | // host manager, and must be destructed before them. crbug.com/724231. |
| 816 | night_light_controller_ = nullptr; |
Ahmed Fakhry | 4bf3f74 | 2018-02-06 17:33:36 | [diff] [blame] | 817 | // Similarly for DockedMagnifierController. |
| 818 | docked_magnifier_controller_ = nullptr; |
Ahmed Fakhry | e96051f | 2017-12-12 17:42:17 | [diff] [blame] | 819 | |
sky | 11cf8db9 | 2017-04-10 23:38:08 | [diff] [blame] | 820 | shell_port_->Shutdown(); |
Scott Violet | 596bb4634 | 2017-06-21 14:43:13 | [diff] [blame] | 821 | window_tree_host_manager_->Shutdown(); |
sky | 5ad143a | 2017-03-22 04:31:23 | [diff] [blame] | 822 | |
sky | 2734438 | 2017-03-08 21:30:32 | [diff] [blame] | 823 | // Depends on |focus_controller_|, so must be destroyed before. |
oshima | e281892 | 2015-07-28 01:18:52 | [diff] [blame] | 824 | window_tree_host_manager_.reset(); |
sky | 2734438 | 2017-03-08 21:30:32 | [diff] [blame] | 825 | focus_controller_->RemoveObserver(this); |
sky | 6861271 | 2017-04-27 04:45:04 | [diff] [blame] | 826 | if (config != Config::CLASSIC && |
| 827 | window_tree_client_->focus_synchronizer()->active_focus_client() == |
| 828 | focus_controller_.get()) { |
| 829 | window_tree_client_->focus_synchronizer()->SetSingletonFocusClient(nullptr); |
| 830 | } |
sky | 2734438 | 2017-03-08 21:30:32 | [diff] [blame] | 831 | focus_controller_.reset(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 832 | screen_position_controller_.reset(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 833 | |
robert.bradford | ab05249 | 2015-05-06 11:09:56 | [diff] [blame] | 834 | display_color_manager_.reset(); |
Steven Bennetts | 7683e34 | 2018-01-02 21:29:52 | [diff] [blame] | 835 | projecting_observer_.reset(); |
| 836 | |
[email protected] | 7bc49bd | 2014-01-22 09:30:34 | [diff] [blame] | 837 | if (display_change_observer_) |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 838 | display_configurator_->RemoveObserver(display_change_observer_.get()); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 839 | if (display_error_observer_) |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 840 | display_configurator_->RemoveObserver(display_error_observer_.get()); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 841 | display_change_observer_.reset(); |
Steven Bennetts | 7683e34 | 2018-01-02 21:29:52 | [diff] [blame] | 842 | display_shutdown_observer_.reset(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 843 | |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 844 | PowerStatus::Shutdown(); |
pneubeck | 8be1f542 | 2014-10-09 16:46:18 | [diff] [blame] | 845 | |
sky | 88bd4be6 | 2016-06-09 17:34:41 | [diff] [blame] | 846 | // Needs to happen right before |instance_| is reset. |
sky | 11cf8db9 | 2017-04-10 23:38:08 | [diff] [blame] | 847 | shell_port_.reset(); |
Xiyuan Xia | 22b1a6c | 2017-04-18 22:46:01 | [diff] [blame] | 848 | session_controller_->RemoveObserver(this); |
Sonny Sasaka | 55f69fc | 2017-08-28 21:29:37 | [diff] [blame] | 849 | // BluetoothPowerController depends on the PrefService and must be destructed |
| 850 | // before it. |
| 851 | bluetooth_power_controller_ = nullptr; |
Qiang Xu | f1400a36 | 2017-09-14 02:28:30 | [diff] [blame] | 852 | // TouchDevicesController depends on the PrefService and must be destructed |
| 853 | // before it. |
| 854 | touch_devices_controller_ = nullptr; |
Ahmed Fakhry | e96051f | 2017-12-12 17:42:17 | [diff] [blame] | 855 | |
Sam McNally | a853cd8 | 2017-08-30 01:55:10 | [diff] [blame] | 856 | local_state_.reset(); |
sky | b073203a | 2017-03-13 16:59:16 | [diff] [blame] | 857 | shell_delegate_.reset(); |
sky | 88bd4be6 | 2016-06-09 17:34:41 | [diff] [blame] | 858 | |
Scott Violet | 17a6172 | 2017-06-19 17:54:31 | [diff] [blame] | 859 | for (auto& observer : shell_observers_) |
| 860 | observer.OnShellDestroyed(); |
| 861 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 862 | DCHECK(instance_ == this); |
achuith | 287b26e | 2015-09-03 17:49:18 | [diff] [blame] | 863 | instance_ = nullptr; |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 864 | } |
| 865 | |
Scott Violet | c8a1c6c | 2017-11-29 23:17:36 | [diff] [blame] | 866 | void Shell::Init(ui::ContextFactory* context_factory, |
| 867 | ui::ContextFactoryPrivate* context_factory_private) { |
sky | 11cf8db9 | 2017-04-10 23:38:08 | [diff] [blame] | 868 | const Config config = shell_port_->GetAshConfig(); |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 869 | |
James Cook | bd0b779 | 2017-11-17 03:24:26 | [diff] [blame] | 870 | // These controllers call Shell::Get() in their constructors, so they cannot |
| 871 | // be in the member initialization list. |
Evan Stade | 48768f4 | 2017-10-10 05:23:30 | [diff] [blame] | 872 | if (switches::IsNightLightEnabled()) |
Mitsuru Oshima | 04b54d0 | 2017-10-09 14:22:45 | [diff] [blame] | 873 | night_light_controller_ = std::make_unique<NightLightController>(); |
Qiang Xu | f1400a36 | 2017-09-14 02:28:30 | [diff] [blame] | 874 | touch_devices_controller_ = std::make_unique<TouchDevicesController>(); |
Mitsuru Oshima | 04b54d0 | 2017-10-09 14:22:45 | [diff] [blame] | 875 | bluetooth_power_controller_ = std::make_unique<BluetoothPowerController>(); |
Sonny Sasaka | 55f69fc | 2017-08-28 21:29:37 | [diff] [blame] | 876 | |
James Cook | 8532dbc | 2017-07-31 21:54:51 | [diff] [blame] | 877 | // Connector can be null in tests. |
Sam McNally | a853cd8 | 2017-08-30 01:55:10 | [diff] [blame] | 878 | if (shell_delegate_->GetShellConnector()) { |
James Cook | 8532dbc | 2017-07-31 21:54:51 | [diff] [blame] | 879 | // Connect to local state prefs now, but wait for an active user before |
| 880 | // connecting to the profile pref service. The login screen has a temporary |
| 881 | // user profile that is not associated with a real user. |
Taiju Tsuiki | 36c517d | 2017-05-18 06:45:43 | [diff] [blame] | 882 | auto pref_registry = base::MakeRefCounted<PrefRegistrySimple>(); |
Wenzhao Zang | 56c29293 | 2017-08-02 04:58:34 | [diff] [blame] | 883 | RegisterLocalStatePrefs(pref_registry.get()); |
tibell | b93c729b | 2017-03-30 00:45:09 | [diff] [blame] | 884 | prefs::ConnectToPrefService( |
Sam McNally | 538fca1e | 2017-07-14 03:10:43 | [diff] [blame] | 885 | shell_delegate_->GetShellConnector(), std::move(pref_registry), |
Sam McNally | e36abbc | 2017-07-20 01:04:28 | [diff] [blame] | 886 | base::Bind(&Shell::OnLocalStatePrefServiceInitialized, |
| 887 | weak_factory_.GetWeakPtr()), |
| 888 | prefs::mojom::kLocalStateServiceName); |
jonross | c4ba1060 | 2017-04-07 20:51:05 | [diff] [blame] | 889 | } |
sky | b073203a | 2017-03-13 16:59:16 | [diff] [blame] | 890 | |
sky | 11cf8db9 | 2017-04-10 23:38:08 | [diff] [blame] | 891 | // Some delegates access ShellPort during their construction. Create them here |
| 892 | // instead of the ShellPort constructor. |
sky | b073203a | 2017-03-13 16:59:16 | [diff] [blame] | 893 | accessibility_delegate_.reset(shell_delegate_->CreateAccessibilityDelegate()); |
Mitsuru Oshima | 04b54d0 | 2017-10-09 14:22:45 | [diff] [blame] | 894 | accessibility_controller_ = std::make_unique<AccessibilityController>( |
James Cook | 5fbdccb | 2017-09-01 21:17:55 | [diff] [blame] | 895 | shell_delegate_->GetShellConnector()); |
Mitsuru Oshima | 04b54d0 | 2017-10-09 14:22:45 | [diff] [blame] | 896 | toast_manager_ = std::make_unique<ToastManager>(); |
sky | 07a24d4 | 2017-03-09 23:57:30 | [diff] [blame] | 897 | |
sky | 07a24d4 | 2017-03-09 23:57:30 | [diff] [blame] | 898 | // Install the custom factory early on so that views::FocusManagers for Tray, |
| 899 | // Shelf, and WallPaper could be created by the factory. |
| 900 | views::FocusManagerFactory::Install(new AshFocusManagerFactory); |
| 901 | |
Mitsuru Oshima | 04b54d0 | 2017-10-09 14:22:45 | [diff] [blame] | 902 | wallpaper_controller_ = std::make_unique<WallpaperController>(); |
sky | 07a24d4 | 2017-03-09 23:57:30 | [diff] [blame] | 903 | |
Mitsuru Oshima | 04b54d0 | 2017-10-09 14:22:45 | [diff] [blame] | 904 | app_list_delegate_impl_ = std::make_unique<AppListDelegateImpl>(); |
sky | 15ef0aa | 2017-01-20 18:55:59 | [diff] [blame] | 905 | |
sky | 11cf8db9 | 2017-04-10 23:38:08 | [diff] [blame] | 906 | // TODO(sky): move creation to ShellPort. |
sky | e5fd122 | 2017-04-12 18:43:23 | [diff] [blame] | 907 | if (config != Config::MASH) |
Mitsuru Oshima | 04b54d0 | 2017-10-09 14:22:45 | [diff] [blame] | 908 | immersive_handler_factory_ = std::make_unique<ImmersiveHandlerFactoryAsh>(); |
sky | b7b5409 | 2016-08-19 16:00:09 | [diff] [blame] | 909 | |
Mitsuru Oshima | 04b54d0 | 2017-10-09 14:22:45 | [diff] [blame] | 910 | window_positioner_ = std::make_unique<WindowPositioner>(); |
sky | 984c189 | 2016-04-20 00:00:34 | [diff] [blame] | 911 | |
sky | 494c6cbd | 2017-03-27 20:57:48 | [diff] [blame] | 912 | if (config == Config::CLASSIC) { |
erg | 36cfb95 | 2017-06-21 19:41:45 | [diff] [blame] | 913 | native_cursor_manager_ = new NativeCursorManagerAshClassic; |
Mitsuru Oshima | 04b54d0 | 2017-10-09 14:22:45 | [diff] [blame] | 914 | cursor_manager_ = std::make_unique<CursorManager>( |
erg | 36cfb95 | 2017-06-21 19:41:45 | [diff] [blame] | 915 | base::WrapUnique(native_cursor_manager_)); |
| 916 | } else if (config == Config::MUS) { |
| 917 | native_cursor_manager_ = new NativeCursorManagerAshMus; |
Mitsuru Oshima | 04b54d0 | 2017-10-09 14:22:45 | [diff] [blame] | 918 | cursor_manager_ = std::make_unique<CursorManager>( |
erg | 36cfb95 | 2017-06-21 19:41:45 | [diff] [blame] | 919 | base::WrapUnique(native_cursor_manager_)); |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 920 | } |
sky | fee520c | 2016-02-11 19:57:46 | [diff] [blame] | 921 | |
Steven Bennetts | cce93919 | 2018-01-12 22:57:12 | [diff] [blame] | 922 | // TODO(stevenjb): ChromeShellDelegate::PreInit currently handles |
| 923 | // DisplayPreference initialization, required for InitializeDisplayManager. |
| 924 | // Before we can move that code into ash/display where it belongs, we need to |
| 925 | // wait for |lcoal_state_| to be set in OnLocalStatePrefServiceInitialized |
| 926 | // before initializing DisplayPreferences (and therefore DisplayManager). |
| 927 | // http://crbug.com/678949. |
sky | b073203a | 2017-03-13 16:59:16 | [diff] [blame] | 928 | shell_delegate_->PreInit(); |
[email protected] | 0249a653 | 2013-10-31 06:53:34 | [diff] [blame] | 929 | |
Steven Bennetts | 7683e34 | 2018-01-02 21:29:52 | [diff] [blame] | 930 | InitializeDisplayManager(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 931 | |
newcomer | 2febb983 | 2017-06-12 17:00:23 | [diff] [blame] | 932 | if (config == Config::CLASSIC) { |
Steven Bennetts | 7683e34 | 2018-01-02 21:29:52 | [diff] [blame] | 933 | // This will initialize aura::Env which requires |display_manager_| to |
| 934 | // be initialized first. |
Scott Violet | c8a1c6c | 2017-11-29 23:17:36 | [diff] [blame] | 935 | aura::Env::GetInstance()->set_context_factory(context_factory); |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 936 | aura::Env::GetInstance()->set_context_factory_private( |
Scott Violet | c8a1c6c | 2017-11-29 23:17:36 | [diff] [blame] | 937 | context_factory_private); |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 938 | } |
[email protected] | ecca62b | 2013-10-09 16:18:53 | [diff] [blame] | 939 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 940 | // The WindowModalityController needs to be at the front of the input event |
| 941 | // pretarget handler list to ensure that it processes input events when modal |
| 942 | // windows are active. |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 943 | window_modality_controller_.reset(new ::wm::WindowModalityController(this)); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 944 | |
[email protected] | e319c7e | 2014-03-14 19:56:14 | [diff] [blame] | 945 | env_filter_.reset(new ::wm::CompoundEventFilter); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 946 | AddPreTargetHandler(env_filter_.get()); |
| 947 | |
sky | 2734438 | 2017-03-08 21:30:32 | [diff] [blame] | 948 | // FocusController takes ownership of AshFocusRules. |
| 949 | focus_controller_ = |
Mitsuru Oshima | 04b54d0 | 2017-10-09 14:22:45 | [diff] [blame] | 950 | std::make_unique<::wm::FocusController>(new wm::AshFocusRules()); |
sky | 2734438 | 2017-03-08 21:30:32 | [diff] [blame] | 951 | focus_controller_->AddObserver(this); |
sky | 6861271 | 2017-04-27 04:45:04 | [diff] [blame] | 952 | if (config != Config::CLASSIC) { |
| 953 | window_tree_client_->focus_synchronizer()->SetSingletonFocusClient( |
| 954 | focus_controller_.get()); |
| 955 | } |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 956 | |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 957 | screen_position_controller_.reset(new ScreenPositionController); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 958 | |
Scott Violet | 596bb4634 | 2017-06-21 14:43:13 | [diff] [blame] | 959 | window_tree_host_manager_->Start(); |
| 960 | AshWindowTreeHostInitParams ash_init_params; |
| 961 | window_tree_host_manager_->CreatePrimaryHost(ash_init_params); |
| 962 | |
Scott Violet | 3c554ae | 2017-12-13 02:25:41 | [diff] [blame] | 963 | time_to_first_present_recorder_ = |
| 964 | std::make_unique<TimeToFirstPresentRecorder>(GetPrimaryRootWindow()); |
| 965 | |
msw | ad3d955 | 2017-05-18 21:23:36 | [diff] [blame] | 966 | root_window_for_new_windows_ = GetPrimaryRootWindow(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 967 | |
Scott Violet | 596bb4634 | 2017-06-21 14:43:13 | [diff] [blame] | 968 | resolution_notification_controller_ = |
Mitsuru Oshima | 04b54d0 | 2017-10-09 14:22:45 | [diff] [blame] | 969 | std::make_unique<ResolutionNotificationController>(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 970 | |
derat | c6250a0 | 2017-01-25 05:51:53 | [diff] [blame] | 971 | if (cursor_manager_) { |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 972 | cursor_manager_->SetDisplay( |
| 973 | display::Screen::GetScreen()->GetPrimaryDisplay()); |
derat | c6250a0 | 2017-01-25 05:51:53 | [diff] [blame] | 974 | } |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 975 | |
sky | 11cf8db9 | 2017-04-10 23:38:08 | [diff] [blame] | 976 | accelerator_controller_ = shell_port_->CreateAcceleratorController(); |
Mitsuru Oshima | 04b54d0 | 2017-10-09 14:22:45 | [diff] [blame] | 977 | tablet_mode_controller_ = std::make_unique<TabletModeController>(); |
| 978 | shelf_controller_ = std::make_unique<ShelfController>(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 979 | |
spang | e9b5127 | 2014-12-11 01:20:10 | [diff] [blame] | 980 | magnifier_key_scroll_handler_ = MagnifierKeyScroller::CreateHandler(); |
[email protected] | e4ea5236 | 2014-02-15 03:21:06 | [diff] [blame] | 981 | AddPreTargetHandler(magnifier_key_scroll_handler_.get()); |
spang | e9b5127 | 2014-12-11 01:20:10 | [diff] [blame] | 982 | speech_feedback_handler_ = SpokenFeedbackToggler::CreateHandler(); |
[email protected] | e4ea5236 | 2014-02-15 03:21:06 | [diff] [blame] | 983 | AddPreTargetHandler(speech_feedback_handler_.get()); |
[email protected] | 3dff2ef | 2014-02-09 22:50:39 | [diff] [blame] | 984 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 985 | // The order in which event filters are added is significant. |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 986 | |
derat | 2d4e62d | 2015-01-09 16:09:17 | [diff] [blame] | 987 | // ui::UserActivityDetector passes events to observers, so let them get |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 988 | // rewritten first. |
derat | 2d4e62d | 2015-01-09 16:09:17 | [diff] [blame] | 989 | user_activity_detector_.reset(new ui::UserActivityDetector); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 990 | |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 991 | overlay_filter_.reset(new OverlayEventFilter); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 992 | AddPreTargetHandler(overlay_filter_.get()); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 993 | |
[email protected] | 60d677d | 2014-05-30 13:07:02 | [diff] [blame] | 994 | accelerator_filter_.reset(new ::wm::AcceleratorFilter( |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 995 | std::unique_ptr<::wm::AcceleratorDelegate>(new AcceleratorDelegate), |
sky | 81a2d79 | 2017-03-17 19:14:39 | [diff] [blame] | 996 | accelerator_controller_->accelerator_history())); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 997 | AddPreTargetHandler(accelerator_filter_.get()); |
| 998 | |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 999 | event_transformation_handler_.reset(new EventTransformationHandler); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 1000 | AddPreTargetHandler(event_transformation_handler_.get()); |
| 1001 | |
sky | 11cf8db9 | 2017-04-10 23:38:08 | [diff] [blame] | 1002 | toplevel_window_event_handler_ = |
Mitsuru Oshima | 04b54d0 | 2017-10-09 14:22:45 | [diff] [blame] | 1003 | std::make_unique<ToplevelWindowEventHandler>(); |
[email protected] | 3537d47 | 2014-01-15 05:45:31 | [diff] [blame] | 1004 | |
sky | 83b1bb1 | 2017-04-24 20:29:28 | [diff] [blame] | 1005 | if (config != Config::MASH) { |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 1006 | system_gesture_filter_.reset(new SystemGestureEventFilter); |
| 1007 | AddPreTargetHandler(system_gesture_filter_.get()); |
| 1008 | } |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 1009 | |
[email protected] | 354520b | 2014-06-21 04:31:01 | [diff] [blame] | 1010 | sticky_keys_controller_.reset(new StickyKeysController); |
Mitsuru Oshima | 04b54d0 | 2017-10-09 14:22:45 | [diff] [blame] | 1011 | screen_pinning_controller_ = std::make_unique<ScreenPinningController>(); |
[email protected] | 354520b | 2014-06-21 04:31:01 | [diff] [blame] | 1012 | |
Toni Barzic | 9d0c82f4 | 2017-12-06 00:53:52 | [diff] [blame] | 1013 | backlights_forced_off_setter_ = std::make_unique<BacklightsForcedOffSetter>(); |
| 1014 | |
Toni Barzic | 85ae39e | 2017-12-07 05:50:18 | [diff] [blame] | 1015 | tray_action_ = |
| 1016 | std::make_unique<TrayAction>(backlights_forced_off_setter_.get()); |
| 1017 | |
jamescook | d9f152f | 2016-11-15 00:53:08 | [diff] [blame] | 1018 | lock_state_controller_ = |
Mitsuru Oshima | 04b54d0 | 2017-10-09 14:22:45 | [diff] [blame] | 1019 | std::make_unique<LockStateController>(shutdown_controller_.get()); |
Toni Barzic | 9d0c82f4 | 2017-12-06 00:53:52 | [diff] [blame] | 1020 | power_button_controller_ = std::make_unique<PowerButtonController>( |
| 1021 | backlights_forced_off_setter_.get()); |
[email protected] | 685442f3 | 2014-02-28 10:40:06 | [diff] [blame] | 1022 | // Pass the initial display state to PowerButtonController. |
| 1023 | power_button_controller_->OnDisplayModeChanged( |
[email protected] | bcec7fb6 | 2014-04-08 20:59:09 | [diff] [blame] | 1024 | display_configurator_->cached_displays()); |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 1025 | |
derat | 036f91b9 | 2017-05-05 00:33:18 | [diff] [blame] | 1026 | // Forward user activity from the window server to |user_activity_detector_|. |
derat | 94887a2 | 2017-01-20 18:17:25 | [diff] [blame] | 1027 | // The connector is unavailable in some tests. |
derat | 036f91b9 | 2017-05-05 00:33:18 | [diff] [blame] | 1028 | if (aura::Env::GetInstance()->mode() == aura::Env::Mode::MUS && |
| 1029 | shell_delegate_->GetShellConnector()) { |
derat | 94887a2 | 2017-01-20 18:17:25 | [diff] [blame] | 1030 | ui::mojom::UserActivityMonitorPtr user_activity_monitor; |
sky | b073203a | 2017-03-13 16:59:16 | [diff] [blame] | 1031 | shell_delegate_->GetShellConnector()->BindInterface(ui::mojom::kServiceName, |
| 1032 | &user_activity_monitor); |
Mitsuru Oshima | 04b54d0 | 2017-10-09 14:22:45 | [diff] [blame] | 1033 | user_activity_forwarder_ = std::make_unique<aura::UserActivityForwarder>( |
derat | 94887a2 | 2017-01-20 18:17:25 | [diff] [blame] | 1034 | std::move(user_activity_monitor), user_activity_detector_.get()); |
| 1035 | } |
| 1036 | |
Scott Violet | 361833fb | 2017-06-21 22:25:20 | [diff] [blame] | 1037 | // In mash drag and drop is handled by mus. |
| 1038 | if (config != Config::MASH) |
Mitsuru Oshima | 04b54d0 | 2017-10-09 14:22:45 | [diff] [blame] | 1039 | drag_drop_controller_ = std::make_unique<DragDropController>(); |
Scott Violet | 361833fb | 2017-06-21 22:25:20 | [diff] [blame] | 1040 | |
oshima | 5a296e8 | 2016-04-29 01:32:27 | [diff] [blame] | 1041 | // |screenshot_controller_| needs to be created (and prepended as a |
mukai | 19274bdd | 2015-02-24 22:37:48 | [diff] [blame] | 1042 | // pre-target handler) at this point, because |mouse_cursor_filter_| needs to |
oshima | 5a296e8 | 2016-04-29 01:32:27 | [diff] [blame] | 1043 | // process mouse events prior to screenshot session. |
mukai | 19274bdd | 2015-02-24 22:37:48 | [diff] [blame] | 1044 | // See http://crbug.com/459214 |
James Cook | 5e9d340 | 2017-11-01 00:20:12 | [diff] [blame] | 1045 | screenshot_controller_ = std::make_unique<ScreenshotController>( |
| 1046 | shell_delegate_->CreateScreenshotDelegate()); |
Mitsuru Oshima | 04b54d0 | 2017-10-09 14:22:45 | [diff] [blame] | 1047 | mouse_cursor_filter_ = std::make_unique<MouseCursorEventFilter>(); |
Scott Violet | 596bb4634 | 2017-06-21 14:43:13 | [diff] [blame] | 1048 | PrependPreTargetHandler(mouse_cursor_filter_.get()); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 1049 | |
| 1050 | // Create Controllers that may need root window. |
| 1051 | // TODO(oshima): Move as many controllers before creating |
| 1052 | // RootWindowController as possible. |
| 1053 | visibility_controller_.reset(new AshVisibilityController); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 1054 | |
sammiequon | 203ae02 | 2016-09-18 17:23:42 | [diff] [blame] | 1055 | laser_pointer_controller_.reset(new LaserPointerController()); |
| 1056 | partial_magnification_controller_.reset(new PartialMagnificationController()); |
Vladislav Kaznacheev | 6d6aaff | 2017-07-22 04:06:32 | [diff] [blame] | 1057 | highlighter_controller_.reset(new HighlighterController()); |
Yue Li | a33960a | 2017-11-01 22:06:07 | [diff] [blame] | 1058 | voice_interaction_controller_ = |
| 1059 | std::make_unique<VoiceInteractionController>(); |
sammiequon | 203ae02 | 2016-09-18 17:23:42 | [diff] [blame] | 1060 | |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 1061 | magnification_controller_.reset(MagnificationController::CreateInstance()); |
Mitsuru Oshima | 04b54d0 | 2017-10-09 14:22:45 | [diff] [blame] | 1062 | mru_window_tracker_ = std::make_unique<MruWindowTracker>(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 1063 | |
[email protected] | 55398d2 | 2013-10-10 19:49:20 | [diff] [blame] | 1064 | autoclick_controller_.reset(AutoclickController::CreateInstance()); |
| 1065 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 1066 | high_contrast_controller_.reset(new HighContrastController); |
Saman Sami | 3fb310d | 2017-11-09 16:51:54 | [diff] [blame] | 1067 | |
Ahmed Fakhry | 4af48e4 | 2018-02-28 17:45:38 | [diff] [blame^] | 1068 | if (features::IsDockedMagnifierEnabled()) { |
Ahmed Fakhry | 4bf3f74 | 2018-02-06 17:33:36 | [diff] [blame] | 1069 | docked_magnifier_controller_ = |
| 1070 | std::make_unique<DockedMagnifierController>(); |
| 1071 | } |
| 1072 | |
Saman Sami | 3fb310d | 2017-11-09 16:51:54 | [diff] [blame] | 1073 | viz::mojom::VideoDetectorObserverPtr observer; |
| 1074 | video_detector_ = |
| 1075 | std::make_unique<VideoDetector>(mojo::MakeRequest(&observer)); |
| 1076 | shell_port_->AddVideoDetectorObserver(std::move(observer)); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 1077 | |
oshima | ebbe6377 | 2015-02-19 18:41:32 | [diff] [blame] | 1078 | tooltip_controller_.reset(new views::corewm::TooltipController( |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 1079 | std::unique_ptr<views::corewm::Tooltip>(new views::corewm::TooltipAura))); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 1080 | AddPreTargetHandler(tooltip_controller_.get()); |
| 1081 | |
hariank | 0dd03dd | 2016-07-14 23:47:33 | [diff] [blame] | 1082 | modality_filter_.reset(new SystemModalContainerEventFilter(this)); |
| 1083 | AddPreTargetHandler(modality_filter_.get()); |
| 1084 | |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 1085 | event_client_.reset(new EventClientImpl); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 1086 | |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 1087 | // Must occur after Shell has installed its early pre-target handlers (for |
| 1088 | // example, WindowModalityController). |
sky | 11cf8db9 | 2017-04-10 23:38:08 | [diff] [blame] | 1089 | shell_port_->CreatePointerWatcherAdapter(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 1090 | |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 1091 | resize_shadow_controller_.reset(new ResizeShadowController()); |
sky | 2734438 | 2017-03-08 21:30:32 | [diff] [blame] | 1092 | shadow_controller_.reset(new ::wm::ShadowController(focus_controller_.get())); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 1093 | |
James Cook | b50959e2 | 2017-08-10 20:24:38 | [diff] [blame] | 1094 | logout_confirmation_controller_ = |
Mitsuru Oshima | 04b54d0 | 2017-10-09 14:22:45 | [diff] [blame] | 1095 | std::make_unique<LogoutConfirmationController>(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 1096 | |
jamescook | ac672433 | 2017-03-21 02:54:43 | [diff] [blame] | 1097 | // May trigger initialization of the Bluetooth adapter. |
| 1098 | tray_bluetooth_helper_->Initialize(); |
| 1099 | |
kylechar | 55f0eaf2 | 2017-01-11 22:57:37 | [diff] [blame] | 1100 | // Create AshTouchTransformController before |
oshima | e281892 | 2015-07-28 01:18:52 | [diff] [blame] | 1101 | // WindowTreeHostManager::InitDisplays() |
kylechar | 55f0eaf2 | 2017-01-11 22:57:37 | [diff] [blame] | 1102 | // since AshTouchTransformController listens on |
oshima | e281892 | 2015-07-28 01:18:52 | [diff] [blame] | 1103 | // WindowTreeHostManager::Observer::OnDisplaysInitialized(). |
Mitsuru Oshima | 04b54d0 | 2017-10-09 14:22:45 | [diff] [blame] | 1104 | touch_transformer_controller_ = std::make_unique<AshTouchTransformController>( |
Scott Violet | 596bb4634 | 2017-06-21 14:43:13 | [diff] [blame] | 1105 | display_configurator_.get(), display_manager_.get(), |
| 1106 | shell_port_->CreateTouchTransformDelegate()); |
[email protected] | 03122891a | 2014-05-13 23:56:49 | [diff] [blame] | 1107 | |
sky | 11cf8db9 | 2017-04-10 23:38:08 | [diff] [blame] | 1108 | keyboard_ui_ = shell_port_->CreateKeyboardUI(); |
sky | fee520c | 2016-02-11 19:57:46 | [diff] [blame] | 1109 | |
Scott Violet | 596bb4634 | 2017-06-21 14:43:13 | [diff] [blame] | 1110 | window_tree_host_manager_->InitHosts(); |
| 1111 | shell_port_->OnHostsInitialized(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 1112 | |
rsadam | 9172bc8a | 2014-10-29 23:37:38 | [diff] [blame] | 1113 | // Needs to be created after InitDisplays() since it may cause the virtual |
| 1114 | // keyboard to be deployed. |
sky | 83b1bb1 | 2017-04-24 20:29:28 | [diff] [blame] | 1115 | if (config != Config::MASH) |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 1116 | virtual_keyboard_controller_.reset(new VirtualKeyboardController); |
rsadam | 9172bc8a | 2014-10-29 23:37:38 | [diff] [blame] | 1117 | |
sadrul | 7a8785e | 2016-02-12 21:54:35 | [diff] [blame] | 1118 | if (cursor_manager_) { |
Steven Bennetts | 6d12eb4 | 2018-01-09 16:49:08 | [diff] [blame] | 1119 | cursor_manager_->HideCursor(); // Hide the mouse cursor on startup. |
erg | eeba7c62 | 2017-04-25 18:06:16 | [diff] [blame] | 1120 | cursor_manager_->SetCursor(ui::CursorType::kPointer); |
sadrul | 7a8785e | 2016-02-12 21:54:35 | [diff] [blame] | 1121 | } |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 1122 | |
Mitsuru Oshima | 04b54d0 | 2017-10-09 14:22:45 | [diff] [blame] | 1123 | peripheral_battery_notifier_ = std::make_unique<PeripheralBatteryNotifier>(); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 1124 | power_event_observer_.reset(new PowerEventObserver()); |
[email protected] | ded58fd | 2013-10-09 07:56:55 | [diff] [blame] | 1125 | user_activity_notifier_.reset( |
[email protected] | b0fa701 | 2014-04-16 12:50:57 | [diff] [blame] | 1126 | new ui::UserActivityPowerManagerNotifier(user_activity_detector_.get())); |
[email protected] | ded58fd | 2013-10-09 07:56:55 | [diff] [blame] | 1127 | video_activity_notifier_.reset( |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 1128 | new VideoActivityNotifier(video_detector_.get())); |
| 1129 | bluetooth_notification_controller_.reset(new BluetoothNotificationController); |
Scott Violet | 596bb4634 | 2017-06-21 14:43:13 | [diff] [blame] | 1130 | screen_orientation_controller_ = |
Mitsuru Oshima | 04b54d0 | 2017-10-09 14:22:45 | [diff] [blame] | 1131 | std::make_unique<ScreenOrientationController>(); |
Scott Violet | 596bb4634 | 2017-06-21 14:43:13 | [diff] [blame] | 1132 | screen_layout_observer_.reset(new ScreenLayoutObserver()); |
yiyix | 90cfee2 | 2017-02-16 05:38:18 | [diff] [blame] | 1133 | sms_observer_.reset(new SmsObserver()); |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 1134 | |
xdai | d491376 | 2017-07-06 00:17:22 | [diff] [blame] | 1135 | split_view_controller_.reset(new SplitViewController()); |
| 1136 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 1137 | // The compositor thread and main message loop have to be running in |
| 1138 | // order to create mirror window. Run it after the main message loop |
| 1139 | // is started. |
Scott Violet | 596bb4634 | 2017-06-21 14:43:13 | [diff] [blame] | 1140 | display_manager_->CreateMirrorWindowAsyncIfAny(); |
bruthig | c24d11f | 2015-06-09 21:30:03 | [diff] [blame] | 1141 | |
Mitsuru Oshima | 04b54d0 | 2017-10-09 14:22:45 | [diff] [blame] | 1142 | message_center_controller_ = std::make_unique<MessageCenterController>(); |
Evan Stade | 2c43a87b3 | 2017-08-31 17:53:10 | [diff] [blame] | 1143 | |
James Cook | 0ba192bf | 2017-12-01 20:53:11 | [diff] [blame] | 1144 | // Mash implements the show taps feature with a separate mojo app. |
| 1145 | // GetShellConnector() is null in unit tests. |
| 1146 | if (config == Config::MASH && shell_delegate_->GetShellConnector() && |
| 1147 | base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowTaps)) { |
| 1148 | mash::mojom::LaunchablePtr launchable; |
James Cook | 2268bef | 2018-02-27 01:12:16 | [diff] [blame] | 1149 | shell_delegate_->GetShellConnector()->BindInterface("touch_hud_app", |
James Cook | 0ba192bf | 2017-12-01 20:53:11 | [diff] [blame] | 1150 | &launchable); |
| 1151 | launchable->Launch(mash::mojom::kWindow, mash::mojom::LaunchMode::DEFAULT); |
| 1152 | } |
| 1153 | |
sky | 00c813f | 2017-03-08 22:48:55 | [diff] [blame] | 1154 | for (auto& observer : shell_observers_) |
ericwilligers | 5eff47d | 2016-10-17 19:19:18 | [diff] [blame] | 1155 | observer.OnShellInitialized(); |
phweiss | 0bf64c5 | 2015-11-17 12:56:18 | [diff] [blame] | 1156 | |
Scott Violet | 41562d1c | 2017-06-26 15:15:48 | [diff] [blame] | 1157 | user_metrics_recorder_->OnShellInitialized(); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 1158 | } |
| 1159 | |
Steven Bennetts | 7683e34 | 2018-01-02 21:29:52 | [diff] [blame] | 1160 | void Shell::InitializeDisplayManager() { |
| 1161 | const Config config = shell_port_->GetAshConfig(); |
| 1162 | bool display_initialized = display_manager_->InitFromCommandLine(); |
| 1163 | |
| 1164 | if (!display_initialized && config != Config::CLASSIC) { |
| 1165 | // Run display configuration off device in mus mode. |
| 1166 | display_manager_->set_configure_displays(true); |
| 1167 | display_configurator_->set_configure_display(true); |
| 1168 | } |
| 1169 | display_configuration_controller_ = |
| 1170 | std::make_unique<DisplayConfigurationController>( |
| 1171 | display_manager_.get(), window_tree_host_manager_.get()); |
| 1172 | display_configurator_->Init(shell_port_->CreateNativeDisplayDelegate(), |
| 1173 | false); |
Qiang Xu | d77a90c | 2018-02-20 19:43:29 | [diff] [blame] | 1174 | persistent_window_controller_ = |
| 1175 | std::make_unique<PersistentWindowController>(); |
Steven Bennetts | 7683e34 | 2018-01-02 21:29:52 | [diff] [blame] | 1176 | |
| 1177 | projecting_observer_ = |
| 1178 | std::make_unique<ProjectingObserver>(display_configurator_.get()); |
| 1179 | |
| 1180 | if (!display_initialized) { |
| 1181 | if (config != Config::CLASSIC && !chromeos::IsRunningAsSystemCompositor()) { |
| 1182 | display::mojom::DevDisplayControllerPtr controller; |
| 1183 | shell_delegate_->GetShellConnector()->BindInterface( |
| 1184 | ui::mojom::kServiceName, &controller); |
| 1185 | display_manager_->SetDevDisplayController(std::move(controller)); |
| 1186 | } |
| 1187 | |
| 1188 | if (config != Config::CLASSIC || chromeos::IsRunningAsSystemCompositor()) { |
| 1189 | display_change_observer_ = |
| 1190 | std::make_unique<display::DisplayChangeObserver>( |
| 1191 | display_configurator_.get(), display_manager_.get()); |
| 1192 | |
| 1193 | display_shutdown_observer_ = std::make_unique<DisplayShutdownObserver>( |
| 1194 | display_configurator_.get()); |
| 1195 | |
| 1196 | // Register |display_change_observer_| first so that the rest of |
| 1197 | // observer gets invoked after the root windows are configured. |
| 1198 | display_configurator_->AddObserver(display_change_observer_.get()); |
| 1199 | display_error_observer_.reset(new DisplayErrorObserver()); |
| 1200 | display_configurator_->AddObserver(display_error_observer_.get()); |
| 1201 | display_configurator_->set_state_controller( |
| 1202 | display_change_observer_.get()); |
| 1203 | display_configurator_->set_mirroring_controller(display_manager_.get()); |
| 1204 | display_configurator_->ForceInitialConfigure(); |
| 1205 | display_initialized = true; |
| 1206 | } |
| 1207 | } |
| 1208 | |
| 1209 | display_color_manager_ = |
| 1210 | std::make_unique<DisplayColorManager>(display_configurator_.get()); |
| 1211 | |
| 1212 | if (!display_initialized) |
| 1213 | display_manager_->InitDefaultDisplay(); |
| 1214 | |
| 1215 | if (config == Config::CLASSIC) |
| 1216 | display_manager_->RefreshFontParams(); |
| 1217 | } |
| 1218 | |
[email protected] | 41baaed | 2013-11-09 04:18:26 | [diff] [blame] | 1219 | void Shell::InitRootWindow(aura::Window* root_window) { |
sky | 2734438 | 2017-03-08 21:30:32 | [diff] [blame] | 1220 | DCHECK(focus_controller_); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 1221 | DCHECK(visibility_controller_.get()); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 1222 | |
sky | 2734438 | 2017-03-08 21:30:32 | [diff] [blame] | 1223 | aura::client::SetFocusClient(root_window, focus_controller_.get()); |
Thiago Farina | 3b086a0 | 2017-05-30 22:32:50 | [diff] [blame] | 1224 | ::wm::SetActivationClient(root_window, focus_controller_.get()); |
sky | 2734438 | 2017-03-08 21:30:32 | [diff] [blame] | 1225 | root_window->AddPreTargetHandler(focus_controller_.get()); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 1226 | aura::client::SetVisibilityClient(root_window, visibility_controller_.get()); |
Scott Violet | 361833fb | 2017-06-21 22:25:20 | [diff] [blame] | 1227 | if (drag_drop_controller_) { |
| 1228 | DCHECK_NE(Config::MASH, GetAshConfig()); |
| 1229 | aura::client::SetDragDropClient(root_window, drag_drop_controller_.get()); |
| 1230 | } else { |
| 1231 | DCHECK_EQ(Config::MASH, GetAshConfig()); |
| 1232 | } |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 1233 | aura::client::SetScreenPositionClient(root_window, |
| 1234 | screen_position_controller_.get()); |
sadrul | 7a8785e | 2016-02-12 21:54:35 | [diff] [blame] | 1235 | aura::client::SetCursorClient(root_window, cursor_manager_.get()); |
Thiago Farina | 3b086a0 | 2017-05-30 22:32:50 | [diff] [blame] | 1236 | ::wm::SetTooltipClient(root_window, tooltip_controller_.get()); |
[email protected] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 1237 | aura::client::SetEventClient(root_window, event_client_.get()); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 1238 | |
Thiago Farina | 3b086a0 | 2017-05-30 22:32:50 | [diff] [blame] | 1239 | ::wm::SetWindowMoveClient(root_window, toplevel_window_event_handler_.get()); |
[email protected] | 3537d47 | 2014-01-15 05:45:31 | [diff] [blame] | 1240 | root_window->AddPreTargetHandler(toplevel_window_event_handler_.get()); |
| 1241 | root_window->AddPostTargetHandler(toplevel_window_event_handler_.get()); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 1242 | } |
| 1243 | |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 1244 | void Shell::CloseAllRootWindowChildWindows() { |
msw | 257a6a23 | 2017-06-01 01:46:30 | [diff] [blame] | 1245 | for (aura::Window* root : GetAllRootWindows()) { |
| 1246 | RootWindowController* controller = RootWindowController::ForWindow(root); |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 1247 | if (controller) { |
| 1248 | controller->CloseChildWindows(); |
| 1249 | } else { |
msw | 257a6a23 | 2017-06-01 01:46:30 | [diff] [blame] | 1250 | while (!root->children().empty()) { |
| 1251 | aura::Window* child = root->children()[0]; |
sky | abcae81 | 2017-01-18 17:01:34 | [diff] [blame] | 1252 | delete child; |
| 1253 | } |
| 1254 | } |
| 1255 | } |
| 1256 | } |
| 1257 | |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 1258 | bool Shell::CanWindowReceiveEvents(aura::Window* window) { |
| 1259 | RootWindowControllerList controllers = GetAllRootWindowControllers(); |
oshima | 9a61ecf | 2016-06-18 10:43:05 | [diff] [blame] | 1260 | for (RootWindowController* controller : controllers) { |
| 1261 | if (controller->CanWindowReceiveEvents(window)) |
[email protected] | 602022b | 2014-03-31 17:07:31 | [diff] [blame] | 1262 | return true; |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 1263 | } |
| 1264 | return false; |
| 1265 | } |
| 1266 | |
[email protected] | 049cf34b | 2012-12-07 17:15:48 | [diff] [blame] | 1267 | //////////////////////////////////////////////////////////////////////////////// |
| 1268 | // Shell, ui::EventTarget overrides: |
| 1269 | |
[email protected] | 869f635 | 2012-12-06 20:47:17 | [diff] [blame] | 1270 | bool Shell::CanAcceptEvent(const ui::Event& event) { |
[email protected] | 5097e69 | 2012-10-30 22:08:41 | [diff] [blame] | 1271 | return true; |
| 1272 | } |
| 1273 | |
| 1274 | ui::EventTarget* Shell::GetParentTarget() { |
[email protected] | ff027885 | 2013-11-05 22:35:48 | [diff] [blame] | 1275 | return aura::Env::GetInstance(); |
[email protected] | 5097e69 | 2012-10-30 22:08:41 | [diff] [blame] | 1276 | } |
| 1277 | |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 1278 | std::unique_ptr<ui::EventTargetIterator> Shell::GetChildIterator() const { |
| 1279 | return std::unique_ptr<ui::EventTargetIterator>(); |
[email protected] | 3e670aa | 2013-12-02 19:04:32 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | ui::EventTargeter* Shell::GetEventTargeter() { |
| 1283 | NOTREACHED(); |
achuith | 287b26e | 2015-09-03 17:49:18 | [diff] [blame] | 1284 | return nullptr; |
[email protected] | 3e670aa | 2013-12-02 19:04:32 | [diff] [blame] | 1285 | } |
| 1286 | |
sky | 2734438 | 2017-03-08 21:30:32 | [diff] [blame] | 1287 | void Shell::OnWindowActivated( |
Thiago Farina | 3b086a0 | 2017-05-30 22:32:50 | [diff] [blame] | 1288 | ::wm::ActivationChangeObserver::ActivationReason reason, |
sky | 2734438 | 2017-03-08 21:30:32 | [diff] [blame] | 1289 | aura::Window* gained_active, |
| 1290 | aura::Window* lost_active) { |
msw | ad3d955 | 2017-05-18 21:23:36 | [diff] [blame] | 1291 | if (gained_active) |
| 1292 | root_window_for_new_windows_ = gained_active->GetRootWindow(); |
sky | 2734438 | 2017-03-08 21:30:32 | [diff] [blame] | 1293 | } |
| 1294 | |
Xiyuan Xia | b64fd0a | 2017-04-13 17:53:14 | [diff] [blame] | 1295 | void Shell::OnSessionStateChanged(session_manager::SessionState state) { |
Aga Wronska | e195ad2 | 2017-12-20 01:38:11 | [diff] [blame] | 1296 | // Initialize the |shelf_window_watcher_| when a session becomes active. |
| 1297 | // Shelf itself is initialized in RootWindowController. |
sky | 5ad143a | 2017-03-22 04:31:23 | [diff] [blame] | 1298 | if (state == session_manager::SessionState::ACTIVE) { |
Aga Wronska | e195ad2 | 2017-12-20 01:38:11 | [diff] [blame] | 1299 | if (!shelf_window_watcher_) |
| 1300 | shelf_window_watcher_ = |
| 1301 | std::make_unique<ShelfWindowWatcher>(shelf_model()); |
oka | c21941d | 2017-06-20 17:54:44 | [diff] [blame] | 1302 | } |
Steven Bennetts | 43b3c21 | 2018-01-08 16:39:58 | [diff] [blame] | 1303 | |
Steven Bennetts | 9fd12ad | 2017-11-09 23:36:27 | [diff] [blame] | 1304 | // NOTE: keyboard::IsKeyboardEnabled() is false in mash, but may not be in |
| 1305 | // unit tests. crbug.com/646565. |
Steven Bennetts | 43b3c21 | 2018-01-08 16:39:58 | [diff] [blame] | 1306 | if (keyboard::IsKeyboardEnabled()) { |
| 1307 | switch (state) { |
| 1308 | case session_manager::SessionState::OOBE: |
| 1309 | case session_manager::SessionState::LOGIN_PRIMARY: |
| 1310 | // Ensure that the keyboard controller is activated for the primary |
| 1311 | // window. |
| 1312 | GetPrimaryRootWindowController()->ActivateKeyboard( |
| 1313 | keyboard::KeyboardController::GetInstance()); |
| 1314 | break; |
| 1315 | case session_manager::SessionState::LOGGED_IN_NOT_ACTIVE: |
| 1316 | case session_manager::SessionState::ACTIVE: |
| 1317 | // Recreate the keyboard on user profile change, to refresh keyboard |
| 1318 | // extensions with the new profile and ensure the extensions call the |
| 1319 | // proper IME. |LOGGED_IN_NOT_ACTIVE| is needed so that the virtual |
| 1320 | // keyboard works on supervised user creation, http://crbug.com/712873. |
| 1321 | // |ACTIVE| is also needed for guest user workflow. |
| 1322 | CreateKeyboard(); |
| 1323 | break; |
| 1324 | default: |
| 1325 | break; |
| 1326 | } |
sky | 5ad143a | 2017-03-22 04:31:23 | [diff] [blame] | 1327 | } |
Scott Violet | 0c0dcde | 2017-08-04 21:48:18 | [diff] [blame] | 1328 | |
| 1329 | shell_port_->UpdateSystemModalAndBlockingContainers(); |
xiyuan | 233f4e7 | 2017-04-06 06:59:56 | [diff] [blame] | 1330 | } |
sky | 5ad143a | 2017-03-22 04:31:23 | [diff] [blame] | 1331 | |
Xiyuan Xia | b64fd0a | 2017-04-13 17:53:14 | [diff] [blame] | 1332 | void Shell::OnLoginStatusChanged(LoginStatus login_status) { |
xiyuan | 233f4e7 | 2017-04-06 06:59:56 | [diff] [blame] | 1333 | UpdateAfterLoginStatusChange(login_status); |
sky | 5ad143a | 2017-03-22 04:31:23 | [diff] [blame] | 1334 | } |
| 1335 | |
Xiyuan Xia | b64fd0a | 2017-04-13 17:53:14 | [diff] [blame] | 1336 | void Shell::OnLockStateChanged(bool locked) { |
xiyuan | 7ebbf7f | 2017-04-10 16:49:10 | [diff] [blame] | 1337 | #ifndef NDEBUG |
| 1338 | // Make sure that there is no system modal in Lock layer when unlocked. |
| 1339 | if (!locked) { |
| 1340 | aura::Window::Windows containers = wm::GetContainersFromAllRootWindows( |
| 1341 | kShellWindowId_LockSystemModalContainer, GetPrimaryRootWindow()); |
| 1342 | for (aura::Window* container : containers) |
| 1343 | DCHECK(container->children().empty()); |
| 1344 | } |
| 1345 | #endif |
| 1346 | } |
| 1347 | |
Sam McNally | e36abbc | 2017-07-20 01:04:28 | [diff] [blame] | 1348 | void Shell::OnLocalStatePrefServiceInitialized( |
| 1349 | std::unique_ptr<::PrefService> pref_service) { |
Sam McNally | a853cd8 | 2017-08-30 01:55:10 | [diff] [blame] | 1350 | DCHECK(!local_state_); |
James Cook | 8532dbc | 2017-07-31 21:54:51 | [diff] [blame] | 1351 | // |pref_service| is null if can't connect to Chrome (as happens when |
Scott Violet | 8ff9c30 | 2018-02-22 22:28:35 | [diff] [blame] | 1352 | // running mash outside of chrome --enable-features=Mash and chrome isn't |
| 1353 | // built). |
Sam McNally | a853cd8 | 2017-08-30 01:55:10 | [diff] [blame] | 1354 | if (!pref_service) |
| 1355 | return; |
| 1356 | |
| 1357 | local_state_ = std::move(pref_service); |
James Cook | bbe5cb1 | 2017-08-08 18:32:21 | [diff] [blame] | 1358 | |
| 1359 | for (auto& observer : shell_observers_) |
Sam McNally | a853cd8 | 2017-08-30 01:55:10 | [diff] [blame] | 1360 | observer.OnLocalStatePrefServiceInitialized(local_state_.get()); |
Sam McNally | e36abbc | 2017-07-20 01:04:28 | [diff] [blame] | 1361 | } |
| 1362 | |
[email protected] | 55f59335 | 2011-12-24 05:42:46 | [diff] [blame] | 1363 | } // namespace ash |