[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] | 431552c | 2012-10-23 00:38:33 | [diff] [blame^] | 43 | #include "ui/base/models/menu_model.h" |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 44 | #include "ui/gfx/display.h" |
| 45 | #include "ui/gfx/screen.h" |
[email protected] | 431552c | 2012-10-23 00:38:33 | [diff] [blame^] | 46 | #include "ui/views/controls/menu/menu_model_adapter.h" |
| 47 | #include "ui/views/controls/menu/menu_runner.h" |
| 48 | #include "ui/views/view_model.h" |
| 49 | #include "ui/views/view_model_utils.h" |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 50 | |
| 51 | namespace ash { |
| 52 | namespace { |
| 53 | |
[email protected] | 697f04c | 2012-10-03 01:15:10 | [diff] [blame] | 54 | #if defined(OS_CHROMEOS) |
| 55 | // Color initially used for the system background after the system has first |
| 56 | // booted. |
| 57 | const SkColor kBootSystemBackgroundColor = 0xFFFEFEFE; |
| 58 | #endif |
| 59 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 60 | // Creates a new window for use as a container. |
| 61 | aura::Window* CreateContainer(int window_id, |
| 62 | const char* name, |
| 63 | aura::Window* parent) { |
| 64 | aura::Window* container = new aura::Window(NULL); |
| 65 | container->set_id(window_id); |
| 66 | container->SetName(name); |
| 67 | container->Init(ui::LAYER_NOT_DRAWN); |
| 68 | parent->AddChild(container); |
| 69 | if (window_id != internal::kShellWindowId_UnparentedControlContainer) |
| 70 | container->Show(); |
| 71 | return container; |
| 72 | } |
| 73 | |
[email protected] | 9505857 | 2012-08-20 14:57:29 | [diff] [blame] | 74 | // Returns all the children of the workspace windows, eg the standard top-level |
| 75 | // windows. |
| 76 | std::vector<aura::Window*> GetWorkspaceWindows(aura::RootWindow* root) { |
| 77 | using aura::Window; |
| 78 | |
| 79 | std::vector<Window*> windows; |
| 80 | Window* container = Shell::GetContainer( |
| 81 | root, internal::kShellWindowId_DefaultContainer); |
| 82 | for (Window::Windows::const_reverse_iterator i = |
| 83 | container->children().rbegin(); |
| 84 | i != container->children().rend(); ++i) { |
| 85 | Window* workspace_window = *i; |
| 86 | if (workspace_window->id() == internal::kShellWindowId_WorkspaceContainer) { |
| 87 | windows.insert(windows.end(), workspace_window->children().begin(), |
| 88 | workspace_window->children().end()); |
| 89 | } |
| 90 | } |
| 91 | return windows; |
| 92 | } |
| 93 | |
| 94 | // Reparents |window| to |new_parent|. |
| 95 | void ReparentWindow(aura::Window* window, aura::Window* new_parent) { |
| 96 | // Update the restore bounds to make it relative to the display. |
| 97 | gfx::Rect restore_bounds(GetRestoreBoundsInParent(window)); |
| 98 | new_parent->AddChild(window); |
| 99 | if (!restore_bounds.IsEmpty()) |
| 100 | SetRestoreBoundsInParent(window, restore_bounds); |
| 101 | } |
| 102 | |
| 103 | // Reparents the appropriate set of windows from |src| to |dst|. |
| 104 | void ReparentAllWindows(aura::RootWindow* src, aura::RootWindow* dst) { |
| 105 | // Set of windows to move. |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 106 | const int kContainerIdsToMove[] = { |
| 107 | internal::kShellWindowId_DefaultContainer, |
| 108 | internal::kShellWindowId_AlwaysOnTopContainer, |
| 109 | internal::kShellWindowId_SystemModalContainer, |
| 110 | internal::kShellWindowId_LockSystemModalContainer, |
[email protected] | 6274d31 | 2012-10-04 22:06:41 | [diff] [blame] | 111 | internal::kShellWindowId_InputMethodContainer, |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 112 | }; |
[email protected] | 9505857 | 2012-08-20 14:57:29 | [diff] [blame] | 113 | // For Workspace2 we need to manually reparent the windows. This way |
| 114 | // Workspace2 can move the windows to the appropriate workspace. |
[email protected] | c96b981 | 2012-10-17 16:04:04 | [diff] [blame] | 115 | std::vector<aura::Window*> windows(GetWorkspaceWindows(src)); |
| 116 | internal::WorkspaceController* workspace_controller = |
| 117 | GetRootWindowController(dst)->workspace_controller(); |
| 118 | for (size_t i = 0; i < windows.size(); ++i) { |
| 119 | aura::Window* new_parent = |
| 120 | workspace_controller->GetParentForNewWindow(windows[i]); |
| 121 | ReparentWindow(windows[i], new_parent); |
[email protected] | 9505857 | 2012-08-20 14:57:29 | [diff] [blame] | 122 | } |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 123 | for (size_t i = 0; i < arraysize(kContainerIdsToMove); i++) { |
| 124 | int id = kContainerIdsToMove[i]; |
[email protected] | c96b981 | 2012-10-17 16:04:04 | [diff] [blame] | 125 | if (id == internal::kShellWindowId_DefaultContainer) |
[email protected] | 9505857 | 2012-08-20 14:57:29 | [diff] [blame] | 126 | continue; |
| 127 | |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 128 | aura::Window* src_container = Shell::GetContainer(src, id); |
| 129 | aura::Window* dst_container = Shell::GetContainer(dst, id); |
| 130 | aura::Window::Windows children = src_container->children(); |
| 131 | for (aura::Window::Windows::iterator iter = children.begin(); |
| 132 | iter != children.end(); ++iter) { |
| 133 | aura::Window* window = *iter; |
| 134 | // Don't move modal screen. |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 135 | if (internal::SystemModalContainerLayoutManager::IsModalBackground( |
| 136 | window)) |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 137 | continue; |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 138 | |
[email protected] | 9505857 | 2012-08-20 14:57:29 | [diff] [blame] | 139 | ReparentWindow(window, dst_container); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 140 | } |
| 141 | } |
| 142 | } |
| 143 | |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 144 | // Mark the container window so that a widget added to this container will |
| 145 | // use the virtual screeen coordinates instead of parent. |
| 146 | void SetUsesScreenCoordinates(aura::Window* container) { |
| 147 | container->SetProperty(internal::kUsesScreenCoordinatesKey, true); |
| 148 | } |
| 149 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 150 | } // namespace |
| 151 | |
| 152 | namespace internal { |
| 153 | |
| 154 | RootWindowController::RootWindowController(aura::RootWindow* root_window) |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 155 | : root_window_(root_window), |
| 156 | root_window_layout_(NULL), |
| 157 | status_area_widget_(NULL), |
| 158 | shelf_(NULL), |
| 159 | panel_layout_manager_(NULL) { |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 160 | SetRootWindowController(root_window, this); |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 161 | screen_dimmer_.reset(new ScreenDimmer(root_window)); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | RootWindowController::~RootWindowController() { |
[email protected] | 6675e1c | 2012-09-11 09:15:45 | [diff] [blame] | 165 | Shutdown(); |
| 166 | root_window_.reset(); |
| 167 | } |
| 168 | |
[email protected] | 88d7112 | 2012-10-18 07:11:01 | [diff] [blame] | 169 | // static |
| 170 | internal::RootWindowController* |
| 171 | RootWindowController::ForLauncher(aura::Window* window) { |
| 172 | if (Shell::IsLauncherPerDisplayEnabled()) |
| 173 | return GetRootWindowController(window->GetRootWindow()); |
| 174 | else |
| 175 | return Shell::GetPrimaryRootWindowController(); |
| 176 | } |
| 177 | |
[email protected] | 6675e1c | 2012-09-11 09:15:45 | [diff] [blame] | 178 | void RootWindowController::Shutdown() { |
| 179 | CloseChildWindows(); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 180 | if (Shell::GetActiveRootWindow() == root_window_.get()) { |
| 181 | Shell::GetInstance()->set_active_root_window( |
| 182 | Shell::GetPrimaryRootWindow() == root_window_.get() ? |
| 183 | NULL : Shell::GetPrimaryRootWindow()); |
| 184 | } |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 185 | SetRootWindowController(root_window_.get(), NULL); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 186 | screen_dimmer_.reset(); |
| 187 | workspace_controller_.reset(); |
[email protected] | 6675e1c | 2012-09-11 09:15:45 | [diff] [blame] | 188 | // Forget with the display ID so that display lookup |
| 189 | // ends up with invalid display. |
| 190 | root_window_->ClearProperty(kDisplayIdKey); |
| 191 | // And this root window should no longer process events. |
| 192 | root_window_->PrepareForShutdown(); |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 193 | |
| 194 | // Launcher widget has an InputMethodBridge that references to |
| 195 | // |input_method_filter_|'s |input_method_|. So explicitly release |
| 196 | // |launcher_| before |input_method_filter_|. And this needs to be |
| 197 | // after we delete all containers in case there are still live |
| 198 | // browser windows which access LauncherModel during close. |
| 199 | launcher_.reset(); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 200 | } |
| 201 | |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 202 | SystemModalContainerLayoutManager* |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 203 | RootWindowController::GetSystemModalLayoutManager(aura::Window* window) { |
| 204 | aura::Window* container = NULL; |
| 205 | if (window) { |
| 206 | container = GetContainer( |
| 207 | kShellWindowId_LockSystemModalContainer); |
| 208 | if (!container->Contains(window)) |
| 209 | container = GetContainer(kShellWindowId_SystemModalContainer); |
| 210 | } else { |
| 211 | user::LoginStatus login = Shell::GetInstance()->tray_delegate() ? |
| 212 | Shell::GetInstance()->tray_delegate()->GetUserLoginStatus() : |
| 213 | user::LOGGED_IN_NONE; |
| 214 | int modal_window_id = (login == user::LOGGED_IN_LOCKED || |
| 215 | login == user::LOGGED_IN_NONE) ? |
| 216 | kShellWindowId_LockSystemModalContainer : |
| 217 | kShellWindowId_SystemModalContainer; |
| 218 | container = GetContainer(modal_window_id); |
| 219 | } |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 220 | return static_cast<SystemModalContainerLayoutManager*>( |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 221 | container->layout_manager()); |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 222 | } |
| 223 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 224 | aura::Window* RootWindowController::GetContainer(int container_id) { |
| 225 | return root_window_->GetChildById(container_id); |
| 226 | } |
| 227 | |
| 228 | void RootWindowController::InitLayoutManagers() { |
| 229 | root_window_layout_ = |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 230 | new RootWindowLayoutManager(root_window_.get()); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 231 | root_window_->SetLayoutManager(root_window_layout_); |
| 232 | |
| 233 | aura::Window* default_container = |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 234 | GetContainer(kShellWindowId_DefaultContainer); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 235 | // Workspace manager has its own layout managers. |
| 236 | workspace_controller_.reset( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 237 | new WorkspaceController(default_container)); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 238 | |
| 239 | aura::Window* always_on_top_container = |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 240 | GetContainer(kShellWindowId_AlwaysOnTopContainer); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 241 | always_on_top_container->SetLayoutManager( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 242 | new BaseLayoutManager( |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 243 | always_on_top_container->GetRootWindow())); |
| 244 | } |
| 245 | |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 246 | void RootWindowController::InitForPrimaryDisplay() { |
| 247 | DCHECK(!status_area_widget_); |
| 248 | ShellDelegate* delegate = Shell::GetInstance()->delegate(); |
[email protected] | 16059276d | 2012-10-22 18:59:50 | [diff] [blame] | 249 | aura::Window* status_container = |
| 250 | GetContainer(ash::internal::kShellWindowId_StatusContainer); |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 251 | // Initialize Primary RootWindow specific items. |
[email protected] | 16059276d | 2012-10-22 18:59:50 | [diff] [blame] | 252 | status_area_widget_ = new internal::StatusAreaWidget(status_container); |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 253 | status_area_widget_->CreateTrayViews(delegate); |
| 254 | // Login screen manages status area visibility by itself. |
| 255 | if (delegate && delegate->IsSessionStarted()) |
| 256 | status_area_widget_->Show(); |
| 257 | |
| 258 | Shell::GetInstance()->focus_cycler()->AddWidget(status_area_widget_); |
| 259 | |
| 260 | internal::ShelfLayoutManager* shelf_layout_manager = |
| 261 | new internal::ShelfLayoutManager(status_area_widget_); |
| 262 | GetContainer(internal::kShellWindowId_LauncherContainer)-> |
| 263 | SetLayoutManager(shelf_layout_manager); |
| 264 | shelf_ = shelf_layout_manager; |
| 265 | |
| 266 | internal::StatusAreaLayoutManager* status_area_layout_manager = |
| 267 | new internal::StatusAreaLayoutManager(shelf_layout_manager); |
| 268 | GetContainer(internal::kShellWindowId_StatusContainer)-> |
| 269 | SetLayoutManager(status_area_layout_manager); |
| 270 | |
| 271 | shelf_layout_manager->set_workspace_controller( |
| 272 | workspace_controller()); |
| 273 | |
| 274 | workspace_controller()->SetShelf(shelf_); |
| 275 | |
| 276 | // Create Panel layout manager |
| 277 | aura::Window* panel_container = GetContainer( |
| 278 | internal::kShellWindowId_PanelContainer); |
| 279 | panel_layout_manager_ = |
| 280 | new internal::PanelLayoutManager(panel_container); |
| 281 | panel_container->SetEventFilter( |
| 282 | new internal::PanelWindowEventFilter( |
| 283 | panel_container, panel_layout_manager_)); |
| 284 | panel_container->SetLayoutManager(panel_layout_manager_); |
| 285 | |
| 286 | if (!delegate || delegate->IsUserLoggedIn()) |
| 287 | CreateLauncher(); |
| 288 | } |
| 289 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 290 | void RootWindowController::CreateContainers() { |
| 291 | CreateContainersInRootWindow(root_window_.get()); |
| 292 | } |
| 293 | |
[email protected] | 697f04c | 2012-10-03 01:15:10 | [diff] [blame] | 294 | void RootWindowController::CreateSystemBackground( |
| 295 | bool is_first_run_after_boot) { |
| 296 | SkColor color = SK_ColorBLACK; |
| 297 | #if defined(OS_CHROMEOS) |
| 298 | if (is_first_run_after_boot) |
| 299 | color = kBootSystemBackgroundColor; |
| 300 | #endif |
[email protected] | c601e73 | 2012-10-11 15:39:37 | [diff] [blame] | 301 | background_.reset(new ColoredWindowController( |
| 302 | root_window_->GetChildById(kShellWindowId_SystemBackgroundContainer), |
| 303 | "SystemBackground")); |
| 304 | background_->SetColor(color); |
| 305 | background_->GetWidget()->Show(); |
[email protected] | 697f04c | 2012-10-03 01:15:10 | [diff] [blame] | 306 | } |
| 307 | |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 308 | void RootWindowController::CreateLauncher() { |
| 309 | if (launcher_.get()) |
| 310 | return; |
| 311 | |
| 312 | aura::Window* default_container = |
| 313 | GetContainer(internal::kShellWindowId_DefaultContainer); |
| 314 | launcher_.reset(new Launcher(default_container, shelf_)); |
| 315 | |
| 316 | launcher_->SetFocusCycler(Shell::GetInstance()->focus_cycler()); |
| 317 | shelf_->SetLauncher(launcher_.get()); |
| 318 | |
| 319 | if (panel_layout_manager_) |
| 320 | panel_layout_manager_->SetLauncher(launcher_.get()); |
| 321 | |
| 322 | ShellDelegate* delegate = Shell::GetInstance()->delegate(); |
| 323 | if (delegate) |
| 324 | launcher_->SetVisible(delegate->IsSessionStarted()); |
| 325 | launcher_->widget()->Show(); |
| 326 | } |
| 327 | |
| 328 | void RootWindowController::ShowLauncher() { |
| 329 | if (!launcher_.get()) |
| 330 | return; |
| 331 | launcher_->SetVisible(true); |
| 332 | } |
| 333 | |
[email protected] | 16059276d | 2012-10-22 18:59:50 | [diff] [blame] | 334 | void RootWindowController::OnLoginStateChanged(user::LoginStatus status) { |
| 335 | // TODO(oshima): remove if when launcher per display is enabled by |
| 336 | // default. |
| 337 | if (shelf_) |
| 338 | shelf_->UpdateVisibilityState(); |
| 339 | } |
| 340 | |
| 341 | void RootWindowController::UpdateAfterLoginStatusChange( |
| 342 | user::LoginStatus status) { |
| 343 | if (status_area_widget_) |
| 344 | status_area_widget_->UpdateAfterLoginStatusChange(status); |
| 345 | } |
| 346 | |
[email protected] | 697f04c | 2012-10-03 01:15:10 | [diff] [blame] | 347 | void RootWindowController::HandleDesktopBackgroundVisible() { |
| 348 | if (background_.get()) |
| 349 | background_->SetColor(SK_ColorBLACK); |
| 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. |
| 475 | // Desktop and lock screen background containers are not part of the |
| 476 | // lock animation so they are not included in those animate groups. |
| 477 | // When screen is locked desktop background is moved to lock screen background |
| 478 | // container (moved back on unlock). We want to make sure that there's an |
| 479 | // opaque layer occluding the non-lock-screen layers. |
| 480 | |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 481 | CreateContainer(kShellWindowId_SystemBackgroundContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 482 | "SystemBackgroundContainer", root_window); |
| 483 | |
| 484 | aura::Window* desktop_background_containers = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 485 | kShellWindowId_DesktopBackgroundContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 486 | "DesktopBackgroundContainer", |
| 487 | root_window); |
| 488 | SetChildWindowVisibilityChangesAnimated(desktop_background_containers); |
| 489 | |
| 490 | aura::Window* non_lock_screen_containers = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 491 | kShellWindowId_NonLockScreenContainersContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 492 | "NonLockScreenContainersContainer", |
| 493 | root_window); |
| 494 | |
| 495 | aura::Window* lock_background_containers = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 496 | kShellWindowId_LockScreenBackgroundContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 497 | "LockScreenBackgroundContainer", |
| 498 | root_window); |
| 499 | SetChildWindowVisibilityChangesAnimated(lock_background_containers); |
| 500 | |
| 501 | aura::Window* lock_screen_containers = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 502 | kShellWindowId_LockScreenContainersContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 503 | "LockScreenContainersContainer", |
| 504 | root_window); |
| 505 | aura::Window* lock_screen_related_containers = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 506 | kShellWindowId_LockScreenRelatedContainersContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 507 | "LockScreenRelatedContainersContainer", |
| 508 | root_window); |
| 509 | |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 510 | CreateContainer(kShellWindowId_UnparentedControlContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 511 | "UnparentedControlContainer", |
| 512 | non_lock_screen_containers); |
| 513 | |
| 514 | aura::Window* default_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 515 | kShellWindowId_DefaultContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 516 | "DefaultContainer", |
| 517 | non_lock_screen_containers); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 518 | SetChildWindowVisibilityChangesAnimated(default_container); |
| 519 | SetUsesScreenCoordinates(default_container); |
| 520 | |
| 521 | aura::Window* always_on_top_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 522 | kShellWindowId_AlwaysOnTopContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 523 | "AlwaysOnTopContainer", |
| 524 | non_lock_screen_containers); |
| 525 | always_on_top_container_handler_.reset( |
| 526 | new ToplevelWindowEventHandler(always_on_top_container)); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 527 | SetChildWindowVisibilityChangesAnimated(always_on_top_container); |
| 528 | SetUsesScreenCoordinates(always_on_top_container); |
| 529 | |
| 530 | aura::Window* panel_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 531 | kShellWindowId_PanelContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 532 | "PanelContainer", |
| 533 | non_lock_screen_containers); |
| 534 | SetUsesScreenCoordinates(panel_container); |
| 535 | |
| 536 | aura::Window* launcher_container = |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 537 | CreateContainer(kShellWindowId_LauncherContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 538 | "LauncherContainer", |
| 539 | non_lock_screen_containers); |
| 540 | SetUsesScreenCoordinates(launcher_container); |
| 541 | |
[email protected] | dc851a4e5 | 2012-10-03 00:05:55 | [diff] [blame] | 542 | aura::Window* app_list_container = |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 543 | CreateContainer(kShellWindowId_AppListContainer, |
[email protected] | dc851a4e5 | 2012-10-03 00:05:55 | [diff] [blame] | 544 | "AppListContainer", |
| 545 | non_lock_screen_containers); |
| 546 | SetUsesScreenCoordinates(app_list_container); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 547 | |
| 548 | aura::Window* modal_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 549 | kShellWindowId_SystemModalContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 550 | "SystemModalContainer", |
| 551 | non_lock_screen_containers); |
| 552 | modal_container_handler_.reset( |
| 553 | new ToplevelWindowEventHandler(modal_container)); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 554 | modal_container->SetLayoutManager( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 555 | new SystemModalContainerLayoutManager(modal_container)); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 556 | SetChildWindowVisibilityChangesAnimated(modal_container); |
| 557 | SetUsesScreenCoordinates(modal_container); |
| 558 | |
| 559 | aura::Window* input_method_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 560 | kShellWindowId_InputMethodContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 561 | "InputMethodContainer", |
| 562 | non_lock_screen_containers); |
| 563 | SetUsesScreenCoordinates(input_method_container); |
| 564 | |
| 565 | // TODO(beng): Figure out if we can make this use |
| 566 | // SystemModalContainerEventFilter instead of stops_event_propagation. |
| 567 | aura::Window* lock_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 568 | kShellWindowId_LockScreenContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 569 | "LockScreenContainer", |
| 570 | lock_screen_containers); |
| 571 | lock_container->SetLayoutManager( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 572 | new BaseLayoutManager(root_window)); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 573 | SetUsesScreenCoordinates(lock_container); |
| 574 | // TODO(beng): stopsevents |
| 575 | |
| 576 | aura::Window* lock_modal_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 577 | kShellWindowId_LockSystemModalContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 578 | "LockSystemModalContainer", |
| 579 | lock_screen_containers); |
| 580 | lock_modal_container_handler_.reset( |
| 581 | new ToplevelWindowEventHandler(lock_modal_container)); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 582 | lock_modal_container->SetLayoutManager( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 583 | new SystemModalContainerLayoutManager(lock_modal_container)); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 584 | SetChildWindowVisibilityChangesAnimated(lock_modal_container); |
| 585 | SetUsesScreenCoordinates(lock_modal_container); |
| 586 | |
| 587 | aura::Window* status_container = |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 588 | CreateContainer(kShellWindowId_StatusContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 589 | "StatusContainer", |
| 590 | lock_screen_related_containers); |
| 591 | SetUsesScreenCoordinates(status_container); |
| 592 | |
| 593 | aura::Window* settings_bubble_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 594 | kShellWindowId_SettingBubbleContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 595 | "SettingBubbleContainer", |
| 596 | lock_screen_related_containers); |
| 597 | SetChildWindowVisibilityChangesAnimated(settings_bubble_container); |
| 598 | SetUsesScreenCoordinates(settings_bubble_container); |
| 599 | |
| 600 | aura::Window* menu_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 601 | kShellWindowId_MenuContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 602 | "MenuContainer", |
| 603 | lock_screen_related_containers); |
| 604 | SetChildWindowVisibilityChangesAnimated(menu_container); |
| 605 | SetUsesScreenCoordinates(menu_container); |
| 606 | |
| 607 | aura::Window* drag_drop_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 608 | kShellWindowId_DragImageAndTooltipContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 609 | "DragImageAndTooltipContainer", |
| 610 | lock_screen_related_containers); |
| 611 | SetChildWindowVisibilityChangesAnimated(drag_drop_container); |
| 612 | SetUsesScreenCoordinates(drag_drop_container); |
| 613 | |
| 614 | aura::Window* overlay_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 615 | kShellWindowId_OverlayContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 616 | "OverlayContainer", |
| 617 | lock_screen_related_containers); |
| 618 | SetUsesScreenCoordinates(overlay_container); |
| 619 | } |
| 620 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 621 | } // namespace internal |
| 622 | } // namespace ash |