[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] | a273d33a | 2013-10-17 12:41:21 | [diff] [blame] | 12 | #include "ash/desktop_background/desktop_background_controller.h" |
[email protected] | b4ddc7a | 2012-08-07 04:17:32 | [diff] [blame] | 13 | #include "ash/desktop_background/desktop_background_widget_controller.h" |
[email protected] | 0bf6173 | 2013-07-02 04:35:10 | [diff] [blame] | 14 | #include "ash/desktop_background/user_wallpaper_delegate.h" |
[email protected] | 6bdf795 | 2012-11-14 10:10:58 | [diff] [blame] | 15 | #include "ash/display/display_manager.h" |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 16 | #include "ash/focus_cycler.h" |
[email protected] | a273d33a | 2013-10-17 12:41:21 | [diff] [blame] | 17 | #include "ash/high_contrast/high_contrast_controller.h" |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 18 | #include "ash/host/ash_window_tree_host.h" |
[email protected] | f8e6aad | 2013-08-30 21:49:11 | [diff] [blame] | 19 | #include "ash/root_window_settings.h" |
[email protected] | fcb123d | 2013-04-17 15:58:49 | [diff] [blame] | 20 | #include "ash/session_state_delegate.h" |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 21 | #include "ash/shelf/shelf_layout_manager.h" |
| 22 | #include "ash/shelf/shelf_types.h" |
| 23 | #include "ash/shelf/shelf_widget.h" |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 24 | #include "ash/shell.h" |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 25 | #include "ash/shell_delegate.h" |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 26 | #include "ash/shell_factory.h" |
| 27 | #include "ash/shell_window_ids.h" |
[email protected] | 2c5db9e | 2014-02-27 13:58:14 | [diff] [blame] | 28 | #include "ash/switchable_windows.h" |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 29 | #include "ash/system/status_area_widget.h" |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 30 | #include "ash/system/tray/system_tray_delegate.h" |
[email protected] | 2b8a9bb | 2013-07-01 22:43:40 | [diff] [blame] | 31 | #include "ash/touch/touch_hud_debug.h" |
| 32 | #include "ash/touch/touch_hud_projection.h" |
[email protected] | 80549c15 | 2013-07-02 01:42:47 | [diff] [blame] | 33 | #include "ash/touch/touch_observer_hud.h" |
| 34 | #include "ash/wm/always_on_top_controller.h" |
[email protected] | beb4e5c | 2013-06-18 15:37:07 | [diff] [blame] | 35 | #include "ash/wm/dock/docked_window_layout_manager.h" |
[email protected] | b8642ec | 2014-04-17 05:20:39 | [diff] [blame^] | 36 | #include "ash/wm/panels/attached_panel_window_targeter.h" |
[email protected] | 7095a65 | 2013-03-07 19:41:49 | [diff] [blame] | 37 | #include "ash/wm/panels/panel_layout_manager.h" |
[email protected] | 10065941 | 2013-06-21 22:59:55 | [diff] [blame] | 38 | #include "ash/wm/panels/panel_window_event_handler.h" |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 39 | #include "ash/wm/root_window_layout_manager.h" |
| 40 | #include "ash/wm/screen_dimmer.h" |
[email protected] | 2a2caa0 | 2013-01-22 20:50:36 | [diff] [blame] | 41 | #include "ash/wm/stacking_controller.h" |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 42 | #include "ash/wm/status_area_layout_manager.h" |
[email protected] | e6e41d2f | 2012-10-29 19:22:19 | [diff] [blame] | 43 | #include "ash/wm/system_background_controller.h" |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 44 | #include "ash/wm/system_modal_container_layout_manager.h" |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 45 | #include "ash/wm/window_properties.h" |
[email protected] | a41b4e1 | 2013-09-20 04:36:34 | [diff] [blame] | 46 | #include "ash/wm/window_state.h" |
[email protected] | 700849f | 2013-04-30 17:49:20 | [diff] [blame] | 47 | #include "ash/wm/window_util.h" |
[email protected] | 1af71f7 | 2014-01-29 20:00:55 | [diff] [blame] | 48 | #include "ash/wm/workspace/workspace_layout_manager.h" |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 49 | #include "ash/wm/workspace_controller.h" |
[email protected] | e6e41d2f | 2012-10-29 19:22:19 | [diff] [blame] | 50 | #include "base/command_line.h" |
[email protected] | 1e84c63 | 2013-06-27 23:12:21 | [diff] [blame] | 51 | #include "base/time/time.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 52 | #include "ui/aura/client/aura_constants.h" |
[email protected] | 2374d181 | 2014-03-04 03:42:27 | [diff] [blame] | 53 | #include "ui/aura/client/screen_position_client.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 54 | #include "ui/aura/window.h" |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 55 | #include "ui/aura/window_delegate.h" |
[email protected] | fcc51c95 | 2014-02-21 21:31:26 | [diff] [blame] | 56 | #include "ui/aura/window_event_dispatcher.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 57 | #include "ui/aura/window_observer.h" |
[email protected] | 8b3e3d8 | 2013-08-20 14:36:30 | [diff] [blame] | 58 | #include "ui/aura/window_tracker.h" |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 59 | #include "ui/base/hit_test.h" |
[email protected] | 431552c | 2012-10-23 00:38:33 | [diff] [blame] | 60 | #include "ui/base/models/menu_model.h" |
[email protected] | f8e6aad | 2013-08-30 21:49:11 | [diff] [blame] | 61 | #include "ui/gfx/display.h" |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 62 | #include "ui/gfx/screen.h" |
[email protected] | 86459e2c | 2013-04-10 13:39:24 | [diff] [blame] | 63 | #include "ui/keyboard/keyboard_controller.h" |
| 64 | #include "ui/keyboard/keyboard_util.h" |
[email protected] | 431552c | 2012-10-23 00:38:33 | [diff] [blame] | 65 | #include "ui/views/controls/menu/menu_runner.h" |
| 66 | #include "ui/views/view_model.h" |
| 67 | #include "ui/views/view_model_utils.h" |
[email protected] | ee3ed1077 | 2014-03-11 22:02:01 | [diff] [blame] | 68 | #include "ui/wm/core/capture_controller.h" |
[email protected] | e319c7e | 2014-03-14 19:56:14 | [diff] [blame] | 69 | #include "ui/wm/core/easy_resize_window_targeter.h" |
[email protected] | ee3ed1077 | 2014-03-11 22:02:01 | [diff] [blame] | 70 | #include "ui/wm/core/visibility_controller.h" |
| 71 | #include "ui/wm/core/window_util.h" |
[email protected] | af4552b2 | 2014-03-21 19:45:01 | [diff] [blame] | 72 | #include "ui/wm/public/drag_drop_client.h" |
| 73 | #include "ui/wm/public/tooltip_client.h" |
[email protected] | 5b251f1 | 2013-12-19 01:50:05 | [diff] [blame] | 74 | #include "ui/wm/public/window_types.h" |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 75 | |
[email protected] | 252eb23 | 2013-08-14 22:09:27 | [diff] [blame] | 76 | #if defined(OS_CHROMEOS) |
| 77 | #include "ash/wm/boot_splash_screen_chromeos.h" |
| 78 | #endif |
| 79 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 80 | namespace ash { |
| 81 | namespace { |
| 82 | |
[email protected] | 252eb23 | 2013-08-14 22:09:27 | [diff] [blame] | 83 | #if defined(OS_CHROMEOS) |
[email protected] | bca9a7e | 2012-11-10 06:25:49 | [diff] [blame] | 84 | // Duration for the animation that hides the boot splash screen, in |
| 85 | // milliseconds. This should be short enough in relation to |
| 86 | // wm/window_animation.cc's brightness/grayscale fade animation that the login |
| 87 | // background image animation isn't hidden by the splash screen animation. |
| 88 | const int kBootSplashScreenHideDurationMs = 500; |
[email protected] | 252eb23 | 2013-08-14 22:09:27 | [diff] [blame] | 89 | #endif |
[email protected] | bca9a7e | 2012-11-10 06:25:49 | [diff] [blame] | 90 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 91 | // Creates a new window for use as a container. |
| 92 | aura::Window* CreateContainer(int window_id, |
| 93 | const char* name, |
| 94 | aura::Window* parent) { |
| 95 | aura::Window* container = new aura::Window(NULL); |
| 96 | container->set_id(window_id); |
| 97 | container->SetName(name); |
[email protected] | 52b02a7 | 2014-01-08 21:41:50 | [diff] [blame] | 98 | container->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 99 | parent->AddChild(container); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 100 | if (window_id != kShellWindowId_UnparentedControlContainer) |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 101 | container->Show(); |
| 102 | return container; |
| 103 | } |
| 104 | |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 105 | float ToRelativeValue(int value, int src, int dst) { |
| 106 | return static_cast<float>(value) / static_cast<float>(src) * dst; |
| 107 | } |
| 108 | |
| 109 | void MoveOriginRelativeToSize(const gfx::Size& src_size, |
| 110 | const gfx::Size& dst_size, |
| 111 | gfx::Rect* bounds_in_out) { |
| 112 | gfx::Point origin = bounds_in_out->origin(); |
| 113 | bounds_in_out->set_origin(gfx::Point( |
| 114 | ToRelativeValue(origin.x(), src_size.width(), dst_size.width()), |
| 115 | ToRelativeValue(origin.y(), src_size.height(), dst_size.height()))); |
| 116 | } |
| 117 | |
[email protected] | 9505857 | 2012-08-20 14:57:29 | [diff] [blame] | 118 | // Reparents |window| to |new_parent|. |
| 119 | void ReparentWindow(aura::Window* window, aura::Window* new_parent) { |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 120 | const gfx::Size src_size = window->parent()->bounds().size(); |
| 121 | const gfx::Size dst_size = new_parent->bounds().size(); |
[email protected] | 9505857 | 2012-08-20 14:57:29 | [diff] [blame] | 122 | // Update the restore bounds to make it relative to the display. |
[email protected] | a41b4e1 | 2013-09-20 04:36:34 | [diff] [blame] | 123 | wm::WindowState* state = wm::GetWindowState(window); |
| 124 | gfx::Rect restore_bounds; |
| 125 | bool has_restore_bounds = state->HasRestoreBounds(); |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 126 | |
[email protected] | 9cfd3d1 | 2014-02-25 15:33:45 | [diff] [blame] | 127 | bool update_bounds = (state->IsNormalOrSnapped() || state->IsMinimized()) && |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 128 | new_parent->id() != kShellWindowId_DockedContainer; |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 129 | gfx::Rect local_bounds; |
| 130 | if (update_bounds) { |
| 131 | local_bounds = state->window()->bounds(); |
| 132 | MoveOriginRelativeToSize(src_size, dst_size, &local_bounds); |
| 133 | } |
| 134 | |
| 135 | if (has_restore_bounds) { |
[email protected] | a41b4e1 | 2013-09-20 04:36:34 | [diff] [blame] | 136 | restore_bounds = state->GetRestoreBoundsInParent(); |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 137 | MoveOriginRelativeToSize(src_size, dst_size, &restore_bounds); |
| 138 | } |
| 139 | |
[email protected] | 9505857 | 2012-08-20 14:57:29 | [diff] [blame] | 140 | new_parent->AddChild(window); |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 141 | |
[email protected] | 8663b7a6 | 2014-01-18 01:24:21 | [diff] [blame] | 142 | // Docked windows have bounds handled by the layout manager in AddChild(). |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 143 | if (update_bounds) |
| 144 | window->SetBounds(local_bounds); |
| 145 | |
[email protected] | a41b4e1 | 2013-09-20 04:36:34 | [diff] [blame] | 146 | if (has_restore_bounds) |
| 147 | state->SetRestoreBoundsInParent(restore_bounds); |
[email protected] | 9505857 | 2012-08-20 14:57:29 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | // Reparents the appropriate set of windows from |src| to |dst|. |
[email protected] | bf9cdb36 | 2013-10-25 19:22:45 | [diff] [blame] | 151 | void ReparentAllWindows(aura::Window* src, aura::Window* dst) { |
[email protected] | 9505857 | 2012-08-20 14:57:29 | [diff] [blame] | 152 | // Set of windows to move. |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 153 | const int kContainerIdsToMove[] = { |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 154 | kShellWindowId_DefaultContainer, |
| 155 | kShellWindowId_DockedContainer, |
| 156 | kShellWindowId_PanelContainer, |
| 157 | kShellWindowId_AlwaysOnTopContainer, |
| 158 | kShellWindowId_SystemModalContainer, |
| 159 | kShellWindowId_LockSystemModalContainer, |
| 160 | kShellWindowId_InputMethodContainer, |
| 161 | kShellWindowId_UnparentedControlContainer, }; |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 162 | for (size_t i = 0; i < arraysize(kContainerIdsToMove); i++) { |
| 163 | int id = kContainerIdsToMove[i]; |
| 164 | aura::Window* src_container = Shell::GetContainer(src, id); |
| 165 | aura::Window* dst_container = Shell::GetContainer(dst, id); |
[email protected] | 5b602190 | 2013-02-26 05:33:29 | [diff] [blame] | 166 | while (!src_container->children().empty()) { |
| 167 | // Restart iteration from the source container windows each time as they |
| 168 | // may change as a result of moving other windows. |
| 169 | aura::Window::Windows::const_iterator iter = |
| 170 | src_container->children().begin(); |
| 171 | while (iter != src_container->children().end() && |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 172 | SystemModalContainerLayoutManager::IsModalBackground(*iter)) { |
[email protected] | 5b602190 | 2013-02-26 05:33:29 | [diff] [blame] | 173 | ++iter; |
| 174 | } |
| 175 | // If the entire window list is modal background windows then stop. |
| 176 | if (iter == src_container->children().end()) |
| 177 | break; |
| 178 | ReparentWindow(*iter, dst_container); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 179 | } |
| 180 | } |
| 181 | } |
| 182 | |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 183 | // Mark the container window so that a widget added to this container will |
| 184 | // use the virtual screeen coordinates instead of parent. |
| 185 | void SetUsesScreenCoordinates(aura::Window* container) { |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 186 | container->SetProperty(kUsesScreenCoordinatesKey, true); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 187 | } |
| 188 | |
[email protected] | e887c6c | 2013-07-08 19:35:53 | [diff] [blame] | 189 | // Mark the container window so that a widget added to this container will |
| 190 | // say in the same root window regardless of the bounds specified. |
| 191 | void DescendantShouldStayInSameRootWindow(aura::Window* container) { |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 192 | container->SetProperty(kStayInSameRootWindowKey, true); |
[email protected] | e887c6c | 2013-07-08 19:35:53 | [diff] [blame] | 193 | } |
| 194 | |
[email protected] | c5be8d67 | 2014-01-07 13:33:41 | [diff] [blame] | 195 | void SetUsesEasyResizeTargeter(aura::Window* container) { |
| 196 | gfx::Insets mouse_extend(-kResizeOutsideBoundsSize, |
| 197 | -kResizeOutsideBoundsSize, |
| 198 | -kResizeOutsideBoundsSize, |
| 199 | -kResizeOutsideBoundsSize); |
| 200 | gfx::Insets touch_extend = mouse_extend.Scale( |
| 201 | kResizeOutsideBoundsScaleForTouch); |
[email protected] | 95f642cb | 2014-01-31 01:35:41 | [diff] [blame] | 202 | container->SetEventTargeter(scoped_ptr<ui::EventTargeter>( |
[email protected] | c5be8d67 | 2014-01-07 13:33:41 | [diff] [blame] | 203 | new ::wm::EasyResizeWindowTargeter(container, mouse_extend, |
| 204 | touch_extend))); |
| 205 | } |
| 206 | |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 207 | // A window delegate which does nothing. Used to create a window that |
| 208 | // is a event target, but do nothing. |
| 209 | class EmptyWindowDelegate : public aura::WindowDelegate { |
| 210 | public: |
| 211 | EmptyWindowDelegate() {} |
| 212 | virtual ~EmptyWindowDelegate() {} |
| 213 | |
| 214 | // aura::WindowDelegate overrides: |
| 215 | virtual gfx::Size GetMinimumSize() const OVERRIDE { |
| 216 | return gfx::Size(); |
| 217 | } |
| 218 | virtual gfx::Size GetMaximumSize() const OVERRIDE { |
| 219 | return gfx::Size(); |
| 220 | } |
| 221 | virtual void OnBoundsChanged(const gfx::Rect& old_bounds, |
| 222 | const gfx::Rect& new_bounds) OVERRIDE { |
| 223 | } |
[email protected] | 62c9f10 | 2014-03-27 06:07:04 | [diff] [blame] | 224 | virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE { |
| 225 | return gfx::kNullCursor; |
| 226 | } |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 227 | virtual int GetNonClientComponent( |
| 228 | const gfx::Point& point) const OVERRIDE { |
| 229 | return HTNOWHERE; |
| 230 | } |
| 231 | virtual bool ShouldDescendIntoChildForEventHandling( |
| 232 | aura::Window* child, |
| 233 | const gfx::Point& location) OVERRIDE { |
| 234 | return false; |
| 235 | } |
| 236 | virtual bool CanFocus() OVERRIDE { |
| 237 | return false; |
| 238 | } |
| 239 | virtual void OnCaptureLost() OVERRIDE { |
| 240 | } |
| 241 | virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { |
| 242 | } |
| 243 | virtual void OnDeviceScaleFactorChanged( |
| 244 | float device_scale_factor) OVERRIDE { |
| 245 | } |
[email protected] | 48f36d9 | 2014-02-28 00:11:37 | [diff] [blame] | 246 | virtual void OnWindowDestroying(aura::Window* window) OVERRIDE {} |
| 247 | virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE { |
[email protected] | febe1fd6 | 2013-08-07 16:07:24 | [diff] [blame] | 248 | delete this; |
| 249 | } |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 250 | virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE { |
| 251 | } |
| 252 | virtual bool HasHitTestMask() const OVERRIDE { |
| 253 | return false; |
| 254 | } |
| 255 | virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE {} |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 256 | |
| 257 | private: |
| 258 | DISALLOW_COPY_AND_ASSIGN(EmptyWindowDelegate); |
| 259 | }; |
| 260 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 261 | } // namespace |
| 262 | |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 263 | void RootWindowController::CreateForPrimaryDisplay(AshWindowTreeHost* host) { |
[email protected] | 2f262033 | 2014-02-28 10:07:38 | [diff] [blame] | 264 | RootWindowController* controller = new RootWindowController(host); |
[email protected] | 608de6c | 2013-10-29 00:14:28 | [diff] [blame] | 265 | controller->Init(RootWindowController::PRIMARY, |
[email protected] | a273d33a | 2013-10-17 12:41:21 | [diff] [blame] | 266 | Shell::GetInstance()->delegate()->IsFirstRunAfterBoot()); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 267 | } |
| 268 | |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 269 | void RootWindowController::CreateForSecondaryDisplay(AshWindowTreeHost* host) { |
[email protected] | 2f262033 | 2014-02-28 10:07:38 | [diff] [blame] | 270 | RootWindowController* controller = new RootWindowController(host); |
[email protected] | 608de6c | 2013-10-29 00:14:28 | [diff] [blame] | 271 | controller->Init(RootWindowController::SECONDARY, false /* first run */); |
| 272 | } |
| 273 | |
| 274 | void RootWindowController::CreateForVirtualKeyboardDisplay( |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 275 | AshWindowTreeHost* host) { |
[email protected] | 2f262033 | 2014-02-28 10:07:38 | [diff] [blame] | 276 | RootWindowController* controller = new RootWindowController(host); |
[email protected] | 608de6c | 2013-10-29 00:14:28 | [diff] [blame] | 277 | controller->Init(RootWindowController::VIRTUAL_KEYBOARD, |
| 278 | false /* first run */); |
[email protected] | 6675e1c | 2012-09-11 09:15:45 | [diff] [blame] | 279 | } |
| 280 | |
[email protected] | 88d7112 | 2012-10-18 07:11:01 | [diff] [blame] | 281 | // static |
[email protected] | 864b5855 | 2013-12-19 04:19:38 | [diff] [blame] | 282 | RootWindowController* RootWindowController::ForShelf(aura::Window* window) { |
[email protected] | 8c0ec43 | 2013-05-10 04:33:39 | [diff] [blame] | 283 | return GetRootWindowController(window->GetRootWindow()); |
[email protected] | 88d7112 | 2012-10-18 07:11:01 | [diff] [blame] | 284 | } |
| 285 | |
[email protected] | a0afeb1 | 2012-12-10 22:57:09 | [diff] [blame] | 286 | // static |
[email protected] | ccff3d7 | 2013-02-06 04:26:28 | [diff] [blame] | 287 | RootWindowController* RootWindowController::ForWindow( |
| 288 | const aura::Window* window) { |
[email protected] | a0afeb1 | 2012-12-10 22:57:09 | [diff] [blame] | 289 | return GetRootWindowController(window->GetRootWindow()); |
| 290 | } |
| 291 | |
| 292 | // static |
[email protected] | d17642d | 2013-09-12 23:44:38 | [diff] [blame] | 293 | RootWindowController* RootWindowController::ForTargetRootWindow() { |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 294 | return GetRootWindowController(Shell::GetTargetRootWindow()); |
[email protected] | a0afeb1 | 2012-12-10 22:57:09 | [diff] [blame] | 295 | } |
| 296 | |
[email protected] | a5c7880 | 2013-12-12 22:07:01 | [diff] [blame] | 297 | // static |
| 298 | aura::Window* RootWindowController::GetContainerForWindow( |
| 299 | aura::Window* window) { |
| 300 | aura::Window* container = window->parent(); |
[email protected] | 5b251f1 | 2013-12-19 01:50:05 | [diff] [blame] | 301 | while (container && container->type() != ui::wm::WINDOW_TYPE_UNKNOWN) |
[email protected] | a5c7880 | 2013-12-12 22:07:01 | [diff] [blame] | 302 | container = container->parent(); |
| 303 | return container; |
| 304 | } |
| 305 | |
[email protected] | a273d33a | 2013-10-17 12:41:21 | [diff] [blame] | 306 | RootWindowController::~RootWindowController() { |
| 307 | Shutdown(); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 308 | ash_host_.reset(); |
[email protected] | a273d33a | 2013-10-17 12:41:21 | [diff] [blame] | 309 | // The CaptureClient needs to be around for as long as the RootWindow is |
| 310 | // valid. |
| 311 | capture_client_.reset(); |
| 312 | } |
| 313 | |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 314 | aura::WindowTreeHost* RootWindowController::GetHost() { |
| 315 | return ash_host_->AsWindowTreeHost(); |
| 316 | } |
| 317 | |
| 318 | const aura::WindowTreeHost* RootWindowController::GetHost() const { |
| 319 | return ash_host_->AsWindowTreeHost(); |
| 320 | } |
| 321 | |
| 322 | aura::Window* RootWindowController::GetRootWindow() { |
| 323 | return GetHost()->window(); |
| 324 | } |
| 325 | |
| 326 | const aura::Window* RootWindowController::GetRootWindow() const { |
| 327 | return GetHost()->window(); |
| 328 | } |
| 329 | |
[email protected] | 0bf6173 | 2013-07-02 04:35:10 | [diff] [blame] | 330 | void RootWindowController::SetWallpaperController( |
| 331 | DesktopBackgroundWidgetController* controller) { |
| 332 | wallpaper_controller_.reset(controller); |
| 333 | } |
| 334 | |
| 335 | void RootWindowController::SetAnimatingWallpaperController( |
| 336 | AnimatingDesktopController* controller) { |
| 337 | if (animating_wallpaper_controller_.get()) |
| 338 | animating_wallpaper_controller_->StopAnimating(); |
| 339 | animating_wallpaper_controller_.reset(controller); |
| 340 | } |
| 341 | |
[email protected] | 6675e1c | 2012-09-11 09:15:45 | [diff] [blame] | 342 | void RootWindowController::Shutdown() { |
[email protected] | d141b92 | 2013-07-09 08:13:17 | [diff] [blame] | 343 | Shell::GetInstance()->RemoveShellObserver(this); |
| 344 | |
[email protected] | 0bf6173 | 2013-07-02 04:35:10 | [diff] [blame] | 345 | if (animating_wallpaper_controller_.get()) |
| 346 | animating_wallpaper_controller_->StopAnimating(); |
| 347 | wallpaper_controller_.reset(); |
| 348 | animating_wallpaper_controller_.reset(); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 349 | aura::Window* root_window = GetRootWindow(); |
[email protected] | d17642d | 2013-09-12 23:44:38 | [diff] [blame] | 350 | // Change the target root window before closing child windows. If any child |
[email protected] | c98a492 | 2013-09-05 20:01:42 | [diff] [blame] | 351 | // 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] | 352 | // window list adding windows from the target root window's containers which |
[email protected] | c98a492 | 2013-09-05 20:01:42 | [diff] [blame] | 353 | // may have already gone away. |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 354 | if (Shell::GetTargetRootWindow() == root_window) { |
[email protected] | d17642d | 2013-09-12 23:44:38 | [diff] [blame] | 355 | Shell::GetInstance()->set_target_root_window( |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 356 | Shell::GetPrimaryRootWindow() == root_window |
| 357 | ? NULL |
| 358 | : Shell::GetPrimaryRootWindow()); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 359 | } |
[email protected] | c98a492 | 2013-09-05 20:01:42 | [diff] [blame] | 360 | |
| 361 | CloseChildWindows(); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 362 | GetRootWindowSettings(root_window)->controller = NULL; |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 363 | screen_dimmer_.reset(); |
| 364 | workspace_controller_.reset(); |
[email protected] | 6675e1c | 2012-09-11 09:15:45 | [diff] [blame] | 365 | // Forget with the display ID so that display lookup |
| 366 | // ends up with invalid display. |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 367 | GetRootWindowSettings(root_window)->display_id = |
[email protected] | f8e6aad | 2013-08-30 21:49:11 | [diff] [blame] | 368 | gfx::Display::kInvalidDisplayID; |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 369 | GetRootWindowSettings(root_window)->shutdown = true; |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 370 | |
[email protected] | 956a6a4 | 2012-10-29 23:58:10 | [diff] [blame] | 371 | system_background_.reset(); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 372 | aura::client::SetScreenPositionClient(root_window, NULL); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 373 | } |
| 374 | |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 375 | SystemModalContainerLayoutManager* |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 376 | RootWindowController::GetSystemModalLayoutManager(aura::Window* window) { |
[email protected] | a5c7880 | 2013-12-12 22:07:01 | [diff] [blame] | 377 | aura::Window* modal_container = NULL; |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 378 | if (window) { |
[email protected] | a5c7880 | 2013-12-12 22:07:01 | [diff] [blame] | 379 | aura::Window* window_container = GetContainerForWindow(window); |
| 380 | if (window_container && |
| 381 | window_container->id() >= kShellWindowId_LockScreenContainer) { |
| 382 | modal_container = GetContainer(kShellWindowId_LockSystemModalContainer); |
[email protected] | 3b162e1 | 2012-11-09 11:52:35 | [diff] [blame] | 383 | } else { |
[email protected] | a5c7880 | 2013-12-12 22:07:01 | [diff] [blame] | 384 | modal_container = GetContainer(kShellWindowId_SystemModalContainer); |
[email protected] | 3b162e1 | 2012-11-09 11:52:35 | [diff] [blame] | 385 | } |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 386 | } else { |
[email protected] | a44afbbd | 2013-07-24 21:49:35 | [diff] [blame] | 387 | int modal_window_id = Shell::GetInstance()->session_state_delegate() |
| 388 | ->IsUserSessionBlocked() ? kShellWindowId_LockSystemModalContainer : |
| 389 | kShellWindowId_SystemModalContainer; |
[email protected] | a5c7880 | 2013-12-12 22:07:01 | [diff] [blame] | 390 | modal_container = GetContainer(modal_window_id); |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 391 | } |
[email protected] | a5c7880 | 2013-12-12 22:07:01 | [diff] [blame] | 392 | return modal_container ? static_cast<SystemModalContainerLayoutManager*>( |
| 393 | modal_container->layout_manager()) : NULL; |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 394 | } |
| 395 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 396 | aura::Window* RootWindowController::GetContainer(int container_id) { |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 397 | return GetRootWindow()->GetChildById(container_id); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 398 | } |
| 399 | |
[email protected] | d8a2495 | 2013-08-05 20:05:05 | [diff] [blame] | 400 | const aura::Window* RootWindowController::GetContainer(int container_id) const { |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 401 | return ash_host_->AsWindowTreeHost()->window()->GetChildById(container_id); |
[email protected] | d8a2495 | 2013-08-05 20:05:05 | [diff] [blame] | 402 | } |
| 403 | |
[email protected] | 864b5855 | 2013-12-19 04:19:38 | [diff] [blame] | 404 | void RootWindowController::ShowShelf() { |
| 405 | if (!shelf_->shelf()) |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 406 | return; |
[email protected] | 864b5855 | 2013-12-19 04:19:38 | [diff] [blame] | 407 | shelf_->shelf()->SetVisible(true); |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 408 | shelf_->status_area_widget()->Show(); |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 409 | } |
| 410 | |
[email protected] | 864b5855 | 2013-12-19 04:19:38 | [diff] [blame] | 411 | void RootWindowController::OnShelfCreated() { |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 412 | if (panel_layout_manager_) |
[email protected] | 864b5855 | 2013-12-19 04:19:38 | [diff] [blame] | 413 | panel_layout_manager_->SetShelf(shelf_->shelf()); |
[email protected] | 7115bd3 | 2013-07-19 08:25:39 | [diff] [blame] | 414 | if (docked_layout_manager_) { |
[email protected] | 864b5855 | 2013-12-19 04:19:38 | [diff] [blame] | 415 | docked_layout_manager_->SetShelf(shelf_->shelf()); |
[email protected] | 7115bd3 | 2013-07-19 08:25:39 | [diff] [blame] | 416 | if (shelf_->shelf_layout_manager()) |
| 417 | docked_layout_manager_->AddObserver(shelf_->shelf_layout_manager()); |
| 418 | } |
[email protected] | b8642ec | 2014-04-17 05:20:39 | [diff] [blame^] | 419 | |
| 420 | // Notify shell observers that the shelf has been created. |
| 421 | Shell::GetInstance()->OnShelfCreatedForRootWindow(GetRootWindow()); |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 422 | } |
| 423 | |
[email protected] | 16059276d | 2012-10-22 18:59:50 | [diff] [blame] | 424 | void RootWindowController::UpdateAfterLoginStatusChange( |
| 425 | user::LoginStatus status) { |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 426 | if (status != user::LOGGED_IN_NONE) |
| 427 | mouse_event_target_.reset(); |
[email protected] | 80549c15 | 2013-07-02 01:42:47 | [diff] [blame] | 428 | if (shelf_->status_area_widget()) |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 429 | shelf_->status_area_widget()->UpdateAfterLoginStatusChange(status); |
[email protected] | 16059276d | 2012-10-22 18:59:50 | [diff] [blame] | 430 | } |
| 431 | |
[email protected] | bca9a7e | 2012-11-10 06:25:49 | [diff] [blame] | 432 | void RootWindowController::HandleInitialDesktopBackgroundAnimationStarted() { |
[email protected] | 252eb23 | 2013-08-14 22:09:27 | [diff] [blame] | 433 | #if defined(OS_CHROMEOS) |
[email protected] | bca9a7e | 2012-11-10 06:25:49 | [diff] [blame] | 434 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 435 | switches::kAshAnimateFromBootSplashScreen) && |
| 436 | boot_splash_screen_.get()) { |
| 437 | // Make the splash screen fade out so it doesn't obscure the desktop |
| 438 | // wallpaper's brightness/grayscale animation. |
| 439 | boot_splash_screen_->StartHideAnimation( |
| 440 | base::TimeDelta::FromMilliseconds(kBootSplashScreenHideDurationMs)); |
| 441 | } |
[email protected] | 252eb23 | 2013-08-14 22:09:27 | [diff] [blame] | 442 | #endif |
[email protected] | bca9a7e | 2012-11-10 06:25:49 | [diff] [blame] | 443 | } |
| 444 | |
[email protected] | 0bf6173 | 2013-07-02 04:35:10 | [diff] [blame] | 445 | void RootWindowController::OnWallpaperAnimationFinished(views::Widget* widget) { |
| 446 | // Make sure the wallpaper is visible. |
[email protected] | bca9a7e | 2012-11-10 06:25:49 | [diff] [blame] | 447 | system_background_->SetColor(SK_ColorBLACK); |
[email protected] | 252eb23 | 2013-08-14 22:09:27 | [diff] [blame] | 448 | #if defined(OS_CHROMEOS) |
[email protected] | bca9a7e | 2012-11-10 06:25:49 | [diff] [blame] | 449 | boot_splash_screen_.reset(); |
[email protected] | 252eb23 | 2013-08-14 22:09:27 | [diff] [blame] | 450 | #endif |
[email protected] | 0bf6173 | 2013-07-02 04:35:10 | [diff] [blame] | 451 | |
| 452 | Shell::GetInstance()->user_wallpaper_delegate()-> |
| 453 | OnWallpaperAnimationFinished(); |
| 454 | // Only removes old component when wallpaper animation finished. If we |
| 455 | // remove the old one before the new wallpaper is done fading in there will |
| 456 | // be a white flash during the animation. |
| 457 | if (animating_wallpaper_controller()) { |
| 458 | DesktopBackgroundWidgetController* controller = |
| 459 | animating_wallpaper_controller()->GetController(true); |
| 460 | // |desktop_widget_| should be the same animating widget we try to move |
| 461 | // to |kDesktopController|. Otherwise, we may close |desktop_widget_| |
| 462 | // before move it to |kDesktopController|. |
| 463 | DCHECK_EQ(controller->widget(), widget); |
| 464 | // Release the old controller and close its background widget. |
| 465 | SetWallpaperController(controller); |
| 466 | } |
[email protected] | 697f04c | 2012-10-03 01:15:10 | [diff] [blame] | 467 | } |
| 468 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 469 | void RootWindowController::CloseChildWindows() { |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 470 | mouse_event_target_.reset(); |
| 471 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 472 | // Deactivate keyboard container before closing child windows and shutting |
| 473 | // down associated layout managers. |
[email protected] | a0b3fb88 | 2014-04-07 19:26:03 | [diff] [blame] | 474 | DeactivateKeyboard(keyboard::KeyboardController::GetInstance()); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 475 | |
[email protected] | 79a87b7e | 2013-01-25 05:08:22 | [diff] [blame] | 476 | // panel_layout_manager_ needs to be shut down before windows are destroyed. |
| 477 | if (panel_layout_manager_) { |
| 478 | panel_layout_manager_->Shutdown(); |
| 479 | panel_layout_manager_ = NULL; |
| 480 | } |
[email protected] | 7115bd3 | 2013-07-19 08:25:39 | [diff] [blame] | 481 | // docked_layout_manager_ needs to be shut down before windows are destroyed. |
| 482 | if (docked_layout_manager_) { |
[email protected] | bb42c93 | 2013-10-31 06:52:06 | [diff] [blame] | 483 | if (shelf_ && shelf_->shelf_layout_manager()) |
[email protected] | 7115bd3 | 2013-07-19 08:25:39 | [diff] [blame] | 484 | docked_layout_manager_->RemoveObserver(shelf_->shelf_layout_manager()); |
| 485 | docked_layout_manager_->Shutdown(); |
| 486 | docked_layout_manager_ = NULL; |
| 487 | } |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 488 | aura::Window* root_window = GetRootWindow(); |
| 489 | aura::client::SetDragDropClient(root_window, NULL); |
[email protected] | 8b3e3d8 | 2013-08-20 14:36:30 | [diff] [blame] | 490 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 491 | // TODO(harrym): Remove when Status Area Widget is a child view. |
[email protected] | bb42c93 | 2013-10-31 06:52:06 | [diff] [blame] | 492 | if (shelf_) { |
| 493 | shelf_->ShutdownStatusAreaWidget(); |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 494 | |
[email protected] | bb42c93 | 2013-10-31 06:52:06 | [diff] [blame] | 495 | if (shelf_->shelf_layout_manager()) |
| 496 | shelf_->shelf_layout_manager()->PrepareForShutdown(); |
| 497 | } |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 498 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 499 | // Close background widget first as it depends on tooltip. |
[email protected] | 0bf6173 | 2013-07-02 04:35:10 | [diff] [blame] | 500 | wallpaper_controller_.reset(); |
| 501 | animating_wallpaper_controller_.reset(); |
[email protected] | b4ddc7a | 2012-08-07 04:17:32 | [diff] [blame] | 502 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 503 | workspace_controller_.reset(); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 504 | aura::client::SetTooltipClient(root_window, NULL); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 505 | |
[email protected] | 0fbfa97 | 2013-10-02 19:23:33 | [diff] [blame] | 506 | // Explicitly destroy top level windows. We do this as during part of |
| 507 | // destruction such windows may query the RootWindow for state. |
[email protected] | 8b3e3d8 | 2013-08-20 14:36:30 | [diff] [blame] | 508 | std::queue<aura::Window*> non_toplevel_windows; |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 509 | non_toplevel_windows.push(root_window); |
[email protected] | 8b3e3d8 | 2013-08-20 14:36:30 | [diff] [blame] | 510 | while (!non_toplevel_windows.empty()) { |
| 511 | aura::Window* non_toplevel_window = non_toplevel_windows.front(); |
| 512 | non_toplevel_windows.pop(); |
| 513 | aura::WindowTracker toplevel_windows; |
| 514 | for (size_t i = 0; i < non_toplevel_window->children().size(); ++i) { |
| 515 | aura::Window* child = non_toplevel_window->children()[i]; |
[email protected] | 0fbfa97 | 2013-10-02 19:23:33 | [diff] [blame] | 516 | if (!child->owned_by_parent()) |
| 517 | continue; |
[email protected] | 8b3e3d8 | 2013-08-20 14:36:30 | [diff] [blame] | 518 | if (child->delegate()) |
| 519 | toplevel_windows.Add(child); |
| 520 | else |
| 521 | non_toplevel_windows.push(child); |
| 522 | } |
| 523 | while (!toplevel_windows.windows().empty()) |
| 524 | delete *toplevel_windows.windows().begin(); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 525 | } |
[email protected] | 8b3e3d8 | 2013-08-20 14:36:30 | [diff] [blame] | 526 | // And then remove the containers. |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 527 | while (!root_window->children().empty()) { |
| 528 | aura::Window* window = root_window->children()[0]; |
[email protected] | 0fbfa97 | 2013-10-02 19:23:33 | [diff] [blame] | 529 | if (window->owned_by_parent()) { |
| 530 | delete window; |
| 531 | } else { |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 532 | root_window->RemoveChild(window); |
[email protected] | 0fbfa97 | 2013-10-02 19:23:33 | [diff] [blame] | 533 | } |
| 534 | } |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 535 | |
[email protected] | bb42c93 | 2013-10-31 06:52:06 | [diff] [blame] | 536 | shelf_.reset(); |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 537 | } |
| 538 | |
[email protected] | bf9cdb36 | 2013-10-25 19:22:45 | [diff] [blame] | 539 | void RootWindowController::MoveWindowsTo(aura::Window* dst) { |
[email protected] | 8039e06c | 2013-01-17 23:34:50 | [diff] [blame] | 540 | // Forget the shelf early so that shelf don't update itself using wrong |
| 541 | // display info. |
| 542 | workspace_controller_->SetShelf(NULL); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 543 | ReparentAllWindows(GetRootWindow(), dst); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 544 | } |
| 545 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 546 | ShelfLayoutManager* RootWindowController::GetShelfLayoutManager() { |
[email protected] | 80549c15 | 2013-07-02 01:42:47 | [diff] [blame] | 547 | return shelf_->shelf_layout_manager(); |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 548 | } |
| 549 | |
[email protected] | a0afeb1 | 2012-12-10 22:57:09 | [diff] [blame] | 550 | SystemTray* RootWindowController::GetSystemTray() { |
| 551 | // We assume in throughout the code that this will not return NULL. If code |
| 552 | // triggers this for valid reasons, it should test status_area_widget first. |
[email protected] | 80549c15 | 2013-07-02 01:42:47 | [diff] [blame] | 553 | CHECK(shelf_->status_area_widget()); |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 554 | return shelf_->status_area_widget()->system_tray(); |
[email protected] | a0afeb1 | 2012-12-10 22:57:09 | [diff] [blame] | 555 | } |
| 556 | |
[email protected] | 940fb1c | 2013-06-18 16:54:28 | [diff] [blame] | 557 | void RootWindowController::ShowContextMenu(const gfx::Point& location_in_screen, |
| 558 | ui::MenuSourceType source_type) { |
[email protected] | 431552c | 2012-10-23 00:38:33 | [diff] [blame] | 559 | DCHECK(Shell::GetInstance()->delegate()); |
| 560 | scoped_ptr<ui::MenuModel> menu_model( |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 561 | Shell::GetInstance()->delegate()->CreateContextMenu( |
| 562 | GetRootWindow(), NULL, NULL)); |
[email protected] | 7f7f65c | 2013-04-17 16:47:13 | [diff] [blame] | 563 | if (!menu_model) |
[email protected] | 8e837ec | 2013-01-31 01:48:33 | [diff] [blame] | 564 | return; |
[email protected] | 431552c | 2012-10-23 00:38:33 | [diff] [blame] | 565 | |
[email protected] | 6175fc4 | 2013-04-05 05:58:58 | [diff] [blame] | 566 | // Background controller may not be set yet if user clicked on status are |
| 567 | // before initial animation completion. See crbug.com/222218 |
[email protected] | 0bf6173 | 2013-07-02 04:35:10 | [diff] [blame] | 568 | if (!wallpaper_controller_.get()) |
[email protected] | 431552c | 2012-10-23 00:38:33 | [diff] [blame] | 569 | return; |
| 570 | |
[email protected] | 6175fc4 | 2013-04-05 05:58:58 | [diff] [blame] | 571 | views::MenuRunner menu_runner(menu_model.get()); |
[email protected] | 0bf6173 | 2013-07-02 04:35:10 | [diff] [blame] | 572 | if (menu_runner.RunMenuAt(wallpaper_controller_->widget(), |
[email protected] | 6175fc4 | 2013-04-05 05:58:58 | [diff] [blame] | 573 | NULL, gfx::Rect(location_in_screen, gfx::Size()), |
[email protected] | 940fb1c | 2013-06-18 16:54:28 | [diff] [blame] | 574 | views::MenuItemView::TOPLEFT, source_type, |
| 575 | views::MenuRunner::CONTEXT_MENU) == |
[email protected] | 6175fc4 | 2013-04-05 05:58:58 | [diff] [blame] | 576 | views::MenuRunner::MENU_DELETED) { |
| 577 | return; |
| 578 | } |
| 579 | |
[email protected] | 431552c | 2012-10-23 00:38:33 | [diff] [blame] | 580 | Shell::GetInstance()->UpdateShelfVisibility(); |
| 581 | } |
| 582 | |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 583 | void RootWindowController::UpdateShelfVisibility() { |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 584 | shelf_->shelf_layout_manager()->UpdateVisibilityState(); |
[email protected] | e74aaf0a | 2012-10-12 18:42:28 | [diff] [blame] | 585 | } |
| 586 | |
[email protected] | 2c9171d2 | 2013-12-10 21:55:10 | [diff] [blame] | 587 | const aura::Window* RootWindowController::GetWindowForFullscreenMode() const { |
[email protected] | 2c9171d2 | 2013-12-10 21:55:10 | [diff] [blame] | 588 | const aura::Window* topmost_window = NULL; |
[email protected] | 2c5db9e | 2014-02-27 13:58:14 | [diff] [blame] | 589 | const aura::Window* active_window = wm::GetActiveWindow(); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 590 | if (active_window && active_window->GetRootWindow() == GetRootWindow() && |
[email protected] | 2c5db9e | 2014-02-27 13:58:14 | [diff] [blame] | 591 | IsSwitchableContainer(active_window->parent())) { |
| 592 | // Use the active window when it is on the current root window to determine |
| 593 | // the fullscreen state to allow temporarily using a panel or docked window |
| 594 | // (which are always above the default container) while a fullscreen |
| 595 | // window is open. We only use the active window when in a switchable |
| 596 | // container as the launcher should not exit fullscreen mode. |
| 597 | topmost_window = active_window; |
| 598 | } else { |
| 599 | // Otherwise, use the topmost window on the root window's default container |
| 600 | // when there is no active window on this root window. |
| 601 | const aura::Window::Windows& windows = |
| 602 | GetContainer(kShellWindowId_DefaultContainer)->children(); |
| 603 | for (aura::Window::Windows::const_reverse_iterator iter = windows.rbegin(); |
| 604 | iter != windows.rend(); ++iter) { |
| 605 | if (((*iter)->type() == ui::wm::WINDOW_TYPE_NORMAL || |
| 606 | (*iter)->type() == ui::wm::WINDOW_TYPE_PANEL) && |
| 607 | (*iter)->layer()->GetTargetVisibility()) { |
| 608 | topmost_window = *iter; |
| 609 | break; |
| 610 | } |
[email protected] | 2c9171d2 | 2013-12-10 21:55:10 | [diff] [blame] | 611 | } |
| 612 | } |
| 613 | while (topmost_window) { |
| 614 | if (wm::GetWindowState(topmost_window)->IsFullscreen()) |
| 615 | return topmost_window; |
[email protected] | e319c7e | 2014-03-14 19:56:14 | [diff] [blame] | 616 | topmost_window = ::wm::GetTransientParent(topmost_window); |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 617 | } |
[email protected] | 700849f | 2013-04-30 17:49:20 | [diff] [blame] | 618 | return NULL; |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 619 | } |
| 620 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 621 | void RootWindowController::ActivateKeyboard( |
| 622 | keyboard::KeyboardController* keyboard_controller) { |
| 623 | if (!keyboard::IsKeyboardEnabled() || |
| 624 | GetContainer(kShellWindowId_VirtualKeyboardContainer)) { |
| 625 | return; |
| 626 | } |
| 627 | DCHECK(keyboard_controller); |
[email protected] | 51f43811 | 2013-11-18 19:32:50 | [diff] [blame] | 628 | if (!keyboard::IsKeyboardUsabilityExperimentEnabled()) { |
| 629 | keyboard_controller->AddObserver(shelf()->shelf_layout_manager()); |
| 630 | keyboard_controller->AddObserver(panel_layout_manager_); |
| 631 | keyboard_controller->AddObserver(docked_layout_manager_); |
[email protected] | 40db36e | 2014-04-04 14:08:18 | [diff] [blame] | 632 | Shell::GetInstance()->delegate()->VirtualKeyboardActivated(true); |
[email protected] | 51f43811 | 2013-11-18 19:32:50 | [diff] [blame] | 633 | } |
[email protected] | b2da9b60 | 2014-03-05 18:39:52 | [diff] [blame] | 634 | aura::Window* parent = GetContainer( |
| 635 | kShellWindowId_VirtualKeyboardParentContainer); |
| 636 | DCHECK(parent); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 637 | aura::Window* keyboard_container = |
| 638 | keyboard_controller->GetContainerWindow(); |
| 639 | keyboard_container->set_id(kShellWindowId_VirtualKeyboardContainer); |
| 640 | parent->AddChild(keyboard_container); |
| 641 | // TODO(oshima): Bounds of keyboard container should be handled by |
| 642 | // RootWindowLayoutManager. Remove this after fixed RootWindowLayoutManager. |
| 643 | keyboard_container->SetBounds(parent->bounds()); |
| 644 | } |
[email protected] | 86459e2c | 2013-04-10 13:39:24 | [diff] [blame] | 645 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 646 | void RootWindowController::DeactivateKeyboard( |
| 647 | keyboard::KeyboardController* keyboard_controller) { |
[email protected] | e1b299b | 2014-01-29 23:53:41 | [diff] [blame] | 648 | if (!keyboard_controller || |
| 649 | !keyboard_controller->keyboard_container_initialized()) { |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 650 | return; |
[email protected] | e1b299b | 2014-01-29 23:53:41 | [diff] [blame] | 651 | } |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 652 | aura::Window* keyboard_container = |
| 653 | keyboard_controller->GetContainerWindow(); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 654 | if (keyboard_container->GetRootWindow() == GetRootWindow()) { |
[email protected] | b2da9b60 | 2014-03-05 18:39:52 | [diff] [blame] | 655 | aura::Window* parent = GetContainer( |
| 656 | kShellWindowId_VirtualKeyboardParentContainer); |
| 657 | DCHECK(parent); |
| 658 | parent->RemoveChild(keyboard_container); |
[email protected] | 51f43811 | 2013-11-18 19:32:50 | [diff] [blame] | 659 | if (!keyboard::IsKeyboardUsabilityExperimentEnabled()) { |
[email protected] | 1025937e | 2014-02-13 01:25:50 | [diff] [blame] | 660 | // Virtual keyboard may be deactivated while still showing, notify all |
| 661 | // observers that keyboard bounds changed to 0 before remove them. |
| 662 | keyboard_controller->NotifyKeyboardBoundsChanging(gfx::Rect()); |
[email protected] | 51f43811 | 2013-11-18 19:32:50 | [diff] [blame] | 663 | keyboard_controller->RemoveObserver(shelf()->shelf_layout_manager()); |
| 664 | keyboard_controller->RemoveObserver(panel_layout_manager_); |
| 665 | keyboard_controller->RemoveObserver(docked_layout_manager_); |
[email protected] | 40db36e | 2014-04-04 14:08:18 | [diff] [blame] | 666 | Shell::GetInstance()->delegate()->VirtualKeyboardActivated(false); |
[email protected] | 51f43811 | 2013-11-18 19:32:50 | [diff] [blame] | 667 | } |
[email protected] | 86459e2c | 2013-04-10 13:39:24 | [diff] [blame] | 668 | } |
| 669 | } |
| 670 | |
[email protected] | 602022b | 2014-03-31 17:07:31 | [diff] [blame] | 671 | bool RootWindowController::IsVirtualKeyboardWindow(aura::Window* window) { |
| 672 | aura::Window* parent = GetContainer( |
| 673 | kShellWindowId_VirtualKeyboardParentContainer); |
| 674 | return parent ? parent->Contains(window) : false; |
| 675 | } |
| 676 | |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 677 | //////////////////////////////////////////////////////////////////////////////// |
| 678 | // RootWindowController, private: |
| 679 | |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 680 | RootWindowController::RootWindowController(AshWindowTreeHost* ash_host) |
| 681 | : ash_host_(ash_host), |
[email protected] | a273d33a | 2013-10-17 12:41:21 | [diff] [blame] | 682 | root_window_layout_(NULL), |
| 683 | docked_layout_manager_(NULL), |
| 684 | panel_layout_manager_(NULL), |
| 685 | touch_hud_debug_(NULL), |
| 686 | touch_hud_projection_(NULL) { |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 687 | aura::Window* root_window = GetRootWindow(); |
| 688 | GetRootWindowSettings(root_window)->controller = this; |
| 689 | screen_dimmer_.reset(new ScreenDimmer(root_window)); |
[email protected] | a273d33a | 2013-10-17 12:41:21 | [diff] [blame] | 690 | |
| 691 | stacking_controller_.reset(new StackingController); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 692 | aura::client::SetWindowTreeClient(root_window, stacking_controller_.get()); |
| 693 | capture_client_.reset(new ::wm::ScopedCaptureClient(root_window)); |
[email protected] | a273d33a | 2013-10-17 12:41:21 | [diff] [blame] | 694 | } |
| 695 | |
[email protected] | 608de6c | 2013-10-29 00:14:28 | [diff] [blame] | 696 | void RootWindowController::Init(RootWindowType root_window_type, |
| 697 | bool first_run_after_boot) { |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 698 | aura::Window* root_window = GetRootWindow(); |
[email protected] | 51f43811 | 2013-11-18 19:32:50 | [diff] [blame] | 699 | Shell* shell = Shell::GetInstance(); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 700 | shell->InitRootWindow(root_window); |
[email protected] | a273d33a | 2013-10-17 12:41:21 | [diff] [blame] | 701 | |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 702 | ash_host_->AsWindowTreeHost()->SetCursor(ui::kCursorPointer); |
| 703 | CreateContainersInRootWindow(root_window); |
[email protected] | 608de6c | 2013-10-29 00:14:28 | [diff] [blame] | 704 | |
[email protected] | 51f43811 | 2013-11-18 19:32:50 | [diff] [blame] | 705 | if (root_window_type == VIRTUAL_KEYBOARD) { |
[email protected] | 0370e2e | 2014-04-14 19:49:06 | [diff] [blame] | 706 | aura::Window* virtual_keyboard_parent_container = GetContainer( |
| 707 | kShellWindowId_VirtualKeyboardParentContainer); |
| 708 | virtual_keyboard_parent_container->SetBounds(root_window->bounds()); |
[email protected] | 51f43811 | 2013-11-18 19:32:50 | [diff] [blame] | 709 | shell->InitKeyboard(); |
[email protected] | 608de6c | 2013-10-29 00:14:28 | [diff] [blame] | 710 | return; |
[email protected] | 51f43811 | 2013-11-18 19:32:50 | [diff] [blame] | 711 | } |
[email protected] | 608de6c | 2013-10-29 00:14:28 | [diff] [blame] | 712 | |
[email protected] | a273d33a | 2013-10-17 12:41:21 | [diff] [blame] | 713 | CreateSystemBackground(first_run_after_boot); |
| 714 | |
| 715 | InitLayoutManagers(); |
| 716 | InitTouchHuds(); |
| 717 | |
| 718 | if (Shell::GetPrimaryRootWindowController()-> |
| 719 | GetSystemModalLayoutManager(NULL)->has_modal_background()) { |
| 720 | GetSystemModalLayoutManager(NULL)->CreateModalBackground(); |
| 721 | } |
| 722 | |
[email protected] | a273d33a | 2013-10-17 12:41:21 | [diff] [blame] | 723 | shell->AddShellObserver(this); |
| 724 | |
[email protected] | 608de6c | 2013-10-29 00:14:28 | [diff] [blame] | 725 | if (root_window_type == PRIMARY) { |
[email protected] | a356579 | 2013-10-18 12:52:37 | [diff] [blame] | 726 | root_window_layout()->OnWindowResized(); |
[email protected] | 51f43811 | 2013-11-18 19:32:50 | [diff] [blame] | 727 | if (!keyboard::IsKeyboardUsabilityExperimentEnabled()) |
| 728 | shell->InitKeyboard(); |
[email protected] | a273d33a | 2013-10-17 12:41:21 | [diff] [blame] | 729 | } else { |
| 730 | root_window_layout()->OnWindowResized(); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 731 | ash_host_->AsWindowTreeHost()->Show(); |
[email protected] | a273d33a | 2013-10-17 12:41:21 | [diff] [blame] | 732 | |
[email protected] | 864b5855 | 2013-12-19 04:19:38 | [diff] [blame] | 733 | // Create a shelf if a user is already logged in. |
[email protected] | a273d33a | 2013-10-17 12:41:21 | [diff] [blame] | 734 | if (shell->session_state_delegate()->NumberOfLoggedInUsers()) |
[email protected] | 864b5855 | 2013-12-19 04:19:38 | [diff] [blame] | 735 | shelf()->CreateShelf(); |
[email protected] | 0e3e7cb | 2014-04-12 05:18:25 | [diff] [blame] | 736 | |
| 737 | // Notify shell observers about new root window. |
| 738 | shell->OnRootWindowAdded(root_window); |
[email protected] | a273d33a | 2013-10-17 12:41:21 | [diff] [blame] | 739 | } |
| 740 | } |
| 741 | |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 742 | void RootWindowController::InitLayoutManagers() { |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 743 | aura::Window* root_window = GetRootWindow(); |
| 744 | root_window_layout_ = new RootWindowLayoutManager(root_window); |
| 745 | root_window->SetLayoutManager(root_window_layout_); |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 746 | |
| 747 | aura::Window* default_container = |
| 748 | GetContainer(kShellWindowId_DefaultContainer); |
| 749 | // Workspace manager has its own layout managers. |
| 750 | workspace_controller_.reset( |
| 751 | new WorkspaceController(default_container)); |
| 752 | |
| 753 | aura::Window* always_on_top_container = |
| 754 | GetContainer(kShellWindowId_AlwaysOnTopContainer); |
| 755 | always_on_top_container->SetLayoutManager( |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 756 | new WorkspaceLayoutManager(always_on_top_container)); |
| 757 | always_on_top_controller_.reset(new AlwaysOnTopController); |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 758 | always_on_top_controller_->SetAlwaysOnTopContainer(always_on_top_container); |
| 759 | |
| 760 | DCHECK(!shelf_.get()); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 761 | aura::Window* shelf_container = GetContainer(kShellWindowId_ShelfContainer); |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 762 | // TODO(harrym): Remove when status area is view. |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 763 | aura::Window* status_container = GetContainer(kShellWindowId_StatusContainer); |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 764 | shelf_.reset(new ShelfWidget( |
| 765 | shelf_container, status_container, workspace_controller())); |
| 766 | |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 767 | if (!Shell::GetInstance()->session_state_delegate()-> |
| 768 | IsActiveUserSessionStarted()) { |
| 769 | // This window exists only to be a event target on login screen. |
| 770 | // It does not have to handle events, nor be visible. |
| 771 | mouse_event_target_.reset(new aura::Window(new EmptyWindowDelegate)); |
[email protected] | 52b02a7 | 2014-01-08 21:41:50 | [diff] [blame] | 772 | mouse_event_target_->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 773 | |
| 774 | aura::Window* lock_background_container = |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 775 | GetContainer(kShellWindowId_LockScreenBackgroundContainer); |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 776 | lock_background_container->AddChild(mouse_event_target_.get()); |
| 777 | mouse_event_target_->Show(); |
| 778 | } |
| 779 | |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 780 | // Create Docked windows layout manager |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 781 | aura::Window* docked_container = GetContainer(kShellWindowId_DockedContainer); |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 782 | docked_layout_manager_ = |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 783 | new DockedWindowLayoutManager(docked_container, workspace_controller()); |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 784 | docked_container->SetLayoutManager(docked_layout_manager_); |
| 785 | |
| 786 | // Create Panel layout manager |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 787 | aura::Window* panel_container = GetContainer(kShellWindowId_PanelContainer); |
| 788 | panel_layout_manager_ = new PanelLayoutManager(panel_container); |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 789 | panel_container->SetLayoutManager(panel_layout_manager_); |
[email protected] | 3537d47 | 2014-01-15 05:45:31 | [diff] [blame] | 790 | panel_container_handler_.reset(new PanelWindowEventHandler); |
| 791 | panel_container->AddPreTargetHandler(panel_container_handler_.get()); |
[email protected] | b8642ec | 2014-04-17 05:20:39 | [diff] [blame^] | 792 | |
| 793 | // Install an AttachedPanelWindowTargeter on the panel container to make it |
| 794 | // easier to correctly target shelf buttons with touch. |
| 795 | gfx::Insets mouse_extend(-kResizeOutsideBoundsSize, |
| 796 | -kResizeOutsideBoundsSize, |
| 797 | -kResizeOutsideBoundsSize, |
| 798 | -kResizeOutsideBoundsSize); |
| 799 | gfx::Insets touch_extend = mouse_extend.Scale( |
| 800 | kResizeOutsideBoundsScaleForTouch); |
| 801 | panel_container->SetEventTargeter(scoped_ptr<ui::EventTargeter>( |
| 802 | new AttachedPanelWindowTargeter(panel_container, |
| 803 | mouse_extend, |
| 804 | touch_extend, |
| 805 | panel_layout_manager_))); |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | void RootWindowController::InitTouchHuds() { |
| 809 | CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 810 | if (command_line->HasSwitch(switches::kAshTouchHud)) |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 811 | set_touch_hud_debug(new TouchHudDebug(GetRootWindow())); |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 812 | if (Shell::GetInstance()->is_touch_hud_projection_enabled()) |
| 813 | EnableTouchHudProjection(); |
| 814 | } |
| 815 | |
| 816 | void RootWindowController::CreateSystemBackground( |
| 817 | bool is_first_run_after_boot) { |
| 818 | SkColor color = SK_ColorBLACK; |
| 819 | #if defined(OS_CHROMEOS) |
| 820 | if (is_first_run_after_boot) |
| 821 | color = kChromeOsBootColor; |
| 822 | #endif |
| 823 | system_background_.reset( |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 824 | new SystemBackgroundController(GetRootWindow(), color)); |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 825 | |
| 826 | #if defined(OS_CHROMEOS) |
| 827 | // Make a copy of the system's boot splash screen so we can composite it |
| 828 | // onscreen until the desktop background is ready. |
| 829 | if (is_first_run_after_boot && |
| 830 | (CommandLine::ForCurrentProcess()->HasSwitch( |
| 831 | switches::kAshCopyHostBackgroundAtBoot) || |
| 832 | CommandLine::ForCurrentProcess()->HasSwitch( |
| 833 | switches::kAshAnimateFromBootSplashScreen))) |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 834 | boot_splash_screen_.reset(new BootSplashScreen(GetHost())); |
[email protected] | 756bda1 | 2013-07-03 08:17:06 | [diff] [blame] | 835 | #endif |
| 836 | } |
| 837 | |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 838 | void RootWindowController::CreateContainersInRootWindow( |
[email protected] | 41baaed | 2013-11-09 04:18:26 | [diff] [blame] | 839 | aura::Window* root_window) { |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 840 | // These containers are just used by PowerButtonController to animate groups |
| 841 | // of containers simultaneously without messing up the current transformations |
| 842 | // on those containers. These are direct children of the root window; all of |
| 843 | // the other containers are their children. |
[email protected] | e6e41d2f | 2012-10-29 19:22:19 | [diff] [blame] | 844 | |
| 845 | // The desktop background container is not part of the lock animation, so it |
| 846 | // is not included in those animate groups. |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 847 | // When screen is locked desktop background is moved to lock screen background |
| 848 | // container (moved back on unlock). We want to make sure that there's an |
| 849 | // opaque layer occluding the non-lock-screen layers. |
[email protected] | e6e41d2f | 2012-10-29 19:22:19 | [diff] [blame] | 850 | aura::Window* desktop_background_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 851 | kShellWindowId_DesktopBackgroundContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 852 | "DesktopBackgroundContainer", |
| 853 | root_window); |
[email protected] | e319c7e | 2014-03-14 19:56:14 | [diff] [blame] | 854 | ::wm::SetChildWindowVisibilityChangesAnimated(desktop_background_container); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 855 | |
| 856 | aura::Window* non_lock_screen_containers = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 857 | kShellWindowId_NonLockScreenContainersContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 858 | "NonLockScreenContainersContainer", |
| 859 | root_window); |
| 860 | |
| 861 | aura::Window* lock_background_containers = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 862 | kShellWindowId_LockScreenBackgroundContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 863 | "LockScreenBackgroundContainer", |
| 864 | root_window); |
[email protected] | e319c7e | 2014-03-14 19:56:14 | [diff] [blame] | 865 | ::wm::SetChildWindowVisibilityChangesAnimated(lock_background_containers); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 866 | |
| 867 | aura::Window* lock_screen_containers = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 868 | kShellWindowId_LockScreenContainersContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 869 | "LockScreenContainersContainer", |
| 870 | root_window); |
| 871 | aura::Window* lock_screen_related_containers = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 872 | kShellWindowId_LockScreenRelatedContainersContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 873 | "LockScreenRelatedContainersContainer", |
| 874 | root_window); |
| 875 | |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 876 | CreateContainer(kShellWindowId_UnparentedControlContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 877 | "UnparentedControlContainer", |
| 878 | non_lock_screen_containers); |
| 879 | |
| 880 | aura::Window* default_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 881 | kShellWindowId_DefaultContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 882 | "DefaultContainer", |
| 883 | non_lock_screen_containers); |
[email protected] | e319c7e | 2014-03-14 19:56:14 | [diff] [blame] | 884 | ::wm::SetChildWindowVisibilityChangesAnimated(default_container); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 885 | SetUsesScreenCoordinates(default_container); |
[email protected] | c5be8d67 | 2014-01-07 13:33:41 | [diff] [blame] | 886 | SetUsesEasyResizeTargeter(default_container); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 887 | |
| 888 | aura::Window* always_on_top_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 889 | kShellWindowId_AlwaysOnTopContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 890 | "AlwaysOnTopContainer", |
| 891 | non_lock_screen_containers); |
[email protected] | e319c7e | 2014-03-14 19:56:14 | [diff] [blame] | 892 | ::wm::SetChildWindowVisibilityChangesAnimated(always_on_top_container); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 893 | SetUsesScreenCoordinates(always_on_top_container); |
| 894 | |
[email protected] | beb4e5c | 2013-06-18 15:37:07 | [diff] [blame] | 895 | aura::Window* docked_container = CreateContainer( |
| 896 | kShellWindowId_DockedContainer, |
| 897 | "DockedContainer", |
| 898 | non_lock_screen_containers); |
[email protected] | e319c7e | 2014-03-14 19:56:14 | [diff] [blame] | 899 | ::wm::SetChildWindowVisibilityChangesAnimated(docked_container); |
[email protected] | beb4e5c | 2013-06-18 15:37:07 | [diff] [blame] | 900 | SetUsesScreenCoordinates(docked_container); |
[email protected] | 1ff0c49 | 2014-01-21 20:20:44 | [diff] [blame] | 901 | SetUsesEasyResizeTargeter(docked_container); |
[email protected] | beb4e5c | 2013-06-18 15:37:07 | [diff] [blame] | 902 | |
[email protected] | 3f13cf1 | 2013-07-12 05:13:59 | [diff] [blame] | 903 | aura::Window* shelf_container = |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 904 | CreateContainer(kShellWindowId_ShelfContainer, |
[email protected] | 3f13cf1 | 2013-07-12 05:13:59 | [diff] [blame] | 905 | "ShelfContainer", |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 906 | non_lock_screen_containers); |
[email protected] | 3f13cf1 | 2013-07-12 05:13:59 | [diff] [blame] | 907 | SetUsesScreenCoordinates(shelf_container); |
| 908 | DescendantShouldStayInSameRootWindow(shelf_container); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 909 | |
[email protected] | f2026eb | 2013-10-22 14:28:56 | [diff] [blame] | 910 | aura::Window* panel_container = CreateContainer( |
| 911 | kShellWindowId_PanelContainer, |
| 912 | "PanelContainer", |
| 913 | non_lock_screen_containers); |
| 914 | SetUsesScreenCoordinates(panel_container); |
| 915 | |
| 916 | aura::Window* shelf_bubble_container = |
| 917 | CreateContainer(kShellWindowId_ShelfBubbleContainer, |
| 918 | "ShelfBubbleContainer", |
| 919 | non_lock_screen_containers); |
| 920 | SetUsesScreenCoordinates(shelf_bubble_container); |
| 921 | DescendantShouldStayInSameRootWindow(shelf_bubble_container); |
| 922 | |
[email protected] | dc851a4e5 | 2012-10-03 00:05:55 | [diff] [blame] | 923 | aura::Window* app_list_container = |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 924 | CreateContainer(kShellWindowId_AppListContainer, |
[email protected] | dc851a4e5 | 2012-10-03 00:05:55 | [diff] [blame] | 925 | "AppListContainer", |
| 926 | non_lock_screen_containers); |
| 927 | SetUsesScreenCoordinates(app_list_container); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 928 | |
| 929 | aura::Window* modal_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 930 | kShellWindowId_SystemModalContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 931 | "SystemModalContainer", |
| 932 | non_lock_screen_containers); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 933 | modal_container->SetLayoutManager( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 934 | new SystemModalContainerLayoutManager(modal_container)); |
[email protected] | e319c7e | 2014-03-14 19:56:14 | [diff] [blame] | 935 | ::wm::SetChildWindowVisibilityChangesAnimated(modal_container); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 936 | SetUsesScreenCoordinates(modal_container); |
[email protected] | c5be8d67 | 2014-01-07 13:33:41 | [diff] [blame] | 937 | SetUsesEasyResizeTargeter(modal_container); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 938 | |
| 939 | aura::Window* input_method_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 940 | kShellWindowId_InputMethodContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 941 | "InputMethodContainer", |
| 942 | non_lock_screen_containers); |
[email protected] | e319c7e | 2014-03-14 19:56:14 | [diff] [blame] | 943 | ::wm::SetChildWindowVisibilityChangesAnimated(input_method_container); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 944 | SetUsesScreenCoordinates(input_method_container); |
| 945 | |
| 946 | // TODO(beng): Figure out if we can make this use |
| 947 | // SystemModalContainerEventFilter instead of stops_event_propagation. |
| 948 | aura::Window* lock_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 949 | kShellWindowId_LockScreenContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 950 | "LockScreenContainer", |
| 951 | lock_screen_containers); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 952 | lock_container->SetLayoutManager(new WorkspaceLayoutManager(lock_container)); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 953 | SetUsesScreenCoordinates(lock_container); |
| 954 | // TODO(beng): stopsevents |
| 955 | |
| 956 | aura::Window* lock_modal_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 957 | kShellWindowId_LockSystemModalContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 958 | "LockSystemModalContainer", |
| 959 | lock_screen_containers); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 960 | lock_modal_container->SetLayoutManager( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 961 | new SystemModalContainerLayoutManager(lock_modal_container)); |
[email protected] | e319c7e | 2014-03-14 19:56:14 | [diff] [blame] | 962 | ::wm::SetChildWindowVisibilityChangesAnimated(lock_modal_container); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 963 | SetUsesScreenCoordinates(lock_modal_container); |
[email protected] | c5be8d67 | 2014-01-07 13:33:41 | [diff] [blame] | 964 | SetUsesEasyResizeTargeter(lock_modal_container); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 965 | |
| 966 | aura::Window* status_container = |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 967 | CreateContainer(kShellWindowId_StatusContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 968 | "StatusContainer", |
| 969 | lock_screen_related_containers); |
| 970 | SetUsesScreenCoordinates(status_container); |
[email protected] | e887c6c | 2013-07-08 19:35:53 | [diff] [blame] | 971 | DescendantShouldStayInSameRootWindow(status_container); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 972 | |
| 973 | aura::Window* settings_bubble_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 974 | kShellWindowId_SettingBubbleContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 975 | "SettingBubbleContainer", |
| 976 | lock_screen_related_containers); |
[email protected] | e319c7e | 2014-03-14 19:56:14 | [diff] [blame] | 977 | ::wm::SetChildWindowVisibilityChangesAnimated(settings_bubble_container); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 978 | SetUsesScreenCoordinates(settings_bubble_container); |
[email protected] | e887c6c | 2013-07-08 19:35:53 | [diff] [blame] | 979 | DescendantShouldStayInSameRootWindow(settings_bubble_container); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 980 | |
| 981 | aura::Window* menu_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 982 | kShellWindowId_MenuContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 983 | "MenuContainer", |
| 984 | lock_screen_related_containers); |
[email protected] | e319c7e | 2014-03-14 19:56:14 | [diff] [blame] | 985 | ::wm::SetChildWindowVisibilityChangesAnimated(menu_container); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 986 | SetUsesScreenCoordinates(menu_container); |
| 987 | |
| 988 | aura::Window* drag_drop_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 989 | kShellWindowId_DragImageAndTooltipContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 990 | "DragImageAndTooltipContainer", |
| 991 | lock_screen_related_containers); |
[email protected] | e319c7e | 2014-03-14 19:56:14 | [diff] [blame] | 992 | ::wm::SetChildWindowVisibilityChangesAnimated(drag_drop_container); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 993 | SetUsesScreenCoordinates(drag_drop_container); |
| 994 | |
| 995 | aura::Window* overlay_container = CreateContainer( |
[email protected] | c0ce80e | 2012-10-05 23:28:27 | [diff] [blame] | 996 | kShellWindowId_OverlayContainer, |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 997 | "OverlayContainer", |
| 998 | lock_screen_related_containers); |
| 999 | SetUsesScreenCoordinates(overlay_container); |
[email protected] | a07615f | 2012-10-24 08:23:08 | [diff] [blame] | 1000 | |
[email protected] | b2da9b60 | 2014-03-05 18:39:52 | [diff] [blame] | 1001 | aura::Window* virtual_keyboard_parent_container = CreateContainer( |
| 1002 | kShellWindowId_VirtualKeyboardParentContainer, |
| 1003 | "VirtualKeyboardParentContainer", |
| 1004 | root_window); |
| 1005 | SetUsesScreenCoordinates(virtual_keyboard_parent_container); |
| 1006 | |
| 1007 | #if defined(OS_CHROMEOS) |
| 1008 | aura::Window* mouse_cursor_container = CreateContainer( |
| 1009 | kShellWindowId_MouseCursorContainer, |
| 1010 | "MouseCursorContainer", |
| 1011 | root_window); |
| 1012 | SetUsesScreenCoordinates(mouse_cursor_container); |
| 1013 | #endif |
| 1014 | |
[email protected] | a07615f | 2012-10-24 08:23:08 | [diff] [blame] | 1015 | CreateContainer(kShellWindowId_PowerButtonAnimationContainer, |
[email protected] | b2da9b60 | 2014-03-05 18:39:52 | [diff] [blame] | 1016 | "PowerButtonAnimationContainer", root_window); |
[email protected] | a4cd6d3 | 2012-09-12 03:42:13 | [diff] [blame] | 1017 | } |
| 1018 | |
[email protected] | d141b92 | 2013-07-09 08:13:17 | [diff] [blame] | 1019 | void RootWindowController::EnableTouchHudProjection() { |
| 1020 | if (touch_hud_projection_) |
| 1021 | return; |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 1022 | set_touch_hud_projection(new TouchHudProjection(GetRootWindow())); |
[email protected] | d141b92 | 2013-07-09 08:13:17 | [diff] [blame] | 1023 | } |
| 1024 | |
| 1025 | void RootWindowController::DisableTouchHudProjection() { |
| 1026 | if (!touch_hud_projection_) |
| 1027 | return; |
| 1028 | touch_hud_projection_->Remove(); |
| 1029 | } |
| 1030 | |
| 1031 | void RootWindowController::OnLoginStateChanged(user::LoginStatus status) { |
| 1032 | shelf_->shelf_layout_manager()->UpdateVisibilityState(); |
| 1033 | } |
| 1034 | |
| 1035 | void RootWindowController::OnTouchHudProjectionToggled(bool enabled) { |
| 1036 | if (enabled) |
| 1037 | EnableTouchHudProjection(); |
| 1038 | else |
| 1039 | DisableTouchHudProjection(); |
| 1040 | } |
| 1041 | |
[email protected] | 6b2d4a0b | 2013-09-06 06:29:54 | [diff] [blame] | 1042 | RootWindowController* GetRootWindowController( |
[email protected] | bf9cdb36 | 2013-10-25 19:22:45 | [diff] [blame] | 1043 | const aura::Window* root_window) { |
[email protected] | 6b2d4a0b | 2013-09-06 06:29:54 | [diff] [blame] | 1044 | return root_window ? GetRootWindowSettings(root_window)->controller : NULL; |
| 1045 | } |
| 1046 | |
[email protected] | d90b839 | 2012-06-13 09:34:56 | [diff] [blame] | 1047 | } // namespace ash |