[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "ash/root_window_controller.h" |
| 6 | |
[email protected] | 8b3e3d8 | 2013-08-20 14:36:30 | [diff] [blame] | 7 | #include <queue> |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 8 | #include <vector> |
| 9 | |
[email protected] | 44d444c | 2013-01-30 01:47:44 | [diff] [blame] | 10 | #include "ash/ash_constants.h" |
[email protected] | e6e41d2f | 2012-10-29 19:22:19 | [diff] [blame] | 11 | #include "ash/ash_switches.h" |
[email protected] | b4ddc7a | 2012-08-07 04:17:32 | [diff] [blame] | 12 | #include "ash/desktop_background/desktop_background_widget_controller.h" |
[email protected] | 0bf6173 | 2013-07-02 04:35:10 | [diff] [blame] | 13 | #include "ash/desktop_background/user_wallpaper_delegate.h" |
[email protected] | 6bdf795 | 2012-11-14 10:10:58 | [diff] [blame] | 14 | #include "ash/display/display_manager.h" |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 15 | #include "ash/focus_cycler.h" |
[email protected] | f8e6aad | 2013-08-30 21:49:11 | [diff] [blame] | 16 | #include "ash/root_window_settings.h" |
[email protected] | fcb123d | 2013-04-17 15:58:49 | [diff] [blame] | 17 | #include "ash/session_state_delegate.h" |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 18 | #include "ash/shelf/shelf_layout_manager.h" |
| 19 | #include "ash/shelf/shelf_types.h" |
| 20 | #include "ash/shelf/shelf_widget.h" |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 21 | #include "ash/shell.h" |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 22 | #include "ash/shell_delegate.h" |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 23 | #include "ash/shell_factory.h" |
| 24 | #include "ash/shell_window_ids.h" |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 25 | #include "ash/system/status_area_widget.h" |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 26 | #include "ash/system/tray/system_tray_delegate.h" |
[email protected] | 2b8a9bb | 2013-07-01 22:43:40 | [diff] [blame] | 27 | #include "ash/touch/touch_hud_debug.h" |
| 28 | #include "ash/touch/touch_hud_projection.h" |
[email protected] | 80549c15 | 2013-07-02 01:42:47 | [diff] [blame] | 29 | #include "ash/touch/touch_observer_hud.h" |
| 30 | #include "ash/wm/always_on_top_controller.h" |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 31 | #include "ash/wm/base_layout_manager.h" |
[email protected] | beb4e5c | 2013-06-18 15:37:07 | [diff] [blame] | 32 | #include "ash/wm/dock/docked_window_layout_manager.h" |
[email protected] | 7095a65 | 2013-03-07 19:41:49 | [diff] [blame] | 33 | #include "ash/wm/panels/panel_layout_manager.h" |
[email protected] | 10065941 | 2013-06-21 22:59:55 | [diff] [blame] | 34 | #include "ash/wm/panels/panel_window_event_handler.h" |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 35 | #include "ash/wm/root_window_layout_manager.h" |
| 36 | #include "ash/wm/screen_dimmer.h" |
[email protected] | 2a2caa0 | 2013-01-22 20:50:36 | [diff] [blame] | 37 | #include "ash/wm/stacking_controller.h" |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 38 | #include "ash/wm/status_area_layout_manager.h" |
[email protected] | e6e41d2f | 2012-10-29 19:22:19 | [diff] [blame] | 39 | #include "ash/wm/system_background_controller.h" |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 40 | #include "ash/wm/system_modal_container_layout_manager.h" |
[email protected] | 5dc51db8 | 2012-09-11 03:39:01 | [diff] [blame] | 41 | #include "ash/wm/toplevel_window_event_handler.h" |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 42 | #include "ash/wm/window_properties.h" |
[email protected] | a41b4e1 | 2013-09-20 04:36:34 | [diff] [blame] | 43 | #include "ash/wm/window_state.h" |
[email protected] | 700849f | 2013-04-30 17:49:20 | [diff] [blame] | 44 | #include "ash/wm/window_util.h" |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 45 | #include "ash/wm/workspace_controller.h" |
[email protected] | e6e41d2f | 2012-10-29 19:22:19 | [diff] [blame] | 46 | #include "base/command_line.h" |
[email protected] | 1e84c63 | 2013-06-27 23:12:21 | [diff] [blame] | 47 | #include "base/time/time.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 48 | #include "ui/aura/client/aura_constants.h" |
[email protected] | 8b3e3d8 | 2013-08-20 14:36:30 | [diff] [blame] | 49 | #include "ui/aura/client/drag_drop_client.h" |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 50 | #include "ui/aura/client/tooltip_client.h" |
| 51 | #include "ui/aura/root_window.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 52 | #include "ui/aura/window.h" |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 53 | #include "ui/aura/window_delegate.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 54 | #include "ui/aura/window_observer.h" |
[email protected] | 8b3e3d8 | 2013-08-20 14:36:30 | [diff] [blame] | 55 | #include "ui/aura/window_tracker.h" |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 56 | #include "ui/base/hit_test.h" |
[email protected] | 431552c | 2012-10-23 00:38:33 | [diff] [blame] | 57 | #include "ui/base/models/menu_model.h" |
[email protected] | f8e6aad | 2013-08-30 21:49:11 | [diff] [blame] | 58 | #include "ui/gfx/display.h" |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 59 | #include "ui/gfx/screen.h" |
[email protected] | 86459e2c | 2013-04-10 13:39:24 | [diff] [blame] | 60 | #include "ui/keyboard/keyboard_controller.h" |
| 61 | #include "ui/keyboard/keyboard_util.h" |
[email protected] | 431552c | 2012-10-23 00:38:33 | [diff] [blame] | 62 | #include "ui/views/controls/menu/menu_runner.h" |
[email protected] | 23a2dc8 | 2013-08-22 15:04:22 | [diff] [blame] | 63 | #include "ui/views/corewm/capture_controller.h" |
[email protected] | b5756e2 | 2012-11-30 01:32:02 | [diff] [blame] | 64 | #include "ui/views/corewm/visibility_controller.h" |
[email protected] | 431552c | 2012-10-23 00:38:33 | [diff] [blame] | 65 | #include "ui/views/view_model.h" |
| 66 | #include "ui/views/view_model_utils.h" |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 67 | |
[email protected] | 252eb23 | 2013-08-14 22:09:27 | [diff] [blame] | 68 | #if defined(OS_CHROMEOS) |
| 69 | #include "ash/wm/boot_splash_screen_chromeos.h" |
| 70 | #endif |
| 71 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 72 | namespace ash { |
| 73 | namespace { |
| 74 | |
[email protected] | 252eb23 | 2013-08-14 22:09:27 | [diff] [blame] | 75 | #if defined(OS_CHROMEOS) |
[email protected] | bca9a7e | 2012-11-10 06:25:49 | [diff] [blame] | 76 | // Duration for the animation that hides the boot splash screen, in |
| 77 | // milliseconds. This should be short enough in relation to |
| 78 | // wm/window_animation.cc's brightness/grayscale fade animation that the login |
| 79 | // background image animation isn't hidden by the splash screen animation. |
| 80 | const int kBootSplashScreenHideDurationMs = 500; |
[email protected] | 252eb23 | 2013-08-14 22:09:27 | [diff] [blame] | 81 | #endif |
[email protected] | bca9a7e | 2012-11-10 06:25:49 | [diff] [blame] | 82 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 83 | // Creates a new window for use as a container. |
| 84 | aura::Window* CreateContainer(int window_id, |
| 85 | const char* name, |
| 86 | aura::Window* parent) { |
| 87 | aura::Window* container = new aura::Window(NULL); |
| 88 | container->set_id(window_id); |
| 89 | container->SetName(name); |
| 90 | container->Init(ui::LAYER_NOT_DRAWN); |
| 91 | parent->AddChild(container); |
| 92 | if (window_id != internal::kShellWindowId_UnparentedControlContainer) |
| 93 | container->Show(); |
| 94 | return container; |
| 95 | } |
| 96 | |
[email protected] | 9505857 | 2012-08-20 14:57:29 | [diff] [blame] | 97 | // Reparents |window| to |new_parent|. |
| 98 | void ReparentWindow(aura::Window* window, aura::Window* new_parent) { |
| 99 | // Update the restore bounds to make it relative to the display. |
[email protected] | a41b4e1 | 2013-09-20 04:36:34 | [diff] [blame] | 100 | wm::WindowState* state = wm::GetWindowState(window); |
| 101 | gfx::Rect restore_bounds; |
| 102 | bool has_restore_bounds = state->HasRestoreBounds(); |
| 103 | if (has_restore_bounds) |
| 104 | restore_bounds = state->GetRestoreBoundsInParent(); |
[email protected] | 9505857 | 2012-08-20 14:57:29 | [diff] [blame] | 105 | new_parent->AddChild(window); |
[email protected] | a41b4e1 | 2013-09-20 04:36:34 | [diff] [blame] | 106 | if (has_restore_bounds) |
| 107 | state->SetRestoreBoundsInParent(restore_bounds); |
[email protected] | 9505857 | 2012-08-20 14:57:29 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | // Reparents the appropriate set of windows from |src| to |dst|. |
| 111 | void ReparentAllWindows(aura::RootWindow* src, aura::RootWindow* dst) { |
| 112 | // Set of windows to move. |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 113 | const int kContainerIdsToMove[] = { |
| 114 | internal::kShellWindowId_DefaultContainer, |
[email protected] | beb4e5c | 2013-06-18 15:37:07 | [diff] [blame] | 115 | internal::kShellWindowId_DockedContainer, |
[email protected] | 95db9c1 | 2013-01-31 11:47:44 | [diff] [blame] | 116 | internal::kShellWindowId_PanelContainer, |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 117 | internal::kShellWindowId_AlwaysOnTopContainer, |
| 118 | internal::kShellWindowId_SystemModalContainer, |
| 119 | internal::kShellWindowId_LockSystemModalContainer, |
[email protected] | 6274d31 | 2012-10-04 22:06:41 | [diff] [blame] | 120 | internal::kShellWindowId_InputMethodContainer, |
[email protected] | a975487 | 2013-01-25 07:44:00 | [diff] [blame] | 121 | internal::kShellWindowId_UnparentedControlContainer, |
[email protected] | f185312 | 2012-06-27 16:21:26 | [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]; |
| 125 | aura::Window* src_container = Shell::GetContainer(src, id); |
| 126 | aura::Window* dst_container = Shell::GetContainer(dst, id); |
[email protected] | 5b602190 | 2013-02-26 05:33:29 | [diff] [blame] | 127 | while (!src_container->children().empty()) { |
| 128 | // Restart iteration from the source container windows each time as they |
| 129 | // may change as a result of moving other windows. |
| 130 | aura::Window::Windows::const_iterator iter = |
| 131 | src_container->children().begin(); |
| 132 | while (iter != src_container->children().end() && |
| 133 | internal::SystemModalContainerLayoutManager::IsModalBackground( |
| 134 | *iter)) { |
| 135 | ++iter; |
| 136 | } |
| 137 | // If the entire window list is modal background windows then stop. |
| 138 | if (iter == src_container->children().end()) |
| 139 | break; |
| 140 | ReparentWindow(*iter, dst_container); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 141 | } |
| 142 | } |
| 143 | } |
| 144 | |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 145 | // Mark the container window so that a widget added to this container will |
| 146 | // use the virtual screeen coordinates instead of parent. |
| 147 | void SetUsesScreenCoordinates(aura::Window* container) { |
| 148 | container->SetProperty(internal::kUsesScreenCoordinatesKey, true); |
| 149 | } |
| 150 | |
[email protected] | e887c6c | 2013-07-08 19:35:53 | [diff] [blame] | 151 | // Mark the container window so that a widget added to this container will |
| 152 | // say in the same root window regardless of the bounds specified. |
| 153 | void DescendantShouldStayInSameRootWindow(aura::Window* container) { |
| 154 | container->SetProperty(internal::kStayInSameRootWindowKey, true); |
| 155 | } |
| 156 | |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 157 | // A window delegate which does nothing. Used to create a window that |
| 158 | // is a event target, but do nothing. |
| 159 | class EmptyWindowDelegate : public aura::WindowDelegate { |
| 160 | public: |
| 161 | EmptyWindowDelegate() {} |
| 162 | virtual ~EmptyWindowDelegate() {} |
| 163 | |
| 164 | // aura::WindowDelegate overrides: |
| 165 | virtual gfx::Size GetMinimumSize() const OVERRIDE { |
| 166 | return gfx::Size(); |
| 167 | } |
| 168 | virtual gfx::Size GetMaximumSize() const OVERRIDE { |
| 169 | return gfx::Size(); |
| 170 | } |
| 171 | virtual void OnBoundsChanged(const gfx::Rect& old_bounds, |
| 172 | const gfx::Rect& new_bounds) OVERRIDE { |
| 173 | } |
| 174 | virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE { |
| 175 | return gfx::kNullCursor; |
| 176 | } |
| 177 | virtual int GetNonClientComponent( |
| 178 | const gfx::Point& point) const OVERRIDE { |
| 179 | return HTNOWHERE; |
| 180 | } |
| 181 | virtual bool ShouldDescendIntoChildForEventHandling( |
| 182 | aura::Window* child, |
| 183 | const gfx::Point& location) OVERRIDE { |
| 184 | return false; |
| 185 | } |
| 186 | virtual bool CanFocus() OVERRIDE { |
| 187 | return false; |
| 188 | } |
| 189 | virtual void OnCaptureLost() OVERRIDE { |
| 190 | } |
| 191 | virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { |
| 192 | } |
| 193 | virtual void OnDeviceScaleFactorChanged( |
| 194 | float device_scale_factor) OVERRIDE { |
| 195 | } |
| 196 | virtual void OnWindowDestroying() OVERRIDE {} |
[email protected] | febe1fd6 | 2013-08-07 16:07:24 | [diff] [blame] | 197 | virtual void OnWindowDestroyed() OVERRIDE { |
| 198 | delete this; |
| 199 | } |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 200 | virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE { |
| 201 | } |
| 202 | virtual bool HasHitTestMask() const OVERRIDE { |
| 203 | return false; |
| 204 | } |
| 205 | virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE {} |
[email protected] | 1ddbe93 | 2013-09-12 06:23:16 | [diff] [blame] | 206 | virtual void DidRecreateLayer(ui::Layer* old_layer, |
| 207 | ui::Layer* new_layer) OVERRIDE {} |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 208 | |
| 209 | private: |
| 210 | DISALLOW_COPY_AND_ASSIGN(EmptyWindowDelegate); |
| 211 | }; |
| 212 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 213 | } // namespace |
| 214 | |
| 215 | namespace internal { |
| 216 | |
| 217 | RootWindowController::RootWindowController(aura::RootWindow* root_window) |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 218 | : root_window_(root_window), |
| 219 | root_window_layout_(NULL), |
[email protected] | beb4e5c | 2013-06-18 15:37:07 | [diff] [blame] | 220 | docked_layout_manager_(NULL), |
[email protected] | bff1755 | 2013-04-25 04:44:55 | [diff] [blame] | 221 | panel_layout_manager_(NULL), |
[email protected] | 2b8a9bb | 2013-07-01 22:43:40 | [diff] [blame] | 222 | touch_hud_debug_(NULL), |
| 223 | touch_hud_projection_(NULL) { |
[email protected] | 6b2d4a0b | 2013-09-06 06:29:54 | [diff] [blame] | 224 | GetRootWindowSettings(root_window)->controller = this; |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 225 | screen_dimmer_.reset(new ScreenDimmer(root_window)); |
[email protected] | 2a2caa0 | 2013-01-22 20:50:36 | [diff] [blame] | 226 | |
[email protected] | 0bf6173 | 2013-07-02 04:35:10 | [diff] [blame] | 227 | stacking_controller_.reset(new StackingController); |
[email protected] | 2a2caa0 | 2013-01-22 20:50:36 | [diff] [blame] | 228 | aura::client::SetStackingClient(root_window, stacking_controller_.get()); |
[email protected] | 23a2dc8 | 2013-08-22 15:04:22 | [diff] [blame] | 229 | capture_client_.reset(new views::corewm::ScopedCaptureClient(root_window)); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | RootWindowController::~RootWindowController() { |
[email protected] | 6675e1c | 2012-09-11 09:15:45 | [diff] [blame] | 233 | Shutdown(); |
| 234 | root_window_.reset(); |
[email protected] | 23a2dc8 | 2013-08-22 15:04:22 | [diff] [blame] | 235 | // The CaptureClient needs to be around for as long as the RootWindow is |
| 236 | // valid. |
| 237 | capture_client_.reset(); |
[email protected] | 6675e1c | 2012-09-11 09:15:45 | [diff] [blame] | 238 | } |
| 239 | |
[email protected] | 88d7112 | 2012-10-18 07:11:01 | [diff] [blame] | 240 | // static |
[email protected] | a0afeb1 | 2012-12-10 22:57:09 | [diff] [blame] | 241 | RootWindowController* RootWindowController::ForLauncher(aura::Window* window) { |
[email protected] | 8c0ec43 | 2013-05-10 04:33:39 | [diff] [blame] | 242 | return GetRootWindowController(window->GetRootWindow()); |
[email protected] | 88d7112 | 2012-10-18 07:11:01 | [diff] [blame] | 243 | } |
| 244 | |
[email protected] | a0afeb1 | 2012-12-10 22:57:09 | [diff] [blame] | 245 | // static |
[email protected] | ccff3d7 | 2013-02-06 04:26:28 | [diff] [blame] | 246 | RootWindowController* RootWindowController::ForWindow( |
| 247 | const aura::Window* window) { |
[email protected] | a0afeb1 | 2012-12-10 22:57:09 | [diff] [blame] | 248 | return GetRootWindowController(window->GetRootWindow()); |
| 249 | } |
| 250 | |
| 251 | // static |
[email protected] | d17642d | 2013-09-12 23:44:38 | [diff] [blame] | 252 | RootWindowController* RootWindowController::ForTargetRootWindow() { |
| 253 | return internal::GetRootWindowController(Shell::GetTargetRootWindow()); |
[email protected] | a0afeb1 | 2012-12-10 22:57:09 | [diff] [blame] | 254 | } |
| 255 | |
[email protected] | 0bf6173 | 2013-07-02 04:35:10 | [diff] [blame] | 256 | void RootWindowController::SetWallpaperController( |
| 257 | DesktopBackgroundWidgetController* controller) { |
| 258 | wallpaper_controller_.reset(controller); |
| 259 | } |
| 260 | |
| 261 | void RootWindowController::SetAnimatingWallpaperController( |
| 262 | AnimatingDesktopController* controller) { |
| 263 | if (animating_wallpaper_controller_.get()) |
| 264 | animating_wallpaper_controller_->StopAnimating(); |
| 265 | animating_wallpaper_controller_.reset(controller); |
| 266 | } |
| 267 | |
[email protected] | 6675e1c | 2012-09-11 09:15:45 | [diff] [blame] | 268 | void RootWindowController::Shutdown() { |
[email protected] | d141b92 | 2013-07-09 08:13:17 | [diff] [blame] | 269 | Shell::GetInstance()->RemoveShellObserver(this); |
| 270 | |
[email protected] | 0bf6173 | 2013-07-02 04:35:10 | [diff] [blame] | 271 | if (animating_wallpaper_controller_.get()) |
| 272 | animating_wallpaper_controller_->StopAnimating(); |
| 273 | wallpaper_controller_.reset(); |
| 274 | animating_wallpaper_controller_.reset(); |
| 275 | |
[email protected] | d17642d | 2013-09-12 23:44:38 | [diff] [blame] | 276 | // Change the target root window before closing child windows. If any child |
[email protected] | c98a492 | 2013-09-05 20:01:42 | [diff] [blame] | 277 | // being removed triggers a relayout of the shelf it will try to build a |
[email protected] | d17642d | 2013-09-12 23:44:38 | [diff] [blame] | 278 | // window list adding windows from the target root window's containers which |
[email protected] | c98a492 | 2013-09-05 20:01:42 | [diff] [blame] | 279 | // may have already gone away. |
[email protected] | d17642d | 2013-09-12 23:44:38 | [diff] [blame] | 280 | if (Shell::GetTargetRootWindow() == root_window_) { |
| 281 | Shell::GetInstance()->set_target_root_window( |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 282 | Shell::GetPrimaryRootWindow() == root_window_.get() ? |
| 283 | NULL : Shell::GetPrimaryRootWindow()); |
| 284 | } |
[email protected] | c98a492 | 2013-09-05 20:01:42 | [diff] [blame] | 285 | |
| 286 | CloseChildWindows(); |
[email protected] | 6b2d4a0b | 2013-09-06 06:29:54 | [diff] [blame] | 287 | GetRootWindowSettings(root_window_.get())->controller = NULL; |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 288 | screen_dimmer_.reset(); |
| 289 | workspace_controller_.reset(); |
[email protected] | 6675e1c | 2012-09-11 09:15:45 | [diff] [blame] | 290 | // Forget with the display ID so that display lookup |
| 291 | // ends up with invalid display. |
[email protected] | f8e6aad | 2013-08-30 21:49:11 | [diff] [blame] | 292 | internal::GetRootWindowSettings(root_window_.get())->display_id = |
| 293 | gfx::Display::kInvalidDisplayID; |
[email protected] | 6675e1c | 2012-09-11 09:15:45 | [diff] [blame] | 294 | // And this root window should no longer process events. |
| 295 | root_window_->PrepareForShutdown(); |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 296 | |
[email protected] | 956a6a4 | 2012-10-29 23:58:10 | [diff] [blame] | 297 | system_background_.reset(); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 298 | } |
| 299 | |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 300 | SystemModalContainerLayoutManager* |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 301 | RootWindowController::GetSystemModalLayoutManager(aura::Window* window) { |
| 302 | aura::Window* container = NULL; |
| 303 | if (window) { |
[email protected] | 3b162e1 | 2012-11-09 11:52:35 | [diff] [blame] | 304 | if (window->parent() && |
| 305 | window->parent()->id() >= kShellWindowId_LockScreenContainer) { |
| 306 | container = GetContainer(kShellWindowId_LockSystemModalContainer); |
| 307 | } else { |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 308 | container = GetContainer(kShellWindowId_SystemModalContainer); |
[email protected] | 3b162e1 | 2012-11-09 11:52:35 | [diff] [blame] | 309 | } |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 310 | } else { |
[email protected] | a44afbbd | 2013-07-24 21:49:35 | [diff] [blame] | 311 | int modal_window_id = Shell::GetInstance()->session_state_delegate() |
| 312 | ->IsUserSessionBlocked() ? kShellWindowId_LockSystemModalContainer : |
| 313 | kShellWindowId_SystemModalContainer; |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 314 | container = GetContainer(modal_window_id); |
| 315 | } |
[email protected] | bb0c7cd4 | 2013-05-20 23:39:45 | [diff] [blame] | 316 | return container ? static_cast<SystemModalContainerLayoutManager*>( |
| 317 | container->layout_manager()) : NULL; |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 318 | } |
| 319 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 320 | aura::Window* RootWindowController::GetContainer(int container_id) { |
| 321 | return root_window_->GetChildById(container_id); |
| 322 | } |
| 323 | |
[email protected] | d8a2495 | 2013-08-05 20:05:05 | [diff] [blame] | 324 | const aura::Window* RootWindowController::GetContainer(int container_id) const { |
| 325 | return root_window_->GetChildById(container_id); |
| 326 | } |
| 327 | |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 328 | void RootWindowController::Init(bool first_run_after_boot) { |
| 329 | root_window_->SetCursor(ui::kCursorPointer); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 330 | CreateContainersInRootWindow(root_window_.get()); |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 331 | CreateSystemBackground(first_run_after_boot); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 332 | |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 333 | InitLayoutManagers(); |
| 334 | InitKeyboard(); |
| 335 | InitTouchHuds(); |
[email protected] | bca9a7e | 2012-11-10 06:25:49 | [diff] [blame] | 336 | |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 337 | if (Shell::GetPrimaryRootWindowController()-> |
| 338 | GetSystemModalLayoutManager(NULL)->has_modal_background()) { |
| 339 | GetSystemModalLayoutManager(NULL)->CreateModalBackground(); |
| 340 | } |
[email protected] | d141b92 | 2013-07-09 08:13:17 | [diff] [blame] | 341 | |
| 342 | Shell::GetInstance()->AddShellObserver(this); |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | void RootWindowController::ShowLauncher() { |
[email protected] | 80549c15 | 2013-07-02 01:42:47 | [diff] [blame] | 346 | if (!shelf_->launcher()) |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 347 | return; |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 348 | shelf_->launcher()->SetVisible(true); |
| 349 | shelf_->status_area_widget()->Show(); |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 350 | } |
| 351 | |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 352 | void RootWindowController::OnLauncherCreated() { |
| 353 | if (panel_layout_manager_) |
| 354 | panel_layout_manager_->SetLauncher(shelf_->launcher()); |
[email protected] | 7115bd3 | 2013-07-19 08:25:39 | [diff] [blame] | 355 | if (docked_layout_manager_) { |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 356 | docked_layout_manager_->SetLauncher(shelf_->launcher()); |
[email protected] | 7115bd3 | 2013-07-19 08:25:39 | [diff] [blame] | 357 | if (shelf_->shelf_layout_manager()) |
| 358 | docked_layout_manager_->AddObserver(shelf_->shelf_layout_manager()); |
| 359 | } |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 360 | } |
| 361 | |
[email protected] | 16059276d | 2012-10-22 18:59:50 | [diff] [blame] | 362 | void RootWindowController::UpdateAfterLoginStatusChange( |
| 363 | user::LoginStatus status) { |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 364 | if (status != user::LOGGED_IN_NONE) |
| 365 | mouse_event_target_.reset(); |
[email protected] | 80549c15 | 2013-07-02 01:42:47 | [diff] [blame] | 366 | if (shelf_->status_area_widget()) |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 367 | shelf_->status_area_widget()->UpdateAfterLoginStatusChange(status); |
[email protected] | 16059276d | 2012-10-22 18:59:50 | [diff] [blame] | 368 | } |
| 369 | |
[email protected] | bca9a7e | 2012-11-10 06:25:49 | [diff] [blame] | 370 | void RootWindowController::HandleInitialDesktopBackgroundAnimationStarted() { |
[email protected] | 252eb23 | 2013-08-14 22:09:27 | [diff] [blame] | 371 | #if defined(OS_CHROMEOS) |
[email protected] | bca9a7e | 2012-11-10 06:25:49 | [diff] [blame] | 372 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 373 | switches::kAshAnimateFromBootSplashScreen) && |
| 374 | boot_splash_screen_.get()) { |
| 375 | // Make the splash screen fade out so it doesn't obscure the desktop |
| 376 | // wallpaper's brightness/grayscale animation. |
| 377 | boot_splash_screen_->StartHideAnimation( |
| 378 | base::TimeDelta::FromMilliseconds(kBootSplashScreenHideDurationMs)); |
| 379 | } |
[email protected] | 252eb23 | 2013-08-14 22:09:27 | [diff] [blame] | 380 | #endif |
[email protected] | bca9a7e | 2012-11-10 06:25:49 | [diff] [blame] | 381 | } |
| 382 | |
[email protected] | 0bf6173 | 2013-07-02 04:35:10 | [diff] [blame] | 383 | void RootWindowController::OnWallpaperAnimationFinished(views::Widget* widget) { |
| 384 | // Make sure the wallpaper is visible. |
[email protected] | bca9a7e | 2012-11-10 06:25:49 | [diff] [blame] | 385 | system_background_->SetColor(SK_ColorBLACK); |
[email protected] | 252eb23 | 2013-08-14 22:09:27 | [diff] [blame] | 386 | #if defined(OS_CHROMEOS) |
[email protected] | bca9a7e | 2012-11-10 06:25:49 | [diff] [blame] | 387 | boot_splash_screen_.reset(); |
[email protected] | 252eb23 | 2013-08-14 22:09:27 | [diff] [blame] | 388 | #endif |
[email protected] | 0bf6173 | 2013-07-02 04:35:10 | [diff] [blame] | 389 | |
| 390 | Shell::GetInstance()->user_wallpaper_delegate()-> |
| 391 | OnWallpaperAnimationFinished(); |
| 392 | // Only removes old component when wallpaper animation finished. If we |
| 393 | // remove the old one before the new wallpaper is done fading in there will |
| 394 | // be a white flash during the animation. |
| 395 | if (animating_wallpaper_controller()) { |
| 396 | DesktopBackgroundWidgetController* controller = |
| 397 | animating_wallpaper_controller()->GetController(true); |
| 398 | // |desktop_widget_| should be the same animating widget we try to move |
| 399 | // to |kDesktopController|. Otherwise, we may close |desktop_widget_| |
| 400 | // before move it to |kDesktopController|. |
| 401 | DCHECK_EQ(controller->widget(), widget); |
| 402 | // Release the old controller and close its background widget. |
| 403 | SetWallpaperController(controller); |
| 404 | } |
[email protected] | 697f04c | 2012-10-03 01:15:10 | [diff] [blame] | 405 | } |
| 406 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 407 | void RootWindowController::CloseChildWindows() { |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 408 | mouse_event_target_.reset(); |
| 409 | |
[email protected] | 80549c15 | 2013-07-02 01:42:47 | [diff] [blame] | 410 | if (!shelf_.get()) |
| 411 | return; |
[email protected] | 79a87b7e | 2013-01-25 05:08:22 | [diff] [blame] | 412 | // panel_layout_manager_ needs to be shut down before windows are destroyed. |
| 413 | if (panel_layout_manager_) { |
| 414 | panel_layout_manager_->Shutdown(); |
| 415 | panel_layout_manager_ = NULL; |
| 416 | } |
[email protected] | 7115bd3 | 2013-07-19 08:25:39 | [diff] [blame] | 417 | // docked_layout_manager_ needs to be shut down before windows are destroyed. |
| 418 | if (docked_layout_manager_) { |
| 419 | if (shelf_->shelf_layout_manager()) |
| 420 | docked_layout_manager_->RemoveObserver(shelf_->shelf_layout_manager()); |
| 421 | docked_layout_manager_->Shutdown(); |
| 422 | docked_layout_manager_ = NULL; |
| 423 | } |
[email protected] | 79a87b7e | 2013-01-25 05:08:22 | [diff] [blame] | 424 | |
[email protected] | 8b3e3d8 | 2013-08-20 14:36:30 | [diff] [blame] | 425 | aura::client::SetDragDropClient(root_window_.get(), NULL); |
| 426 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 427 | // TODO(harrym): Remove when Status Area Widget is a child view. |
[email protected] | 80549c15 | 2013-07-02 01:42:47 | [diff] [blame] | 428 | shelf_->ShutdownStatusAreaWidget(); |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 429 | |
[email protected] | 80549c15 | 2013-07-02 01:42:47 | [diff] [blame] | 430 | if (shelf_->shelf_layout_manager()) |
[email protected] | a3e41271 | 2013-07-11 09:32:58 | [diff] [blame] | 431 | shelf_->shelf_layout_manager()->PrepareForShutdown(); |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 432 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 433 | // Close background widget first as it depends on tooltip. |
[email protected] | 0bf6173 | 2013-07-02 04:35:10 | [diff] [blame] | 434 | wallpaper_controller_.reset(); |
| 435 | animating_wallpaper_controller_.reset(); |
[email protected] | b4ddc7a | 2012-08-07 04:17:32 | [diff] [blame] | 436 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 437 | workspace_controller_.reset(); |
| 438 | aura::client::SetTooltipClient(root_window_.get(), NULL); |
| 439 | |
[email protected] | 0fbfa97 | 2013-10-02 19:23:33 | [diff] [blame^] | 440 | // Explicitly destroy top level windows. We do this as during part of |
| 441 | // destruction such windows may query the RootWindow for state. |
[email protected] | 8b3e3d8 | 2013-08-20 14:36:30 | [diff] [blame] | 442 | std::queue<aura::Window*> non_toplevel_windows; |
| 443 | non_toplevel_windows.push(root_window_.get()); |
| 444 | while (!non_toplevel_windows.empty()) { |
| 445 | aura::Window* non_toplevel_window = non_toplevel_windows.front(); |
| 446 | non_toplevel_windows.pop(); |
| 447 | aura::WindowTracker toplevel_windows; |
| 448 | for (size_t i = 0; i < non_toplevel_window->children().size(); ++i) { |
| 449 | aura::Window* child = non_toplevel_window->children()[i]; |
[email protected] | 0fbfa97 | 2013-10-02 19:23:33 | [diff] [blame^] | 450 | if (!child->owned_by_parent()) |
| 451 | continue; |
[email protected] | 8b3e3d8 | 2013-08-20 14:36:30 | [diff] [blame] | 452 | if (child->delegate()) |
| 453 | toplevel_windows.Add(child); |
| 454 | else |
| 455 | non_toplevel_windows.push(child); |
| 456 | } |
| 457 | while (!toplevel_windows.windows().empty()) |
| 458 | delete *toplevel_windows.windows().begin(); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 459 | } |
[email protected] | 8b3e3d8 | 2013-08-20 14:36:30 | [diff] [blame] | 460 | // And then remove the containers. |
[email protected] | 0fbfa97 | 2013-10-02 19:23:33 | [diff] [blame^] | 461 | while (!root_window_->children().empty()) { |
| 462 | aura::Window* window = root_window_->children()[0]; |
| 463 | if (window->owned_by_parent()) { |
| 464 | delete window; |
| 465 | } else { |
| 466 | root_window_->RemoveChild(window); |
| 467 | } |
| 468 | } |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 469 | |
| 470 | shelf_.reset(NULL); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 471 | } |
| 472 | |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 473 | void RootWindowController::MoveWindowsTo(aura::RootWindow* dst) { |
[email protected] | 8039e06c | 2013-01-17 23:34:50 | [diff] [blame] | 474 | // Forget the shelf early so that shelf don't update itself using wrong |
| 475 | // display info. |
| 476 | workspace_controller_->SetShelf(NULL); |
[email protected] | 9505857 | 2012-08-20 14:57:29 | [diff] [blame] | 477 | ReparentAllWindows(root_window_.get(), dst); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 478 | } |
| 479 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 480 | ShelfLayoutManager* RootWindowController::GetShelfLayoutManager() { |
[email protected] | 80549c15 | 2013-07-02 01:42:47 | [diff] [blame] | 481 | return shelf_->shelf_layout_manager(); |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 482 | } |
| 483 | |
[email protected] | a0afeb1 | 2012-12-10 22:57:09 | [diff] [blame] | 484 | SystemTray* RootWindowController::GetSystemTray() { |
| 485 | // We assume in throughout the code that this will not return NULL. If code |
| 486 | // triggers this for valid reasons, it should test status_area_widget first. |
[email protected] | 80549c15 | 2013-07-02 01:42:47 | [diff] [blame] | 487 | CHECK(shelf_->status_area_widget()); |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 488 | return shelf_->status_area_widget()->system_tray(); |
[email protected] | a0afeb1 | 2012-12-10 22:57:09 | [diff] [blame] | 489 | } |
| 490 | |
[email protected] | 940fb1c | 2013-06-18 16:54:28 | [diff] [blame] | 491 | void RootWindowController::ShowContextMenu(const gfx::Point& location_in_screen, |
| 492 | ui::MenuSourceType source_type) { |
[email protected] | 431552c | 2012-10-23 00:38:33 | [diff] [blame] | 493 | DCHECK(Shell::GetInstance()->delegate()); |
| 494 | scoped_ptr<ui::MenuModel> menu_model( |
[email protected] | 8c0ec43 | 2013-05-10 04:33:39 | [diff] [blame] | 495 | Shell::GetInstance()->delegate()->CreateContextMenu(root_window())); |
[email protected] | 7f7f65c | 2013-04-17 16:47:13 | [diff] [blame] | 496 | if (!menu_model) |
[email protected] | 8e837ec | 2013-01-31 01:48:33 | [diff] [blame] | 497 | return; |
[email protected] | 431552c | 2012-10-23 00:38:33 | [diff] [blame] | 498 | |
[email protected] | 6175fc4 | 2013-04-05 05:58:58 | [diff] [blame] | 499 | // Background controller may not be set yet if user clicked on status are |
| 500 | // before initial animation completion. See crbug.com/222218 |
[email protected] | 0bf6173 | 2013-07-02 04:35:10 | [diff] [blame] | 501 | if (!wallpaper_controller_.get()) |
[email protected] | 431552c | 2012-10-23 00:38:33 | [diff] [blame] | 502 | return; |
| 503 | |
[email protected] | 6175fc4 | 2013-04-05 05:58:58 | [diff] [blame] | 504 | views::MenuRunner menu_runner(menu_model.get()); |
[email protected] | 0bf6173 | 2013-07-02 04:35:10 | [diff] [blame] | 505 | if (menu_runner.RunMenuAt(wallpaper_controller_->widget(), |
[email protected] | 6175fc4 | 2013-04-05 05:58:58 | [diff] [blame] | 506 | NULL, gfx::Rect(location_in_screen, gfx::Size()), |
[email protected] | 940fb1c | 2013-06-18 16:54:28 | [diff] [blame] | 507 | views::MenuItemView::TOPLEFT, source_type, |
| 508 | views::MenuRunner::CONTEXT_MENU) == |
[email protected] | 6175fc4 | 2013-04-05 05:58:58 | [diff] [blame] | 509 | views::MenuRunner::MENU_DELETED) { |
| 510 | return; |
| 511 | } |
| 512 | |
[email protected] | 431552c | 2012-10-23 00:38:33 | [diff] [blame] | 513 | Shell::GetInstance()->UpdateShelfVisibility(); |
| 514 | } |
| 515 | |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 516 | void RootWindowController::UpdateShelfVisibility() { |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 517 | shelf_->shelf_layout_manager()->UpdateVisibilityState(); |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 518 | } |
| 519 | |
[email protected] | e3bc88e | 2013-09-06 06:22:06 | [diff] [blame] | 520 | const aura::Window* RootWindowController::GetTopmostFullscreenWindow() const { |
| 521 | const aura::Window::Windows& windows = |
| 522 | GetContainer(kShellWindowId_DefaultContainer)->children(); |
| 523 | for (aura::Window::Windows::const_reverse_iterator iter = windows.rbegin(); |
| 524 | iter != windows.rend(); ++iter) { |
[email protected] | a41b4e1 | 2013-09-20 04:36:34 | [diff] [blame] | 525 | if (wm::GetWindowState(*iter)->IsFullscreen()) |
[email protected] | e3bc88e | 2013-09-06 06:22:06 | [diff] [blame] | 526 | return *iter; |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 527 | } |
[email protected] | 700849f | 2013-04-30 17:49:20 | [diff] [blame] | 528 | return NULL; |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 529 | } |
| 530 | |
[email protected] | 86459e2c | 2013-04-10 13:39:24 | [diff] [blame] | 531 | void RootWindowController::InitKeyboard() { |
| 532 | if (keyboard::IsKeyboardEnabled()) { |
| 533 | aura::Window* parent = root_window(); |
| 534 | |
| 535 | keyboard::KeyboardControllerProxy* proxy = |
| 536 | Shell::GetInstance()->delegate()->CreateKeyboardControllerProxy(); |
| 537 | keyboard_controller_.reset( |
| 538 | new keyboard::KeyboardController(proxy)); |
[email protected] | 5416f28 | 2013-04-29 20:52:48 | [diff] [blame] | 539 | |
| 540 | keyboard_controller_->AddObserver(shelf()->shelf_layout_manager()); |
| 541 | keyboard_controller_->AddObserver(panel_layout_manager_); |
| 542 | |
[email protected] | 45c6667 | 2013-10-01 22:48:56 | [diff] [blame] | 543 | // Deletes the old container since |keyboard_controller_| creates a |
| 544 | // new container window in GetContainerWindow(). |
| 545 | delete GetContainer(kShellWindowId_VirtualKeyboardContainer); |
| 546 | |
[email protected] | 86459e2c | 2013-04-10 13:39:24 | [diff] [blame] | 547 | aura::Window* keyboard_container = |
| 548 | keyboard_controller_->GetContainerWindow(); |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 549 | keyboard_container->set_id(kShellWindowId_VirtualKeyboardContainer); |
[email protected] | 86459e2c | 2013-04-10 13:39:24 | [diff] [blame] | 550 | parent->AddChild(keyboard_container); |
[email protected] | e0f7113 | 2013-04-17 12:32:51 | [diff] [blame] | 551 | keyboard_container->SetBounds(parent->bounds()); |
[email protected] | 86459e2c | 2013-04-10 13:39:24 | [diff] [blame] | 552 | } |
| 553 | } |
| 554 | |
| 555 | |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 556 | //////////////////////////////////////////////////////////////////////////////// |
| 557 | // RootWindowController, private: |
| 558 | |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 559 | void RootWindowController::InitLayoutManagers() { |
| 560 | root_window_layout_ = |
| 561 | new RootWindowLayoutManager(root_window_.get()); |
| 562 | root_window_->SetLayoutManager(root_window_layout_); |
| 563 | |
| 564 | aura::Window* default_container = |
| 565 | GetContainer(kShellWindowId_DefaultContainer); |
| 566 | // Workspace manager has its own layout managers. |
| 567 | workspace_controller_.reset( |
| 568 | new WorkspaceController(default_container)); |
| 569 | |
| 570 | aura::Window* always_on_top_container = |
| 571 | GetContainer(kShellWindowId_AlwaysOnTopContainer); |
| 572 | always_on_top_container->SetLayoutManager( |
| 573 | new BaseLayoutManager( |
| 574 | always_on_top_container->GetRootWindow())); |
| 575 | always_on_top_controller_.reset(new internal::AlwaysOnTopController); |
| 576 | always_on_top_controller_->SetAlwaysOnTopContainer(always_on_top_container); |
| 577 | |
| 578 | DCHECK(!shelf_.get()); |
| 579 | aura::Window* shelf_container = |
| 580 | GetContainer(internal::kShellWindowId_ShelfContainer); |
| 581 | // TODO(harrym): Remove when status area is view. |
| 582 | aura::Window* status_container = |
| 583 | GetContainer(internal::kShellWindowId_StatusContainer); |
| 584 | shelf_.reset(new ShelfWidget( |
| 585 | shelf_container, status_container, workspace_controller())); |
| 586 | |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 587 | if (!Shell::GetInstance()->session_state_delegate()-> |
| 588 | IsActiveUserSessionStarted()) { |
| 589 | // This window exists only to be a event target on login screen. |
| 590 | // It does not have to handle events, nor be visible. |
| 591 | mouse_event_target_.reset(new aura::Window(new EmptyWindowDelegate)); |
| 592 | mouse_event_target_->Init(ui::LAYER_NOT_DRAWN); |
| 593 | |
| 594 | aura::Window* lock_background_container = |
| 595 | GetContainer(internal::kShellWindowId_LockScreenBackgroundContainer); |
| 596 | lock_background_container->AddChild(mouse_event_target_.get()); |
| 597 | mouse_event_target_->Show(); |
| 598 | } |
| 599 | |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 600 | // Create Docked windows layout manager |
| 601 | aura::Window* docked_container = GetContainer( |
| 602 | internal::kShellWindowId_DockedContainer); |
| 603 | docked_layout_manager_ = |
| 604 | new internal::DockedWindowLayoutManager(docked_container); |
| 605 | docked_container_handler_.reset( |
| 606 | new ToplevelWindowEventHandler(docked_container)); |
| 607 | docked_container->SetLayoutManager(docked_layout_manager_); |
| 608 | |
| 609 | // Create Panel layout manager |
| 610 | aura::Window* panel_container = GetContainer( |
| 611 | internal::kShellWindowId_PanelContainer); |
| 612 | panel_layout_manager_ = |
| 613 | new internal::PanelLayoutManager(panel_container); |
| 614 | panel_container_handler_.reset( |
| 615 | new PanelWindowEventHandler(panel_container)); |
| 616 | panel_container->SetLayoutManager(panel_layout_manager_); |
| 617 | } |
| 618 | |
| 619 | void RootWindowController::InitTouchHuds() { |
| 620 | CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 621 | if (command_line->HasSwitch(switches::kAshTouchHud)) |
| 622 | set_touch_hud_debug(new TouchHudDebug(root_window_.get())); |
| 623 | if (Shell::GetInstance()->is_touch_hud_projection_enabled()) |
| 624 | EnableTouchHudProjection(); |
| 625 | } |
| 626 | |
| 627 | void RootWindowController::CreateSystemBackground( |
| 628 | bool is_first_run_after_boot) { |
| 629 | SkColor color = SK_ColorBLACK; |
| 630 | #if defined(OS_CHROMEOS) |
| 631 | if (is_first_run_after_boot) |
| 632 | color = kChromeOsBootColor; |
| 633 | #endif |
| 634 | system_background_.reset( |
| 635 | new SystemBackgroundController(root_window_.get(), color)); |
| 636 | |
| 637 | #if defined(OS_CHROMEOS) |
| 638 | // Make a copy of the system's boot splash screen so we can composite it |
| 639 | // onscreen until the desktop background is ready. |
| 640 | if (is_first_run_after_boot && |
| 641 | (CommandLine::ForCurrentProcess()->HasSwitch( |
| 642 | switches::kAshCopyHostBackgroundAtBoot) || |
| 643 | CommandLine::ForCurrentProcess()->HasSwitch( |
| 644 | switches::kAshAnimateFromBootSplashScreen))) |
| 645 | boot_splash_screen_.reset(new BootSplashScreen(root_window_.get())); |
| 646 | #endif |
| 647 | } |
| 648 | |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 649 | void RootWindowController::CreateContainersInRootWindow( |
| 650 | aura::RootWindow* root_window) { |
| 651 | // These containers are just used by PowerButtonController to animate groups |
| 652 | // of containers simultaneously without messing up the current transformations |
| 653 | // on those containers. These are direct children of the root window; all of |
| 654 | // the other containers are their children. |
[email protected] | e6e41d2f | 2012-10-29 19:22:19 | [diff] [blame] | 655 | |
| 656 | // The desktop background container is not part of the lock animation, so it |
| 657 | // is not included in those animate groups. |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 658 | // When screen is locked desktop background is moved to lock screen background |
| 659 | // container (moved back on unlock). We want to make sure that there's an |
| 660 | // opaque layer occluding the non-lock-screen layers. |
[email protected] | e6e41d2f | 2012-10-29 19:22:19 | [diff] [blame] | 661 | aura::Window* desktop_background_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 662 | kShellWindowId_DesktopBackgroundContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 663 | "DesktopBackgroundContainer", |
| 664 | root_window); |
[email protected] | b5756e2 | 2012-11-30 01:32:02 | [diff] [blame] | 665 | views::corewm::SetChildWindowVisibilityChangesAnimated( |
| 666 | desktop_background_container); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 667 | |
| 668 | aura::Window* non_lock_screen_containers = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 669 | kShellWindowId_NonLockScreenContainersContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 670 | "NonLockScreenContainersContainer", |
| 671 | root_window); |
| 672 | |
| 673 | aura::Window* lock_background_containers = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 674 | kShellWindowId_LockScreenBackgroundContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 675 | "LockScreenBackgroundContainer", |
| 676 | root_window); |
[email protected] | b5756e2 | 2012-11-30 01:32:02 | [diff] [blame] | 677 | views::corewm::SetChildWindowVisibilityChangesAnimated( |
| 678 | lock_background_containers); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 679 | |
| 680 | aura::Window* lock_screen_containers = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 681 | kShellWindowId_LockScreenContainersContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 682 | "LockScreenContainersContainer", |
| 683 | root_window); |
| 684 | aura::Window* lock_screen_related_containers = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 685 | kShellWindowId_LockScreenRelatedContainersContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 686 | "LockScreenRelatedContainersContainer", |
| 687 | root_window); |
| 688 | |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 689 | CreateContainer(kShellWindowId_UnparentedControlContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 690 | "UnparentedControlContainer", |
| 691 | non_lock_screen_containers); |
| 692 | |
| 693 | aura::Window* default_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 694 | kShellWindowId_DefaultContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 695 | "DefaultContainer", |
| 696 | non_lock_screen_containers); |
[email protected] | b5756e2 | 2012-11-30 01:32:02 | [diff] [blame] | 697 | views::corewm::SetChildWindowVisibilityChangesAnimated(default_container); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 698 | SetUsesScreenCoordinates(default_container); |
| 699 | |
| 700 | aura::Window* always_on_top_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 701 | kShellWindowId_AlwaysOnTopContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 702 | "AlwaysOnTopContainer", |
| 703 | non_lock_screen_containers); |
| 704 | always_on_top_container_handler_.reset( |
| 705 | new ToplevelWindowEventHandler(always_on_top_container)); |
[email protected] | b5756e2 | 2012-11-30 01:32:02 | [diff] [blame] | 706 | views::corewm::SetChildWindowVisibilityChangesAnimated( |
| 707 | always_on_top_container); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 708 | SetUsesScreenCoordinates(always_on_top_container); |
| 709 | |
[email protected] | beb4e5c | 2013-06-18 15:37:07 | [diff] [blame] | 710 | aura::Window* docked_container = CreateContainer( |
| 711 | kShellWindowId_DockedContainer, |
| 712 | "DockedContainer", |
| 713 | non_lock_screen_containers); |
[email protected] | 5eab6e9 | 2013-09-19 19:09:27 | [diff] [blame] | 714 | views::corewm::SetChildWindowVisibilityChangesAnimated(docked_container); |
[email protected] | beb4e5c | 2013-06-18 15:37:07 | [diff] [blame] | 715 | SetUsesScreenCoordinates(docked_container); |
| 716 | |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 717 | aura::Window* panel_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 718 | kShellWindowId_PanelContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 719 | "PanelContainer", |
| 720 | non_lock_screen_containers); |
| 721 | SetUsesScreenCoordinates(panel_container); |
| 722 | |
[email protected] | 3f13cf1 | 2013-07-12 05:13:59 | [diff] [blame] | 723 | aura::Window* shelf_container = |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 724 | CreateContainer(kShellWindowId_ShelfContainer, |
[email protected] | 3f13cf1 | 2013-07-12 05:13:59 | [diff] [blame] | 725 | "ShelfContainer", |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 726 | non_lock_screen_containers); |
[email protected] | 3f13cf1 | 2013-07-12 05:13:59 | [diff] [blame] | 727 | SetUsesScreenCoordinates(shelf_container); |
| 728 | DescendantShouldStayInSameRootWindow(shelf_container); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 729 | |
[email protected] | dc851a4e5 | 2012-10-03 00:05:55 | [diff] [blame] | 730 | aura::Window* app_list_container = |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 731 | CreateContainer(kShellWindowId_AppListContainer, |
[email protected] | dc851a4e5 | 2012-10-03 00:05:55 | [diff] [blame] | 732 | "AppListContainer", |
| 733 | non_lock_screen_containers); |
| 734 | SetUsesScreenCoordinates(app_list_container); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 735 | |
| 736 | aura::Window* modal_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 737 | kShellWindowId_SystemModalContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 738 | "SystemModalContainer", |
| 739 | non_lock_screen_containers); |
| 740 | modal_container_handler_.reset( |
| 741 | new ToplevelWindowEventHandler(modal_container)); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 742 | modal_container->SetLayoutManager( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 743 | new SystemModalContainerLayoutManager(modal_container)); |
[email protected] | b5756e2 | 2012-11-30 01:32:02 | [diff] [blame] | 744 | views::corewm::SetChildWindowVisibilityChangesAnimated(modal_container); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 745 | SetUsesScreenCoordinates(modal_container); |
| 746 | |
| 747 | aura::Window* input_method_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 748 | kShellWindowId_InputMethodContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 749 | "InputMethodContainer", |
| 750 | non_lock_screen_containers); |
| 751 | SetUsesScreenCoordinates(input_method_container); |
| 752 | |
| 753 | // TODO(beng): Figure out if we can make this use |
| 754 | // SystemModalContainerEventFilter instead of stops_event_propagation. |
| 755 | aura::Window* lock_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 756 | kShellWindowId_LockScreenContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 757 | "LockScreenContainer", |
| 758 | lock_screen_containers); |
| 759 | lock_container->SetLayoutManager( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 760 | new BaseLayoutManager(root_window)); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 761 | SetUsesScreenCoordinates(lock_container); |
| 762 | // TODO(beng): stopsevents |
| 763 | |
| 764 | aura::Window* lock_modal_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 765 | kShellWindowId_LockSystemModalContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 766 | "LockSystemModalContainer", |
| 767 | lock_screen_containers); |
| 768 | lock_modal_container_handler_.reset( |
| 769 | new ToplevelWindowEventHandler(lock_modal_container)); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 770 | lock_modal_container->SetLayoutManager( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 771 | new SystemModalContainerLayoutManager(lock_modal_container)); |
[email protected] | b5756e2 | 2012-11-30 01:32:02 | [diff] [blame] | 772 | views::corewm::SetChildWindowVisibilityChangesAnimated(lock_modal_container); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 773 | SetUsesScreenCoordinates(lock_modal_container); |
| 774 | |
| 775 | aura::Window* status_container = |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 776 | CreateContainer(kShellWindowId_StatusContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 777 | "StatusContainer", |
| 778 | lock_screen_related_containers); |
| 779 | SetUsesScreenCoordinates(status_container); |
[email protected] | e887c6c | 2013-07-08 19:35:53 | [diff] [blame] | 780 | DescendantShouldStayInSameRootWindow(status_container); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 781 | |
| 782 | aura::Window* settings_bubble_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 783 | kShellWindowId_SettingBubbleContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 784 | "SettingBubbleContainer", |
| 785 | lock_screen_related_containers); |
[email protected] | b5756e2 | 2012-11-30 01:32:02 | [diff] [blame] | 786 | views::corewm::SetChildWindowVisibilityChangesAnimated( |
| 787 | settings_bubble_container); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 788 | SetUsesScreenCoordinates(settings_bubble_container); |
[email protected] | e887c6c | 2013-07-08 19:35:53 | [diff] [blame] | 789 | DescendantShouldStayInSameRootWindow(settings_bubble_container); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 790 | |
| 791 | aura::Window* menu_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 792 | kShellWindowId_MenuContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 793 | "MenuContainer", |
| 794 | lock_screen_related_containers); |
[email protected] | b5756e2 | 2012-11-30 01:32:02 | [diff] [blame] | 795 | views::corewm::SetChildWindowVisibilityChangesAnimated(menu_container); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 796 | SetUsesScreenCoordinates(menu_container); |
| 797 | |
| 798 | aura::Window* drag_drop_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 799 | kShellWindowId_DragImageAndTooltipContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 800 | "DragImageAndTooltipContainer", |
| 801 | lock_screen_related_containers); |
[email protected] | b5756e2 | 2012-11-30 01:32:02 | [diff] [blame] | 802 | views::corewm::SetChildWindowVisibilityChangesAnimated(drag_drop_container); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 803 | SetUsesScreenCoordinates(drag_drop_container); |
| 804 | |
| 805 | aura::Window* overlay_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 806 | kShellWindowId_OverlayContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 807 | "OverlayContainer", |
| 808 | lock_screen_related_containers); |
| 809 | SetUsesScreenCoordinates(overlay_container); |
[email protected] | a07615f | 2012-10-24 08:23:08 | [diff] [blame] | 810 | |
| 811 | CreateContainer(kShellWindowId_PowerButtonAnimationContainer, |
| 812 | "PowerButtonAnimationContainer", root_window) ; |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 813 | } |
| 814 | |
[email protected] | d141b92 | 2013-07-09 08:13:17 | [diff] [blame] | 815 | void RootWindowController::EnableTouchHudProjection() { |
| 816 | if (touch_hud_projection_) |
| 817 | return; |
| 818 | set_touch_hud_projection(new TouchHudProjection(root_window_.get())); |
| 819 | } |
| 820 | |
| 821 | void RootWindowController::DisableTouchHudProjection() { |
| 822 | if (!touch_hud_projection_) |
| 823 | return; |
| 824 | touch_hud_projection_->Remove(); |
| 825 | } |
| 826 | |
| 827 | void RootWindowController::OnLoginStateChanged(user::LoginStatus status) { |
[email protected] | fb23d56 | 2013-09-25 00:43:10 | [diff] [blame] | 828 | if (status != user::LOGGED_IN_NONE) |
| 829 | InitKeyboard(); |
[email protected] | d141b92 | 2013-07-09 08:13:17 | [diff] [blame] | 830 | shelf_->shelf_layout_manager()->UpdateVisibilityState(); |
| 831 | } |
| 832 | |
| 833 | void RootWindowController::OnTouchHudProjectionToggled(bool enabled) { |
| 834 | if (enabled) |
| 835 | EnableTouchHudProjection(); |
| 836 | else |
| 837 | DisableTouchHudProjection(); |
| 838 | } |
| 839 | |
[email protected] | 6b2d4a0b | 2013-09-06 06:29:54 | [diff] [blame] | 840 | RootWindowController* GetRootWindowController( |
| 841 | const aura::RootWindow* root_window) { |
| 842 | return root_window ? GetRootWindowSettings(root_window)->controller : NULL; |
| 843 | } |
| 844 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 845 | } // namespace internal |
| 846 | } // namespace ash |