[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] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 7 | #include <vector> |
| 8 | |
[email protected] | b4ddc7a | 2012-08-07 04:17:32 | [diff] [blame] | 9 | #include "ash/desktop_background/desktop_background_widget_controller.h" |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 10 | #include "ash/display/display_controller.h" |
[email protected] | 6675e1c | 2012-09-11 09:15:45 | [diff] [blame] | 11 | #include "ash/display/multi_display_manager.h" |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 12 | #include "ash/focus_cycler.h" |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 13 | #include "ash/shell.h" |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 14 | #include "ash/shell_delegate.h" |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 15 | #include "ash/shell_factory.h" |
| 16 | #include "ash/shell_window_ids.h" |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 17 | #include "ash/system/status_area_widget.h" |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 18 | #include "ash/system/tray/system_tray_delegate.h" |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 19 | #include "ash/wm/base_layout_manager.h" |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 20 | #include "ash/wm/panel_layout_manager.h" |
| 21 | #include "ash/wm/panel_window_event_filter.h" |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 22 | #include "ash/wm/property_util.h" |
| 23 | #include "ash/wm/root_window_layout_manager.h" |
| 24 | #include "ash/wm/screen_dimmer.h" |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 25 | #include "ash/wm/shelf_layout_manager.h" |
| 26 | #include "ash/wm/shelf_types.h" |
| 27 | #include "ash/wm/status_area_layout_manager.h" |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 28 | #include "ash/wm/system_modal_container_layout_manager.h" |
[email protected] | 5dc51db8 | 2012-09-11 03:39:01 | [diff] [blame] | 29 | #include "ash/wm/toplevel_window_event_handler.h" |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 30 | #include "ash/wm/visibility_controller.h" |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 31 | #include "ash/wm/window_properties.h" |
[email protected] | c601e73 | 2012-10-11 15:39:37 | [diff] [blame] | 32 | #include "ash/wm/workspace/colored_window_controller.h" |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 33 | #include "ash/wm/workspace_controller.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 34 | #include "ui/aura/client/activation_client.h" |
| 35 | #include "ui/aura/client/aura_constants.h" |
| 36 | #include "ui/aura/client/capture_client.h" |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 37 | #include "ui/aura/client/tooltip_client.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 38 | #include "ui/aura/focus_manager.h" |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 39 | #include "ui/aura/root_window.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 40 | #include "ui/aura/window.h" |
| 41 | #include "ui/aura/window_observer.h" |
[email protected] | 1d03024 | 2012-06-28 18:34:08 | [diff] [blame] | 42 | #include "ui/aura/window_tracker.h" |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 43 | #include "ui/gfx/display.h" |
| 44 | #include "ui/gfx/screen.h" |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 45 | |
| 46 | namespace ash { |
| 47 | namespace { |
| 48 | |
[email protected] | 697f04c | 2012-10-03 01:15:10 | [diff] [blame] | 49 | #if defined(OS_CHROMEOS) |
| 50 | // Color initially used for the system background after the system has first |
| 51 | // booted. |
| 52 | const SkColor kBootSystemBackgroundColor = 0xFFFEFEFE; |
| 53 | #endif |
| 54 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 55 | // Creates a new window for use as a container. |
| 56 | aura::Window* CreateContainer(int window_id, |
| 57 | const char* name, |
| 58 | aura::Window* parent) { |
| 59 | aura::Window* container = new aura::Window(NULL); |
| 60 | container->set_id(window_id); |
| 61 | container->SetName(name); |
| 62 | container->Init(ui::LAYER_NOT_DRAWN); |
| 63 | parent->AddChild(container); |
| 64 | if (window_id != internal::kShellWindowId_UnparentedControlContainer) |
| 65 | container->Show(); |
| 66 | return container; |
| 67 | } |
| 68 | |
[email protected] | 9505857 | 2012-08-20 14:57:29 | [diff] [blame] | 69 | // Returns all the children of the workspace windows, eg the standard top-level |
| 70 | // windows. |
| 71 | std::vector<aura::Window*> GetWorkspaceWindows(aura::RootWindow* root) { |
| 72 | using aura::Window; |
| 73 | |
| 74 | std::vector<Window*> windows; |
| 75 | Window* container = Shell::GetContainer( |
| 76 | root, internal::kShellWindowId_DefaultContainer); |
| 77 | for (Window::Windows::const_reverse_iterator i = |
| 78 | container->children().rbegin(); |
| 79 | i != container->children().rend(); ++i) { |
| 80 | Window* workspace_window = *i; |
| 81 | if (workspace_window->id() == internal::kShellWindowId_WorkspaceContainer) { |
| 82 | windows.insert(windows.end(), workspace_window->children().begin(), |
| 83 | workspace_window->children().end()); |
| 84 | } |
| 85 | } |
| 86 | return windows; |
| 87 | } |
| 88 | |
| 89 | // Reparents |window| to |new_parent|. |
| 90 | void ReparentWindow(aura::Window* window, aura::Window* new_parent) { |
| 91 | // Update the restore bounds to make it relative to the display. |
| 92 | gfx::Rect restore_bounds(GetRestoreBoundsInParent(window)); |
| 93 | new_parent->AddChild(window); |
| 94 | if (!restore_bounds.IsEmpty()) |
| 95 | SetRestoreBoundsInParent(window, restore_bounds); |
| 96 | } |
| 97 | |
| 98 | // Reparents the appropriate set of windows from |src| to |dst|. |
| 99 | void ReparentAllWindows(aura::RootWindow* src, aura::RootWindow* dst) { |
| 100 | // Set of windows to move. |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 101 | const int kContainerIdsToMove[] = { |
| 102 | internal::kShellWindowId_DefaultContainer, |
| 103 | internal::kShellWindowId_AlwaysOnTopContainer, |
| 104 | internal::kShellWindowId_SystemModalContainer, |
| 105 | internal::kShellWindowId_LockSystemModalContainer, |
[email protected] | 6274d31 | 2012-10-04 22:06:41 | [diff] [blame] | 106 | internal::kShellWindowId_InputMethodContainer, |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 107 | }; |
[email protected] | 9505857 | 2012-08-20 14:57:29 | [diff] [blame] | 108 | // For Workspace2 we need to manually reparent the windows. This way |
| 109 | // Workspace2 can move the windows to the appropriate workspace. |
[email protected] | c96b981 | 2012-10-17 16:04:04 | [diff] [blame^] | 110 | std::vector<aura::Window*> windows(GetWorkspaceWindows(src)); |
| 111 | internal::WorkspaceController* workspace_controller = |
| 112 | GetRootWindowController(dst)->workspace_controller(); |
| 113 | for (size_t i = 0; i < windows.size(); ++i) { |
| 114 | aura::Window* new_parent = |
| 115 | workspace_controller->GetParentForNewWindow(windows[i]); |
| 116 | ReparentWindow(windows[i], new_parent); |
[email protected] | 9505857 | 2012-08-20 14:57:29 | [diff] [blame] | 117 | } |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 118 | for (size_t i = 0; i < arraysize(kContainerIdsToMove); i++) { |
| 119 | int id = kContainerIdsToMove[i]; |
[email protected] | c96b981 | 2012-10-17 16:04:04 | [diff] [blame^] | 120 | if (id == internal::kShellWindowId_DefaultContainer) |
[email protected] | 9505857 | 2012-08-20 14:57:29 | [diff] [blame] | 121 | continue; |
| 122 | |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 123 | aura::Window* src_container = Shell::GetContainer(src, id); |
| 124 | aura::Window* dst_container = Shell::GetContainer(dst, id); |
| 125 | aura::Window::Windows children = src_container->children(); |
| 126 | for (aura::Window::Windows::iterator iter = children.begin(); |
| 127 | iter != children.end(); ++iter) { |
| 128 | aura::Window* window = *iter; |
| 129 | // Don't move modal screen. |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 130 | if (internal::SystemModalContainerLayoutManager::IsModalBackground( |
| 131 | window)) |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 132 | continue; |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 133 | |
[email protected] | 9505857 | 2012-08-20 14:57:29 | [diff] [blame] | 134 | ReparentWindow(window, dst_container); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 135 | } |
| 136 | } |
| 137 | } |
| 138 | |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 139 | // Mark the container window so that a widget added to this container will |
| 140 | // use the virtual screeen coordinates instead of parent. |
| 141 | void SetUsesScreenCoordinates(aura::Window* container) { |
| 142 | container->SetProperty(internal::kUsesScreenCoordinatesKey, true); |
| 143 | } |
| 144 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 145 | } // namespace |
| 146 | |
| 147 | namespace internal { |
| 148 | |
| 149 | RootWindowController::RootWindowController(aura::RootWindow* root_window) |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 150 | : root_window_(root_window), |
| 151 | root_window_layout_(NULL), |
| 152 | status_area_widget_(NULL), |
| 153 | shelf_(NULL), |
| 154 | panel_layout_manager_(NULL) { |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 155 | SetRootWindowController(root_window, this); |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 156 | screen_dimmer_.reset(new ScreenDimmer(root_window)); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | RootWindowController::~RootWindowController() { |
[email protected] | 6675e1c | 2012-09-11 09:15:45 | [diff] [blame] | 160 | Shutdown(); |
| 161 | root_window_.reset(); |
| 162 | } |
| 163 | |
| 164 | void RootWindowController::Shutdown() { |
| 165 | CloseChildWindows(); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 166 | if (Shell::GetActiveRootWindow() == root_window_.get()) { |
| 167 | Shell::GetInstance()->set_active_root_window( |
| 168 | Shell::GetPrimaryRootWindow() == root_window_.get() ? |
| 169 | NULL : Shell::GetPrimaryRootWindow()); |
| 170 | } |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 171 | SetRootWindowController(root_window_.get(), NULL); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 172 | screen_dimmer_.reset(); |
| 173 | workspace_controller_.reset(); |
[email protected] | 6675e1c | 2012-09-11 09:15:45 | [diff] [blame] | 174 | // Forget with the display ID so that display lookup |
| 175 | // ends up with invalid display. |
| 176 | root_window_->ClearProperty(kDisplayIdKey); |
| 177 | // And this root window should no longer process events. |
| 178 | root_window_->PrepareForShutdown(); |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 179 | |
| 180 | // Launcher widget has an InputMethodBridge that references to |
| 181 | // |input_method_filter_|'s |input_method_|. So explicitly release |
| 182 | // |launcher_| before |input_method_filter_|. And this needs to be |
| 183 | // after we delete all containers in case there are still live |
| 184 | // browser windows which access LauncherModel during close. |
| 185 | launcher_.reset(); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 186 | } |
| 187 | |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 188 | SystemModalContainerLayoutManager* |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 189 | RootWindowController::GetSystemModalLayoutManager(aura::Window* window) { |
| 190 | aura::Window* container = NULL; |
| 191 | if (window) { |
| 192 | container = GetContainer( |
| 193 | kShellWindowId_LockSystemModalContainer); |
| 194 | if (!container->Contains(window)) |
| 195 | container = GetContainer(kShellWindowId_SystemModalContainer); |
| 196 | } else { |
| 197 | user::LoginStatus login = Shell::GetInstance()->tray_delegate() ? |
| 198 | Shell::GetInstance()->tray_delegate()->GetUserLoginStatus() : |
| 199 | user::LOGGED_IN_NONE; |
| 200 | int modal_window_id = (login == user::LOGGED_IN_LOCKED || |
| 201 | login == user::LOGGED_IN_NONE) ? |
| 202 | kShellWindowId_LockSystemModalContainer : |
| 203 | kShellWindowId_SystemModalContainer; |
| 204 | container = GetContainer(modal_window_id); |
| 205 | } |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 206 | return static_cast<SystemModalContainerLayoutManager*>( |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 207 | container->layout_manager()); |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 208 | } |
| 209 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 210 | aura::Window* RootWindowController::GetContainer(int container_id) { |
| 211 | return root_window_->GetChildById(container_id); |
| 212 | } |
| 213 | |
| 214 | void RootWindowController::InitLayoutManagers() { |
| 215 | root_window_layout_ = |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 216 | new RootWindowLayoutManager(root_window_.get()); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 217 | root_window_->SetLayoutManager(root_window_layout_); |
| 218 | |
| 219 | aura::Window* default_container = |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 220 | GetContainer(kShellWindowId_DefaultContainer); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 221 | // Workspace manager has its own layout managers. |
| 222 | workspace_controller_.reset( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 223 | new WorkspaceController(default_container)); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 224 | |
| 225 | aura::Window* always_on_top_container = |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 226 | GetContainer(kShellWindowId_AlwaysOnTopContainer); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 227 | always_on_top_container->SetLayoutManager( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 228 | new BaseLayoutManager( |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 229 | always_on_top_container->GetRootWindow())); |
| 230 | } |
| 231 | |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 232 | void RootWindowController::InitForPrimaryDisplay() { |
| 233 | DCHECK(!status_area_widget_); |
| 234 | ShellDelegate* delegate = Shell::GetInstance()->delegate(); |
| 235 | |
| 236 | // Initialize Primary RootWindow specific items. |
| 237 | status_area_widget_ = new internal::StatusAreaWidget(); |
| 238 | status_area_widget_->CreateTrayViews(delegate); |
| 239 | // Login screen manages status area visibility by itself. |
| 240 | if (delegate && delegate->IsSessionStarted()) |
| 241 | status_area_widget_->Show(); |
| 242 | |
| 243 | Shell::GetInstance()->focus_cycler()->AddWidget(status_area_widget_); |
| 244 | |
| 245 | internal::ShelfLayoutManager* shelf_layout_manager = |
| 246 | new internal::ShelfLayoutManager(status_area_widget_); |
| 247 | GetContainer(internal::kShellWindowId_LauncherContainer)-> |
| 248 | SetLayoutManager(shelf_layout_manager); |
| 249 | shelf_ = shelf_layout_manager; |
| 250 | |
| 251 | internal::StatusAreaLayoutManager* status_area_layout_manager = |
| 252 | new internal::StatusAreaLayoutManager(shelf_layout_manager); |
| 253 | GetContainer(internal::kShellWindowId_StatusContainer)-> |
| 254 | SetLayoutManager(status_area_layout_manager); |
| 255 | |
| 256 | shelf_layout_manager->set_workspace_controller( |
| 257 | workspace_controller()); |
| 258 | |
| 259 | workspace_controller()->SetShelf(shelf_); |
| 260 | |
| 261 | // Create Panel layout manager |
| 262 | aura::Window* panel_container = GetContainer( |
| 263 | internal::kShellWindowId_PanelContainer); |
| 264 | panel_layout_manager_ = |
| 265 | new internal::PanelLayoutManager(panel_container); |
| 266 | panel_container->SetEventFilter( |
| 267 | new internal::PanelWindowEventFilter( |
| 268 | panel_container, panel_layout_manager_)); |
| 269 | panel_container->SetLayoutManager(panel_layout_manager_); |
| 270 | |
| 271 | if (!delegate || delegate->IsUserLoggedIn()) |
| 272 | CreateLauncher(); |
| 273 | } |
| 274 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 275 | void RootWindowController::CreateContainers() { |
| 276 | CreateContainersInRootWindow(root_window_.get()); |
| 277 | } |
| 278 | |
[email protected] | 697f04c | 2012-10-03 01:15:10 | [diff] [blame] | 279 | void RootWindowController::CreateSystemBackground( |
| 280 | bool is_first_run_after_boot) { |
| 281 | SkColor color = SK_ColorBLACK; |
| 282 | #if defined(OS_CHROMEOS) |
| 283 | if (is_first_run_after_boot) |
| 284 | color = kBootSystemBackgroundColor; |
| 285 | #endif |
[email protected] | c601e73 | 2012-10-11 15:39:37 | [diff] [blame] | 286 | background_.reset(new ColoredWindowController( |
| 287 | root_window_->GetChildById(kShellWindowId_SystemBackgroundContainer), |
| 288 | "SystemBackground")); |
| 289 | background_->SetColor(color); |
| 290 | background_->GetWidget()->Show(); |
[email protected] | 697f04c | 2012-10-03 01:15:10 | [diff] [blame] | 291 | } |
| 292 | |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 293 | void RootWindowController::CreateLauncher() { |
| 294 | if (launcher_.get()) |
| 295 | return; |
| 296 | |
| 297 | aura::Window* default_container = |
| 298 | GetContainer(internal::kShellWindowId_DefaultContainer); |
| 299 | launcher_.reset(new Launcher(default_container, shelf_)); |
| 300 | |
| 301 | launcher_->SetFocusCycler(Shell::GetInstance()->focus_cycler()); |
| 302 | shelf_->SetLauncher(launcher_.get()); |
| 303 | |
| 304 | if (panel_layout_manager_) |
| 305 | panel_layout_manager_->SetLauncher(launcher_.get()); |
| 306 | |
| 307 | ShellDelegate* delegate = Shell::GetInstance()->delegate(); |
| 308 | if (delegate) |
| 309 | launcher_->SetVisible(delegate->IsSessionStarted()); |
| 310 | launcher_->widget()->Show(); |
| 311 | } |
| 312 | |
| 313 | void RootWindowController::ShowLauncher() { |
| 314 | if (!launcher_.get()) |
| 315 | return; |
| 316 | launcher_->SetVisible(true); |
| 317 | } |
| 318 | |
[email protected] | 697f04c | 2012-10-03 01:15:10 | [diff] [blame] | 319 | void RootWindowController::HandleDesktopBackgroundVisible() { |
| 320 | if (background_.get()) |
| 321 | background_->SetColor(SK_ColorBLACK); |
| 322 | } |
| 323 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 324 | void RootWindowController::CloseChildWindows() { |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 325 | // The status area needs to be shut down before the windows are destroyed. |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 326 | if (status_area_widget_) { |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 327 | status_area_widget_->Shutdown(); |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 328 | status_area_widget_ = NULL; |
| 329 | } |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 330 | |
| 331 | // Closing the windows frees the workspace controller. |
| 332 | if (shelf_) |
| 333 | shelf_->set_workspace_controller(NULL); |
| 334 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 335 | // Close background widget first as it depends on tooltip. |
[email protected] | d86de6b2 | 2012-10-05 19:32:58 | [diff] [blame] | 336 | root_window_->SetProperty(kDesktopController, |
[email protected] | b4ddc7a | 2012-08-07 04:17:32 | [diff] [blame] | 337 | static_cast<DesktopBackgroundWidgetController*>(NULL)); |
[email protected] | d86de6b2 | 2012-10-05 19:32:58 | [diff] [blame] | 338 | root_window_->SetProperty(kAnimatingDesktopController, |
| 339 | static_cast<AnimatingDesktopController*>(NULL)); |
[email protected] | b4ddc7a | 2012-08-07 04:17:32 | [diff] [blame] | 340 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 341 | workspace_controller_.reset(); |
| 342 | aura::client::SetTooltipClient(root_window_.get(), NULL); |
| 343 | |
| 344 | while (!root_window_->children().empty()) { |
| 345 | aura::Window* child = root_window_->children()[0]; |
| 346 | delete child; |
| 347 | } |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 348 | |
| 349 | // All containers are deleted, so reset shelf_. |
| 350 | shelf_ = NULL; |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 351 | } |
| 352 | |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 353 | void RootWindowController::MoveWindowsTo(aura::RootWindow* dst) { |
| 354 | aura::Window* focused = dst->GetFocusManager()->GetFocusedWindow(); |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 355 | aura::WindowTracker tracker; |
| 356 | if (focused) |
| 357 | tracker.Add(focused); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 358 | aura::client::ActivationClient* activation_client = |
| 359 | aura::client::GetActivationClient(dst); |
| 360 | aura::Window* active = activation_client->GetActiveWindow(); |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 361 | if (active && focused != active) |
| 362 | tracker.Add(active); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 363 | // Deactivate the window to close menu / bubble windows. |
| 364 | activation_client->DeactivateWindow(active); |
| 365 | // Release capture if any. |
| 366 | aura::client::GetCaptureClient(root_window_.get())-> |
| 367 | SetCapture(NULL); |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 368 | // Clear the focused window if any. This is necessary because a |
| 369 | // window may be deleted when losing focus (fullscreen flash for |
| 370 | // example). If the focused window is still alive after move, it'll |
| 371 | // be re-focused below. |
| 372 | dst->GetFocusManager()->SetFocusedWindow(NULL, NULL); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 373 | |
[email protected] | 9505857 | 2012-08-20 14:57:29 | [diff] [blame] | 374 | ReparentAllWindows(root_window_.get(), dst); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 375 | |
| 376 | // Restore focused or active window if it's still alive. |
[email protected] | 1d03024 | 2012-06-28 18:34:08 | [diff] [blame] | 377 | if (focused && tracker.Contains(focused) && dst->Contains(focused)) { |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 378 | dst->GetFocusManager()->SetFocusedWindow(focused, NULL); |
[email protected] | 1d03024 | 2012-06-28 18:34:08 | [diff] [blame] | 379 | } else if (active && tracker.Contains(active) && dst->Contains(active)) { |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 380 | activation_client->ActivateWindow(active); |
| 381 | } |
| 382 | } |
| 383 | |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 384 | void RootWindowController::UpdateShelfVisibility() { |
| 385 | shelf_->UpdateVisibilityState(); |
| 386 | } |
| 387 | |
| 388 | void RootWindowController::SetShelfAutoHideBehavior( |
| 389 | ShelfAutoHideBehavior behavior) { |
| 390 | shelf_->SetAutoHideBehavior(behavior); |
| 391 | } |
| 392 | |
| 393 | ShelfAutoHideBehavior RootWindowController::GetShelfAutoHideBehavior() const { |
| 394 | return shelf_->auto_hide_behavior(); |
| 395 | } |
| 396 | |
| 397 | bool RootWindowController::SetShelfAlignment(ShelfAlignment alignment) { |
| 398 | return shelf_->SetAlignment(alignment); |
| 399 | } |
| 400 | |
| 401 | ShelfAlignment RootWindowController::GetShelfAlignment() { |
| 402 | return shelf_->alignment(); |
| 403 | } |
| 404 | |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 405 | //////////////////////////////////////////////////////////////////////////////// |
| 406 | // RootWindowController, private: |
| 407 | |
| 408 | void RootWindowController::CreateContainersInRootWindow( |
| 409 | aura::RootWindow* root_window) { |
| 410 | // These containers are just used by PowerButtonController to animate groups |
| 411 | // of containers simultaneously without messing up the current transformations |
| 412 | // on those containers. These are direct children of the root window; all of |
| 413 | // the other containers are their children. |
| 414 | // Desktop and lock screen background containers are not part of the |
| 415 | // lock animation so they are not included in those animate groups. |
| 416 | // When screen is locked desktop background is moved to lock screen background |
| 417 | // container (moved back on unlock). We want to make sure that there's an |
| 418 | // opaque layer occluding the non-lock-screen layers. |
| 419 | |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 420 | CreateContainer(kShellWindowId_SystemBackgroundContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 421 | "SystemBackgroundContainer", root_window); |
| 422 | |
| 423 | aura::Window* desktop_background_containers = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 424 | kShellWindowId_DesktopBackgroundContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 425 | "DesktopBackgroundContainer", |
| 426 | root_window); |
| 427 | SetChildWindowVisibilityChangesAnimated(desktop_background_containers); |
| 428 | |
| 429 | aura::Window* non_lock_screen_containers = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 430 | kShellWindowId_NonLockScreenContainersContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 431 | "NonLockScreenContainersContainer", |
| 432 | root_window); |
| 433 | |
| 434 | aura::Window* lock_background_containers = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 435 | kShellWindowId_LockScreenBackgroundContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 436 | "LockScreenBackgroundContainer", |
| 437 | root_window); |
| 438 | SetChildWindowVisibilityChangesAnimated(lock_background_containers); |
| 439 | |
| 440 | aura::Window* lock_screen_containers = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 441 | kShellWindowId_LockScreenContainersContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 442 | "LockScreenContainersContainer", |
| 443 | root_window); |
| 444 | aura::Window* lock_screen_related_containers = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 445 | kShellWindowId_LockScreenRelatedContainersContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 446 | "LockScreenRelatedContainersContainer", |
| 447 | root_window); |
| 448 | |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 449 | CreateContainer(kShellWindowId_UnparentedControlContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 450 | "UnparentedControlContainer", |
| 451 | non_lock_screen_containers); |
| 452 | |
| 453 | aura::Window* default_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 454 | kShellWindowId_DefaultContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 455 | "DefaultContainer", |
| 456 | non_lock_screen_containers); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 457 | SetChildWindowVisibilityChangesAnimated(default_container); |
| 458 | SetUsesScreenCoordinates(default_container); |
| 459 | |
| 460 | aura::Window* always_on_top_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 461 | kShellWindowId_AlwaysOnTopContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 462 | "AlwaysOnTopContainer", |
| 463 | non_lock_screen_containers); |
| 464 | always_on_top_container_handler_.reset( |
| 465 | new ToplevelWindowEventHandler(always_on_top_container)); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 466 | SetChildWindowVisibilityChangesAnimated(always_on_top_container); |
| 467 | SetUsesScreenCoordinates(always_on_top_container); |
| 468 | |
| 469 | aura::Window* panel_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 470 | kShellWindowId_PanelContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 471 | "PanelContainer", |
| 472 | non_lock_screen_containers); |
| 473 | SetUsesScreenCoordinates(panel_container); |
| 474 | |
| 475 | aura::Window* launcher_container = |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 476 | CreateContainer(kShellWindowId_LauncherContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 477 | "LauncherContainer", |
| 478 | non_lock_screen_containers); |
| 479 | SetUsesScreenCoordinates(launcher_container); |
| 480 | |
[email protected] | dc851a4e5 | 2012-10-03 00:05:55 | [diff] [blame] | 481 | aura::Window* app_list_container = |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 482 | CreateContainer(kShellWindowId_AppListContainer, |
[email protected] | dc851a4e5 | 2012-10-03 00:05:55 | [diff] [blame] | 483 | "AppListContainer", |
| 484 | non_lock_screen_containers); |
| 485 | SetUsesScreenCoordinates(app_list_container); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 486 | |
| 487 | aura::Window* modal_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 488 | kShellWindowId_SystemModalContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 489 | "SystemModalContainer", |
| 490 | non_lock_screen_containers); |
| 491 | modal_container_handler_.reset( |
| 492 | new ToplevelWindowEventHandler(modal_container)); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 493 | modal_container->SetLayoutManager( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 494 | new SystemModalContainerLayoutManager(modal_container)); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 495 | SetChildWindowVisibilityChangesAnimated(modal_container); |
| 496 | SetUsesScreenCoordinates(modal_container); |
| 497 | |
| 498 | aura::Window* input_method_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 499 | kShellWindowId_InputMethodContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 500 | "InputMethodContainer", |
| 501 | non_lock_screen_containers); |
| 502 | SetUsesScreenCoordinates(input_method_container); |
| 503 | |
| 504 | // TODO(beng): Figure out if we can make this use |
| 505 | // SystemModalContainerEventFilter instead of stops_event_propagation. |
| 506 | aura::Window* lock_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 507 | kShellWindowId_LockScreenContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 508 | "LockScreenContainer", |
| 509 | lock_screen_containers); |
| 510 | lock_container->SetLayoutManager( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 511 | new BaseLayoutManager(root_window)); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 512 | SetUsesScreenCoordinates(lock_container); |
| 513 | // TODO(beng): stopsevents |
| 514 | |
| 515 | aura::Window* lock_modal_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 516 | kShellWindowId_LockSystemModalContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 517 | "LockSystemModalContainer", |
| 518 | lock_screen_containers); |
| 519 | lock_modal_container_handler_.reset( |
| 520 | new ToplevelWindowEventHandler(lock_modal_container)); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 521 | lock_modal_container->SetLayoutManager( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 522 | new SystemModalContainerLayoutManager(lock_modal_container)); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 523 | SetChildWindowVisibilityChangesAnimated(lock_modal_container); |
| 524 | SetUsesScreenCoordinates(lock_modal_container); |
| 525 | |
| 526 | aura::Window* status_container = |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 527 | CreateContainer(kShellWindowId_StatusContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 528 | "StatusContainer", |
| 529 | lock_screen_related_containers); |
| 530 | SetUsesScreenCoordinates(status_container); |
| 531 | |
| 532 | aura::Window* settings_bubble_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 533 | kShellWindowId_SettingBubbleContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 534 | "SettingBubbleContainer", |
| 535 | lock_screen_related_containers); |
| 536 | SetChildWindowVisibilityChangesAnimated(settings_bubble_container); |
| 537 | SetUsesScreenCoordinates(settings_bubble_container); |
| 538 | |
| 539 | aura::Window* menu_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 540 | kShellWindowId_MenuContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 541 | "MenuContainer", |
| 542 | lock_screen_related_containers); |
| 543 | SetChildWindowVisibilityChangesAnimated(menu_container); |
| 544 | SetUsesScreenCoordinates(menu_container); |
| 545 | |
| 546 | aura::Window* drag_drop_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 547 | kShellWindowId_DragImageAndTooltipContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 548 | "DragImageAndTooltipContainer", |
| 549 | lock_screen_related_containers); |
| 550 | SetChildWindowVisibilityChangesAnimated(drag_drop_container); |
| 551 | SetUsesScreenCoordinates(drag_drop_container); |
| 552 | |
| 553 | aura::Window* overlay_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 554 | kShellWindowId_OverlayContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 555 | "OverlayContainer", |
| 556 | lock_screen_related_containers); |
| 557 | SetUsesScreenCoordinates(overlay_container); |
| 558 | } |
| 559 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 560 | } // namespace internal |
| 561 | } // namespace ash |