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