Chromium Code Reviews| 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/common/wm_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" |
| 16 #include "ash/common/wm/always_on_top_controller.h" | 16 #include "ash/common/wm/always_on_top_controller.h" |
| 17 #include "ash/common/wm/container_finder.h" | 17 #include "ash/common/wm/container_finder.h" |
| 18 #include "ash/common/wm/dock/docked_window_layout_manager.h" | 18 #include "ash/common/wm/dock/docked_window_layout_manager.h" |
| 19 #include "ash/common/wm/lock_layout_manager.h" | 19 #include "ash/common/wm/lock_layout_manager.h" |
| 20 #include "ash/common/wm/panels/panel_layout_manager.h" | 20 #include "ash/common/wm/panels/panel_layout_manager.h" |
| 21 #include "ash/common/wm/root_window_layout_manager.h" | 21 #include "ash/common/wm/root_window_layout_manager.h" |
| 22 #include "ash/common/wm/system_modal_container_layout_manager.h" | 22 #include "ash/common/wm/system_modal_container_layout_manager.h" |
| 23 #include "ash/common/wm/window_state.h" | 23 #include "ash/common/wm/window_state.h" |
| 24 #include "ash/common/wm/wm_snap_to_pixel_layout_manager.h" | 24 #include "ash/common/wm/wm_snap_to_pixel_layout_manager.h" |
| 25 #include "ash/common/wm/workspace/workspace_layout_manager.h" | 25 #include "ash/common/wm/workspace/workspace_layout_manager.h" |
| 26 #include "ash/common/wm/workspace_controller.h" | 26 #include "ash/common/wm/workspace_controller.h" |
| 27 #include "ash/common/wm_shell.h" | 27 #include "ash/common/wm_shell.h" |
| 28 #include "ash/common/wm_window.h" | 28 #include "ash/common/wm_window.h" |
| 29 #include "ash/public/cpp/shell_window_ids.h" | 29 #include "ash/public/cpp/shell_window_ids.h" |
| 30 #include "ash/root_window_controller.h" | |
| 31 #include "ash/shell.h" | |
| 30 #include "base/memory/ptr_util.h" | 32 #include "base/memory/ptr_util.h" |
| 33 #include "ui/aura/env.h" | |
| 34 #include "ui/aura/mus/window_mus.h" | |
| 35 #include "ui/aura/mus/window_tree_client.h" | |
| 31 #include "ui/aura/window.h" | 36 #include "ui/aura/window.h" |
| 32 #include "ui/aura/window_event_dispatcher.h" | 37 #include "ui/aura/window_event_dispatcher.h" |
| 33 #include "ui/aura/window_tree_host.h" | 38 #include "ui/aura/window_tree_host.h" |
| 34 #include "ui/base/models/menu_model.h" | 39 #include "ui/base/models/menu_model.h" |
| 35 #include "ui/events/event_targeter.h" | 40 #include "ui/events/event_targeter.h" |
| 36 #include "ui/events/event_utils.h" | 41 #include "ui/events/event_utils.h" |
| 37 #include "ui/views/controls/menu/menu_model_adapter.h" | 42 #include "ui/views/controls/menu/menu_model_adapter.h" |
| 38 #include "ui/views/controls/menu/menu_runner.h" | 43 #include "ui/views/controls/menu/menu_runner.h" |
| 39 | 44 |
| 40 namespace ash { | 45 namespace ash { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 window->SetShellWindowId(window_id); | 149 window->SetShellWindowId(window_id); |
| 145 window->SetName(name); | 150 window->SetName(name); |
| 146 parent->AddChild(window); | 151 parent->AddChild(window); |
| 147 if (window_id != kShellWindowId_UnparentedControlContainer) | 152 if (window_id != kShellWindowId_UnparentedControlContainer) |
| 148 window->Show(); | 153 window->Show(); |
| 149 return window; | 154 return window; |
| 150 } | 155 } |
| 151 | 156 |
| 152 } // namespace | 157 } // namespace |
| 153 | 158 |
| 154 WmRootWindowController::WmRootWindowController(WmWindow* root) : root_(root) {} | 159 WmRootWindowController::WmRootWindowController( |
| 160 RootWindowController* root_window_controller, | |
| 161 WmWindow* root) | |
| 162 : root_window_controller_(root_window_controller), root_(root) {} | |
|
James Cook
2017/01/10 22:41:13
nit: either DCHECK root_window_controller and root
sky
2017/01/10 23:06:56
Done.
| |
| 155 | 163 |
| 156 WmRootWindowController::~WmRootWindowController() { | 164 WmRootWindowController::~WmRootWindowController() { |
| 157 if (animating_wallpaper_widget_controller_.get()) | 165 if (animating_wallpaper_widget_controller_.get()) |
| 158 animating_wallpaper_widget_controller_->StopAnimating(); | 166 animating_wallpaper_widget_controller_->StopAnimating(); |
| 159 } | 167 } |
| 160 | 168 |
| 161 void WmRootWindowController::SetWallpaperWidgetController( | 169 void WmRootWindowController::SetWallpaperWidgetController( |
| 162 WallpaperWidgetController* controller) { | 170 WallpaperWidgetController* controller) { |
| 163 wallpaper_widget_controller_.reset(controller); | 171 wallpaper_widget_controller_.reset(controller); |
| 164 } | 172 } |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 192 WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked() | 200 WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked() |
| 193 ? kShellWindowId_LockSystemModalContainer | 201 ? kShellWindowId_LockSystemModalContainer |
| 194 : kShellWindowId_SystemModalContainer; | 202 : kShellWindowId_SystemModalContainer; |
| 195 modal_container = GetContainer(modal_window_id); | 203 modal_container = GetContainer(modal_window_id); |
| 196 } | 204 } |
| 197 return modal_container ? static_cast<SystemModalContainerLayoutManager*>( | 205 return modal_container ? static_cast<SystemModalContainerLayoutManager*>( |
| 198 modal_container->GetLayoutManager()) | 206 modal_container->GetLayoutManager()) |
| 199 : nullptr; | 207 : nullptr; |
| 200 } | 208 } |
| 201 | 209 |
| 210 bool WmRootWindowController::HasShelf() { | |
| 211 return GetShelf()->shelf_widget() != nullptr; | |
| 212 } | |
| 213 | |
| 214 WmShelf* WmRootWindowController::GetShelf() { | |
| 215 return root_window_controller_->wm_shelf(); | |
| 216 } | |
| 217 | |
| 202 void WmRootWindowController::CreateShelf() { | 218 void WmRootWindowController::CreateShelf() { |
| 203 WmShelf* shelf = GetShelf(); | 219 WmShelf* shelf = GetShelf(); |
| 204 if (shelf->IsShelfInitialized()) | 220 if (shelf->IsShelfInitialized()) |
| 205 return; | 221 return; |
| 206 shelf->InitializeShelf(); | 222 shelf->InitializeShelf(); |
| 207 | 223 |
| 208 if (panel_layout_manager_) | 224 if (panel_layout_manager_) |
| 209 panel_layout_manager_->SetShelf(shelf); | 225 panel_layout_manager_->SetShelf(shelf); |
| 210 if (docked_window_layout_manager_) { | 226 if (docked_window_layout_manager_) { |
| 211 docked_window_layout_manager_->SetShelf(shelf); | 227 docked_window_layout_manager_->SetShelf(shelf); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 230 shelf->shelf_widget()->status_area_widget()->Show(); | 246 shelf->shelf_widget()->status_area_widget()->Show(); |
| 231 } | 247 } |
| 232 | 248 |
| 233 SystemTray* WmRootWindowController::GetSystemTray() { | 249 SystemTray* WmRootWindowController::GetSystemTray() { |
| 234 ShelfWidget* shelf_widget = GetShelf()->shelf_widget(); | 250 ShelfWidget* shelf_widget = GetShelf()->shelf_widget(); |
| 235 if (!shelf_widget || !shelf_widget->status_area_widget()) | 251 if (!shelf_widget || !shelf_widget->status_area_widget()) |
| 236 return nullptr; | 252 return nullptr; |
| 237 return shelf_widget->status_area_widget()->system_tray(); | 253 return shelf_widget->status_area_widget()->system_tray(); |
| 238 } | 254 } |
| 239 | 255 |
| 256 WmWindow* WmRootWindowController::GetWindow() { | |
| 257 return root_; | |
| 258 } | |
| 259 | |
| 240 WmWindow* WmRootWindowController::GetContainer(int container_id) { | 260 WmWindow* WmRootWindowController::GetContainer(int container_id) { |
| 241 return root_->GetChildByShellWindowId(container_id); | 261 return root_->GetChildByShellWindowId(container_id); |
| 242 } | 262 } |
| 243 | 263 |
| 244 const WmWindow* WmRootWindowController::GetContainer(int container_id) const { | 264 const WmWindow* WmRootWindowController::GetContainer(int container_id) const { |
| 245 return root_->GetChildByShellWindowId(container_id); | 265 return root_->GetChildByShellWindowId(container_id); |
| 246 } | 266 } |
| 247 | 267 |
| 248 void WmRootWindowController::ConfigureWidgetInitParamsForContainer( | 268 void WmRootWindowController::ConfigureWidgetInitParamsForContainer( |
| 249 views::Widget* widget, | 269 views::Widget* widget, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 294 | 314 |
| 295 menu_runner_.reset(new views::MenuRunner( | 315 menu_runner_.reset(new views::MenuRunner( |
| 296 menu_model_adapter_->CreateMenu(), | 316 menu_model_adapter_->CreateMenu(), |
| 297 views::MenuRunner::CONTEXT_MENU | views::MenuRunner::ASYNC)); | 317 views::MenuRunner::CONTEXT_MENU | views::MenuRunner::ASYNC)); |
| 298 ignore_result( | 318 ignore_result( |
| 299 menu_runner_->RunMenuAt(wallpaper_widget_controller()->widget(), nullptr, | 319 menu_runner_->RunMenuAt(wallpaper_widget_controller()->widget(), nullptr, |
| 300 gfx::Rect(location_in_screen, gfx::Size()), | 320 gfx::Rect(location_in_screen, gfx::Size()), |
| 301 views::MENU_ANCHOR_TOPLEFT, source_type)); | 321 views::MENU_ANCHOR_TOPLEFT, source_type)); |
| 302 } | 322 } |
| 303 | 323 |
| 304 void WmRootWindowController::OnInitialWallpaperAnimationStarted() {} | 324 void WmRootWindowController::OnInitialWallpaperAnimationStarted() { |
| 325 root_window_controller_->OnInitialWallpaperAnimationStarted(); | |
| 326 } | |
| 305 | 327 |
| 306 void WmRootWindowController::OnWallpaperAnimationFinished( | 328 void WmRootWindowController::OnWallpaperAnimationFinished( |
| 307 views::Widget* widget) { | 329 views::Widget* widget) { |
| 330 root_window_controller_->OnWallpaperAnimationFinished(widget); | |
| 308 WmShell::Get()->wallpaper_delegate()->OnWallpaperAnimationFinished(); | 331 WmShell::Get()->wallpaper_delegate()->OnWallpaperAnimationFinished(); |
| 309 // Only removes old component when wallpaper animation finished. If we | 332 // Only removes old component when wallpaper animation finished. If we |
| 310 // remove the old one before the new wallpaper is done fading in there will | 333 // remove the old one before the new wallpaper is done fading in there will |
| 311 // be a white flash during the animation. | 334 // be a white flash during the animation. |
| 312 if (animating_wallpaper_widget_controller()) { | 335 if (animating_wallpaper_widget_controller()) { |
| 313 WallpaperWidgetController* controller = | 336 WallpaperWidgetController* controller = |
| 314 animating_wallpaper_widget_controller()->GetController(true); | 337 animating_wallpaper_widget_controller()->GetController(true); |
| 315 DCHECK_EQ(controller->widget(), widget); | 338 DCHECK_EQ(controller->widget(), widget); |
| 316 // Release the old controller and close its wallpaper widget. | 339 // Release the old controller and close its wallpaper widget. |
| 317 SetWallpaperWidgetController(controller); | 340 SetWallpaperWidgetController(controller); |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 619 } | 642 } |
| 620 | 643 |
| 621 shelf->DestroyShelfWidget(); | 644 shelf->DestroyShelfWidget(); |
| 622 | 645 |
| 623 // CloseChildWindows() may be called twice during the shutdown of ash | 646 // CloseChildWindows() may be called twice during the shutdown of ash |
| 624 // unittests. Avoid notifying WmShelf that the shelf has been destroyed twice. | 647 // unittests. Avoid notifying WmShelf that the shelf has been destroyed twice. |
| 625 if (shelf->IsShelfInitialized()) | 648 if (shelf->IsShelfInitialized()) |
| 626 shelf->ShutdownShelf(); | 649 shelf->ShutdownShelf(); |
| 627 } | 650 } |
| 628 | 651 |
| 652 bool WmRootWindowController::ShouldDestroyWindowInCloseChildWindows( | |
| 653 WmWindow* window) { | |
| 654 if (!WmWindowAura::GetAuraWindow(window)->owned_by_parent()) | |
| 655 return false; | |
| 656 | |
| 657 if (aura::Env::GetInstance()->mode() == aura::Env::Mode::LOCAL) | |
| 658 return true; | |
| 659 | |
| 660 aura::WindowMus* window_mus = | |
| 661 aura::WindowMus::Get(WmWindowAura::GetAuraWindow(window)); | |
| 662 return Shell::window_tree_client()->WasCreatedByThisClient(window_mus) || | |
| 663 Shell::window_tree_client()->IsRoot(window_mus); | |
| 664 } | |
| 665 | |
| 629 void WmRootWindowController::OnMenuClosed() { | 666 void WmRootWindowController::OnMenuClosed() { |
| 630 menu_runner_.reset(); | 667 menu_runner_.reset(); |
| 631 menu_model_adapter_.reset(); | 668 menu_model_adapter_.reset(); |
| 632 menu_model_.reset(); | 669 menu_model_.reset(); |
| 633 GetShelf()->UpdateVisibilityState(); | 670 GetShelf()->UpdateVisibilityState(); |
| 634 } | 671 } |
| 635 | 672 |
| 636 } // namespace ash | 673 } // namespace ash |
| OLD | NEW |