[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "ash/root_window_controller.h" |
| 6 | |
[email protected] | 8b3e3d8 | 2013-08-20 14:36:30 | [diff] [blame] | 7 | #include <queue> |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 8 | #include <vector> |
| 9 | |
sky | 0702b27 | 2016-06-03 22:10:41 | [diff] [blame] | 10 | #include "ash/aura/aura_layout_manager_adapter.h" |
| 11 | #include "ash/aura/wm_shelf_aura.h" |
| 12 | #include "ash/aura/wm_window_aura.h" |
jamescook | e044e1c | 2016-06-13 20:56:18 | [diff] [blame] | 13 | #include "ash/common/ash_constants.h" |
msw | d9b1b34 | 2016-06-17 20:19:57 | [diff] [blame] | 14 | #include "ash/common/ash_switches.h" |
jamescook | 26f3209 | 2016-06-17 04:26:52 | [diff] [blame] | 15 | #include "ash/common/focus_cycler.h" |
sky | c096d9f | 2016-06-02 13:46:26 | [diff] [blame] | 16 | #include "ash/common/root_window_controller_common.h" |
jamescook | 2b624c5a | 2016-06-08 01:34:02 | [diff] [blame] | 17 | #include "ash/common/session/session_state_delegate.h" |
jamescook | 1b474d6a | 2016-06-04 05:56:00 | [diff] [blame] | 18 | #include "ash/common/shelf/shelf_types.h" |
sky | c096d9f | 2016-06-02 13:46:26 | [diff] [blame] | 19 | #include "ash/common/shell_window_ids.h" |
jamescook | 2a4d1eb | 2016-06-09 20:10:07 | [diff] [blame] | 20 | #include "ash/common/system/tray/system_tray_delegate.h" |
sky | d606377 | 2016-06-01 17:52:21 | [diff] [blame] | 21 | #include "ash/common/wm/always_on_top_controller.h" |
| 22 | #include "ash/common/wm/container_finder.h" |
| 23 | #include "ash/common/wm/dock/docked_window_layout_manager.h" |
| 24 | #include "ash/common/wm/fullscreen_window_finder.h" |
| 25 | #include "ash/common/wm/panels/panel_layout_manager.h" |
sky | c096d9f | 2016-06-02 13:46:26 | [diff] [blame] | 26 | #include "ash/common/wm/root_window_layout_manager.h" |
sky | d606377 | 2016-06-01 17:52:21 | [diff] [blame] | 27 | #include "ash/common/wm/switchable_windows.h" |
| 28 | #include "ash/common/wm/window_state.h" |
sky | d606377 | 2016-06-01 17:52:21 | [diff] [blame] | 29 | #include "ash/common/wm/workspace/workspace_layout_manager.h" |
| 30 | #include "ash/common/wm/workspace/workspace_layout_manager_delegate.h" |
sky | 0702b27 | 2016-06-03 22:10:41 | [diff] [blame] | 31 | #include "ash/common/wm_shell.h" |
| 32 | #include "ash/common/wm_window.h" |
[email protected] | a273d33a | 2013-10-17 12:41:21 | [diff] [blame] | 33 | #include "ash/desktop_background/desktop_background_controller.h" |
[email protected] | b4ddc7a | 2012-08-07 04:17:32 | [diff] [blame] | 34 | #include "ash/desktop_background/desktop_background_widget_controller.h" |
[email protected] | 0bf6173 | 2013-07-02 04:35:10 | [diff] [blame] | 35 | #include "ash/desktop_background/user_wallpaper_delegate.h" |
[email protected] | 6bdf795 | 2012-11-14 10:10:58 | [diff] [blame] | 36 | #include "ash/display/display_manager.h" |
[email protected] | a273d33a | 2013-10-17 12:41:21 | [diff] [blame] | 37 | #include "ash/high_contrast/high_contrast_controller.h" |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 38 | #include "ash/host/ash_window_tree_host.h" |
[email protected] | f8e6aad | 2013-08-30 21:49:11 | [diff] [blame] | 39 | #include "ash/root_window_settings.h" |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 40 | #include "ash/shelf/shelf_layout_manager.h" |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 41 | #include "ash/shelf/shelf_widget.h" |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 42 | #include "ash/shell.h" |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 43 | #include "ash/shell_delegate.h" |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 44 | #include "ash/shell_factory.h" |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 45 | #include "ash/system/status_area_widget.h" |
[email protected] | a825e831 | 2014-05-05 22:05:01 | [diff] [blame] | 46 | #include "ash/system/tray/system_tray_notifier.h" |
[email protected] | 2b8a9bb | 2013-07-01 22:43:40 | [diff] [blame] | 47 | #include "ash/touch/touch_hud_debug.h" |
| 48 | #include "ash/touch/touch_hud_projection.h" |
[email protected] | 80549c15 | 2013-07-02 01:42:47 | [diff] [blame] | 49 | #include "ash/touch/touch_observer_hud.h" |
[email protected] | 68d5133 | 2014-06-06 13:51:13 | [diff] [blame] | 50 | #include "ash/wm/lock_layout_manager.h" |
[email protected] | b8642ec | 2014-04-17 05:20:39 | [diff] [blame] | 51 | #include "ash/wm/panels/attached_panel_window_targeter.h" |
[email protected] | 10065941 | 2013-06-21 22:59:55 | [diff] [blame] | 52 | #include "ash/wm/panels/panel_window_event_handler.h" |
[email protected] | 2a2caa0 | 2013-01-22 20:50:36 | [diff] [blame] | 53 | #include "ash/wm/stacking_controller.h" |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 54 | #include "ash/wm/status_area_layout_manager.h" |
[email protected] | e6e41d2f | 2012-10-29 19:22:19 | [diff] [blame] | 55 | #include "ash/wm/system_background_controller.h" |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 56 | #include "ash/wm/system_modal_container_layout_manager.h" |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 57 | #include "ash/wm/window_properties.h" |
sky | 8d5646fe | 2016-04-15 17:03:46 | [diff] [blame] | 58 | #include "ash/wm/window_state_aura.h" |
[email protected] | 700849f | 2013-04-30 17:49:20 | [diff] [blame] | 59 | #include "ash/wm/window_util.h" |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 60 | #include "ash/wm/workspace_controller.h" |
[email protected] | e6e41d2f | 2012-10-29 19:22:19 | [diff] [blame] | 61 | #include "base/command_line.h" |
jonross | a90d898 | 2016-05-16 18:14:25 | [diff] [blame] | 62 | #include "base/macros.h" |
sky | 1e30f06 | 2016-04-14 21:19:16 | [diff] [blame] | 63 | #include "base/memory/ptr_util.h" |
[email protected] | 1e84c63 | 2013-06-27 23:12:21 | [diff] [blame] | 64 | #include "base/time/time.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 65 | #include "ui/aura/client/aura_constants.h" |
[email protected] | 2374d181 | 2014-03-04 03:42:27 | [diff] [blame] | 66 | #include "ui/aura/client/screen_position_client.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 67 | #include "ui/aura/window.h" |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 68 | #include "ui/aura/window_delegate.h" |
[email protected] | fcc51c95 | 2014-02-21 21:31:26 | [diff] [blame] | 69 | #include "ui/aura/window_event_dispatcher.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 70 | #include "ui/aura/window_observer.h" |
[email protected] | 8b3e3d8 | 2013-08-20 14:36:30 | [diff] [blame] | 71 | #include "ui/aura/window_tracker.h" |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 72 | #include "ui/base/hit_test.h" |
[email protected] | 431552c | 2012-10-23 00:38:33 | [diff] [blame] | 73 | #include "ui/base/models/menu_model.h" |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 74 | #include "ui/display/display.h" |
| 75 | #include "ui/display/screen.h" |
[email protected] | 86459e2c | 2013-04-10 13:39:24 | [diff] [blame] | 76 | #include "ui/keyboard/keyboard_controller.h" |
| 77 | #include "ui/keyboard/keyboard_util.h" |
jonross | a90d898 | 2016-05-16 18:14:25 | [diff] [blame] | 78 | #include "ui/views/controls/menu/menu_model_adapter.h" |
[email protected] | 431552c | 2012-10-23 00:38:33 | [diff] [blame] | 79 | #include "ui/views/controls/menu/menu_runner.h" |
| 80 | #include "ui/views/view_model.h" |
| 81 | #include "ui/views/view_model_utils.h" |
[email protected] | ee3ed1077 | 2014-03-11 22:02:01 | [diff] [blame] | 82 | #include "ui/wm/core/capture_controller.h" |
| 83 | #include "ui/wm/core/visibility_controller.h" |
| 84 | #include "ui/wm/core/window_util.h" |
[email protected] | af4552b2 | 2014-03-21 19:45:01 | [diff] [blame] | 85 | #include "ui/wm/public/drag_drop_client.h" |
| 86 | #include "ui/wm/public/tooltip_client.h" |
[email protected] | 5b251f1 | 2013-12-19 01:50:05 | [diff] [blame] | 87 | #include "ui/wm/public/window_types.h" |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 88 | |
[email protected] | 252eb23 | 2013-08-14 22:09:27 | [diff] [blame] | 89 | #if defined(OS_CHROMEOS) |
[email protected] | 7d48759 | 2014-07-24 03:54:50 | [diff] [blame] | 90 | #include "ash/ash_touch_exploration_manager_chromeos.h" |
[email protected] | 252eb23 | 2013-08-14 22:09:27 | [diff] [blame] | 91 | #include "ash/wm/boot_splash_screen_chromeos.h" |
[email protected] | a825e831 | 2014-05-05 22:05:01 | [diff] [blame] | 92 | #include "ui/chromeos/touch_exploration_controller.h" |
[email protected] | 252eb23 | 2013-08-14 22:09:27 | [diff] [blame] | 93 | #endif |
| 94 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 95 | namespace ash { |
| 96 | namespace { |
| 97 | |
[email protected] | 252eb23 | 2013-08-14 22:09:27 | [diff] [blame] | 98 | #if defined(OS_CHROMEOS) |
[email protected] | bca9a7e | 2012-11-10 06:25:49 | [diff] [blame] | 99 | // Duration for the animation that hides the boot splash screen, in |
| 100 | // milliseconds. This should be short enough in relation to |
| 101 | // wm/window_animation.cc's brightness/grayscale fade animation that the login |
| 102 | // background image animation isn't hidden by the splash screen animation. |
| 103 | const int kBootSplashScreenHideDurationMs = 500; |
[email protected] | 252eb23 | 2013-08-14 22:09:27 | [diff] [blame] | 104 | #endif |
[email protected] | bca9a7e | 2012-11-10 06:25:49 | [diff] [blame] | 105 | |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 106 | float ToRelativeValue(int value, int src, int dst) { |
| 107 | return static_cast<float>(value) / static_cast<float>(src) * dst; |
| 108 | } |
| 109 | |
| 110 | void MoveOriginRelativeToSize(const gfx::Size& src_size, |
| 111 | const gfx::Size& dst_size, |
| 112 | gfx::Rect* bounds_in_out) { |
| 113 | gfx::Point origin = bounds_in_out->origin(); |
| 114 | bounds_in_out->set_origin(gfx::Point( |
| 115 | ToRelativeValue(origin.x(), src_size.width(), dst_size.width()), |
| 116 | ToRelativeValue(origin.y(), src_size.height(), dst_size.height()))); |
| 117 | } |
| 118 | |
[email protected] | 9505857 | 2012-08-20 14:57:29 | [diff] [blame] | 119 | // Reparents |window| to |new_parent|. |
| 120 | void ReparentWindow(aura::Window* window, aura::Window* new_parent) { |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 121 | const gfx::Size src_size = window->parent()->bounds().size(); |
| 122 | const gfx::Size dst_size = new_parent->bounds().size(); |
[email protected] | 9505857 | 2012-08-20 14:57:29 | [diff] [blame] | 123 | // Update the restore bounds to make it relative to the display. |
[email protected] | a41b4e1 | 2013-09-20 04:36:34 | [diff] [blame] | 124 | wm::WindowState* state = wm::GetWindowState(window); |
| 125 | gfx::Rect restore_bounds; |
| 126 | bool has_restore_bounds = state->HasRestoreBounds(); |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 127 | |
[email protected] | 9cfd3d1 | 2014-02-25 15:33:45 | [diff] [blame] | 128 | bool update_bounds = (state->IsNormalOrSnapped() || state->IsMinimized()) && |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 129 | new_parent->id() != kShellWindowId_DockedContainer; |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 130 | gfx::Rect local_bounds; |
| 131 | if (update_bounds) { |
sky | 0702b27 | 2016-06-03 22:10:41 | [diff] [blame] | 132 | local_bounds = WmWindowAura::GetAuraWindow(state->window())->bounds(); |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 133 | MoveOriginRelativeToSize(src_size, dst_size, &local_bounds); |
| 134 | } |
| 135 | |
| 136 | if (has_restore_bounds) { |
[email protected] | a41b4e1 | 2013-09-20 04:36:34 | [diff] [blame] | 137 | restore_bounds = state->GetRestoreBoundsInParent(); |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 138 | MoveOriginRelativeToSize(src_size, dst_size, &restore_bounds); |
| 139 | } |
| 140 | |
[email protected] | 9505857 | 2012-08-20 14:57:29 | [diff] [blame] | 141 | new_parent->AddChild(window); |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 142 | |
[email protected] | 8663b7a6 | 2014-01-18 01:24:21 | [diff] [blame] | 143 | // Docked windows have bounds handled by the layout manager in AddChild(). |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 144 | if (update_bounds) |
| 145 | window->SetBounds(local_bounds); |
| 146 | |
[email protected] | a41b4e1 | 2013-09-20 04:36:34 | [diff] [blame] | 147 | if (has_restore_bounds) |
| 148 | state->SetRestoreBoundsInParent(restore_bounds); |
[email protected] | 9505857 | 2012-08-20 14:57:29 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | // Reparents the appropriate set of windows from |src| to |dst|. |
[email protected] | bf9cdb36 | 2013-10-25 19:22:45 | [diff] [blame] | 152 | void ReparentAllWindows(aura::Window* src, aura::Window* dst) { |
[email protected] | 9505857 | 2012-08-20 14:57:29 | [diff] [blame] | 153 | // Set of windows to move. |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 154 | const int kContainerIdsToMove[] = { |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 155 | kShellWindowId_DefaultContainer, |
| 156 | kShellWindowId_DockedContainer, |
| 157 | kShellWindowId_PanelContainer, |
| 158 | kShellWindowId_AlwaysOnTopContainer, |
| 159 | kShellWindowId_SystemModalContainer, |
| 160 | kShellWindowId_LockSystemModalContainer, |
tengs | f98986c | 2014-12-06 01:42:21 | [diff] [blame] | 161 | kShellWindowId_UnparentedControlContainer, |
oshima | 022a954 | 2015-05-01 00:15:02 | [diff] [blame] | 162 | kShellWindowId_OverlayContainer, |
| 163 | }; |
| 164 | const int kExtraContainerIdsToMoveInUnifiedMode[] = { |
| 165 | kShellWindowId_LockScreenContainer, |
| 166 | kShellWindowId_LockScreenBackgroundContainer, |
| 167 | }; |
| 168 | std::vector<int> container_ids( |
| 169 | kContainerIdsToMove, |
| 170 | kContainerIdsToMove + arraysize(kContainerIdsToMove)); |
| 171 | // Check the default_multi_display_mode because this is also necessary |
| 172 | // in trasition between mirror <-> unified mode. |
oshima | 628a617 | 2015-08-01 01:33:14 | [diff] [blame] | 173 | if (Shell::GetInstance() |
| 174 | ->display_manager() |
| 175 | ->current_default_multi_display_mode() == DisplayManager::UNIFIED) { |
oshima | 022a954 | 2015-05-01 00:15:02 | [diff] [blame] | 176 | for (int id : kExtraContainerIdsToMoveInUnifiedMode) |
| 177 | container_ids.push_back(id); |
| 178 | } |
| 179 | |
| 180 | for (int id : container_ids) { |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 181 | aura::Window* src_container = Shell::GetContainer(src, id); |
| 182 | aura::Window* dst_container = Shell::GetContainer(dst, id); |
[email protected] | 5b602190 | 2013-02-26 05:33:29 | [diff] [blame] | 183 | while (!src_container->children().empty()) { |
| 184 | // Restart iteration from the source container windows each time as they |
| 185 | // may change as a result of moving other windows. |
| 186 | aura::Window::Windows::const_iterator iter = |
| 187 | src_container->children().begin(); |
| 188 | while (iter != src_container->children().end() && |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 189 | SystemModalContainerLayoutManager::IsModalBackground(*iter)) { |
[email protected] | 5b602190 | 2013-02-26 05:33:29 | [diff] [blame] | 190 | ++iter; |
| 191 | } |
| 192 | // If the entire window list is modal background windows then stop. |
| 193 | if (iter == src_container->children().end()) |
| 194 | break; |
| 195 | ReparentWindow(*iter, dst_container); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 196 | } |
| 197 | } |
| 198 | } |
| 199 | |
oshima | 9a61ecf | 2016-06-18 10:43:05 | [diff] [blame^] | 200 | bool IsWindowAboveContainer(aura::Window* window, |
| 201 | aura::Window* blocking_container) { |
| 202 | std::vector<aura::Window*> target_path; |
| 203 | std::vector<aura::Window*> blocking_path; |
| 204 | |
| 205 | while (window) { |
| 206 | target_path.push_back(window); |
| 207 | window = window->parent(); |
| 208 | } |
| 209 | |
| 210 | while (blocking_container) { |
| 211 | blocking_path.push_back(blocking_container); |
| 212 | blocking_container = blocking_container->parent(); |
| 213 | } |
| 214 | |
| 215 | // The root window is put at the end so that we compare windows at |
| 216 | // the same depth. |
| 217 | while (!blocking_path.empty()) { |
| 218 | if (target_path.empty()) |
| 219 | return false; |
| 220 | |
| 221 | aura::Window* target = target_path.back(); |
| 222 | target_path.pop_back(); |
| 223 | aura::Window* blocking = blocking_path.back(); |
| 224 | blocking_path.pop_back(); |
| 225 | |
| 226 | // Still on the same path, continue. |
| 227 | if (target == blocking) |
| 228 | continue; |
| 229 | |
| 230 | // This can happen only if unparented window is passed because |
| 231 | // first element must be the same root. |
| 232 | if (!target->parent() || !blocking->parent()) |
| 233 | return false; |
| 234 | |
| 235 | aura::Window* common_parent = target->parent(); |
| 236 | DCHECK_EQ(common_parent, blocking->parent()); |
| 237 | aura::Window::Windows windows = common_parent->children(); |
| 238 | auto blocking_iter = std::find(windows.begin(), windows.end(), blocking); |
| 239 | // If the target window is above blocking window, the window can handle |
| 240 | // events. |
| 241 | return std::find(blocking_iter, windows.end(), target) != windows.end(); |
| 242 | } |
| 243 | |
| 244 | return true; |
| 245 | } |
| 246 | |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 247 | // A window delegate which does nothing. Used to create a window that |
| 248 | // is a event target, but do nothing. |
| 249 | class EmptyWindowDelegate : public aura::WindowDelegate { |
| 250 | public: |
| 251 | EmptyWindowDelegate() {} |
dcheng | 1f4538e | 2014-10-27 23:57:05 | [diff] [blame] | 252 | ~EmptyWindowDelegate() override {} |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 253 | |
| 254 | // aura::WindowDelegate overrides: |
dcheng | 1f4538e | 2014-10-27 23:57:05 | [diff] [blame] | 255 | gfx::Size GetMinimumSize() const override { return gfx::Size(); } |
| 256 | gfx::Size GetMaximumSize() const override { return gfx::Size(); } |
| 257 | void OnBoundsChanged(const gfx::Rect& old_bounds, |
| 258 | const gfx::Rect& new_bounds) override {} |
| 259 | gfx::NativeCursor GetCursor(const gfx::Point& point) override { |
[email protected] | 62c9f10 | 2014-03-27 06:07:04 | [diff] [blame] | 260 | return gfx::kNullCursor; |
| 261 | } |
dcheng | 1f4538e | 2014-10-27 23:57:05 | [diff] [blame] | 262 | int GetNonClientComponent(const gfx::Point& point) const override { |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 263 | return HTNOWHERE; |
| 264 | } |
dcheng | 1f4538e | 2014-10-27 23:57:05 | [diff] [blame] | 265 | bool ShouldDescendIntoChildForEventHandling( |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 266 | aura::Window* child, |
mostynb | 10d6b38 | 2014-10-03 16:23:45 | [diff] [blame] | 267 | const gfx::Point& location) override { |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 268 | return false; |
| 269 | } |
dcheng | 1f4538e | 2014-10-27 23:57:05 | [diff] [blame] | 270 | bool CanFocus() override { return false; } |
| 271 | void OnCaptureLost() override {} |
danakj | 85d970e | 2015-04-04 00:15:24 | [diff] [blame] | 272 | void OnPaint(const ui::PaintContext& context) override {} |
dcheng | 1f4538e | 2014-10-27 23:57:05 | [diff] [blame] | 273 | void OnDeviceScaleFactorChanged(float device_scale_factor) override {} |
| 274 | void OnWindowDestroying(aura::Window* window) override {} |
| 275 | void OnWindowDestroyed(aura::Window* window) override { delete this; } |
| 276 | void OnWindowTargetVisibilityChanged(bool visible) override {} |
| 277 | bool HasHitTestMask() const override { return false; } |
| 278 | void GetHitTestMask(gfx::Path* mask) const override {} |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 279 | |
| 280 | private: |
| 281 | DISALLOW_COPY_AND_ASSIGN(EmptyWindowDelegate); |
| 282 | }; |
| 283 | |
sky | 1e30f06 | 2016-04-14 21:19:16 | [diff] [blame] | 284 | class WorkspaceLayoutManagerDelegateImpl |
| 285 | : public wm::WorkspaceLayoutManagerDelegate { |
| 286 | public: |
| 287 | explicit WorkspaceLayoutManagerDelegateImpl(aura::Window* root_window) |
| 288 | : root_window_(root_window) {} |
| 289 | ~WorkspaceLayoutManagerDelegateImpl() override = default; |
| 290 | |
| 291 | void set_shelf(ShelfLayoutManager* shelf) { shelf_ = shelf; } |
| 292 | |
| 293 | // WorkspaceLayoutManagerDelegate: |
| 294 | void UpdateShelfVisibility() override { |
| 295 | if (shelf_) |
| 296 | shelf_->UpdateVisibilityState(); |
| 297 | } |
| 298 | void OnFullscreenStateChanged(bool is_fullscreen) override { |
| 299 | if (shelf_) { |
sky | 80556bc4 | 2016-06-07 22:46:13 | [diff] [blame] | 300 | ash::Shell::GetInstance()->NotifyFullscreenStateChange( |
| 301 | is_fullscreen, WmWindowAura::Get(root_window_)); |
sky | 1e30f06 | 2016-04-14 21:19:16 | [diff] [blame] | 302 | } |
| 303 | } |
| 304 | |
| 305 | private: |
| 306 | aura::Window* root_window_; |
| 307 | ShelfLayoutManager* shelf_ = nullptr; |
| 308 | |
| 309 | DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerDelegateImpl); |
| 310 | }; |
| 311 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 312 | } // namespace |
| 313 | |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 314 | void RootWindowController::CreateForPrimaryDisplay(AshWindowTreeHost* host) { |
[email protected] | 2f262033 | 2014-02-28 10:07:38 | [diff] [blame] | 315 | RootWindowController* controller = new RootWindowController(host); |
[email protected] | 608de6c | 2013-10-29 00:14:28 | [diff] [blame] | 316 | controller->Init(RootWindowController::PRIMARY, |
[email protected] | a273d33a | 2013-10-17 12:41:21 | [diff] [blame] | 317 | Shell::GetInstance()->delegate()->IsFirstRunAfterBoot()); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 318 | } |
| 319 | |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 320 | void RootWindowController::CreateForSecondaryDisplay(AshWindowTreeHost* host) { |
[email protected] | 2f262033 | 2014-02-28 10:07:38 | [diff] [blame] | 321 | RootWindowController* controller = new RootWindowController(host); |
[email protected] | 608de6c | 2013-10-29 00:14:28 | [diff] [blame] | 322 | controller->Init(RootWindowController::SECONDARY, false /* first run */); |
| 323 | } |
| 324 | |
[email protected] | 88d7112 | 2012-10-18 07:11:01 | [diff] [blame] | 325 | // static |
[email protected] | ccff3d7 | 2013-02-06 04:26:28 | [diff] [blame] | 326 | RootWindowController* RootWindowController::ForWindow( |
| 327 | const aura::Window* window) { |
oshima | 9eea82da | 2014-09-13 01:11:07 | [diff] [blame] | 328 | CHECK(Shell::HasInstance()); |
[email protected] | a0afeb1 | 2012-12-10 22:57:09 | [diff] [blame] | 329 | return GetRootWindowController(window->GetRootWindow()); |
| 330 | } |
| 331 | |
| 332 | // static |
[email protected] | d17642d | 2013-09-12 23:44:38 | [diff] [blame] | 333 | RootWindowController* RootWindowController::ForTargetRootWindow() { |
oshima | 9eea82da | 2014-09-13 01:11:07 | [diff] [blame] | 334 | CHECK(Shell::HasInstance()); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 335 | return GetRootWindowController(Shell::GetTargetRootWindow()); |
[email protected] | a0afeb1 | 2012-12-10 22:57:09 | [diff] [blame] | 336 | } |
| 337 | |
[email protected] | a273d33a | 2013-10-17 12:41:21 | [diff] [blame] | 338 | RootWindowController::~RootWindowController() { |
| 339 | Shutdown(); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 340 | ash_host_.reset(); |
[email protected] | a273d33a | 2013-10-17 12:41:21 | [diff] [blame] | 341 | // The CaptureClient needs to be around for as long as the RootWindow is |
| 342 | // valid. |
| 343 | capture_client_.reset(); |
| 344 | } |
| 345 | |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 346 | aura::WindowTreeHost* RootWindowController::GetHost() { |
| 347 | return ash_host_->AsWindowTreeHost(); |
| 348 | } |
| 349 | |
| 350 | const aura::WindowTreeHost* RootWindowController::GetHost() const { |
| 351 | return ash_host_->AsWindowTreeHost(); |
| 352 | } |
| 353 | |
| 354 | aura::Window* RootWindowController::GetRootWindow() { |
| 355 | return GetHost()->window(); |
| 356 | } |
| 357 | |
| 358 | const aura::Window* RootWindowController::GetRootWindow() const { |
| 359 | return GetHost()->window(); |
| 360 | } |
| 361 | |
[email protected] | 0bf6173 | 2013-07-02 04:35:10 | [diff] [blame] | 362 | void RootWindowController::SetWallpaperController( |
| 363 | DesktopBackgroundWidgetController* controller) { |
| 364 | wallpaper_controller_.reset(controller); |
| 365 | } |
| 366 | |
| 367 | void RootWindowController::SetAnimatingWallpaperController( |
| 368 | AnimatingDesktopController* controller) { |
| 369 | if (animating_wallpaper_controller_.get()) |
| 370 | animating_wallpaper_controller_->StopAnimating(); |
| 371 | animating_wallpaper_controller_.reset(controller); |
| 372 | } |
| 373 | |
[email protected] | 6675e1c | 2012-09-11 09:15:45 | [diff] [blame] | 374 | void RootWindowController::Shutdown() { |
sky | 88bd4be6 | 2016-06-09 17:34:41 | [diff] [blame] | 375 | WmShell::Get()->RemoveShellObserver(this); |
[email protected] | a825e831 | 2014-05-05 22:05:01 | [diff] [blame] | 376 | |
| 377 | #if defined(OS_CHROMEOS) |
[email protected] | 7d48759 | 2014-07-24 03:54:50 | [diff] [blame] | 378 | if (touch_exploration_manager_) { |
| 379 | touch_exploration_manager_.reset(); |
[email protected] | a825e831 | 2014-05-05 22:05:01 | [diff] [blame] | 380 | } |
| 381 | #endif |
[email protected] | d141b92 | 2013-07-09 08:13:17 | [diff] [blame] | 382 | |
[email protected] | 0bf6173 | 2013-07-02 04:35:10 | [diff] [blame] | 383 | if (animating_wallpaper_controller_.get()) |
| 384 | animating_wallpaper_controller_->StopAnimating(); |
| 385 | wallpaper_controller_.reset(); |
| 386 | animating_wallpaper_controller_.reset(); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 387 | aura::Window* root_window = GetRootWindow(); |
sky | 88bd4be6 | 2016-06-09 17:34:41 | [diff] [blame] | 388 | Shell* shell = Shell::GetInstance(); |
[email protected] | d17642d | 2013-09-12 23:44:38 | [diff] [blame] | 389 | // Change the target root window before closing child windows. If any child |
[email protected] | c98a492 | 2013-09-05 20:01:42 | [diff] [blame] | 390 | // being removed triggers a relayout of the shelf it will try to build a |
[email protected] | d17642d | 2013-09-12 23:44:38 | [diff] [blame] | 391 | // window list adding windows from the target root window's containers which |
[email protected] | c98a492 | 2013-09-05 20:01:42 | [diff] [blame] | 392 | // may have already gone away. |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 393 | if (Shell::GetTargetRootWindow() == root_window) { |
[email protected] | a825e831 | 2014-05-05 22:05:01 | [diff] [blame] | 394 | shell->set_target_root_window( |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 395 | Shell::GetPrimaryRootWindow() == root_window |
| 396 | ? NULL |
| 397 | : Shell::GetPrimaryRootWindow()); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 398 | } |
[email protected] | c98a492 | 2013-09-05 20:01:42 | [diff] [blame] | 399 | |
| 400 | CloseChildWindows(); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 401 | GetRootWindowSettings(root_window)->controller = NULL; |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 402 | workspace_controller_.reset(); |
[email protected] | 6675e1c | 2012-09-11 09:15:45 | [diff] [blame] | 403 | // Forget with the display ID so that display lookup |
| 404 | // ends up with invalid display. |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 405 | GetRootWindowSettings(root_window)->display_id = |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 406 | display::Display::kInvalidDisplayID; |
[email protected] | 8f5209c | 2014-05-22 20:36:11 | [diff] [blame] | 407 | ash_host_->PrepareForShutdown(); |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 408 | |
[email protected] | 956a6a4 | 2012-10-29 23:58:10 | [diff] [blame] | 409 | system_background_.reset(); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 410 | aura::client::SetScreenPositionClient(root_window, NULL); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 411 | } |
| 412 | |
oshima | 9a61ecf | 2016-06-18 10:43:05 | [diff] [blame^] | 413 | bool RootWindowController::CanWindowReceiveEvents(aura::Window* window) { |
| 414 | if (GetRootWindow() != window->GetRootWindow()) |
| 415 | return false; |
| 416 | |
| 417 | // Always allow events to fall through to the virtual keyboard even if |
| 418 | // displaying a system modal dialog. |
| 419 | if (IsVirtualKeyboardWindow(window)) |
| 420 | return true; |
| 421 | |
| 422 | aura::Window* blocking_container = nullptr; |
| 423 | |
| 424 | int modal_container_id = 0; |
| 425 | if (Shell::GetInstance()->session_state_delegate()->IsUserSessionBlocked()) { |
| 426 | blocking_container = |
| 427 | GetContainer(kShellWindowId_LockScreenContainersContainer); |
| 428 | modal_container_id = kShellWindowId_LockSystemModalContainer; |
| 429 | } else { |
| 430 | modal_container_id = kShellWindowId_SystemModalContainer; |
| 431 | } |
| 432 | aura::Window* modal_container = GetContainer(modal_container_id); |
| 433 | SystemModalContainerLayoutManager* modal_layout_manager = nullptr; |
| 434 | modal_layout_manager = static_cast<SystemModalContainerLayoutManager*>( |
| 435 | modal_container->layout_manager()); |
| 436 | |
| 437 | if (modal_layout_manager->has_modal_background()) |
| 438 | blocking_container = modal_container; |
| 439 | else |
| 440 | modal_container = nullptr; // Don't check modal dialogs. |
| 441 | |
| 442 | // In normal session. |
| 443 | if (!blocking_container) |
| 444 | return true; |
| 445 | |
| 446 | if (!IsWindowAboveContainer(window, blocking_container)) |
| 447 | return false; |
| 448 | |
| 449 | // If the window is in the target modal container, only allow the top most |
| 450 | // one. |
| 451 | if (modal_container && modal_container->Contains(window)) |
| 452 | return modal_layout_manager->IsPartOfActiveModalWindow(window); |
| 453 | |
| 454 | return true; |
| 455 | } |
| 456 | |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 457 | SystemModalContainerLayoutManager* |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 458 | RootWindowController::GetSystemModalLayoutManager(aura::Window* window) { |
[email protected] | a5c7880 | 2013-12-12 22:07:01 | [diff] [blame] | 459 | aura::Window* modal_container = NULL; |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 460 | if (window) { |
sky | 0702b27 | 2016-06-03 22:10:41 | [diff] [blame] | 461 | aura::Window* window_container = WmWindowAura::GetAuraWindow( |
| 462 | wm::GetContainerForWindow(WmWindowAura::Get(window))); |
[email protected] | a5c7880 | 2013-12-12 22:07:01 | [diff] [blame] | 463 | if (window_container && |
| 464 | window_container->id() >= kShellWindowId_LockScreenContainer) { |
| 465 | modal_container = GetContainer(kShellWindowId_LockSystemModalContainer); |
[email protected] | 3b162e1 | 2012-11-09 11:52:35 | [diff] [blame] | 466 | } else { |
[email protected] | a5c7880 | 2013-12-12 22:07:01 | [diff] [blame] | 467 | modal_container = GetContainer(kShellWindowId_SystemModalContainer); |
[email protected] | 3b162e1 | 2012-11-09 11:52:35 | [diff] [blame] | 468 | } |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 469 | } else { |
[email protected] | a44afbbd | 2013-07-24 21:49:35 | [diff] [blame] | 470 | int modal_window_id = Shell::GetInstance()->session_state_delegate() |
| 471 | ->IsUserSessionBlocked() ? kShellWindowId_LockSystemModalContainer : |
| 472 | kShellWindowId_SystemModalContainer; |
[email protected] | a5c7880 | 2013-12-12 22:07:01 | [diff] [blame] | 473 | modal_container = GetContainer(modal_window_id); |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 474 | } |
[email protected] | a5c7880 | 2013-12-12 22:07:01 | [diff] [blame] | 475 | return modal_container ? static_cast<SystemModalContainerLayoutManager*>( |
| 476 | modal_container->layout_manager()) : NULL; |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 477 | } |
| 478 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 479 | aura::Window* RootWindowController::GetContainer(int container_id) { |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 480 | return GetRootWindow()->GetChildById(container_id); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 481 | } |
| 482 | |
[email protected] | d8a2495 | 2013-08-05 20:05:05 | [diff] [blame] | 483 | const aura::Window* RootWindowController::GetContainer(int container_id) const { |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 484 | return ash_host_->AsWindowTreeHost()->window()->GetChildById(container_id); |
[email protected] | d8a2495 | 2013-08-05 20:05:05 | [diff] [blame] | 485 | } |
| 486 | |
[email protected] | 864b5855 | 2013-12-19 04:19:38 | [diff] [blame] | 487 | void RootWindowController::ShowShelf() { |
jamescook | 612205f | 2016-05-26 06:02:11 | [diff] [blame] | 488 | if (!shelf_widget_->shelf()) |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 489 | return; |
jamescook | 612205f | 2016-05-26 06:02:11 | [diff] [blame] | 490 | shelf_widget_->shelf()->SetVisible(true); |
| 491 | shelf_widget_->status_area_widget()->Show(); |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 492 | } |
| 493 | |
jamescook | 6500ad13 | 2016-05-27 06:15:54 | [diff] [blame] | 494 | void RootWindowController::CreateShelf() { |
| 495 | if (shelf_widget_->shelf()) |
| 496 | return; |
jamescook | be6ed82 | 2016-06-06 20:08:55 | [diff] [blame] | 497 | shelf_widget_->CreateShelf(wm_shelf_aura_.get()); |
jamescook | 6500ad13 | 2016-05-27 06:15:54 | [diff] [blame] | 498 | |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 499 | if (panel_layout_manager_) |
jamescook | be6ed82 | 2016-06-06 20:08:55 | [diff] [blame] | 500 | panel_layout_manager_->SetShelf(wm_shelf_aura_.get()); |
[email protected] | 7115bd3 | 2013-07-19 08:25:39 | [diff] [blame] | 501 | if (docked_layout_manager_) { |
jamescook | be6ed82 | 2016-06-06 20:08:55 | [diff] [blame] | 502 | docked_layout_manager_->SetShelf(wm_shelf_aura_.get()); |
jamescook | 612205f | 2016-05-26 06:02:11 | [diff] [blame] | 503 | if (shelf_widget_->shelf_layout_manager()) |
| 504 | docked_layout_manager_->AddObserver( |
| 505 | shelf_widget_->shelf_layout_manager()); |
[email protected] | 7115bd3 | 2013-07-19 08:25:39 | [diff] [blame] | 506 | } |
[email protected] | b8642ec | 2014-04-17 05:20:39 | [diff] [blame] | 507 | |
| 508 | // Notify shell observers that the shelf has been created. |
sky | 80556bc4 | 2016-06-07 22:46:13 | [diff] [blame] | 509 | Shell::GetInstance()->OnShelfCreatedForRootWindow( |
| 510 | WmWindowAura::Get(GetRootWindow())); |
jamescook | 6500ad13 | 2016-05-27 06:15:54 | [diff] [blame] | 511 | |
| 512 | shelf_widget_->PostCreateShelf(); |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 513 | } |
| 514 | |
jamescook | 6afad6d | 2016-06-01 00:35:01 | [diff] [blame] | 515 | Shelf* RootWindowController::GetShelf() const { |
| 516 | // TODO(jamescook): Shelf should be owned by this class, not by ShelfWidget. |
| 517 | return shelf_widget_->shelf(); |
| 518 | } |
| 519 | |
sky | e79274a | 2016-06-08 05:39:02 | [diff] [blame] | 520 | void RootWindowController::UpdateAfterLoginStatusChange(LoginStatus status) { |
| 521 | if (status != LoginStatus::NOT_LOGGED_IN) |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 522 | mouse_event_target_.reset(); |
jamescook | 612205f | 2016-05-26 06:02:11 | [diff] [blame] | 523 | if (shelf_widget_->status_area_widget()) |
| 524 | shelf_widget_->status_area_widget()->UpdateAfterLoginStatusChange(status); |
[email protected] | 16059276d | 2012-10-22 18:59:50 | [diff] [blame] | 525 | } |
| 526 | |
[email protected] | bca9a7e | 2012-11-10 06:25:49 | [diff] [blame] | 527 | void RootWindowController::HandleInitialDesktopBackgroundAnimationStarted() { |
[email protected] | 252eb23 | 2013-08-14 22:09:27 | [diff] [blame] | 528 | #if defined(OS_CHROMEOS) |
pgal.u-szeged | d84534d3 | 2014-10-29 12:34:30 | [diff] [blame] | 529 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
[email protected] | bca9a7e | 2012-11-10 06:25:49 | [diff] [blame] | 530 | switches::kAshAnimateFromBootSplashScreen) && |
| 531 | boot_splash_screen_.get()) { |
| 532 | // Make the splash screen fade out so it doesn't obscure the desktop |
| 533 | // wallpaper's brightness/grayscale animation. |
| 534 | boot_splash_screen_->StartHideAnimation( |
| 535 | base::TimeDelta::FromMilliseconds(kBootSplashScreenHideDurationMs)); |
| 536 | } |
[email protected] | 252eb23 | 2013-08-14 22:09:27 | [diff] [blame] | 537 | #endif |
[email protected] | bca9a7e | 2012-11-10 06:25:49 | [diff] [blame] | 538 | } |
| 539 | |
[email protected] | 0bf6173 | 2013-07-02 04:35:10 | [diff] [blame] | 540 | void RootWindowController::OnWallpaperAnimationFinished(views::Widget* widget) { |
| 541 | // Make sure the wallpaper is visible. |
[email protected] | bca9a7e | 2012-11-10 06:25:49 | [diff] [blame] | 542 | system_background_->SetColor(SK_ColorBLACK); |
[email protected] | 252eb23 | 2013-08-14 22:09:27 | [diff] [blame] | 543 | #if defined(OS_CHROMEOS) |
[email protected] | bca9a7e | 2012-11-10 06:25:49 | [diff] [blame] | 544 | boot_splash_screen_.reset(); |
[email protected] | 252eb23 | 2013-08-14 22:09:27 | [diff] [blame] | 545 | #endif |
[email protected] | 0bf6173 | 2013-07-02 04:35:10 | [diff] [blame] | 546 | |
| 547 | Shell::GetInstance()->user_wallpaper_delegate()-> |
| 548 | OnWallpaperAnimationFinished(); |
| 549 | // Only removes old component when wallpaper animation finished. If we |
| 550 | // remove the old one before the new wallpaper is done fading in there will |
| 551 | // be a white flash during the animation. |
| 552 | if (animating_wallpaper_controller()) { |
| 553 | DesktopBackgroundWidgetController* controller = |
| 554 | animating_wallpaper_controller()->GetController(true); |
| 555 | // |desktop_widget_| should be the same animating widget we try to move |
| 556 | // to |kDesktopController|. Otherwise, we may close |desktop_widget_| |
| 557 | // before move it to |kDesktopController|. |
| 558 | DCHECK_EQ(controller->widget(), widget); |
| 559 | // Release the old controller and close its background widget. |
| 560 | SetWallpaperController(controller); |
| 561 | } |
[email protected] | 697f04c | 2012-10-03 01:15:10 | [diff] [blame] | 562 | } |
| 563 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 564 | void RootWindowController::CloseChildWindows() { |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 565 | mouse_event_target_.reset(); |
| 566 | |
[email protected] | 2a57beb5 | 2014-06-09 20:02:26 | [diff] [blame] | 567 | // Remove observer as deactivating keyboard causes |docked_layout_manager_| |
| 568 | // to fire notifications. |
jamescook | 612205f | 2016-05-26 06:02:11 | [diff] [blame] | 569 | if (docked_layout_manager_ && shelf_widget_ && |
| 570 | shelf_widget_->shelf_layout_manager()) |
| 571 | docked_layout_manager_->RemoveObserver( |
| 572 | shelf_widget_->shelf_layout_manager()); |
[email protected] | 2a57beb5 | 2014-06-09 20:02:26 | [diff] [blame] | 573 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 574 | // Deactivate keyboard container before closing child windows and shutting |
| 575 | // down associated layout managers. |
[email protected] | a0b3fb88 | 2014-04-07 19:26:03 | [diff] [blame] | 576 | DeactivateKeyboard(keyboard::KeyboardController::GetInstance()); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 577 | |
[email protected] | 79a87b7e | 2013-01-25 05:08:22 | [diff] [blame] | 578 | // panel_layout_manager_ needs to be shut down before windows are destroyed. |
| 579 | if (panel_layout_manager_) { |
| 580 | panel_layout_manager_->Shutdown(); |
| 581 | panel_layout_manager_ = NULL; |
| 582 | } |
[email protected] | 7115bd3 | 2013-07-19 08:25:39 | [diff] [blame] | 583 | // docked_layout_manager_ needs to be shut down before windows are destroyed. |
| 584 | if (docked_layout_manager_) { |
[email protected] | 7115bd3 | 2013-07-19 08:25:39 | [diff] [blame] | 585 | docked_layout_manager_->Shutdown(); |
| 586 | docked_layout_manager_ = NULL; |
| 587 | } |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 588 | aura::Window* root_window = GetRootWindow(); |
| 589 | aura::client::SetDragDropClient(root_window, NULL); |
[email protected] | 8b3e3d8 | 2013-08-20 14:36:30 | [diff] [blame] | 590 | |
jamescook | 612205f | 2016-05-26 06:02:11 | [diff] [blame] | 591 | if (shelf_widget_) |
| 592 | shelf_widget_->Shutdown(); |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 593 | |
jamescook | be6ed82 | 2016-06-06 20:08:55 | [diff] [blame] | 594 | wm_shelf_aura_->Shutdown(); |
| 595 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 596 | // Close background widget first as it depends on tooltip. |
[email protected] | 0bf6173 | 2013-07-02 04:35:10 | [diff] [blame] | 597 | wallpaper_controller_.reset(); |
| 598 | animating_wallpaper_controller_.reset(); |
[email protected] | b4ddc7a | 2012-08-07 04:17:32 | [diff] [blame] | 599 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 600 | workspace_controller_.reset(); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 601 | aura::client::SetTooltipClient(root_window, NULL); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 602 | |
[email protected] | 0fbfa97 | 2013-10-02 19:23:33 | [diff] [blame] | 603 | // Explicitly destroy top level windows. We do this as during part of |
| 604 | // destruction such windows may query the RootWindow for state. |
oshima | f38efa9 | 2015-10-27 19:06:52 | [diff] [blame] | 605 | aura::WindowTracker non_toplevel_windows; |
| 606 | non_toplevel_windows.Add(root_window); |
| 607 | while (!non_toplevel_windows.windows().empty()) { |
| 608 | const aura::Window* non_toplevel_window = |
| 609 | *non_toplevel_windows.windows().begin(); |
| 610 | non_toplevel_windows.Remove(const_cast<aura::Window*>(non_toplevel_window)); |
[email protected] | 8b3e3d8 | 2013-08-20 14:36:30 | [diff] [blame] | 611 | aura::WindowTracker toplevel_windows; |
| 612 | for (size_t i = 0; i < non_toplevel_window->children().size(); ++i) { |
| 613 | aura::Window* child = non_toplevel_window->children()[i]; |
[email protected] | 0fbfa97 | 2013-10-02 19:23:33 | [diff] [blame] | 614 | if (!child->owned_by_parent()) |
| 615 | continue; |
[email protected] | 8b3e3d8 | 2013-08-20 14:36:30 | [diff] [blame] | 616 | if (child->delegate()) |
| 617 | toplevel_windows.Add(child); |
| 618 | else |
oshima | f38efa9 | 2015-10-27 19:06:52 | [diff] [blame] | 619 | non_toplevel_windows.Add(child); |
[email protected] | 8b3e3d8 | 2013-08-20 14:36:30 | [diff] [blame] | 620 | } |
| 621 | while (!toplevel_windows.windows().empty()) |
| 622 | delete *toplevel_windows.windows().begin(); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 623 | } |
[email protected] | 8b3e3d8 | 2013-08-20 14:36:30 | [diff] [blame] | 624 | // And then remove the containers. |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 625 | while (!root_window->children().empty()) { |
| 626 | aura::Window* window = root_window->children()[0]; |
[email protected] | 0fbfa97 | 2013-10-02 19:23:33 | [diff] [blame] | 627 | if (window->owned_by_parent()) { |
| 628 | delete window; |
| 629 | } else { |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 630 | root_window->RemoveChild(window); |
[email protected] | 0fbfa97 | 2013-10-02 19:23:33 | [diff] [blame] | 631 | } |
| 632 | } |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 633 | |
jamescook | 612205f | 2016-05-26 06:02:11 | [diff] [blame] | 634 | shelf_widget_.reset(); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 635 | } |
| 636 | |
[email protected] | bf9cdb36 | 2013-10-25 19:22:45 | [diff] [blame] | 637 | void RootWindowController::MoveWindowsTo(aura::Window* dst) { |
[email protected] | 8039e06c | 2013-01-17 23:34:50 | [diff] [blame] | 638 | // Forget the shelf early so that shelf don't update itself using wrong |
| 639 | // display info. |
sky | 1e30f06 | 2016-04-14 21:19:16 | [diff] [blame] | 640 | workspace_controller_->SetShelf(nullptr); |
| 641 | workspace_controller_->layout_manager()->DeleteDelegate(); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 642 | ReparentAllWindows(GetRootWindow(), dst); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 643 | } |
| 644 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 645 | ShelfLayoutManager* RootWindowController::GetShelfLayoutManager() { |
jamescook | 612205f | 2016-05-26 06:02:11 | [diff] [blame] | 646 | return shelf_widget_->shelf_layout_manager(); |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 647 | } |
| 648 | |
[email protected] | a0afeb1 | 2012-12-10 22:57:09 | [diff] [blame] | 649 | SystemTray* RootWindowController::GetSystemTray() { |
| 650 | // We assume in throughout the code that this will not return NULL. If code |
| 651 | // triggers this for valid reasons, it should test status_area_widget first. |
jamescook | 612205f | 2016-05-26 06:02:11 | [diff] [blame] | 652 | CHECK(shelf_widget_->status_area_widget()); |
| 653 | return shelf_widget_->status_area_widget()->system_tray(); |
[email protected] | a0afeb1 | 2012-12-10 22:57:09 | [diff] [blame] | 654 | } |
| 655 | |
[email protected] | 940fb1c | 2013-06-18 16:54:28 | [diff] [blame] | 656 | void RootWindowController::ShowContextMenu(const gfx::Point& location_in_screen, |
| 657 | ui::MenuSourceType source_type) { |
msw | 141c6b2 | 2016-03-04 00:55:30 | [diff] [blame] | 658 | ShellDelegate* delegate = Shell::GetInstance()->delegate(); |
| 659 | DCHECK(delegate); |
jamescook | da53c14 | 2016-06-08 23:38:56 | [diff] [blame] | 660 | menu_model_.reset(delegate->CreateContextMenu(wm_shelf_aura_.get(), nullptr)); |
jonross | a90d898 | 2016-05-16 18:14:25 | [diff] [blame] | 661 | if (!menu_model_) |
[email protected] | 8e837ec | 2013-01-31 01:48:33 | [diff] [blame] | 662 | return; |
[email protected] | 431552c | 2012-10-23 00:38:33 | [diff] [blame] | 663 | |
jonross | a90d898 | 2016-05-16 18:14:25 | [diff] [blame] | 664 | menu_model_adapter_.reset(new views::MenuModelAdapter( |
| 665 | menu_model_.get(), |
| 666 | base::Bind(&RootWindowController::OnMenuClosed, base::Unretained(this)))); |
| 667 | |
[email protected] | 6175fc4 | 2013-04-05 05:58:58 | [diff] [blame] | 668 | // Background controller may not be set yet if user clicked on status are |
| 669 | // before initial animation completion. See crbug.com/222218 |
[email protected] | 0bf6173 | 2013-07-02 04:35:10 | [diff] [blame] | 670 | if (!wallpaper_controller_.get()) |
[email protected] | 431552c | 2012-10-23 00:38:33 | [diff] [blame] | 671 | return; |
| 672 | |
jonross | a90d898 | 2016-05-16 18:14:25 | [diff] [blame] | 673 | menu_runner_.reset(new views::MenuRunner( |
| 674 | menu_model_adapter_->CreateMenu(), |
| 675 | views::MenuRunner::CONTEXT_MENU | views::MenuRunner::ASYNC)); |
| 676 | ignore_result( |
| 677 | menu_runner_->RunMenuAt(wallpaper_controller_->widget(), NULL, |
| 678 | gfx::Rect(location_in_screen, gfx::Size()), |
| 679 | views::MENU_ANCHOR_TOPLEFT, source_type)); |
[email protected] | 431552c | 2012-10-23 00:38:33 | [diff] [blame] | 680 | } |
| 681 | |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 682 | void RootWindowController::UpdateShelfVisibility() { |
jamescook | 612205f | 2016-05-26 06:02:11 | [diff] [blame] | 683 | shelf_widget_->shelf_layout_manager()->UpdateVisibilityState(); |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 684 | } |
| 685 | |
varkha | d99fa94f | 2015-06-29 22:35:46 | [diff] [blame] | 686 | aura::Window* RootWindowController::GetWindowForFullscreenMode() { |
sky | 0702b27 | 2016-06-03 22:10:41 | [diff] [blame] | 687 | return WmWindowAura::GetAuraWindow( |
| 688 | wm::GetWindowForFullscreenMode(WmWindowAura::Get(GetRootWindow()))); |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 689 | } |
| 690 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 691 | void RootWindowController::ActivateKeyboard( |
| 692 | keyboard::KeyboardController* keyboard_controller) { |
| 693 | if (!keyboard::IsKeyboardEnabled() || |
| 694 | GetContainer(kShellWindowId_VirtualKeyboardContainer)) { |
| 695 | return; |
| 696 | } |
| 697 | DCHECK(keyboard_controller); |
jamescook | 612205f | 2016-05-26 06:02:11 | [diff] [blame] | 698 | keyboard_controller->AddObserver(shelf_widget()->shelf_layout_manager()); |
bshe | 9858b4a | 2014-09-16 20:46:38 | [diff] [blame] | 699 | keyboard_controller->AddObserver(panel_layout_manager_); |
| 700 | keyboard_controller->AddObserver(docked_layout_manager_); |
| 701 | keyboard_controller->AddObserver(workspace_controller_->layout_manager()); |
rsadam | 7bd510bb | 2014-12-09 20:10:56 | [diff] [blame] | 702 | keyboard_controller->AddObserver( |
| 703 | always_on_top_controller_->GetLayoutManager()); |
bshe | 9858b4a | 2014-09-16 20:46:38 | [diff] [blame] | 704 | Shell::GetInstance()->delegate()->VirtualKeyboardActivated(true); |
bshe | c387542 | 2014-09-29 13:21:30 | [diff] [blame] | 705 | aura::Window* parent = GetContainer(kShellWindowId_ImeWindowParentContainer); |
[email protected] | b2da9b60 | 2014-03-05 18:39:52 | [diff] [blame] | 706 | DCHECK(parent); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 707 | aura::Window* keyboard_container = |
| 708 | keyboard_controller->GetContainerWindow(); |
| 709 | keyboard_container->set_id(kShellWindowId_VirtualKeyboardContainer); |
| 710 | parent->AddChild(keyboard_container); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 711 | } |
[email protected] | 86459e2c | 2013-04-10 13:39:24 | [diff] [blame] | 712 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 713 | void RootWindowController::DeactivateKeyboard( |
| 714 | keyboard::KeyboardController* keyboard_controller) { |
[email protected] | e1b299b | 2014-01-29 23:53:41 | [diff] [blame] | 715 | if (!keyboard_controller || |
| 716 | !keyboard_controller->keyboard_container_initialized()) { |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 717 | return; |
[email protected] | e1b299b | 2014-01-29 23:53:41 | [diff] [blame] | 718 | } |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 719 | aura::Window* keyboard_container = |
| 720 | keyboard_controller->GetContainerWindow(); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 721 | if (keyboard_container->GetRootWindow() == GetRootWindow()) { |
bshe | c387542 | 2014-09-29 13:21:30 | [diff] [blame] | 722 | aura::Window* parent = |
| 723 | GetContainer(kShellWindowId_ImeWindowParentContainer); |
[email protected] | b2da9b60 | 2014-03-05 18:39:52 | [diff] [blame] | 724 | DCHECK(parent); |
| 725 | parent->RemoveChild(keyboard_container); |
bshe | 9858b4a | 2014-09-16 20:46:38 | [diff] [blame] | 726 | // Virtual keyboard may be deactivated while still showing, notify all |
| 727 | // observers that keyboard bounds changed to 0 before remove them. |
| 728 | keyboard_controller->NotifyKeyboardBoundsChanging(gfx::Rect()); |
jamescook | 612205f | 2016-05-26 06:02:11 | [diff] [blame] | 729 | keyboard_controller->RemoveObserver(shelf_widget()->shelf_layout_manager()); |
bshe | 9858b4a | 2014-09-16 20:46:38 | [diff] [blame] | 730 | keyboard_controller->RemoveObserver(panel_layout_manager_); |
| 731 | keyboard_controller->RemoveObserver(docked_layout_manager_); |
| 732 | keyboard_controller->RemoveObserver( |
| 733 | workspace_controller_->layout_manager()); |
rsadam | 7bd510bb | 2014-12-09 20:10:56 | [diff] [blame] | 734 | keyboard_controller->RemoveObserver( |
| 735 | always_on_top_controller_->GetLayoutManager()); |
bshe | 9858b4a | 2014-09-16 20:46:38 | [diff] [blame] | 736 | Shell::GetInstance()->delegate()->VirtualKeyboardActivated(false); |
[email protected] | 86459e2c | 2013-04-10 13:39:24 | [diff] [blame] | 737 | } |
| 738 | } |
| 739 | |
[email protected] | 602022b | 2014-03-31 17:07:31 | [diff] [blame] | 740 | bool RootWindowController::IsVirtualKeyboardWindow(aura::Window* window) { |
bshe | c387542 | 2014-09-29 13:21:30 | [diff] [blame] | 741 | aura::Window* parent = GetContainer(kShellWindowId_ImeWindowParentContainer); |
[email protected] | 602022b | 2014-03-31 17:07:31 | [diff] [blame] | 742 | return parent ? parent->Contains(window) : false; |
| 743 | } |
| 744 | |
dmazzoni | ff86e347 | 2016-06-03 19:52:32 | [diff] [blame] | 745 | void RootWindowController::SetTouchAccessibilityAnchorPoint( |
| 746 | const gfx::Point& anchor_point) { |
| 747 | #if defined(OS_CHROMEOS) |
| 748 | if (touch_exploration_manager_) |
| 749 | touch_exploration_manager_->SetTouchAccessibilityAnchorPoint(anchor_point); |
| 750 | #endif // defined(OS_CHROMEOS) |
| 751 | } |
| 752 | |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 753 | //////////////////////////////////////////////////////////////////////////////// |
| 754 | // RootWindowController, private: |
| 755 | |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 756 | RootWindowController::RootWindowController(AshWindowTreeHost* ash_host) |
| 757 | : ash_host_(ash_host), |
jamescook | be6ed82 | 2016-06-06 20:08:55 | [diff] [blame] | 758 | wm_shelf_aura_(new WmShelfAura), |
[email protected] | a273d33a | 2013-10-17 12:41:21 | [diff] [blame] | 759 | docked_layout_manager_(NULL), |
| 760 | panel_layout_manager_(NULL), |
| 761 | touch_hud_debug_(NULL), |
| 762 | touch_hud_projection_(NULL) { |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 763 | aura::Window* root_window = GetRootWindow(); |
sky | ee78dde | 2016-06-01 01:21:43 | [diff] [blame] | 764 | root_window_controller_common_.reset( |
sky | 0702b27 | 2016-06-03 22:10:41 | [diff] [blame] | 765 | new RootWindowControllerCommon(WmWindowAura::Get(root_window))); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 766 | GetRootWindowSettings(root_window)->controller = this; |
[email protected] | a273d33a | 2013-10-17 12:41:21 | [diff] [blame] | 767 | |
| 768 | stacking_controller_.reset(new StackingController); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 769 | aura::client::SetWindowTreeClient(root_window, stacking_controller_.get()); |
| 770 | capture_client_.reset(new ::wm::ScopedCaptureClient(root_window)); |
[email protected] | a273d33a | 2013-10-17 12:41:21 | [diff] [blame] | 771 | } |
| 772 | |
[email protected] | 608de6c | 2013-10-29 00:14:28 | [diff] [blame] | 773 | void RootWindowController::Init(RootWindowType root_window_type, |
| 774 | bool first_run_after_boot) { |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 775 | aura::Window* root_window = GetRootWindow(); |
[email protected] | 51f43811 | 2013-11-18 19:32:50 | [diff] [blame] | 776 | Shell* shell = Shell::GetInstance(); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 777 | shell->InitRootWindow(root_window); |
[email protected] | a273d33a | 2013-10-17 12:41:21 | [diff] [blame] | 778 | |
sky | ee78dde | 2016-06-01 01:21:43 | [diff] [blame] | 779 | root_window_controller_common_->CreateContainers(); |
[email protected] | 608de6c | 2013-10-29 00:14:28 | [diff] [blame] | 780 | |
[email protected] | a273d33a | 2013-10-17 12:41:21 | [diff] [blame] | 781 | CreateSystemBackground(first_run_after_boot); |
| 782 | |
| 783 | InitLayoutManagers(); |
| 784 | InitTouchHuds(); |
| 785 | |
| 786 | if (Shell::GetPrimaryRootWindowController()-> |
| 787 | GetSystemModalLayoutManager(NULL)->has_modal_background()) { |
| 788 | GetSystemModalLayoutManager(NULL)->CreateModalBackground(); |
| 789 | } |
| 790 | |
sky | 88bd4be6 | 2016-06-09 17:34:41 | [diff] [blame] | 791 | WmShell::Get()->AddShellObserver(this); |
[email protected] | a273d33a | 2013-10-17 12:41:21 | [diff] [blame] | 792 | |
sky | 7cd30704 | 2016-06-01 21:10:48 | [diff] [blame] | 793 | root_window_controller_common_->root_window_layout()->OnWindowResized(); |
[email protected] | 608de6c | 2013-10-29 00:14:28 | [diff] [blame] | 794 | if (root_window_type == PRIMARY) { |
bshe | 9858b4a | 2014-09-16 20:46:38 | [diff] [blame] | 795 | shell->InitKeyboard(); |
[email protected] | a273d33a | 2013-10-17 12:41:21 | [diff] [blame] | 796 | } else { |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 797 | ash_host_->AsWindowTreeHost()->Show(); |
[email protected] | a273d33a | 2013-10-17 12:41:21 | [diff] [blame] | 798 | |
[email protected] | 864b5855 | 2013-12-19 04:19:38 | [diff] [blame] | 799 | // Create a shelf if a user is already logged in. |
[email protected] | a273d33a | 2013-10-17 12:41:21 | [diff] [blame] | 800 | if (shell->session_state_delegate()->NumberOfLoggedInUsers()) |
jamescook | 6500ad13 | 2016-05-27 06:15:54 | [diff] [blame] | 801 | CreateShelf(); |
[email protected] | 0e3e7cb | 2014-04-12 05:18:25 | [diff] [blame] | 802 | |
| 803 | // Notify shell observers about new root window. |
sky | 80556bc4 | 2016-06-07 22:46:13 | [diff] [blame] | 804 | shell->OnRootWindowAdded(WmWindowAura::Get(root_window)); |
[email protected] | a273d33a | 2013-10-17 12:41:21 | [diff] [blame] | 805 | } |
[email protected] | a825e831 | 2014-05-05 22:05:01 | [diff] [blame] | 806 | |
| 807 | #if defined(OS_CHROMEOS) |
pgal.u-szeged | d84534d3 | 2014-10-29 12:34:30 | [diff] [blame] | 808 | if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
[email protected] | 2e0b235 | 2014-07-28 13:28:28 | [diff] [blame] | 809 | switches::kAshDisableTouchExplorationMode)) { |
[email protected] | 7d48759 | 2014-07-24 03:54:50 | [diff] [blame] | 810 | touch_exploration_manager_.reset(new AshTouchExplorationManager(this)); |
[email protected] | a825e831 | 2014-05-05 22:05:01 | [diff] [blame] | 811 | } |
| 812 | #endif |
[email protected] | a273d33a | 2013-10-17 12:41:21 | [diff] [blame] | 813 | } |
| 814 | |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 815 | void RootWindowController::InitLayoutManagers() { |
sky | 7cd30704 | 2016-06-01 21:10:48 | [diff] [blame] | 816 | root_window_controller_common_->CreateLayoutManagers(); |
| 817 | |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 818 | aura::Window* root_window = GetRootWindow(); |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 819 | |
| 820 | aura::Window* default_container = |
| 821 | GetContainer(kShellWindowId_DefaultContainer); |
| 822 | // Workspace manager has its own layout managers. |
sky | 1e30f06 | 2016-04-14 21:19:16 | [diff] [blame] | 823 | |
sky | e782a26 | 2016-05-31 20:28:57 | [diff] [blame] | 824 | aura::Window* modal_container = |
| 825 | root_window->GetChildById(kShellWindowId_SystemModalContainer); |
| 826 | DCHECK(modal_container); |
| 827 | modal_container->SetLayoutManager( |
| 828 | new SystemModalContainerLayoutManager(modal_container)); |
| 829 | |
| 830 | aura::Window* lock_container = |
| 831 | root_window->GetChildById(kShellWindowId_LockScreenContainer); |
| 832 | DCHECK(lock_container); |
| 833 | lock_container->SetLayoutManager(new LockLayoutManager(lock_container)); |
| 834 | |
| 835 | aura::Window* lock_modal_container = |
| 836 | root_window->GetChildById(kShellWindowId_LockSystemModalContainer); |
| 837 | DCHECK(lock_modal_container); |
| 838 | lock_modal_container->SetLayoutManager( |
| 839 | new SystemModalContainerLayoutManager(lock_modal_container)); |
| 840 | |
sky | 1e30f06 | 2016-04-14 21:19:16 | [diff] [blame] | 841 | WorkspaceLayoutManagerDelegateImpl* workspace_layout_manager_delegate = |
| 842 | new WorkspaceLayoutManagerDelegateImpl(root_window); |
| 843 | workspace_controller_.reset(new WorkspaceController( |
| 844 | default_container, base::WrapUnique(workspace_layout_manager_delegate))); |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 845 | |
sky | 0702b27 | 2016-06-03 22:10:41 | [diff] [blame] | 846 | WmWindow* always_on_top_container = |
| 847 | WmWindowAura::Get(GetContainer(kShellWindowId_AlwaysOnTopContainer)); |
rsadam | 7bd510bb | 2014-12-09 20:10:56 | [diff] [blame] | 848 | always_on_top_controller_.reset( |
| 849 | new AlwaysOnTopController(always_on_top_container)); |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 850 | |
jamescook | 612205f | 2016-05-26 06:02:11 | [diff] [blame] | 851 | DCHECK(!shelf_widget_.get()); |
sky | 0702b27 | 2016-06-03 22:10:41 | [diff] [blame] | 852 | WmWindow* shelf_container = |
| 853 | WmWindowAura::Get(GetContainer(kShellWindowId_ShelfContainer)); |
| 854 | WmWindow* status_container = |
| 855 | WmWindowAura::Get(GetContainer(kShellWindowId_StatusContainer)); |
jamescook | 612205f | 2016-05-26 06:02:11 | [diff] [blame] | 856 | shelf_widget_.reset(new ShelfWidget(shelf_container, status_container, |
jamescook | aada0db9 | 2016-06-17 22:10:02 | [diff] [blame] | 857 | wm_shelf_aura_.get(), |
jamescook | 612205f | 2016-05-26 06:02:11 | [diff] [blame] | 858 | workspace_controller())); |
| 859 | workspace_layout_manager_delegate->set_shelf( |
| 860 | shelf_widget_->shelf_layout_manager()); |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 861 | |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 862 | if (!Shell::GetInstance()->session_state_delegate()-> |
| 863 | IsActiveUserSessionStarted()) { |
| 864 | // This window exists only to be a event target on login screen. |
| 865 | // It does not have to handle events, nor be visible. |
| 866 | mouse_event_target_.reset(new aura::Window(new EmptyWindowDelegate)); |
danakj | b161836d | 2015-04-03 05:14:18 | [diff] [blame] | 867 | mouse_event_target_->Init(ui::LAYER_NOT_DRAWN); |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 868 | |
| 869 | aura::Window* lock_background_container = |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 870 | GetContainer(kShellWindowId_LockScreenBackgroundContainer); |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 871 | lock_background_container->AddChild(mouse_event_target_.get()); |
| 872 | mouse_event_target_->Show(); |
| 873 | } |
| 874 | |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 875 | // Create Docked windows layout manager |
sky | 0702b27 | 2016-06-03 22:10:41 | [diff] [blame] | 876 | WmWindow* docked_container = |
| 877 | WmWindowAura::Get(GetContainer(kShellWindowId_DockedContainer)); |
sky | ca412269 | 2016-04-26 04:47:57 | [diff] [blame] | 878 | docked_layout_manager_ = new DockedWindowLayoutManager(docked_container); |
sky | 3f7af881 | 2016-04-21 19:30:03 | [diff] [blame] | 879 | docked_container->SetLayoutManager(base::WrapUnique(docked_layout_manager_)); |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 880 | |
[email protected] | 1ca79d4 | 2014-07-18 16:26:10 | [diff] [blame] | 881 | // Installs SnapLayoutManager to containers who set the |
| 882 | // |kSnapsChildrenToPhysicalPixelBoundary| property. |
| 883 | wm::InstallSnapLayoutManagerToContainers(root_window); |
| 884 | |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 885 | // Create Panel layout manager |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 886 | aura::Window* panel_container = GetContainer(kShellWindowId_PanelContainer); |
sky | 0702b27 | 2016-06-03 22:10:41 | [diff] [blame] | 887 | WmWindow* wm_panel_container = WmWindowAura::Get(panel_container); |
sky | ad031502 | 2016-04-25 19:40:31 | [diff] [blame] | 888 | panel_layout_manager_ = new PanelLayoutManager(wm_panel_container); |
| 889 | wm_panel_container->SetLayoutManager(base::WrapUnique(panel_layout_manager_)); |
[email protected] | 3537d47 | 2014-01-15 05:45:31 | [diff] [blame] | 890 | panel_container_handler_.reset(new PanelWindowEventHandler); |
| 891 | panel_container->AddPreTargetHandler(panel_container_handler_.get()); |
[email protected] | b8642ec | 2014-04-17 05:20:39 | [diff] [blame] | 892 | |
| 893 | // Install an AttachedPanelWindowTargeter on the panel container to make it |
| 894 | // easier to correctly target shelf buttons with touch. |
| 895 | gfx::Insets mouse_extend(-kResizeOutsideBoundsSize, |
| 896 | -kResizeOutsideBoundsSize, |
| 897 | -kResizeOutsideBoundsSize, |
| 898 | -kResizeOutsideBoundsSize); |
| 899 | gfx::Insets touch_extend = mouse_extend.Scale( |
| 900 | kResizeOutsideBoundsScaleForTouch); |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 901 | panel_container->SetEventTargeter( |
| 902 | std::unique_ptr<ui::EventTargeter>(new AttachedPanelWindowTargeter( |
| 903 | panel_container, mouse_extend, touch_extend, panel_layout_manager_))); |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | void RootWindowController::InitTouchHuds() { |
pgal.u-szeged | d84534d3 | 2014-10-29 12:34:30 | [diff] [blame] | 907 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 908 | if (command_line->HasSwitch(switches::kAshTouchHud)) |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 909 | set_touch_hud_debug(new TouchHudDebug(GetRootWindow())); |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 910 | if (Shell::GetInstance()->is_touch_hud_projection_enabled()) |
| 911 | EnableTouchHudProjection(); |
| 912 | } |
| 913 | |
| 914 | void RootWindowController::CreateSystemBackground( |
| 915 | bool is_first_run_after_boot) { |
| 916 | SkColor color = SK_ColorBLACK; |
| 917 | #if defined(OS_CHROMEOS) |
| 918 | if (is_first_run_after_boot) |
| 919 | color = kChromeOsBootColor; |
| 920 | #endif |
| 921 | system_background_.reset( |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 922 | new SystemBackgroundController(GetRootWindow(), color)); |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 923 | |
| 924 | #if defined(OS_CHROMEOS) |
| 925 | // Make a copy of the system's boot splash screen so we can composite it |
| 926 | // onscreen until the desktop background is ready. |
| 927 | if (is_first_run_after_boot && |
pgal.u-szeged | d84534d3 | 2014-10-29 12:34:30 | [diff] [blame] | 928 | (base::CommandLine::ForCurrentProcess()->HasSwitch( |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 929 | switches::kAshCopyHostBackgroundAtBoot) || |
pgal.u-szeged | d84534d3 | 2014-10-29 12:34:30 | [diff] [blame] | 930 | base::CommandLine::ForCurrentProcess()->HasSwitch( |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 931 | switches::kAshAnimateFromBootSplashScreen))) |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 932 | boot_splash_screen_.reset(new BootSplashScreen(GetHost())); |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 933 | #endif |
| 934 | } |
| 935 | |
[email protected] | d141b92 | 2013-07-09 08:13:17 | [diff] [blame] | 936 | void RootWindowController::EnableTouchHudProjection() { |
| 937 | if (touch_hud_projection_) |
| 938 | return; |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 939 | set_touch_hud_projection(new TouchHudProjection(GetRootWindow())); |
[email protected] | d141b92 | 2013-07-09 08:13:17 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | void RootWindowController::DisableTouchHudProjection() { |
| 943 | if (!touch_hud_projection_) |
| 944 | return; |
| 945 | touch_hud_projection_->Remove(); |
| 946 | } |
| 947 | |
jonross | a90d898 | 2016-05-16 18:14:25 | [diff] [blame] | 948 | void RootWindowController::OnMenuClosed() { |
| 949 | menu_runner_.reset(); |
| 950 | menu_model_adapter_.reset(); |
| 951 | menu_model_.reset(); |
| 952 | Shell::GetInstance()->UpdateShelfVisibility(); |
| 953 | } |
| 954 | |
sky | e79274a | 2016-06-08 05:39:02 | [diff] [blame] | 955 | void RootWindowController::OnLoginStateChanged(LoginStatus status) { |
jamescook | 612205f | 2016-05-26 06:02:11 | [diff] [blame] | 956 | shelf_widget_->shelf_layout_manager()->UpdateVisibilityState(); |
[email protected] | d141b92 | 2013-07-09 08:13:17 | [diff] [blame] | 957 | } |
| 958 | |
| 959 | void RootWindowController::OnTouchHudProjectionToggled(bool enabled) { |
| 960 | if (enabled) |
| 961 | EnableTouchHudProjection(); |
| 962 | else |
| 963 | DisableTouchHudProjection(); |
| 964 | } |
| 965 | |
[email protected] | 6b2d4a0b | 2013-09-06 06:29:54 | [diff] [blame] | 966 | RootWindowController* GetRootWindowController( |
[email protected] | bf9cdb36 | 2013-10-25 19:22:45 | [diff] [blame] | 967 | const aura::Window* root_window) { |
jamescook | 5d74ac0 | 2016-05-12 19:57:12 | [diff] [blame] | 968 | if (!root_window) |
| 969 | return nullptr; |
| 970 | |
| 971 | if (Shell::GetInstance()->in_mus()) { |
| 972 | // On mus, like desktop aura, each top-level widget has its own root window, |
| 973 | // so |root_window| is not necessarily the display's root. For now, just |
| 974 | // the use the primary display root. |
| 975 | // TODO(jamescook): Multi-display support. This depends on how mus windows |
| 976 | // will be owned by displays. |
| 977 | aura::Window* primary_root_window = Shell::GetInstance() |
| 978 | ->window_tree_host_manager() |
| 979 | ->GetPrimaryRootWindow(); |
| 980 | return GetRootWindowSettings(primary_root_window)->controller; |
| 981 | } |
| 982 | |
| 983 | return GetRootWindowSettings(root_window)->controller; |
[email protected] | 6b2d4a0b | 2013-09-06 06:29:54 | [diff] [blame] | 984 | } |
| 985 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 986 | } // namespace ash |