| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/common/wm_root_window_controller.h" | 5 #include "ash/root_window_controller.h" |
| 6 | 6 |
| 7 #include "ash/aura/wm_window_aura.h" | 7 #include "ash/aura/wm_window_aura.h" |
| 8 #include "ash/common/session/session_state_delegate.h" | 8 #include "ash/common/session/session_state_delegate.h" |
| 9 #include "ash/common/shelf/shelf_layout_manager.h" | 9 #include "ash/common/shelf/shelf_layout_manager.h" |
| 10 #include "ash/common/shelf/shelf_widget.h" | 10 #include "ash/common/shelf/shelf_widget.h" |
| 11 #include "ash/common/shelf/wm_shelf.h" | 11 #include "ash/common/shelf/wm_shelf.h" |
| 12 #include "ash/common/shell_delegate.h" | 12 #include "ash/common/shell_delegate.h" |
| 13 #include "ash/common/system/status_area_widget.h" | 13 #include "ash/common/system/status_area_widget.h" |
| 14 #include "ash/common/wallpaper/wallpaper_delegate.h" | 14 #include "ash/common/wallpaper/wallpaper_delegate.h" |
| 15 #include "ash/common/wallpaper/wallpaper_widget_controller.h" | 15 #include "ash/common/wallpaper/wallpaper_widget_controller.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 34 #include "ui/aura/mus/window_mus.h" | 34 #include "ui/aura/mus/window_mus.h" |
| 35 #include "ui/aura/mus/window_tree_client.h" | 35 #include "ui/aura/mus/window_tree_client.h" |
| 36 #include "ui/aura/window.h" | 36 #include "ui/aura/window.h" |
| 37 #include "ui/aura/window_event_dispatcher.h" | 37 #include "ui/aura/window_event_dispatcher.h" |
| 38 #include "ui/aura/window_tree_host.h" | 38 #include "ui/aura/window_tree_host.h" |
| 39 #include "ui/base/models/menu_model.h" | 39 #include "ui/base/models/menu_model.h" |
| 40 #include "ui/events/event_targeter.h" | 40 #include "ui/events/event_targeter.h" |
| 41 #include "ui/events/event_utils.h" | 41 #include "ui/events/event_utils.h" |
| 42 #include "ui/views/controls/menu/menu_model_adapter.h" | 42 #include "ui/views/controls/menu/menu_model_adapter.h" |
| 43 #include "ui/views/controls/menu/menu_runner.h" | 43 #include "ui/views/controls/menu/menu_runner.h" |
| 44 #include "ui/wm/core/coordinate_conversion.h" |
| 44 | 45 |
| 46 // TODO(sky): this file is temporary and here to make review easier. The |
| 47 // contents of this file will be folded into root_window_controller.cc shortly. |
| 45 namespace ash { | 48 namespace ash { |
| 46 namespace { | 49 namespace { |
| 47 | 50 |
| 48 // Scales |value| that is originally between 0 and |src_max| to be between | 51 // Scales |value| that is originally between 0 and |src_max| to be between |
| 49 // 0 and |dst_max|. | 52 // 0 and |dst_max|. |
| 50 float ToRelativeValue(int value, int src_max, int dst_max) { | 53 float ToRelativeValue(int value, int src_max, int dst_max) { |
| 51 return static_cast<float>(value) / static_cast<float>(src_max) * dst_max; | 54 return static_cast<float>(value) / static_cast<float>(src_max) * dst_max; |
| 52 } | 55 } |
| 53 | 56 |
| 54 // Uses ToRelativeValue() to scale the origin of |bounds_in_out|. The | 57 // Uses ToRelativeValue() to scale the origin of |bounds_in_out|. The |
| 55 // width/height are not changed. | 58 // width/height are not changed. |
| 56 void MoveOriginRelativeToSize(const gfx::Size& src_size, | 59 void MoveOriginRelativeToSize(const gfx::Size& src_size, |
| 57 const gfx::Size& dst_size, | 60 const gfx::Size& dst_size, |
| 58 gfx::Rect* bounds_in_out) { | 61 gfx::Rect* bounds_in_out) { |
| 59 gfx::Point origin = bounds_in_out->origin(); | 62 gfx::Point origin = bounds_in_out->origin(); |
| 60 bounds_in_out->set_origin(gfx::Point( | 63 bounds_in_out->set_origin(gfx::Point( |
| 61 ToRelativeValue(origin.x(), src_size.width(), dst_size.width()), | 64 ToRelativeValue(origin.x(), src_size.width(), dst_size.width()), |
| 62 ToRelativeValue(origin.y(), src_size.height(), dst_size.height()))); | 65 ToRelativeValue(origin.y(), src_size.height(), dst_size.height()))); |
| 63 } | 66 } |
| 64 | 67 |
| 65 // Reparents |window| to |new_parent|. | 68 // Reparents |window| to |new_parent|. |
| 69 // TODO(sky): This should take an aura::Window. http://crbug.com/671246. |
| 66 void ReparentWindow(WmWindow* window, WmWindow* new_parent) { | 70 void ReparentWindow(WmWindow* window, WmWindow* new_parent) { |
| 67 const gfx::Size src_size = window->GetParent()->GetBounds().size(); | 71 const gfx::Size src_size = window->GetParent()->GetBounds().size(); |
| 68 const gfx::Size dst_size = new_parent->GetBounds().size(); | 72 const gfx::Size dst_size = new_parent->GetBounds().size(); |
| 69 // Update the restore bounds to make it relative to the display. | 73 // Update the restore bounds to make it relative to the display. |
| 70 wm::WindowState* state = window->GetWindowState(); | 74 wm::WindowState* state = window->GetWindowState(); |
| 71 gfx::Rect restore_bounds; | 75 gfx::Rect restore_bounds; |
| 72 bool has_restore_bounds = state->HasRestoreBounds(); | 76 bool has_restore_bounds = state->HasRestoreBounds(); |
| 73 | 77 |
| 74 bool update_bounds = | 78 bool update_bounds = |
| 75 (state->IsNormalOrSnapped() || state->IsMinimized()) && | 79 (state->IsNormalOrSnapped() || state->IsMinimized()) && |
| (...skipping 13 matching lines...) Expand all Loading... |
| 89 | 93 |
| 90 // Docked windows have bounds handled by the layout manager in AddChild(). | 94 // Docked windows have bounds handled by the layout manager in AddChild(). |
| 91 if (update_bounds) | 95 if (update_bounds) |
| 92 window->SetBounds(local_bounds); | 96 window->SetBounds(local_bounds); |
| 93 | 97 |
| 94 if (has_restore_bounds) | 98 if (has_restore_bounds) |
| 95 state->SetRestoreBoundsInParent(restore_bounds); | 99 state->SetRestoreBoundsInParent(restore_bounds); |
| 96 } | 100 } |
| 97 | 101 |
| 98 // Reparents the appropriate set of windows from |src| to |dst|. | 102 // Reparents the appropriate set of windows from |src| to |dst|. |
| 103 // TODO(sky): This should take an aura::Window. http://crbug.com/671246. |
| 99 void ReparentAllWindows(WmWindow* src, WmWindow* dst) { | 104 void ReparentAllWindows(WmWindow* src, WmWindow* dst) { |
| 100 // Set of windows to move. | 105 // Set of windows to move. |
| 101 const int kContainerIdsToMove[] = { | 106 const int kContainerIdsToMove[] = { |
| 102 kShellWindowId_DefaultContainer, | 107 kShellWindowId_DefaultContainer, |
| 103 kShellWindowId_DockedContainer, | 108 kShellWindowId_DockedContainer, |
| 104 kShellWindowId_PanelContainer, | 109 kShellWindowId_PanelContainer, |
| 105 kShellWindowId_AlwaysOnTopContainer, | 110 kShellWindowId_AlwaysOnTopContainer, |
| 106 kShellWindowId_SystemModalContainer, | 111 kShellWindowId_SystemModalContainer, |
| 107 kShellWindowId_LockSystemModalContainer, | 112 kShellWindowId_LockSystemModalContainer, |
| 108 kShellWindowId_UnparentedControlContainer, | 113 kShellWindowId_UnparentedControlContainer, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 135 ++iter; | 140 ++iter; |
| 136 } | 141 } |
| 137 // If the entire window list is modal background windows then stop. | 142 // If the entire window list is modal background windows then stop. |
| 138 if (iter == src_container_children.end()) | 143 if (iter == src_container_children.end()) |
| 139 break; | 144 break; |
| 140 ReparentWindow(*iter, dst_container); | 145 ReparentWindow(*iter, dst_container); |
| 141 } | 146 } |
| 142 } | 147 } |
| 143 } | 148 } |
| 144 | 149 |
| 150 // TODO(sky): This should take an aura::Window. http://crbug.com/671246. |
| 151 bool ShouldDestroyWindowInCloseChildWindows(WmWindow* window) { |
| 152 if (!WmWindowAura::GetAuraWindow(window)->owned_by_parent()) |
| 153 return false; |
| 154 |
| 155 if (!WmShell::Get()->IsRunningInMash()) |
| 156 return true; |
| 157 |
| 158 aura::WindowMus* window_mus = |
| 159 aura::WindowMus::Get(WmWindowAura::GetAuraWindow(window)); |
| 160 return Shell::window_tree_client()->WasCreatedByThisClient(window_mus) || |
| 161 Shell::window_tree_client()->IsRoot(window_mus); |
| 162 } |
| 163 |
| 145 // Creates a new window for use as a container. | 164 // Creates a new window for use as a container. |
| 165 // TODO(sky): This should create an aura::Window. http://crbug.com/671246. |
| 146 WmWindow* CreateContainer(int window_id, const char* name, WmWindow* parent) { | 166 WmWindow* CreateContainer(int window_id, const char* name, WmWindow* parent) { |
| 147 WmWindow* window = WmShell::Get()->NewWindow(ui::wm::WINDOW_TYPE_UNKNOWN, | 167 WmWindow* window = WmShell::Get()->NewWindow(ui::wm::WINDOW_TYPE_UNKNOWN, |
| 148 ui::LAYER_NOT_DRAWN); | 168 ui::LAYER_NOT_DRAWN); |
| 149 window->SetShellWindowId(window_id); | 169 window->SetShellWindowId(window_id); |
| 150 window->SetName(name); | 170 window->SetName(name); |
| 151 parent->AddChild(window); | 171 parent->AddChild(window); |
| 152 if (window_id != kShellWindowId_UnparentedControlContainer) | 172 if (window_id != kShellWindowId_UnparentedControlContainer) |
| 153 window->Show(); | 173 window->Show(); |
| 154 return window; | 174 return window; |
| 155 } | 175 } |
| 156 | 176 |
| 157 } // namespace | 177 } // namespace |
| 158 | 178 |
| 159 WmRootWindowController::WmRootWindowController( | 179 void RootWindowController::SetWallpaperWidgetController( |
| 160 RootWindowController* root_window_controller, | |
| 161 WmWindow* root) | |
| 162 : root_window_controller_(root_window_controller), root_(root) { | |
| 163 DCHECK(root_window_controller_); | |
| 164 DCHECK(root_); | |
| 165 } | |
| 166 | |
| 167 WmRootWindowController::~WmRootWindowController() { | |
| 168 if (animating_wallpaper_widget_controller_.get()) | |
| 169 animating_wallpaper_widget_controller_->StopAnimating(); | |
| 170 } | |
| 171 | |
| 172 void WmRootWindowController::SetWallpaperWidgetController( | |
| 173 WallpaperWidgetController* controller) { | 180 WallpaperWidgetController* controller) { |
| 174 wallpaper_widget_controller_.reset(controller); | 181 wallpaper_widget_controller_.reset(controller); |
| 175 } | 182 } |
| 176 | 183 |
| 177 void WmRootWindowController::SetAnimatingWallpaperWidgetController( | 184 void RootWindowController::SetAnimatingWallpaperWidgetController( |
| 178 AnimatingWallpaperWidgetController* controller) { | 185 AnimatingWallpaperWidgetController* controller) { |
| 179 if (animating_wallpaper_widget_controller_.get()) | 186 if (animating_wallpaper_widget_controller_.get()) |
| 180 animating_wallpaper_widget_controller_->StopAnimating(); | 187 animating_wallpaper_widget_controller_->StopAnimating(); |
| 181 animating_wallpaper_widget_controller_.reset(controller); | 188 animating_wallpaper_widget_controller_.reset(controller); |
| 182 } | 189 } |
| 183 | 190 |
| 184 wm::WorkspaceWindowState WmRootWindowController::GetWorkspaceWindowState() { | 191 wm::WorkspaceWindowState RootWindowController::GetWorkspaceWindowState() { |
| 185 return workspace_controller_ ? workspace_controller()->GetWindowState() | 192 return workspace_controller_ ? workspace_controller()->GetWindowState() |
| 186 : wm::WORKSPACE_WINDOW_STATE_DEFAULT; | 193 : wm::WORKSPACE_WINDOW_STATE_DEFAULT; |
| 187 } | 194 } |
| 188 | 195 |
| 189 SystemModalContainerLayoutManager* | 196 SystemModalContainerLayoutManager* |
| 190 WmRootWindowController::GetSystemModalLayoutManager(WmWindow* window) { | 197 RootWindowController::GetSystemModalLayoutManager(WmWindow* window) { |
| 191 WmWindow* modal_container = nullptr; | 198 aura::Window* modal_container = nullptr; |
| 192 if (window) { | 199 if (window) { |
| 193 WmWindow* window_container = wm::GetContainerForWindow(window); | 200 WmWindow* window_container = wm::GetContainerForWindow(window); |
| 194 if (window_container && | 201 const int container_id = (window_container && |
| 195 window_container->GetShellWindowId() >= | 202 window_container->GetShellWindowId() >= |
| 196 kShellWindowId_LockScreenContainer) { | 203 kShellWindowId_LockScreenContainer) |
| 197 modal_container = GetContainer(kShellWindowId_LockSystemModalContainer); | 204 ? kShellWindowId_LockSystemModalContainer |
| 198 } else { | 205 : kShellWindowId_SystemModalContainer; |
| 199 modal_container = GetContainer(kShellWindowId_SystemModalContainer); | 206 modal_container = GetContainer(container_id); |
| 200 } | |
| 201 } else { | 207 } else { |
| 202 int modal_window_id = | 208 int modal_window_id = |
| 203 WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked() | 209 WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked() |
| 204 ? kShellWindowId_LockSystemModalContainer | 210 ? kShellWindowId_LockSystemModalContainer |
| 205 : kShellWindowId_SystemModalContainer; | 211 : kShellWindowId_SystemModalContainer; |
| 206 modal_container = GetContainer(modal_window_id); | 212 modal_container = GetContainer(modal_window_id); |
| 207 } | 213 } |
| 208 return modal_container ? static_cast<SystemModalContainerLayoutManager*>( | 214 return modal_container |
| 209 modal_container->GetLayoutManager()) | 215 ? static_cast<SystemModalContainerLayoutManager*>( |
| 210 : nullptr; | 216 WmWindowAura::Get(modal_container)->GetLayoutManager()) |
| 217 : nullptr; |
| 211 } | 218 } |
| 212 | 219 |
| 213 bool WmRootWindowController::HasShelf() { | 220 void RootWindowController::CreateShelf() { |
| 214 return GetShelf()->shelf_widget() != nullptr; | 221 if (wm_shelf_->IsShelfInitialized()) |
| 215 } | |
| 216 | |
| 217 WmShelf* WmRootWindowController::GetShelf() { | |
| 218 return root_window_controller_->wm_shelf(); | |
| 219 } | |
| 220 | |
| 221 void WmRootWindowController::CreateShelf() { | |
| 222 WmShelf* shelf = GetShelf(); | |
| 223 if (shelf->IsShelfInitialized()) | |
| 224 return; | 222 return; |
| 225 shelf->InitializeShelf(); | 223 wm_shelf_->InitializeShelf(); |
| 226 | 224 |
| 227 if (panel_layout_manager_) | 225 if (panel_layout_manager_) |
| 228 panel_layout_manager_->SetShelf(shelf); | 226 panel_layout_manager_->SetShelf(wm_shelf_.get()); |
| 229 if (docked_window_layout_manager_) { | 227 if (docked_window_layout_manager_) { |
| 230 docked_window_layout_manager_->SetShelf(shelf); | 228 docked_window_layout_manager_->SetShelf(wm_shelf_.get()); |
| 231 if (shelf->shelf_layout_manager()) | 229 if (wm_shelf_->shelf_layout_manager()) |
| 232 docked_window_layout_manager_->AddObserver(shelf->shelf_layout_manager()); | 230 docked_window_layout_manager_->AddObserver( |
| 231 wm_shelf_->shelf_layout_manager()); |
| 233 } | 232 } |
| 234 | 233 |
| 235 // Notify shell observers that the shelf has been created. | 234 // Notify shell observers that the shelf has been created. |
| 236 // TODO(jamescook): Move this into WmShelf::InitializeShelf(). This will | 235 // TODO(jamescook): Move this into WmShelf::InitializeShelf(). This will |
| 237 // require changing AttachedPanelWidgetTargeter's access to WmShelf. | 236 // require changing AttachedPanelWidgetTargeter's access to WmShelf. |
| 238 WmShell::Get()->NotifyShelfCreatedForRootWindow(GetWindow()); | 237 WmShell::Get()->NotifyShelfCreatedForRootWindow( |
| 238 WmWindowAura::Get(GetRootWindow())); |
| 239 | 239 |
| 240 shelf->shelf_widget()->PostCreateShelf(); | 240 wm_shelf_->shelf_widget()->PostCreateShelf(); |
| 241 } | 241 } |
| 242 | 242 |
| 243 void WmRootWindowController::ShowShelf() { | 243 void RootWindowController::ShowShelf() { |
| 244 WmShelf* shelf = GetShelf(); | 244 if (!wm_shelf_->IsShelfInitialized()) |
| 245 if (!shelf->IsShelfInitialized()) | |
| 246 return; | 245 return; |
| 247 // TODO(jamescook): Move this into WmShelf. | 246 // TODO(jamescook): Move this into WmShelf. |
| 248 shelf->shelf_widget()->SetShelfVisibility(true); | 247 wm_shelf_->shelf_widget()->SetShelfVisibility(true); |
| 249 shelf->shelf_widget()->status_area_widget()->Show(); | 248 wm_shelf_->shelf_widget()->status_area_widget()->Show(); |
| 250 } | 249 } |
| 251 | 250 |
| 252 SystemTray* WmRootWindowController::GetSystemTray() { | 251 const WmWindow* RootWindowController::GetWindow() const { |
| 253 ShelfWidget* shelf_widget = GetShelf()->shelf_widget(); | 252 return WmWindowAura::Get(GetRootWindow()); |
| 254 if (!shelf_widget || !shelf_widget->status_area_widget()) | |
| 255 return nullptr; | |
| 256 return shelf_widget->status_area_widget()->system_tray(); | |
| 257 } | 253 } |
| 258 | 254 |
| 259 WmWindow* WmRootWindowController::GetWindow() { | 255 const WmWindow* RootWindowController::GetWmContainer(int container_id) const { |
| 260 return root_; | 256 const aura::Window* window = GetContainer(container_id); |
| 257 return WmWindowAura::Get(window); |
| 261 } | 258 } |
| 262 | 259 |
| 263 WmWindow* WmRootWindowController::GetContainer(int container_id) { | 260 void RootWindowController::ConfigureWidgetInitParamsForContainer( |
| 264 return root_->GetChildByShellWindowId(container_id); | |
| 265 } | |
| 266 | |
| 267 const WmWindow* WmRootWindowController::GetContainer(int container_id) const { | |
| 268 return root_->GetChildByShellWindowId(container_id); | |
| 269 } | |
| 270 | |
| 271 void WmRootWindowController::ConfigureWidgetInitParamsForContainer( | |
| 272 views::Widget* widget, | 261 views::Widget* widget, |
| 273 int shell_container_id, | 262 int shell_container_id, |
| 274 views::Widget::InitParams* init_params) { | 263 views::Widget::InitParams* init_params) { |
| 275 init_params->parent = WmWindowAura::GetAuraWindow( | 264 init_params->parent = GetContainer(shell_container_id); |
| 276 GetWindow()->GetChildByShellWindowId(shell_container_id)); | |
| 277 } | 265 } |
| 278 | 266 |
| 279 WmWindow* WmRootWindowController::FindEventTarget( | 267 WmWindow* RootWindowController::FindEventTarget( |
| 280 const gfx::Point& location_in_screen) { | 268 const gfx::Point& location_in_screen) { |
| 281 gfx::Point location_in_root = | 269 gfx::Point location_in_root(location_in_screen); |
| 282 GetWindow()->ConvertPointFromScreen(location_in_screen); | 270 ::wm::ConvertPointFromScreen(GetRootWindow(), &location_in_root); |
| 283 aura::Window* root = WmWindowAura::GetAuraWindow(GetWindow()); | |
| 284 ui::MouseEvent test_event(ui::ET_MOUSE_MOVED, location_in_root, | 271 ui::MouseEvent test_event(ui::ET_MOUSE_MOVED, location_in_root, |
| 285 location_in_root, ui::EventTimeForNow(), | 272 location_in_root, ui::EventTimeForNow(), |
| 286 ui::EF_NONE, ui::EF_NONE); | 273 ui::EF_NONE, ui::EF_NONE); |
| 287 ui::EventTarget* event_handler = static_cast<ui::EventTarget*>(root) | 274 ui::EventTarget* event_handler = |
| 288 ->GetEventTargeter() | 275 static_cast<ui::EventTarget*>(GetRootWindow()) |
| 289 ->FindTargetForEvent(root, &test_event); | 276 ->GetEventTargeter() |
| 277 ->FindTargetForEvent(GetRootWindow(), &test_event); |
| 290 return WmWindowAura::Get(static_cast<aura::Window*>(event_handler)); | 278 return WmWindowAura::Get(static_cast<aura::Window*>(event_handler)); |
| 291 } | 279 } |
| 292 | 280 |
| 293 gfx::Point WmRootWindowController::GetLastMouseLocationInRoot() { | 281 gfx::Point RootWindowController::GetLastMouseLocationInRoot() { |
| 294 return WmWindowAura::GetAuraWindow(GetWindow()) | 282 return window_tree_host_->dispatcher()->GetLastMouseLocationInRoot(); |
| 295 ->GetHost() | |
| 296 ->dispatcher() | |
| 297 ->GetLastMouseLocationInRoot(); | |
| 298 } | 283 } |
| 299 | 284 |
| 300 void WmRootWindowController::ShowContextMenu( | 285 void RootWindowController::ShowContextMenu(const gfx::Point& location_in_screen, |
| 301 const gfx::Point& location_in_screen, | 286 ui::MenuSourceType source_type) { |
| 302 ui::MenuSourceType source_type) { | |
| 303 ShellDelegate* delegate = WmShell::Get()->delegate(); | 287 ShellDelegate* delegate = WmShell::Get()->delegate(); |
| 304 DCHECK(delegate); | 288 DCHECK(delegate); |
| 305 menu_model_.reset(delegate->CreateContextMenu(GetShelf(), nullptr)); | 289 menu_model_.reset(delegate->CreateContextMenu(wm_shelf_.get(), nullptr)); |
| 306 if (!menu_model_) | 290 if (!menu_model_) |
| 307 return; | 291 return; |
| 308 | 292 |
| 309 menu_model_adapter_.reset(new views::MenuModelAdapter( | 293 menu_model_adapter_ = base::MakeUnique<views::MenuModelAdapter>( |
| 310 menu_model_.get(), base::Bind(&WmRootWindowController::OnMenuClosed, | 294 menu_model_.get(), |
| 311 base::Unretained(this)))); | 295 base::Bind(&RootWindowController::OnMenuClosed, base::Unretained(this))); |
| 312 | 296 |
| 313 // The wallpaper controller may not be set yet if the user clicked on the | 297 // The wallpaper controller may not be set yet if the user clicked on the |
| 314 // status area before the initial animation completion. See crbug.com/222218 | 298 // status area before the initial animation completion. See crbug.com/222218 |
| 315 if (!wallpaper_widget_controller()) | 299 if (!wallpaper_widget_controller()) |
| 316 return; | 300 return; |
| 317 | 301 |
| 318 menu_runner_.reset(new views::MenuRunner( | 302 menu_runner_ = base::MakeUnique<views::MenuRunner>( |
| 319 menu_model_adapter_->CreateMenu(), | 303 menu_model_adapter_->CreateMenu(), |
| 320 views::MenuRunner::CONTEXT_MENU | views::MenuRunner::ASYNC)); | 304 views::MenuRunner::CONTEXT_MENU | views::MenuRunner::ASYNC); |
| 321 ignore_result( | 305 ignore_result( |
| 322 menu_runner_->RunMenuAt(wallpaper_widget_controller()->widget(), nullptr, | 306 menu_runner_->RunMenuAt(wallpaper_widget_controller()->widget(), nullptr, |
| 323 gfx::Rect(location_in_screen, gfx::Size()), | 307 gfx::Rect(location_in_screen, gfx::Size()), |
| 324 views::MENU_ANCHOR_TOPLEFT, source_type)); | 308 views::MENU_ANCHOR_TOPLEFT, source_type)); |
| 325 } | 309 } |
| 326 | 310 |
| 327 void WmRootWindowController::OnInitialWallpaperAnimationStarted() { | 311 void RootWindowController::UpdateAfterLoginStatusChange(LoginStatus status) { |
| 328 root_window_controller_->OnInitialWallpaperAnimationStarted(); | |
| 329 } | |
| 330 | |
| 331 void WmRootWindowController::OnWallpaperAnimationFinished( | |
| 332 views::Widget* widget) { | |
| 333 root_window_controller_->OnWallpaperAnimationFinished(widget); | |
| 334 WmShell::Get()->wallpaper_delegate()->OnWallpaperAnimationFinished(); | |
| 335 // Only removes old component when wallpaper animation finished. If we | |
| 336 // remove the old one before the new wallpaper is done fading in there will | |
| 337 // be a white flash during the animation. | |
| 338 if (animating_wallpaper_widget_controller()) { | |
| 339 WallpaperWidgetController* controller = | |
| 340 animating_wallpaper_widget_controller()->GetController(true); | |
| 341 DCHECK_EQ(controller->widget(), widget); | |
| 342 // Release the old controller and close its wallpaper widget. | |
| 343 SetWallpaperWidgetController(controller); | |
| 344 } | |
| 345 } | |
| 346 | |
| 347 void WmRootWindowController::UpdateAfterLoginStatusChange(LoginStatus status) { | |
| 348 StatusAreaWidget* status_area_widget = | 312 StatusAreaWidget* status_area_widget = |
| 349 GetShelf()->shelf_widget()->status_area_widget(); | 313 wm_shelf_->shelf_widget()->status_area_widget(); |
| 350 if (status_area_widget) | 314 if (status_area_widget) |
| 351 status_area_widget->UpdateAfterLoginStatusChange(status); | 315 status_area_widget->UpdateAfterLoginStatusChange(status); |
| 352 } | 316 } |
| 353 | 317 |
| 354 void WmRootWindowController::MoveWindowsTo(WmWindow* dest) { | 318 bool RootWindowController::HasShelf() { |
| 319 return wm_shelf_->shelf_widget() != nullptr; |
| 320 } |
| 321 |
| 322 WmShelf* RootWindowController::GetShelf() { |
| 323 return wm_shelf_.get(); |
| 324 } |
| 325 |
| 326 void RootWindowController::MoveWindowsTo(aura::Window* dst) { |
| 355 // Clear the workspace controller, so it doesn't incorrectly update the shelf. | 327 // Clear the workspace controller, so it doesn't incorrectly update the shelf. |
| 356 workspace_controller_.reset(); | 328 workspace_controller_.reset(); |
| 357 ReparentAllWindows(GetWindow(), dest); | 329 ReparentAllWindows(GetWindow(), WmWindowAura::Get(dst)); |
| 358 } | 330 } |
| 359 | 331 |
| 360 void WmRootWindowController::CreateContainers() { | 332 void RootWindowController::CreateContainers() { |
| 333 WmWindow* root = GetWindow(); |
| 361 // These containers are just used by PowerButtonController to animate groups | 334 // These containers are just used by PowerButtonController to animate groups |
| 362 // of containers simultaneously without messing up the current transformations | 335 // of containers simultaneously without messing up the current transformations |
| 363 // on those containers. These are direct children of the root window; all of | 336 // on those containers. These are direct children of the root window; all of |
| 364 // the other containers are their children. | 337 // the other containers are their children. |
| 365 | 338 |
| 366 // The wallpaper container is not part of the lock animation, so it is not | 339 // The wallpaper container is not part of the lock animation, so it is not |
| 367 // included in those animate groups. When the screen is locked, the wallpaper | 340 // included in those animate groups. When the screen is locked, the wallpaper |
| 368 // is moved to the lock screen wallpaper container (and moved back on unlock). | 341 // is moved to the lock screen wallpaper container (and moved back on unlock). |
| 369 // Ensure that there's an opaque layer occluding the non-lock-screen layers. | 342 // Ensure that there's an opaque layer occluding the non-lock-screen layers. |
| 370 WmWindow* wallpaper_container = CreateContainer( | 343 WmWindow* wallpaper_container = CreateContainer( |
| 371 kShellWindowId_WallpaperContainer, "WallpaperContainer", root_); | 344 kShellWindowId_WallpaperContainer, "WallpaperContainer", root); |
| 372 wallpaper_container->SetChildWindowVisibilityChangesAnimated(); | 345 wallpaper_container->SetChildWindowVisibilityChangesAnimated(); |
| 373 | 346 |
| 374 WmWindow* non_lock_screen_containers = | 347 WmWindow* non_lock_screen_containers = |
| 375 CreateContainer(kShellWindowId_NonLockScreenContainersContainer, | 348 CreateContainer(kShellWindowId_NonLockScreenContainersContainer, |
| 376 "NonLockScreenContainersContainer", root_); | 349 "NonLockScreenContainersContainer", root); |
| 377 // Clip all windows inside this container, as half pixel of the window's | 350 // Clip all windows inside this container, as half pixel of the window's |
| 378 // texture may become visible when the screen is scaled. crbug.com/368591. | 351 // texture may become visible when the screen is scaled. crbug.com/368591. |
| 379 non_lock_screen_containers->SetMasksToBounds(true); | 352 non_lock_screen_containers->SetMasksToBounds(true); |
| 380 | 353 |
| 381 WmWindow* lock_wallpaper_containers = | 354 WmWindow* lock_wallpaper_containers = |
| 382 CreateContainer(kShellWindowId_LockScreenWallpaperContainer, | 355 CreateContainer(kShellWindowId_LockScreenWallpaperContainer, |
| 383 "LockScreenWallpaperContainer", root_); | 356 "LockScreenWallpaperContainer", root); |
| 384 lock_wallpaper_containers->SetChildWindowVisibilityChangesAnimated(); | 357 lock_wallpaper_containers->SetChildWindowVisibilityChangesAnimated(); |
| 385 | 358 |
| 386 WmWindow* lock_screen_containers = | 359 WmWindow* lock_screen_containers = |
| 387 CreateContainer(kShellWindowId_LockScreenContainersContainer, | 360 CreateContainer(kShellWindowId_LockScreenContainersContainer, |
| 388 "LockScreenContainersContainer", root_); | 361 "LockScreenContainersContainer", root); |
| 389 WmWindow* lock_screen_related_containers = | 362 WmWindow* lock_screen_related_containers = |
| 390 CreateContainer(kShellWindowId_LockScreenRelatedContainersContainer, | 363 CreateContainer(kShellWindowId_LockScreenRelatedContainersContainer, |
| 391 "LockScreenRelatedContainersContainer", root_); | 364 "LockScreenRelatedContainersContainer", root); |
| 392 | 365 |
| 393 CreateContainer(kShellWindowId_UnparentedControlContainer, | 366 CreateContainer(kShellWindowId_UnparentedControlContainer, |
| 394 "UnparentedControlContainer", non_lock_screen_containers); | 367 "UnparentedControlContainer", non_lock_screen_containers); |
| 395 | 368 |
| 396 WmWindow* default_container = | 369 WmWindow* default_container = |
| 397 CreateContainer(kShellWindowId_DefaultContainer, "DefaultContainer", | 370 CreateContainer(kShellWindowId_DefaultContainer, "DefaultContainer", |
| 398 non_lock_screen_containers); | 371 non_lock_screen_containers); |
| 399 default_container->SetChildWindowVisibilityChangesAnimated(); | 372 default_container->SetChildWindowVisibilityChangesAnimated(); |
| 400 default_container->SetSnapsChildrenToPhysicalPixelBoundary(); | 373 default_container->SetSnapsChildrenToPhysicalPixelBoundary(); |
| 401 default_container->SetBoundsInScreenBehaviorForChildren( | 374 default_container->SetBoundsInScreenBehaviorForChildren( |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES); | 491 WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES); |
| 519 | 492 |
| 520 WmWindow* overlay_container = | 493 WmWindow* overlay_container = |
| 521 CreateContainer(kShellWindowId_OverlayContainer, "OverlayContainer", | 494 CreateContainer(kShellWindowId_OverlayContainer, "OverlayContainer", |
| 522 lock_screen_related_containers); | 495 lock_screen_related_containers); |
| 523 overlay_container->SetSnapsChildrenToPhysicalPixelBoundary(); | 496 overlay_container->SetSnapsChildrenToPhysicalPixelBoundary(); |
| 524 overlay_container->SetBoundsInScreenBehaviorForChildren( | 497 overlay_container->SetBoundsInScreenBehaviorForChildren( |
| 525 WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES); | 498 WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES); |
| 526 | 499 |
| 527 WmWindow* mouse_cursor_container = CreateContainer( | 500 WmWindow* mouse_cursor_container = CreateContainer( |
| 528 kShellWindowId_MouseCursorContainer, "MouseCursorContainer", root_); | 501 kShellWindowId_MouseCursorContainer, "MouseCursorContainer", root); |
| 529 mouse_cursor_container->SetBoundsInScreenBehaviorForChildren( | 502 mouse_cursor_container->SetBoundsInScreenBehaviorForChildren( |
| 530 WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES); | 503 WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES); |
| 531 | 504 |
| 532 CreateContainer(kShellWindowId_PowerButtonAnimationContainer, | 505 CreateContainer(kShellWindowId_PowerButtonAnimationContainer, |
| 533 "PowerButtonAnimationContainer", root_); | 506 "PowerButtonAnimationContainer", root); |
| 534 } | 507 } |
| 535 | 508 |
| 536 void WmRootWindowController::CreateLayoutManagers() { | 509 void RootWindowController::CreateLayoutManagers() { |
| 537 GetShelf()->CreateShelfWidget(GetWindow()); | 510 GetShelf()->CreateShelfWidget(GetWindow()); |
| 538 | 511 |
| 539 root_window_layout_manager_ = new wm::RootWindowLayoutManager(root_); | 512 WmWindow* root = GetWindow(); |
| 540 root_->SetLayoutManager(base::WrapUnique(root_window_layout_manager_)); | 513 root_window_layout_manager_ = new wm::RootWindowLayoutManager(root); |
| 514 root->SetLayoutManager(base::WrapUnique(root_window_layout_manager_)); |
| 541 | 515 |
| 542 WmWindow* default_container = GetContainer(kShellWindowId_DefaultContainer); | 516 WmWindow* default_container = GetWmContainer(kShellWindowId_DefaultContainer); |
| 543 // Installs WorkspaceLayoutManager on |default_container|. | 517 // Installs WorkspaceLayoutManager on |default_container|. |
| 544 workspace_controller_.reset(new WorkspaceController(default_container)); | 518 workspace_controller_.reset(new WorkspaceController(default_container)); |
| 545 | 519 |
| 546 WmWindow* modal_container = GetContainer(kShellWindowId_SystemModalContainer); | 520 WmWindow* modal_container = |
| 521 GetWmContainer(kShellWindowId_SystemModalContainer); |
| 547 DCHECK(modal_container); | 522 DCHECK(modal_container); |
| 548 modal_container->SetLayoutManager( | 523 modal_container->SetLayoutManager( |
| 549 base::MakeUnique<SystemModalContainerLayoutManager>(modal_container)); | 524 base::MakeUnique<SystemModalContainerLayoutManager>(modal_container)); |
| 550 | 525 |
| 551 WmWindow* lock_modal_container = | 526 WmWindow* lock_modal_container = |
| 552 GetContainer(kShellWindowId_LockSystemModalContainer); | 527 GetWmContainer(kShellWindowId_LockSystemModalContainer); |
| 553 DCHECK(lock_modal_container); | 528 DCHECK(lock_modal_container); |
| 554 lock_modal_container->SetLayoutManager( | 529 lock_modal_container->SetLayoutManager( |
| 555 base::MakeUnique<SystemModalContainerLayoutManager>( | 530 base::MakeUnique<SystemModalContainerLayoutManager>( |
| 556 lock_modal_container)); | 531 lock_modal_container)); |
| 557 | 532 |
| 558 WmWindow* lock_container = GetContainer(kShellWindowId_LockScreenContainer); | 533 WmWindow* lock_container = GetWmContainer(kShellWindowId_LockScreenContainer); |
| 559 DCHECK(lock_container); | 534 DCHECK(lock_container); |
| 560 lock_container->SetLayoutManager( | 535 lock_container->SetLayoutManager( |
| 561 base::MakeUnique<LockLayoutManager>(lock_container)); | 536 base::MakeUnique<LockLayoutManager>(lock_container)); |
| 562 | 537 |
| 563 WmWindow* always_on_top_container = | 538 WmWindow* always_on_top_container = |
| 564 GetContainer(kShellWindowId_AlwaysOnTopContainer); | 539 GetWmContainer(kShellWindowId_AlwaysOnTopContainer); |
| 565 DCHECK(always_on_top_container); | 540 DCHECK(always_on_top_container); |
| 566 always_on_top_controller_ = | 541 always_on_top_controller_ = |
| 567 base::MakeUnique<AlwaysOnTopController>(always_on_top_container); | 542 base::MakeUnique<AlwaysOnTopController>(always_on_top_container); |
| 568 | 543 |
| 569 // Create Docked windows layout manager | 544 // Create Docked windows layout manager |
| 570 WmWindow* docked_container = GetContainer(kShellWindowId_DockedContainer); | 545 WmWindow* docked_container = GetWmContainer(kShellWindowId_DockedContainer); |
| 571 docked_window_layout_manager_ = | 546 docked_window_layout_manager_ = |
| 572 new DockedWindowLayoutManager(docked_container); | 547 new DockedWindowLayoutManager(docked_container); |
| 573 docked_container->SetLayoutManager( | 548 docked_container->SetLayoutManager( |
| 574 base::WrapUnique(docked_window_layout_manager_)); | 549 base::WrapUnique(docked_window_layout_manager_)); |
| 575 | 550 |
| 576 // Create Panel layout manager | 551 // Create Panel layout manager |
| 577 WmWindow* panel_container = GetContainer(kShellWindowId_PanelContainer); | 552 WmWindow* panel_container = GetWmContainer(kShellWindowId_PanelContainer); |
| 578 panel_layout_manager_ = new PanelLayoutManager(panel_container); | 553 panel_layout_manager_ = new PanelLayoutManager(panel_container); |
| 579 panel_container->SetLayoutManager(base::WrapUnique(panel_layout_manager_)); | 554 panel_container->SetLayoutManager(base::WrapUnique(panel_layout_manager_)); |
| 580 | 555 |
| 581 wm::WmSnapToPixelLayoutManager::InstallOnContainers(root_); | 556 wm::WmSnapToPixelLayoutManager::InstallOnContainers(root); |
| 582 } | 557 } |
| 583 | 558 |
| 584 void WmRootWindowController::ResetRootForNewWindowsIfNecessary() { | 559 void RootWindowController::ResetRootForNewWindowsIfNecessary() { |
| 585 WmShell* shell = WmShell::Get(); | 560 WmShell* shell = WmShell::Get(); |
| 586 // Change the target root window before closing child windows. If any child | 561 // Change the target root window before closing child windows. If any child |
| 587 // being removed triggers a relayout of the shelf it will try to build a | 562 // being removed triggers a relayout of the shelf it will try to build a |
| 588 // window list adding windows from the target root window's containers which | 563 // window list adding windows from the target root window's containers which |
| 589 // may have already gone away. | 564 // may have already gone away. |
| 590 if (shell->GetRootWindowForNewWindows() == GetWindow()) { | 565 WmWindow* root = GetWindow(); |
| 566 if (shell->GetRootWindowForNewWindows() == root) { |
| 591 // The root window for new windows is being destroyed. Switch to the primary | 567 // The root window for new windows is being destroyed. Switch to the primary |
| 592 // root window if possible. | 568 // root window if possible. |
| 593 WmWindow* primary_root = shell->GetPrimaryRootWindow(); | 569 WmWindow* primary_root = shell->GetPrimaryRootWindow(); |
| 594 shell->set_root_window_for_new_windows( | 570 shell->set_root_window_for_new_windows(primary_root == root ? nullptr |
| 595 primary_root == GetWindow() ? nullptr : primary_root); | 571 : primary_root); |
| 596 } | 572 } |
| 597 } | 573 } |
| 598 | 574 |
| 599 void WmRootWindowController::CloseChildWindows() { | 575 // TODO(sky): fold into CloseChildWindows() when move back. |
| 576 void RootWindowController::CloseChildWindowsImpl() { |
| 600 // NOTE: this may be called multiple times. | 577 // NOTE: this may be called multiple times. |
| 601 | 578 |
| 602 // |panel_layout_manager_| needs to be shut down before windows are destroyed. | 579 // |panel_layout_manager_| needs to be shut down before windows are destroyed. |
| 603 if (panel_layout_manager_) { | 580 if (panel_layout_manager_) { |
| 604 panel_layout_manager_->Shutdown(); | 581 panel_layout_manager_->Shutdown(); |
| 605 panel_layout_manager_ = nullptr; | 582 panel_layout_manager_ = nullptr; |
| 606 } | 583 } |
| 607 | 584 |
| 608 // |docked_window_layout_manager_| needs to be shut down before windows are | 585 // |docked_window_layout_manager_| needs to be shut down before windows are |
| 609 // destroyed. | 586 // destroyed. |
| 610 if (docked_window_layout_manager_) { | 587 if (docked_window_layout_manager_) { |
| 611 docked_window_layout_manager_->Shutdown(); | 588 docked_window_layout_manager_->Shutdown(); |
| 612 docked_window_layout_manager_ = nullptr; | 589 docked_window_layout_manager_ = nullptr; |
| 613 } | 590 } |
| 614 | 591 |
| 615 WmShelf* shelf = GetShelf(); | 592 WmShelf* shelf = GetShelf(); |
| 616 shelf->ShutdownShelfWidget(); | 593 shelf->ShutdownShelfWidget(); |
| 617 | 594 |
| 618 workspace_controller_.reset(); | 595 workspace_controller_.reset(); |
| 619 | 596 |
| 620 // Explicitly destroy top level windows. We do this because such windows may | 597 // Explicitly destroy top level windows. We do this because such windows may |
| 621 // query the RootWindow for state. | 598 // query the RootWindow for state. |
| 622 WmWindowTracker non_toplevel_windows; | 599 WmWindowTracker non_toplevel_windows; |
| 623 non_toplevel_windows.Add(root_); | 600 WmWindow* root = GetWindow(); |
| 601 non_toplevel_windows.Add(root); |
| 624 while (!non_toplevel_windows.windows().empty()) { | 602 while (!non_toplevel_windows.windows().empty()) { |
| 625 WmWindow* non_toplevel_window = non_toplevel_windows.Pop(); | 603 WmWindow* non_toplevel_window = non_toplevel_windows.Pop(); |
| 626 WmWindowTracker toplevel_windows; | 604 WmWindowTracker toplevel_windows; |
| 627 for (WmWindow* child : non_toplevel_window->GetChildren()) { | 605 for (WmWindow* child : non_toplevel_window->GetChildren()) { |
| 628 if (!ShouldDestroyWindowInCloseChildWindows(child)) | 606 if (!ShouldDestroyWindowInCloseChildWindows(child)) |
| 629 continue; | 607 continue; |
| 630 if (child->HasNonClientArea()) | 608 if (child->HasNonClientArea()) |
| 631 toplevel_windows.Add(child); | 609 toplevel_windows.Add(child); |
| 632 else | 610 else |
| 633 non_toplevel_windows.Add(child); | 611 non_toplevel_windows.Add(child); |
| 634 } | 612 } |
| 635 while (!toplevel_windows.windows().empty()) | 613 while (!toplevel_windows.windows().empty()) |
| 636 toplevel_windows.Pop()->Destroy(); | 614 toplevel_windows.Pop()->Destroy(); |
| 637 } | 615 } |
| 638 // And then remove the containers. | 616 // And then remove the containers. |
| 639 while (!root_->GetChildren().empty()) { | 617 while (!root->GetChildren().empty()) { |
| 640 WmWindow* child = root_->GetChildren()[0]; | 618 WmWindow* child = root->GetChildren()[0]; |
| 641 if (ShouldDestroyWindowInCloseChildWindows(child)) | 619 if (ShouldDestroyWindowInCloseChildWindows(child)) |
| 642 child->Destroy(); | 620 child->Destroy(); |
| 643 else | 621 else |
| 644 root_->RemoveChild(child); | 622 root->RemoveChild(child); |
| 645 } | 623 } |
| 646 | 624 |
| 647 shelf->DestroyShelfWidget(); | 625 shelf->DestroyShelfWidget(); |
| 648 | 626 |
| 649 // CloseChildWindows() may be called twice during the shutdown of ash | 627 // CloseChildWindows() may be called twice during the shutdown of ash |
| 650 // unittests. Avoid notifying WmShelf that the shelf has been destroyed twice. | 628 // unittests. Avoid notifying WmShelf that the shelf has been destroyed twice. |
| 651 if (shelf->IsShelfInitialized()) | 629 if (shelf->IsShelfInitialized()) |
| 652 shelf->ShutdownShelf(); | 630 shelf->ShutdownShelf(); |
| 653 } | 631 } |
| 654 | 632 |
| 655 bool WmRootWindowController::ShouldDestroyWindowInCloseChildWindows( | 633 void RootWindowController::OnMenuClosed() { |
| 656 WmWindow* window) { | |
| 657 if (!WmWindowAura::GetAuraWindow(window)->owned_by_parent()) | |
| 658 return false; | |
| 659 | |
| 660 if (aura::Env::GetInstance()->mode() == aura::Env::Mode::LOCAL) | |
| 661 return true; | |
| 662 | |
| 663 aura::WindowMus* window_mus = | |
| 664 aura::WindowMus::Get(WmWindowAura::GetAuraWindow(window)); | |
| 665 return Shell::window_tree_client()->WasCreatedByThisClient(window_mus) || | |
| 666 Shell::window_tree_client()->IsRoot(window_mus); | |
| 667 } | |
| 668 | |
| 669 void WmRootWindowController::OnMenuClosed() { | |
| 670 menu_runner_.reset(); | 634 menu_runner_.reset(); |
| 671 menu_model_adapter_.reset(); | 635 menu_model_adapter_.reset(); |
| 672 menu_model_.reset(); | 636 menu_model_.reset(); |
| 673 GetShelf()->UpdateVisibilityState(); | 637 wm_shelf_->UpdateVisibilityState(); |
| 674 } | 638 } |
| 675 | 639 |
| 676 } // namespace ash | 640 } // namespace ash |
| OLD | NEW |