blob: 5a1b36e01d6ea28b98d98c261eabe189688a47aa [file] [log] [blame]
[email protected]d90b8392012-06-13 09:34:561// 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]8d625fb2012-07-18 16:40:067#include <vector>
8
[email protected]e6e41d2f2012-10-29 19:22:199#include "ash/ash_switches.h"
[email protected]b4ddc7a2012-08-07 04:17:3210#include "ash/desktop_background/desktop_background_widget_controller.h"
[email protected]8d625fb2012-07-18 16:40:0611#include "ash/display/display_controller.h"
[email protected]6bdf7952012-11-14 10:10:5812#include "ash/display/display_manager.h"
[email protected]e74aaf0a2012-10-12 18:42:2813#include "ash/focus_cycler.h"
[email protected]d90b8392012-06-13 09:34:5614#include "ash/shell.h"
[email protected]e74aaf0a2012-10-12 18:42:2815#include "ash/shell_delegate.h"
[email protected]d90b8392012-06-13 09:34:5616#include "ash/shell_factory.h"
17#include "ash/shell_window_ids.h"
[email protected]e74aaf0a2012-10-12 18:42:2818#include "ash/system/status_area_widget.h"
[email protected]8674b312012-10-12 19:02:4419#include "ash/system/tray/system_tray_delegate.h"
[email protected]d90b8392012-06-13 09:34:5620#include "ash/wm/base_layout_manager.h"
[email protected]bca9a7e2012-11-10 06:25:4921#include "ash/wm/boot_splash_screen.h"
[email protected]e74aaf0a2012-10-12 18:42:2822#include "ash/wm/panel_layout_manager.h"
23#include "ash/wm/panel_window_event_filter.h"
[email protected]d90b8392012-06-13 09:34:5624#include "ash/wm/property_util.h"
25#include "ash/wm/root_window_layout_manager.h"
26#include "ash/wm/screen_dimmer.h"
[email protected]e74aaf0a2012-10-12 18:42:2827#include "ash/wm/shelf_layout_manager.h"
28#include "ash/wm/shelf_types.h"
29#include "ash/wm/status_area_layout_manager.h"
[email protected]e6e41d2f2012-10-29 19:22:1930#include "ash/wm/system_background_controller.h"
[email protected]d90b8392012-06-13 09:34:5631#include "ash/wm/system_modal_container_layout_manager.h"
[email protected]5dc51db82012-09-11 03:39:0132#include "ash/wm/toplevel_window_event_handler.h"
[email protected]d90b8392012-06-13 09:34:5633#include "ash/wm/visibility_controller.h"
[email protected]8d625fb2012-07-18 16:40:0634#include "ash/wm/window_properties.h"
[email protected]d90b8392012-06-13 09:34:5635#include "ash/wm/workspace_controller.h"
[email protected]e6e41d2f2012-10-29 19:22:1936#include "base/command_line.h"
[email protected]bca9a7e2012-11-10 06:25:4937#include "base/time.h"
[email protected]f1853122012-06-27 16:21:2638#include "ui/aura/client/activation_client.h"
39#include "ui/aura/client/aura_constants.h"
40#include "ui/aura/client/capture_client.h"
[email protected]d90b8392012-06-13 09:34:5641#include "ui/aura/client/tooltip_client.h"
[email protected]f1853122012-06-27 16:21:2642#include "ui/aura/focus_manager.h"
[email protected]d90b8392012-06-13 09:34:5643#include "ui/aura/root_window.h"
[email protected]f1853122012-06-27 16:21:2644#include "ui/aura/window.h"
45#include "ui/aura/window_observer.h"
[email protected]1d030242012-06-28 18:34:0846#include "ui/aura/window_tracker.h"
[email protected]431552c2012-10-23 00:38:3347#include "ui/base/models/menu_model.h"
[email protected]8d625fb2012-07-18 16:40:0648#include "ui/gfx/display.h"
49#include "ui/gfx/screen.h"
[email protected]431552c2012-10-23 00:38:3350#include "ui/views/controls/menu/menu_model_adapter.h"
51#include "ui/views/controls/menu/menu_runner.h"
52#include "ui/views/view_model.h"
53#include "ui/views/view_model_utils.h"
[email protected]d90b8392012-06-13 09:34:5654
55namespace ash {
56namespace {
57
[email protected]bca9a7e2012-11-10 06:25:4958#if defined(OS_CHROMEOS)
59// Background color used for the Chrome OS boot splash screen.
60const SkColor kChromeOsBootColor = SkColorSetARGB(0xff, 0xfe, 0xfe, 0xfe);
61#endif
62
63// Duration for the animation that hides the boot splash screen, in
64// milliseconds. This should be short enough in relation to
65// wm/window_animation.cc's brightness/grayscale fade animation that the login
66// background image animation isn't hidden by the splash screen animation.
67const int kBootSplashScreenHideDurationMs = 500;
68
[email protected]d90b8392012-06-13 09:34:5669// Creates a new window for use as a container.
70aura::Window* CreateContainer(int window_id,
71 const char* name,
72 aura::Window* parent) {
73 aura::Window* container = new aura::Window(NULL);
74 container->set_id(window_id);
75 container->SetName(name);
76 container->Init(ui::LAYER_NOT_DRAWN);
77 parent->AddChild(container);
78 if (window_id != internal::kShellWindowId_UnparentedControlContainer)
79 container->Show();
80 return container;
81}
82
[email protected]95058572012-08-20 14:57:2983// Returns all the children of the workspace windows, eg the standard top-level
84// windows.
85std::vector<aura::Window*> GetWorkspaceWindows(aura::RootWindow* root) {
86 using aura::Window;
87
88 std::vector<Window*> windows;
89 Window* container = Shell::GetContainer(
90 root, internal::kShellWindowId_DefaultContainer);
91 for (Window::Windows::const_reverse_iterator i =
92 container->children().rbegin();
93 i != container->children().rend(); ++i) {
94 Window* workspace_window = *i;
95 if (workspace_window->id() == internal::kShellWindowId_WorkspaceContainer) {
96 windows.insert(windows.end(), workspace_window->children().begin(),
97 workspace_window->children().end());
98 }
99 }
100 return windows;
101}
102
103// Reparents |window| to |new_parent|.
104void ReparentWindow(aura::Window* window, aura::Window* new_parent) {
105 // Update the restore bounds to make it relative to the display.
106 gfx::Rect restore_bounds(GetRestoreBoundsInParent(window));
107 new_parent->AddChild(window);
108 if (!restore_bounds.IsEmpty())
109 SetRestoreBoundsInParent(window, restore_bounds);
110}
111
112// Reparents the appropriate set of windows from |src| to |dst|.
113void ReparentAllWindows(aura::RootWindow* src, aura::RootWindow* dst) {
114 // Set of windows to move.
[email protected]f1853122012-06-27 16:21:26115 const int kContainerIdsToMove[] = {
116 internal::kShellWindowId_DefaultContainer,
117 internal::kShellWindowId_AlwaysOnTopContainer,
118 internal::kShellWindowId_SystemModalContainer,
119 internal::kShellWindowId_LockSystemModalContainer,
[email protected]6274d312012-10-04 22:06:41120 internal::kShellWindowId_InputMethodContainer,
[email protected]f1853122012-06-27 16:21:26121 };
[email protected]ef0e32cc2012-10-31 20:57:33122 // For workspace windows we need to manually reparent the windows. This way
123 // workspace can move the windows to the appropriate workspace.
[email protected]c96b9812012-10-17 16:04:04124 std::vector<aura::Window*> windows(GetWorkspaceWindows(src));
125 internal::WorkspaceController* workspace_controller =
126 GetRootWindowController(dst)->workspace_controller();
127 for (size_t i = 0; i < windows.size(); ++i) {
128 aura::Window* new_parent =
129 workspace_controller->GetParentForNewWindow(windows[i]);
130 ReparentWindow(windows[i], new_parent);
[email protected]95058572012-08-20 14:57:29131 }
[email protected]f1853122012-06-27 16:21:26132 for (size_t i = 0; i < arraysize(kContainerIdsToMove); i++) {
133 int id = kContainerIdsToMove[i];
[email protected]c96b9812012-10-17 16:04:04134 if (id == internal::kShellWindowId_DefaultContainer)
[email protected]95058572012-08-20 14:57:29135 continue;
136
[email protected]f1853122012-06-27 16:21:26137 aura::Window* src_container = Shell::GetContainer(src, id);
138 aura::Window* dst_container = Shell::GetContainer(dst, id);
139 aura::Window::Windows children = src_container->children();
140 for (aura::Window::Windows::iterator iter = children.begin();
141 iter != children.end(); ++iter) {
142 aura::Window* window = *iter;
143 // Don't move modal screen.
[email protected]c0ce80e2012-10-05 23:28:27144 if (internal::SystemModalContainerLayoutManager::IsModalBackground(
145 window))
[email protected]f1853122012-06-27 16:21:26146 continue;
[email protected]f059c6942012-07-21 14:27:57147
[email protected]95058572012-08-20 14:57:29148 ReparentWindow(window, dst_container);
[email protected]f1853122012-06-27 16:21:26149 }
150 }
151}
152
[email protected]8d625fb2012-07-18 16:40:06153// Mark the container window so that a widget added to this container will
154// use the virtual screeen coordinates instead of parent.
155void SetUsesScreenCoordinates(aura::Window* container) {
156 container->SetProperty(internal::kUsesScreenCoordinatesKey, true);
157}
158
[email protected]d90b8392012-06-13 09:34:56159} // namespace
160
161namespace internal {
162
163RootWindowController::RootWindowController(aura::RootWindow* root_window)
[email protected]e74aaf0a2012-10-12 18:42:28164 : root_window_(root_window),
165 root_window_layout_(NULL),
166 status_area_widget_(NULL),
167 shelf_(NULL),
168 panel_layout_manager_(NULL) {
[email protected]d90b8392012-06-13 09:34:56169 SetRootWindowController(root_window, this);
[email protected]c0ce80e2012-10-05 23:28:27170 screen_dimmer_.reset(new ScreenDimmer(root_window));
[email protected]d90b8392012-06-13 09:34:56171}
172
173RootWindowController::~RootWindowController() {
[email protected]6675e1c2012-09-11 09:15:45174 Shutdown();
175 root_window_.reset();
176}
177
[email protected]88d71122012-10-18 07:11:01178// static
179internal::RootWindowController*
180RootWindowController::ForLauncher(aura::Window* window) {
181 if (Shell::IsLauncherPerDisplayEnabled())
182 return GetRootWindowController(window->GetRootWindow());
183 else
184 return Shell::GetPrimaryRootWindowController();
185}
186
[email protected]6675e1c2012-09-11 09:15:45187void RootWindowController::Shutdown() {
188 CloseChildWindows();
[email protected]f634dd32012-07-23 22:49:07189 if (Shell::GetActiveRootWindow() == root_window_.get()) {
190 Shell::GetInstance()->set_active_root_window(
191 Shell::GetPrimaryRootWindow() == root_window_.get() ?
192 NULL : Shell::GetPrimaryRootWindow());
193 }
[email protected]d90b8392012-06-13 09:34:56194 SetRootWindowController(root_window_.get(), NULL);
[email protected]d90b8392012-06-13 09:34:56195 screen_dimmer_.reset();
196 workspace_controller_.reset();
[email protected]6675e1c2012-09-11 09:15:45197 // Forget with the display ID so that display lookup
198 // ends up with invalid display.
199 root_window_->ClearProperty(kDisplayIdKey);
200 // And this root window should no longer process events.
201 root_window_->PrepareForShutdown();
[email protected]e74aaf0a2012-10-12 18:42:28202
[email protected]956a6a42012-10-29 23:58:10203 system_background_.reset();
204
[email protected]e74aaf0a2012-10-12 18:42:28205 // Launcher widget has an InputMethodBridge that references to
206 // |input_method_filter_|'s |input_method_|. So explicitly release
207 // |launcher_| before |input_method_filter_|. And this needs to be
208 // after we delete all containers in case there are still live
209 // browser windows which access LauncherModel during close.
210 launcher_.reset();
[email protected]d90b8392012-06-13 09:34:56211}
212
[email protected]c0ce80e2012-10-05 23:28:27213SystemModalContainerLayoutManager*
[email protected]8674b312012-10-12 19:02:44214RootWindowController::GetSystemModalLayoutManager(aura::Window* window) {
215 aura::Window* container = NULL;
216 if (window) {
[email protected]3b162e12012-11-09 11:52:35217 if (window->parent() &&
218 window->parent()->id() >= kShellWindowId_LockScreenContainer) {
219 container = GetContainer(kShellWindowId_LockSystemModalContainer);
220 } else {
[email protected]8674b312012-10-12 19:02:44221 container = GetContainer(kShellWindowId_SystemModalContainer);
[email protected]3b162e12012-11-09 11:52:35222 }
[email protected]8674b312012-10-12 19:02:44223 } else {
[email protected]31f19e32012-10-30 22:31:23224 user::LoginStatus login = Shell::GetInstance()->status_area_widget() ?
[email protected]8674b312012-10-12 19:02:44225 Shell::GetInstance()->tray_delegate()->GetUserLoginStatus() :
226 user::LOGGED_IN_NONE;
227 int modal_window_id = (login == user::LOGGED_IN_LOCKED ||
228 login == user::LOGGED_IN_NONE) ?
229 kShellWindowId_LockSystemModalContainer :
230 kShellWindowId_SystemModalContainer;
231 container = GetContainer(modal_window_id);
232 }
[email protected]c0ce80e2012-10-05 23:28:27233 return static_cast<SystemModalContainerLayoutManager*>(
[email protected]8674b312012-10-12 19:02:44234 container->layout_manager());
[email protected]c0ce80e2012-10-05 23:28:27235}
236
[email protected]d90b8392012-06-13 09:34:56237aura::Window* RootWindowController::GetContainer(int container_id) {
238 return root_window_->GetChildById(container_id);
239}
240
241void RootWindowController::InitLayoutManagers() {
242 root_window_layout_ =
[email protected]c0ce80e2012-10-05 23:28:27243 new RootWindowLayoutManager(root_window_.get());
[email protected]d90b8392012-06-13 09:34:56244 root_window_->SetLayoutManager(root_window_layout_);
245
246 aura::Window* default_container =
[email protected]c0ce80e2012-10-05 23:28:27247 GetContainer(kShellWindowId_DefaultContainer);
[email protected]d90b8392012-06-13 09:34:56248 // Workspace manager has its own layout managers.
249 workspace_controller_.reset(
[email protected]c0ce80e2012-10-05 23:28:27250 new WorkspaceController(default_container));
[email protected]d90b8392012-06-13 09:34:56251
252 aura::Window* always_on_top_container =
[email protected]c0ce80e2012-10-05 23:28:27253 GetContainer(kShellWindowId_AlwaysOnTopContainer);
[email protected]d90b8392012-06-13 09:34:56254 always_on_top_container->SetLayoutManager(
[email protected]c0ce80e2012-10-05 23:28:27255 new BaseLayoutManager(
[email protected]d90b8392012-06-13 09:34:56256 always_on_top_container->GetRootWindow()));
257}
258
[email protected]e74aaf0a2012-10-12 18:42:28259void RootWindowController::InitForPrimaryDisplay() {
260 DCHECK(!status_area_widget_);
[email protected]16059276d2012-10-22 18:59:50261 aura::Window* status_container =
262 GetContainer(ash::internal::kShellWindowId_StatusContainer);
[email protected]e74aaf0a2012-10-12 18:42:28263 // Initialize Primary RootWindow specific items.
[email protected]16059276d2012-10-22 18:59:50264 status_area_widget_ = new internal::StatusAreaWidget(status_container);
[email protected]51ed5992012-11-07 10:14:39265 status_area_widget_->CreateTrayViews();
[email protected]e74aaf0a2012-10-12 18:42:28266 // Login screen manages status area visibility by itself.
[email protected]51ed5992012-11-07 10:14:39267 ShellDelegate* shell_delegate = Shell::GetInstance()->delegate();
[email protected]02dbd1a2012-11-08 22:50:13268 if (shell_delegate->IsSessionStarted())
[email protected]e74aaf0a2012-10-12 18:42:28269 status_area_widget_->Show();
270
271 Shell::GetInstance()->focus_cycler()->AddWidget(status_area_widget_);
272
273 internal::ShelfLayoutManager* shelf_layout_manager =
274 new internal::ShelfLayoutManager(status_area_widget_);
275 GetContainer(internal::kShellWindowId_LauncherContainer)->
276 SetLayoutManager(shelf_layout_manager);
277 shelf_ = shelf_layout_manager;
278
279 internal::StatusAreaLayoutManager* status_area_layout_manager =
280 new internal::StatusAreaLayoutManager(shelf_layout_manager);
281 GetContainer(internal::kShellWindowId_StatusContainer)->
282 SetLayoutManager(status_area_layout_manager);
283
284 shelf_layout_manager->set_workspace_controller(
285 workspace_controller());
286
287 workspace_controller()->SetShelf(shelf_);
288
289 // Create Panel layout manager
290 aura::Window* panel_container = GetContainer(
291 internal::kShellWindowId_PanelContainer);
292 panel_layout_manager_ =
293 new internal::PanelLayoutManager(panel_container);
[email protected]304594c2012-11-13 16:35:27294 panel_container->AddPreTargetHandler(
[email protected]e74aaf0a2012-10-12 18:42:28295 new internal::PanelWindowEventFilter(
296 panel_container, panel_layout_manager_));
297 panel_container->SetLayoutManager(panel_layout_manager_);
298
[email protected]02dbd1a2012-11-08 22:50:13299 if (shell_delegate->IsUserLoggedIn())
[email protected]e74aaf0a2012-10-12 18:42:28300 CreateLauncher();
301}
302
[email protected]d90b8392012-06-13 09:34:56303void RootWindowController::CreateContainers() {
304 CreateContainersInRootWindow(root_window_.get());
305}
306
[email protected]697f04c2012-10-03 01:15:10307void RootWindowController::CreateSystemBackground(
308 bool is_first_run_after_boot) {
[email protected]bca9a7e2012-11-10 06:25:49309 SkColor color = SK_ColorBLACK;
[email protected]697f04c2012-10-03 01:15:10310#if defined(OS_CHROMEOS)
[email protected]bca9a7e2012-11-10 06:25:49311 if (is_first_run_after_boot)
312 color = kChromeOsBootColor;
[email protected]697f04c2012-10-03 01:15:10313#endif
[email protected]e6e41d2f2012-10-29 19:22:19314 system_background_.reset(
[email protected]bca9a7e2012-11-10 06:25:49315 new SystemBackgroundController(root_window_.get(), color));
316
317#if defined(OS_CHROMEOS)
318 // Make a copy of the system's boot splash screen so we can composite it
319 // onscreen until the desktop background is ready.
320 if (is_first_run_after_boot &&
321 (CommandLine::ForCurrentProcess()->HasSwitch(
322 switches::kAshCopyHostBackgroundAtBoot) ||
323 CommandLine::ForCurrentProcess()->HasSwitch(
324 switches::kAshAnimateFromBootSplashScreen)))
325 boot_splash_screen_.reset(new BootSplashScreen(root_window_.get()));
326#endif
[email protected]697f04c2012-10-03 01:15:10327}
328
[email protected]e74aaf0a2012-10-12 18:42:28329void RootWindowController::CreateLauncher() {
330 if (launcher_.get())
331 return;
332
333 aura::Window* default_container =
334 GetContainer(internal::kShellWindowId_DefaultContainer);
335 launcher_.reset(new Launcher(default_container, shelf_));
336
337 launcher_->SetFocusCycler(Shell::GetInstance()->focus_cycler());
338 shelf_->SetLauncher(launcher_.get());
339
340 if (panel_layout_manager_)
341 panel_layout_manager_->SetLauncher(launcher_.get());
342
343 ShellDelegate* delegate = Shell::GetInstance()->delegate();
344 if (delegate)
345 launcher_->SetVisible(delegate->IsSessionStarted());
346 launcher_->widget()->Show();
347}
348
349void RootWindowController::ShowLauncher() {
350 if (!launcher_.get())
351 return;
352 launcher_->SetVisible(true);
[email protected]cb47bcb32012-11-05 21:36:38353 status_area_widget_->Show();
[email protected]e74aaf0a2012-10-12 18:42:28354}
355
[email protected]16059276d2012-10-22 18:59:50356void RootWindowController::OnLoginStateChanged(user::LoginStatus status) {
357 // TODO(oshima): remove if when launcher per display is enabled by
358 // default.
359 if (shelf_)
360 shelf_->UpdateVisibilityState();
361}
362
363void RootWindowController::UpdateAfterLoginStatusChange(
364 user::LoginStatus status) {
365 if (status_area_widget_)
366 status_area_widget_->UpdateAfterLoginStatusChange(status);
367}
368
[email protected]bca9a7e2012-11-10 06:25:49369void RootWindowController::HandleInitialDesktopBackgroundAnimationStarted() {
370 if (CommandLine::ForCurrentProcess()->HasSwitch(
371 switches::kAshAnimateFromBootSplashScreen) &&
372 boot_splash_screen_.get()) {
373 // Make the splash screen fade out so it doesn't obscure the desktop
374 // wallpaper's brightness/grayscale animation.
375 boot_splash_screen_->StartHideAnimation(
376 base::TimeDelta::FromMilliseconds(kBootSplashScreenHideDurationMs));
377 }
378}
379
[email protected]697f04c2012-10-03 01:15:10380void RootWindowController::HandleDesktopBackgroundVisible() {
[email protected]bca9a7e2012-11-10 06:25:49381 system_background_->SetColor(SK_ColorBLACK);
382 boot_splash_screen_.reset();
[email protected]697f04c2012-10-03 01:15:10383}
384
[email protected]d90b8392012-06-13 09:34:56385void RootWindowController::CloseChildWindows() {
[email protected]e74aaf0a2012-10-12 18:42:28386 // The status area needs to be shut down before the windows are destroyed.
[email protected]8674b312012-10-12 19:02:44387 if (status_area_widget_) {
[email protected]e74aaf0a2012-10-12 18:42:28388 status_area_widget_->Shutdown();
[email protected]8674b312012-10-12 19:02:44389 status_area_widget_ = NULL;
390 }
[email protected]e74aaf0a2012-10-12 18:42:28391
392 // Closing the windows frees the workspace controller.
393 if (shelf_)
394 shelf_->set_workspace_controller(NULL);
395
[email protected]d90b8392012-06-13 09:34:56396 // Close background widget first as it depends on tooltip.
[email protected]d86de6b22012-10-05 19:32:58397 root_window_->SetProperty(kDesktopController,
[email protected]b4ddc7a2012-08-07 04:17:32398 static_cast<DesktopBackgroundWidgetController*>(NULL));
[email protected]d86de6b22012-10-05 19:32:58399 root_window_->SetProperty(kAnimatingDesktopController,
400 static_cast<AnimatingDesktopController*>(NULL));
[email protected]b4ddc7a2012-08-07 04:17:32401
[email protected]d90b8392012-06-13 09:34:56402 workspace_controller_.reset();
403 aura::client::SetTooltipClient(root_window_.get(), NULL);
404
405 while (!root_window_->children().empty()) {
406 aura::Window* child = root_window_->children()[0];
407 delete child;
408 }
[email protected]e74aaf0a2012-10-12 18:42:28409
410 // All containers are deleted, so reset shelf_.
411 shelf_ = NULL;
[email protected]d90b8392012-06-13 09:34:56412}
413
[email protected]f1853122012-06-27 16:21:26414void RootWindowController::MoveWindowsTo(aura::RootWindow* dst) {
415 aura::Window* focused = dst->GetFocusManager()->GetFocusedWindow();
[email protected]dbf835d82012-09-11 18:23:09416 aura::WindowTracker tracker;
417 if (focused)
418 tracker.Add(focused);
[email protected]f1853122012-06-27 16:21:26419 aura::client::ActivationClient* activation_client =
420 aura::client::GetActivationClient(dst);
421 aura::Window* active = activation_client->GetActiveWindow();
[email protected]dbf835d82012-09-11 18:23:09422 if (active && focused != active)
423 tracker.Add(active);
[email protected]f1853122012-06-27 16:21:26424 // Deactivate the window to close menu / bubble windows.
425 activation_client->DeactivateWindow(active);
426 // Release capture if any.
427 aura::client::GetCaptureClient(root_window_.get())->
428 SetCapture(NULL);
[email protected]dbf835d82012-09-11 18:23:09429 // Clear the focused window if any. This is necessary because a
430 // window may be deleted when losing focus (fullscreen flash for
431 // example). If the focused window is still alive after move, it'll
432 // be re-focused below.
433 dst->GetFocusManager()->SetFocusedWindow(NULL, NULL);
[email protected]f1853122012-06-27 16:21:26434
[email protected]95058572012-08-20 14:57:29435 ReparentAllWindows(root_window_.get(), dst);
[email protected]f1853122012-06-27 16:21:26436
437 // Restore focused or active window if it's still alive.
[email protected]1d030242012-06-28 18:34:08438 if (focused && tracker.Contains(focused) && dst->Contains(focused)) {
[email protected]f1853122012-06-27 16:21:26439 dst->GetFocusManager()->SetFocusedWindow(focused, NULL);
[email protected]1d030242012-06-28 18:34:08440 } else if (active && tracker.Contains(active) && dst->Contains(active)) {
[email protected]f1853122012-06-27 16:21:26441 activation_client->ActivateWindow(active);
442 }
443}
444
[email protected]431552c2012-10-23 00:38:33445void RootWindowController::ShowContextMenu(
446 const gfx::Point& location_in_screen) {
447 aura::RootWindow* target = Shell::IsLauncherPerDisplayEnabled() ?
448 root_window() : Shell::GetPrimaryRootWindow();
449 DCHECK(Shell::GetInstance()->delegate());
450 scoped_ptr<ui::MenuModel> menu_model(
451 Shell::GetInstance()->delegate()->CreateContextMenu(target));
452
453 views::MenuModelAdapter menu_model_adapter(menu_model.get());
454 views::MenuRunner menu_runner(menu_model_adapter.CreateMenu());
455 views::Widget* widget =
456 root_window_->GetProperty(kDesktopController)->widget();
457
458 if (menu_runner.RunMenuAt(
459 widget, NULL, gfx::Rect(location_in_screen, gfx::Size()),
460 views::MenuItemView::TOPLEFT, views::MenuRunner::CONTEXT_MENU) ==
461 views::MenuRunner::MENU_DELETED)
462 return;
463
464 Shell::GetInstance()->UpdateShelfVisibility();
465}
466
[email protected]e74aaf0a2012-10-12 18:42:28467void RootWindowController::UpdateShelfVisibility() {
468 shelf_->UpdateVisibilityState();
469}
470
471void RootWindowController::SetShelfAutoHideBehavior(
472 ShelfAutoHideBehavior behavior) {
473 shelf_->SetAutoHideBehavior(behavior);
474}
475
476ShelfAutoHideBehavior RootWindowController::GetShelfAutoHideBehavior() const {
477 return shelf_->auto_hide_behavior();
478}
479
480bool RootWindowController::SetShelfAlignment(ShelfAlignment alignment) {
481 return shelf_->SetAlignment(alignment);
482}
483
484ShelfAlignment RootWindowController::GetShelfAlignment() {
485 return shelf_->alignment();
486}
487
[email protected]431552c2012-10-23 00:38:33488bool RootWindowController::IsShelfAutoHideMenuHideChecked() {
489 return GetShelfAutoHideBehavior() == ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS;
490}
491
492ShelfAutoHideBehavior
493RootWindowController::GetToggledShelfAutoHideBehavior() {
494 return IsShelfAutoHideMenuHideChecked() ?
495 ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER :
496 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS;
497}
498
[email protected]a4cd6d32012-09-12 03:42:13499////////////////////////////////////////////////////////////////////////////////
500// RootWindowController, private:
501
502void RootWindowController::CreateContainersInRootWindow(
503 aura::RootWindow* root_window) {
504 // These containers are just used by PowerButtonController to animate groups
505 // of containers simultaneously without messing up the current transformations
506 // on those containers. These are direct children of the root window; all of
507 // the other containers are their children.
[email protected]e6e41d2f2012-10-29 19:22:19508
509 // The desktop background container is not part of the lock animation, so it
510 // is not included in those animate groups.
[email protected]a4cd6d32012-09-12 03:42:13511 // When screen is locked desktop background is moved to lock screen background
512 // container (moved back on unlock). We want to make sure that there's an
513 // opaque layer occluding the non-lock-screen layers.
[email protected]e6e41d2f2012-10-29 19:22:19514 aura::Window* desktop_background_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27515 kShellWindowId_DesktopBackgroundContainer,
[email protected]a4cd6d32012-09-12 03:42:13516 "DesktopBackgroundContainer",
517 root_window);
[email protected]e6e41d2f2012-10-29 19:22:19518 SetChildWindowVisibilityChangesAnimated(desktop_background_container);
[email protected]a4cd6d32012-09-12 03:42:13519
520 aura::Window* non_lock_screen_containers = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27521 kShellWindowId_NonLockScreenContainersContainer,
[email protected]a4cd6d32012-09-12 03:42:13522 "NonLockScreenContainersContainer",
523 root_window);
524
525 aura::Window* lock_background_containers = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27526 kShellWindowId_LockScreenBackgroundContainer,
[email protected]a4cd6d32012-09-12 03:42:13527 "LockScreenBackgroundContainer",
528 root_window);
529 SetChildWindowVisibilityChangesAnimated(lock_background_containers);
530
531 aura::Window* lock_screen_containers = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27532 kShellWindowId_LockScreenContainersContainer,
[email protected]a4cd6d32012-09-12 03:42:13533 "LockScreenContainersContainer",
534 root_window);
535 aura::Window* lock_screen_related_containers = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27536 kShellWindowId_LockScreenRelatedContainersContainer,
[email protected]a4cd6d32012-09-12 03:42:13537 "LockScreenRelatedContainersContainer",
538 root_window);
539
[email protected]c0ce80e2012-10-05 23:28:27540 CreateContainer(kShellWindowId_UnparentedControlContainer,
[email protected]a4cd6d32012-09-12 03:42:13541 "UnparentedControlContainer",
542 non_lock_screen_containers);
543
544 aura::Window* default_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27545 kShellWindowId_DefaultContainer,
[email protected]a4cd6d32012-09-12 03:42:13546 "DefaultContainer",
547 non_lock_screen_containers);
[email protected]a4cd6d32012-09-12 03:42:13548 SetChildWindowVisibilityChangesAnimated(default_container);
549 SetUsesScreenCoordinates(default_container);
550
551 aura::Window* always_on_top_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27552 kShellWindowId_AlwaysOnTopContainer,
[email protected]a4cd6d32012-09-12 03:42:13553 "AlwaysOnTopContainer",
554 non_lock_screen_containers);
555 always_on_top_container_handler_.reset(
556 new ToplevelWindowEventHandler(always_on_top_container));
[email protected]a4cd6d32012-09-12 03:42:13557 SetChildWindowVisibilityChangesAnimated(always_on_top_container);
558 SetUsesScreenCoordinates(always_on_top_container);
559
560 aura::Window* panel_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27561 kShellWindowId_PanelContainer,
[email protected]a4cd6d32012-09-12 03:42:13562 "PanelContainer",
563 non_lock_screen_containers);
564 SetUsesScreenCoordinates(panel_container);
565
566 aura::Window* launcher_container =
[email protected]c0ce80e2012-10-05 23:28:27567 CreateContainer(kShellWindowId_LauncherContainer,
[email protected]a4cd6d32012-09-12 03:42:13568 "LauncherContainer",
569 non_lock_screen_containers);
570 SetUsesScreenCoordinates(launcher_container);
571
[email protected]dc851a4e52012-10-03 00:05:55572 aura::Window* app_list_container =
[email protected]c0ce80e2012-10-05 23:28:27573 CreateContainer(kShellWindowId_AppListContainer,
[email protected]dc851a4e52012-10-03 00:05:55574 "AppListContainer",
575 non_lock_screen_containers);
576 SetUsesScreenCoordinates(app_list_container);
[email protected]a4cd6d32012-09-12 03:42:13577
578 aura::Window* modal_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27579 kShellWindowId_SystemModalContainer,
[email protected]a4cd6d32012-09-12 03:42:13580 "SystemModalContainer",
581 non_lock_screen_containers);
582 modal_container_handler_.reset(
583 new ToplevelWindowEventHandler(modal_container));
[email protected]a4cd6d32012-09-12 03:42:13584 modal_container->SetLayoutManager(
[email protected]c0ce80e2012-10-05 23:28:27585 new SystemModalContainerLayoutManager(modal_container));
[email protected]a4cd6d32012-09-12 03:42:13586 SetChildWindowVisibilityChangesAnimated(modal_container);
587 SetUsesScreenCoordinates(modal_container);
588
589 aura::Window* input_method_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27590 kShellWindowId_InputMethodContainer,
[email protected]a4cd6d32012-09-12 03:42:13591 "InputMethodContainer",
592 non_lock_screen_containers);
593 SetUsesScreenCoordinates(input_method_container);
594
595 // TODO(beng): Figure out if we can make this use
596 // SystemModalContainerEventFilter instead of stops_event_propagation.
597 aura::Window* lock_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27598 kShellWindowId_LockScreenContainer,
[email protected]a4cd6d32012-09-12 03:42:13599 "LockScreenContainer",
600 lock_screen_containers);
601 lock_container->SetLayoutManager(
[email protected]c0ce80e2012-10-05 23:28:27602 new BaseLayoutManager(root_window));
[email protected]a4cd6d32012-09-12 03:42:13603 SetUsesScreenCoordinates(lock_container);
604 // TODO(beng): stopsevents
605
606 aura::Window* lock_modal_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27607 kShellWindowId_LockSystemModalContainer,
[email protected]a4cd6d32012-09-12 03:42:13608 "LockSystemModalContainer",
609 lock_screen_containers);
610 lock_modal_container_handler_.reset(
611 new ToplevelWindowEventHandler(lock_modal_container));
[email protected]a4cd6d32012-09-12 03:42:13612 lock_modal_container->SetLayoutManager(
[email protected]c0ce80e2012-10-05 23:28:27613 new SystemModalContainerLayoutManager(lock_modal_container));
[email protected]a4cd6d32012-09-12 03:42:13614 SetChildWindowVisibilityChangesAnimated(lock_modal_container);
615 SetUsesScreenCoordinates(lock_modal_container);
616
617 aura::Window* status_container =
[email protected]c0ce80e2012-10-05 23:28:27618 CreateContainer(kShellWindowId_StatusContainer,
[email protected]a4cd6d32012-09-12 03:42:13619 "StatusContainer",
620 lock_screen_related_containers);
621 SetUsesScreenCoordinates(status_container);
622
623 aura::Window* settings_bubble_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27624 kShellWindowId_SettingBubbleContainer,
[email protected]a4cd6d32012-09-12 03:42:13625 "SettingBubbleContainer",
626 lock_screen_related_containers);
627 SetChildWindowVisibilityChangesAnimated(settings_bubble_container);
628 SetUsesScreenCoordinates(settings_bubble_container);
629
630 aura::Window* menu_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27631 kShellWindowId_MenuContainer,
[email protected]a4cd6d32012-09-12 03:42:13632 "MenuContainer",
633 lock_screen_related_containers);
634 SetChildWindowVisibilityChangesAnimated(menu_container);
635 SetUsesScreenCoordinates(menu_container);
636
637 aura::Window* drag_drop_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27638 kShellWindowId_DragImageAndTooltipContainer,
[email protected]a4cd6d32012-09-12 03:42:13639 "DragImageAndTooltipContainer",
640 lock_screen_related_containers);
641 SetChildWindowVisibilityChangesAnimated(drag_drop_container);
642 SetUsesScreenCoordinates(drag_drop_container);
643
644 aura::Window* overlay_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27645 kShellWindowId_OverlayContainer,
[email protected]a4cd6d32012-09-12 03:42:13646 "OverlayContainer",
647 lock_screen_related_containers);
648 SetUsesScreenCoordinates(overlay_container);
[email protected]a07615f2012-10-24 08:23:08649
650 CreateContainer(kShellWindowId_PowerButtonAnimationContainer,
651 "PowerButtonAnimationContainer", root_window) ;
[email protected]a4cd6d32012-09-12 03:42:13652}
653
[email protected]d90b8392012-06-13 09:34:56654} // namespace internal
655} // namespace ash