| 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 27 matching lines...) Expand all Loading... |
| 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 |
| 145 // Creates a new window for use as a container. | 150 // Creates a new window for use as a container. |
| 151 // TODO(sky): This should create an aura::Window. http://crbug.com/671246. |
| 146 WmWindow* CreateContainer(int window_id, const char* name, WmWindow* parent) { | 152 WmWindow* CreateContainer(int window_id, const char* name, WmWindow* parent) { |
| 147 WmWindow* window = WmShell::Get()->NewWindow(ui::wm::WINDOW_TYPE_UNKNOWN, | 153 WmWindow* window = WmShell::Get()->NewWindow(ui::wm::WINDOW_TYPE_UNKNOWN, |
| 148 ui::LAYER_NOT_DRAWN); | 154 ui::LAYER_NOT_DRAWN); |
| 149 window->SetShellWindowId(window_id); | 155 window->SetShellWindowId(window_id); |
| 150 window->SetName(name); | 156 window->SetName(name); |
| 151 parent->AddChild(window); | 157 parent->AddChild(window); |
| 152 if (window_id != kShellWindowId_UnparentedControlContainer) | 158 if (window_id != kShellWindowId_UnparentedControlContainer) |
| 153 window->Show(); | 159 window->Show(); |
| 154 return window; | 160 return window; |
| 155 } | 161 } |
| 156 | 162 |
| 163 // TODO(sky): This should take an aura::Window. http://crbug.com/671246. |
| 164 bool ShouldDestroyWindowInCloseChildWindows(WmWindow* window) { |
| 165 if (!WmWindowAura::GetAuraWindow(window)->owned_by_parent()) |
| 166 return false; |
| 167 |
| 168 if (!WmShell::Get()->IsRunningInMash()) |
| 169 return true; |
| 170 |
| 171 aura::WindowMus* window_mus = |
| 172 aura::WindowMus::Get(WmWindowAura::GetAuraWindow(window)); |
| 173 return Shell::window_tree_client()->WasCreatedByThisClient(window_mus) || |
| 174 Shell::window_tree_client()->IsRoot(window_mus); |
| 175 } |
| 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 WmWindow* 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 if (window_container && |
| 195 window_container->GetShellWindowId() >= | 202 window_container->GetShellWindowId() >= |
| 196 kShellWindowId_LockScreenContainer) { | 203 kShellWindowId_LockScreenContainer) { |
| 197 modal_container = GetContainer(kShellWindowId_LockSystemModalContainer); | 204 modal_container = GetWmContainer(kShellWindowId_LockSystemModalContainer); |
| 198 } else { | 205 } else { |
| 199 modal_container = GetContainer(kShellWindowId_SystemModalContainer); | 206 modal_container = GetWmContainer(kShellWindowId_SystemModalContainer); |
| 200 } | 207 } |
| 201 } else { | 208 } else { |
| 202 int modal_window_id = | 209 int modal_window_id = |
| 203 WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked() | 210 WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked() |
| 204 ? kShellWindowId_LockSystemModalContainer | 211 ? kShellWindowId_LockSystemModalContainer |
| 205 : kShellWindowId_SystemModalContainer; | 212 : kShellWindowId_SystemModalContainer; |
| 206 modal_container = GetContainer(modal_window_id); | 213 modal_container = GetWmContainer(modal_window_id); |
| 207 } | 214 } |
| 208 return modal_container ? static_cast<SystemModalContainerLayoutManager*>( | 215 return modal_container ? static_cast<SystemModalContainerLayoutManager*>( |
| 209 modal_container->GetLayoutManager()) | 216 modal_container->GetLayoutManager()) |
| 210 : nullptr; | 217 : nullptr; |
| 211 } | 218 } |
| 212 | 219 |
| 213 bool WmRootWindowController::HasShelf() { | 220 bool RootWindowController::HasShelf() { |
| 214 return GetShelf()->shelf_widget() != nullptr; | 221 return wm_shelf_->shelf_widget() != nullptr; |
| 215 } | 222 } |
| 216 | 223 |
| 217 WmShelf* WmRootWindowController::GetShelf() { | 224 WmShelf* RootWindowController::GetShelf() { |
| 218 return root_window_controller_->wm_shelf(); | 225 return wm_shelf_.get(); |
| 219 } | 226 } |
| 220 | 227 |
| 221 void WmRootWindowController::CreateShelf() { | 228 void RootWindowController::CreateShelf() { |
| 222 WmShelf* shelf = GetShelf(); | 229 if (wm_shelf_->IsShelfInitialized()) |
| 223 if (shelf->IsShelfInitialized()) | |
| 224 return; | 230 return; |
| 225 shelf->InitializeShelf(); | 231 wm_shelf_->InitializeShelf(); |
| 226 | 232 |
| 227 if (panel_layout_manager_) | 233 if (panel_layout_manager_) |
| 228 panel_layout_manager_->SetShelf(shelf); | 234 panel_layout_manager_->SetShelf(wm_shelf_.get()); |
| 229 if (docked_window_layout_manager_) { | 235 if (docked_window_layout_manager_) { |
| 230 docked_window_layout_manager_->SetShelf(shelf); | 236 docked_window_layout_manager_->SetShelf(wm_shelf_.get()); |
| 231 if (shelf->shelf_layout_manager()) | 237 if (wm_shelf_->shelf_layout_manager()) |
| 232 docked_window_layout_manager_->AddObserver(shelf->shelf_layout_manager()); | 238 docked_window_layout_manager_->AddObserver( |
| 239 wm_shelf_->shelf_layout_manager()); |
| 233 } | 240 } |
| 234 | 241 |
| 235 // Notify shell observers that the shelf has been created. | 242 // Notify shell observers that the shelf has been created. |
| 236 // TODO(jamescook): Move this into WmShelf::InitializeShelf(). This will | 243 // TODO(jamescook): Move this into WmShelf::InitializeShelf(). This will |
| 237 // require changing AttachedPanelWidgetTargeter's access to WmShelf. | 244 // require changing AttachedPanelWidgetTargeter's access to WmShelf. |
| 238 WmShell::Get()->NotifyShelfCreatedForRootWindow(GetWindow()); | 245 WmShell::Get()->NotifyShelfCreatedForRootWindow( |
| 246 WmWindowAura::Get(GetRootWindow())); |
| 239 | 247 |
| 240 shelf->shelf_widget()->PostCreateShelf(); | 248 wm_shelf_->shelf_widget()->PostCreateShelf(); |
| 241 } | 249 } |
| 242 | 250 |
| 243 void WmRootWindowController::ShowShelf() { | 251 void RootWindowController::ShowShelf() { |
| 244 WmShelf* shelf = GetShelf(); | 252 if (!wm_shelf_->IsShelfInitialized()) |
| 245 if (!shelf->IsShelfInitialized()) | |
| 246 return; | 253 return; |
| 247 // TODO(jamescook): Move this into WmShelf. | 254 // TODO(jamescook): Move this into WmShelf. |
| 248 shelf->shelf_widget()->SetShelfVisibility(true); | 255 wm_shelf_->shelf_widget()->SetShelfVisibility(true); |
| 249 shelf->shelf_widget()->status_area_widget()->Show(); | 256 wm_shelf_->shelf_widget()->status_area_widget()->Show(); |
| 250 } | 257 } |
| 251 | 258 |
| 252 SystemTray* WmRootWindowController::GetSystemTray() { | 259 const WmWindow* RootWindowController::GetWindow() const { |
| 253 ShelfWidget* shelf_widget = GetShelf()->shelf_widget(); | 260 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 } | 261 } |
| 258 | 262 |
| 259 WmWindow* WmRootWindowController::GetWindow() { | 263 const WmWindow* RootWindowController::GetWmContainer(int container_id) const { |
| 260 return root_; | 264 const aura::Window* window = GetContainer(container_id); |
| 265 return WmWindowAura::Get(window); |
| 261 } | 266 } |
| 262 | 267 |
| 263 WmWindow* WmRootWindowController::GetContainer(int container_id) { | 268 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, | 269 views::Widget* widget, |
| 273 int shell_container_id, | 270 int shell_container_id, |
| 274 views::Widget::InitParams* init_params) { | 271 views::Widget::InitParams* init_params) { |
| 275 init_params->parent = WmWindowAura::GetAuraWindow( | 272 init_params->parent = GetContainer(shell_container_id); |
| 276 GetWindow()->GetChildByShellWindowId(shell_container_id)); | |
| 277 } | 273 } |
| 278 | 274 |
| 279 WmWindow* WmRootWindowController::FindEventTarget( | 275 WmWindow* RootWindowController::FindEventTarget( |
| 280 const gfx::Point& location_in_screen) { | 276 const gfx::Point& location_in_screen) { |
| 281 gfx::Point location_in_root = | 277 gfx::Point location_in_root(location_in_screen); |
| 282 GetWindow()->ConvertPointFromScreen(location_in_screen); | 278 aura::Window* root_window = GetRootWindow(); |
| 283 aura::Window* root = WmWindowAura::GetAuraWindow(GetWindow()); | 279 ::wm::ConvertPointFromScreen(root_window, &location_in_root); |
| 284 ui::MouseEvent test_event(ui::ET_MOUSE_MOVED, location_in_root, | 280 ui::MouseEvent test_event(ui::ET_MOUSE_MOVED, location_in_root, |
| 285 location_in_root, ui::EventTimeForNow(), | 281 location_in_root, ui::EventTimeForNow(), |
| 286 ui::EF_NONE, ui::EF_NONE); | 282 ui::EF_NONE, ui::EF_NONE); |
| 287 ui::EventTarget* event_handler = static_cast<ui::EventTarget*>(root) | 283 ui::EventTarget* event_handler = |
| 288 ->GetEventTargeter() | 284 static_cast<ui::EventTarget*>(root_window) |
| 289 ->FindTargetForEvent(root, &test_event); | 285 ->GetEventTargeter() |
| 286 ->FindTargetForEvent(root_window, &test_event); |
| 290 return WmWindowAura::Get(static_cast<aura::Window*>(event_handler)); | 287 return WmWindowAura::Get(static_cast<aura::Window*>(event_handler)); |
| 291 } | 288 } |
| 292 | 289 |
| 293 gfx::Point WmRootWindowController::GetLastMouseLocationInRoot() { | 290 gfx::Point RootWindowController::GetLastMouseLocationInRoot() { |
| 294 return WmWindowAura::GetAuraWindow(GetWindow()) | 291 return window_tree_host_->dispatcher()->GetLastMouseLocationInRoot(); |
| 295 ->GetHost() | |
| 296 ->dispatcher() | |
| 297 ->GetLastMouseLocationInRoot(); | |
| 298 } | 292 } |
| 299 | 293 |
| 300 void WmRootWindowController::ShowContextMenu( | 294 void RootWindowController::ShowContextMenu(const gfx::Point& location_in_screen, |
| 301 const gfx::Point& location_in_screen, | 295 ui::MenuSourceType source_type) { |
| 302 ui::MenuSourceType source_type) { | |
| 303 ShellDelegate* delegate = WmShell::Get()->delegate(); | 296 ShellDelegate* delegate = WmShell::Get()->delegate(); |
| 304 DCHECK(delegate); | 297 DCHECK(delegate); |
| 305 menu_model_.reset(delegate->CreateContextMenu(GetShelf(), nullptr)); | 298 menu_model_.reset(delegate->CreateContextMenu(wm_shelf_.get(), nullptr)); |
| 306 if (!menu_model_) | 299 if (!menu_model_) |
| 307 return; | 300 return; |
| 308 | 301 |
| 309 menu_model_adapter_.reset(new views::MenuModelAdapter( | 302 menu_model_adapter_ = base::MakeUnique<views::MenuModelAdapter>( |
| 310 menu_model_.get(), base::Bind(&WmRootWindowController::OnMenuClosed, | 303 menu_model_.get(), |
| 311 base::Unretained(this)))); | 304 base::Bind(&RootWindowController::OnMenuClosed, base::Unretained(this))); |
| 312 | 305 |
| 313 // The wallpaper controller may not be set yet if the user clicked on the | 306 // 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 | 307 // status area before the initial animation completion. See crbug.com/222218 |
| 315 if (!wallpaper_widget_controller()) | 308 if (!wallpaper_widget_controller()) |
| 316 return; | 309 return; |
| 317 | 310 |
| 318 menu_runner_.reset(new views::MenuRunner( | 311 menu_runner_ = base::MakeUnique<views::MenuRunner>( |
| 319 menu_model_adapter_->CreateMenu(), | 312 menu_model_adapter_->CreateMenu(), |
| 320 views::MenuRunner::CONTEXT_MENU | views::MenuRunner::ASYNC)); | 313 views::MenuRunner::CONTEXT_MENU | views::MenuRunner::ASYNC); |
| 321 ignore_result( | 314 ignore_result( |
| 322 menu_runner_->RunMenuAt(wallpaper_widget_controller()->widget(), nullptr, | 315 menu_runner_->RunMenuAt(wallpaper_widget_controller()->widget(), nullptr, |
| 323 gfx::Rect(location_in_screen, gfx::Size()), | 316 gfx::Rect(location_in_screen, gfx::Size()), |
| 324 views::MENU_ANCHOR_TOPLEFT, source_type)); | 317 views::MENU_ANCHOR_TOPLEFT, source_type)); |
| 325 } | 318 } |
| 326 | 319 |
| 327 void WmRootWindowController::OnInitialWallpaperAnimationStarted() { | 320 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 = | 321 StatusAreaWidget* status_area_widget = |
| 349 GetShelf()->shelf_widget()->status_area_widget(); | 322 wm_shelf_->shelf_widget()->status_area_widget(); |
| 350 if (status_area_widget) | 323 if (status_area_widget) |
| 351 status_area_widget->UpdateAfterLoginStatusChange(status); | 324 status_area_widget->UpdateAfterLoginStatusChange(status); |
| 352 } | 325 } |
| 353 | 326 |
| 354 void WmRootWindowController::MoveWindowsTo(WmWindow* dest) { | 327 void RootWindowController::MoveWindowsTo(aura::Window* dst) { |
| 355 // Clear the workspace controller, so it doesn't incorrectly update the shelf. | 328 // Clear the workspace controller, so it doesn't incorrectly update the shelf. |
| 356 workspace_controller_.reset(); | 329 workspace_controller_.reset(); |
| 357 ReparentAllWindows(GetWindow(), dest); | 330 ReparentAllWindows(GetWindow(), WmWindowAura::Get(dst)); |
| 358 } | 331 } |
| 359 | 332 |
| 360 void WmRootWindowController::CreateContainers() { | 333 void RootWindowController::CreateContainers() { |
| 334 WmWindow* root = GetWindow(); |
| 361 // These containers are just used by PowerButtonController to animate groups | 335 // These containers are just used by PowerButtonController to animate groups |
| 362 // of containers simultaneously without messing up the current transformations | 336 // of containers simultaneously without messing up the current transformations |
| 363 // on those containers. These are direct children of the root window; all of | 337 // on those containers. These are direct children of the root window; all of |
| 364 // the other containers are their children. | 338 // the other containers are their children. |
| 365 | 339 |
| 366 // The wallpaper container is not part of the lock animation, so it is not | 340 // 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 | 341 // 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). | 342 // 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. | 343 // Ensure that there's an opaque layer occluding the non-lock-screen layers. |
| 370 WmWindow* wallpaper_container = CreateContainer( | 344 WmWindow* wallpaper_container = CreateContainer( |
| 371 kShellWindowId_WallpaperContainer, "WallpaperContainer", root_); | 345 kShellWindowId_WallpaperContainer, "WallpaperContainer", root); |
| 372 wallpaper_container->SetChildWindowVisibilityChangesAnimated(); | 346 wallpaper_container->SetChildWindowVisibilityChangesAnimated(); |
| 373 | 347 |
| 374 WmWindow* non_lock_screen_containers = | 348 WmWindow* non_lock_screen_containers = |
| 375 CreateContainer(kShellWindowId_NonLockScreenContainersContainer, | 349 CreateContainer(kShellWindowId_NonLockScreenContainersContainer, |
| 376 "NonLockScreenContainersContainer", root_); | 350 "NonLockScreenContainersContainer", root); |
| 377 // Clip all windows inside this container, as half pixel of the window's | 351 // 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. | 352 // texture may become visible when the screen is scaled. crbug.com/368591. |
| 379 non_lock_screen_containers->SetMasksToBounds(true); | 353 non_lock_screen_containers->SetMasksToBounds(true); |
| 380 | 354 |
| 381 WmWindow* lock_wallpaper_containers = | 355 WmWindow* lock_wallpaper_containers = |
| 382 CreateContainer(kShellWindowId_LockScreenWallpaperContainer, | 356 CreateContainer(kShellWindowId_LockScreenWallpaperContainer, |
| 383 "LockScreenWallpaperContainer", root_); | 357 "LockScreenWallpaperContainer", root); |
| 384 lock_wallpaper_containers->SetChildWindowVisibilityChangesAnimated(); | 358 lock_wallpaper_containers->SetChildWindowVisibilityChangesAnimated(); |
| 385 | 359 |
| 386 WmWindow* lock_screen_containers = | 360 WmWindow* lock_screen_containers = |
| 387 CreateContainer(kShellWindowId_LockScreenContainersContainer, | 361 CreateContainer(kShellWindowId_LockScreenContainersContainer, |
| 388 "LockScreenContainersContainer", root_); | 362 "LockScreenContainersContainer", root); |
| 389 WmWindow* lock_screen_related_containers = | 363 WmWindow* lock_screen_related_containers = |
| 390 CreateContainer(kShellWindowId_LockScreenRelatedContainersContainer, | 364 CreateContainer(kShellWindowId_LockScreenRelatedContainersContainer, |
| 391 "LockScreenRelatedContainersContainer", root_); | 365 "LockScreenRelatedContainersContainer", root); |
| 392 | 366 |
| 393 CreateContainer(kShellWindowId_UnparentedControlContainer, | 367 CreateContainer(kShellWindowId_UnparentedControlContainer, |
| 394 "UnparentedControlContainer", non_lock_screen_containers); | 368 "UnparentedControlContainer", non_lock_screen_containers); |
| 395 | 369 |
| 396 WmWindow* default_container = | 370 WmWindow* default_container = |
| 397 CreateContainer(kShellWindowId_DefaultContainer, "DefaultContainer", | 371 CreateContainer(kShellWindowId_DefaultContainer, "DefaultContainer", |
| 398 non_lock_screen_containers); | 372 non_lock_screen_containers); |
| 399 default_container->SetChildWindowVisibilityChangesAnimated(); | 373 default_container->SetChildWindowVisibilityChangesAnimated(); |
| 400 default_container->SetSnapsChildrenToPhysicalPixelBoundary(); | 374 default_container->SetSnapsChildrenToPhysicalPixelBoundary(); |
| 401 default_container->SetBoundsInScreenBehaviorForChildren( | 375 default_container->SetBoundsInScreenBehaviorForChildren( |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES); | 492 WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES); |
| 519 | 493 |
| 520 WmWindow* overlay_container = | 494 WmWindow* overlay_container = |
| 521 CreateContainer(kShellWindowId_OverlayContainer, "OverlayContainer", | 495 CreateContainer(kShellWindowId_OverlayContainer, "OverlayContainer", |
| 522 lock_screen_related_containers); | 496 lock_screen_related_containers); |
| 523 overlay_container->SetSnapsChildrenToPhysicalPixelBoundary(); | 497 overlay_container->SetSnapsChildrenToPhysicalPixelBoundary(); |
| 524 overlay_container->SetBoundsInScreenBehaviorForChildren( | 498 overlay_container->SetBoundsInScreenBehaviorForChildren( |
| 525 WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES); | 499 WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES); |
| 526 | 500 |
| 527 WmWindow* mouse_cursor_container = CreateContainer( | 501 WmWindow* mouse_cursor_container = CreateContainer( |
| 528 kShellWindowId_MouseCursorContainer, "MouseCursorContainer", root_); | 502 kShellWindowId_MouseCursorContainer, "MouseCursorContainer", root); |
| 529 mouse_cursor_container->SetBoundsInScreenBehaviorForChildren( | 503 mouse_cursor_container->SetBoundsInScreenBehaviorForChildren( |
| 530 WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES); | 504 WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES); |
| 531 | 505 |
| 532 CreateContainer(kShellWindowId_PowerButtonAnimationContainer, | 506 CreateContainer(kShellWindowId_PowerButtonAnimationContainer, |
| 533 "PowerButtonAnimationContainer", root_); | 507 "PowerButtonAnimationContainer", root); |
| 534 } | 508 } |
| 535 | 509 |
| 536 void WmRootWindowController::CreateLayoutManagers() { | 510 void RootWindowController::CreateLayoutManagers() { |
| 537 GetShelf()->CreateShelfWidget(GetWindow()); | 511 GetShelf()->CreateShelfWidget(GetWindow()); |
| 538 | 512 |
| 539 root_window_layout_manager_ = new wm::RootWindowLayoutManager(root_); | 513 WmWindow* root = GetWindow(); |
| 540 root_->SetLayoutManager(base::WrapUnique(root_window_layout_manager_)); | 514 root_window_layout_manager_ = new wm::RootWindowLayoutManager(root); |
| 515 root->SetLayoutManager(base::WrapUnique(root_window_layout_manager_)); |
| 541 | 516 |
| 542 WmWindow* default_container = GetContainer(kShellWindowId_DefaultContainer); | 517 WmWindow* default_container = GetWmContainer(kShellWindowId_DefaultContainer); |
| 543 // Installs WorkspaceLayoutManager on |default_container|. | 518 // Installs WorkspaceLayoutManager on |default_container|. |
| 544 workspace_controller_.reset(new WorkspaceController(default_container)); | 519 workspace_controller_.reset(new WorkspaceController(default_container)); |
| 545 | 520 |
| 546 WmWindow* modal_container = GetContainer(kShellWindowId_SystemModalContainer); | 521 WmWindow* modal_container = |
| 522 GetWmContainer(kShellWindowId_SystemModalContainer); |
| 547 DCHECK(modal_container); | 523 DCHECK(modal_container); |
| 548 modal_container->SetLayoutManager( | 524 modal_container->SetLayoutManager( |
| 549 base::MakeUnique<SystemModalContainerLayoutManager>(modal_container)); | 525 base::MakeUnique<SystemModalContainerLayoutManager>(modal_container)); |
| 550 | 526 |
| 551 WmWindow* lock_modal_container = | 527 WmWindow* lock_modal_container = |
| 552 GetContainer(kShellWindowId_LockSystemModalContainer); | 528 GetWmContainer(kShellWindowId_LockSystemModalContainer); |
| 553 DCHECK(lock_modal_container); | 529 DCHECK(lock_modal_container); |
| 554 lock_modal_container->SetLayoutManager( | 530 lock_modal_container->SetLayoutManager( |
| 555 base::MakeUnique<SystemModalContainerLayoutManager>( | 531 base::MakeUnique<SystemModalContainerLayoutManager>( |
| 556 lock_modal_container)); | 532 lock_modal_container)); |
| 557 | 533 |
| 558 WmWindow* lock_container = GetContainer(kShellWindowId_LockScreenContainer); | 534 WmWindow* lock_container = GetWmContainer(kShellWindowId_LockScreenContainer); |
| 559 DCHECK(lock_container); | 535 DCHECK(lock_container); |
| 560 lock_container->SetLayoutManager( | 536 lock_container->SetLayoutManager( |
| 561 base::MakeUnique<LockLayoutManager>(lock_container)); | 537 base::MakeUnique<LockLayoutManager>(lock_container)); |
| 562 | 538 |
| 563 WmWindow* always_on_top_container = | 539 WmWindow* always_on_top_container = |
| 564 GetContainer(kShellWindowId_AlwaysOnTopContainer); | 540 GetWmContainer(kShellWindowId_AlwaysOnTopContainer); |
| 565 DCHECK(always_on_top_container); | 541 DCHECK(always_on_top_container); |
| 566 always_on_top_controller_ = | 542 always_on_top_controller_ = |
| 567 base::MakeUnique<AlwaysOnTopController>(always_on_top_container); | 543 base::MakeUnique<AlwaysOnTopController>(always_on_top_container); |
| 568 | 544 |
| 569 // Create Docked windows layout manager | 545 // Create Docked windows layout manager |
| 570 WmWindow* docked_container = GetContainer(kShellWindowId_DockedContainer); | 546 WmWindow* docked_container = GetWmContainer(kShellWindowId_DockedContainer); |
| 571 docked_window_layout_manager_ = | 547 docked_window_layout_manager_ = |
| 572 new DockedWindowLayoutManager(docked_container); | 548 new DockedWindowLayoutManager(docked_container); |
| 573 docked_container->SetLayoutManager( | 549 docked_container->SetLayoutManager( |
| 574 base::WrapUnique(docked_window_layout_manager_)); | 550 base::WrapUnique(docked_window_layout_manager_)); |
| 575 | 551 |
| 576 // Create Panel layout manager | 552 // Create Panel layout manager |
| 577 WmWindow* panel_container = GetContainer(kShellWindowId_PanelContainer); | 553 WmWindow* panel_container = GetWmContainer(kShellWindowId_PanelContainer); |
| 578 panel_layout_manager_ = new PanelLayoutManager(panel_container); | 554 panel_layout_manager_ = new PanelLayoutManager(panel_container); |
| 579 panel_container->SetLayoutManager(base::WrapUnique(panel_layout_manager_)); | 555 panel_container->SetLayoutManager(base::WrapUnique(panel_layout_manager_)); |
| 580 | 556 |
| 581 wm::WmSnapToPixelLayoutManager::InstallOnContainers(root_); | 557 wm::WmSnapToPixelLayoutManager::InstallOnContainers(root); |
| 582 } | 558 } |
| 583 | 559 |
| 584 void WmRootWindowController::ResetRootForNewWindowsIfNecessary() { | 560 void RootWindowController::ResetRootForNewWindowsIfNecessary() { |
| 585 WmShell* shell = WmShell::Get(); | 561 WmShell* shell = WmShell::Get(); |
| 586 // Change the target root window before closing child windows. If any child | 562 // 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 | 563 // 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 | 564 // window list adding windows from the target root window's containers which |
| 589 // may have already gone away. | 565 // may have already gone away. |
| 590 if (shell->GetRootWindowForNewWindows() == GetWindow()) { | 566 WmWindow* root = GetWindow(); |
| 567 if (shell->GetRootWindowForNewWindows() == root) { |
| 591 // The root window for new windows is being destroyed. Switch to the primary | 568 // The root window for new windows is being destroyed. Switch to the primary |
| 592 // root window if possible. | 569 // root window if possible. |
| 593 WmWindow* primary_root = shell->GetPrimaryRootWindow(); | 570 WmWindow* primary_root = shell->GetPrimaryRootWindow(); |
| 594 shell->set_root_window_for_new_windows( | 571 shell->set_root_window_for_new_windows(primary_root == root ? nullptr |
| 595 primary_root == GetWindow() ? nullptr : primary_root); | 572 : primary_root); |
| 596 } | 573 } |
| 597 } | 574 } |
| 598 | 575 |
| 599 void WmRootWindowController::CloseChildWindows() { | 576 // TODO(sky): fold into CloseChildWindows() when move back. |
| 577 void RootWindowController::CloseChildWindowsImpl() { |
| 600 // NOTE: this may be called multiple times. | 578 // NOTE: this may be called multiple times. |
| 601 | 579 |
| 602 // |panel_layout_manager_| needs to be shut down before windows are destroyed. | 580 // |panel_layout_manager_| needs to be shut down before windows are destroyed. |
| 603 if (panel_layout_manager_) { | 581 if (panel_layout_manager_) { |
| 604 panel_layout_manager_->Shutdown(); | 582 panel_layout_manager_->Shutdown(); |
| 605 panel_layout_manager_ = nullptr; | 583 panel_layout_manager_ = nullptr; |
| 606 } | 584 } |
| 607 | 585 |
| 608 // |docked_window_layout_manager_| needs to be shut down before windows are | 586 // |docked_window_layout_manager_| needs to be shut down before windows are |
| 609 // destroyed. | 587 // destroyed. |
| 610 if (docked_window_layout_manager_) { | 588 if (docked_window_layout_manager_) { |
| 611 docked_window_layout_manager_->Shutdown(); | 589 docked_window_layout_manager_->Shutdown(); |
| 612 docked_window_layout_manager_ = nullptr; | 590 docked_window_layout_manager_ = nullptr; |
| 613 } | 591 } |
| 614 | 592 |
| 615 WmShelf* shelf = GetShelf(); | 593 WmShelf* shelf = GetShelf(); |
| 616 shelf->ShutdownShelfWidget(); | 594 shelf->ShutdownShelfWidget(); |
| 617 | 595 |
| 618 workspace_controller_.reset(); | 596 workspace_controller_.reset(); |
| 619 | 597 |
| 620 // Explicitly destroy top level windows. We do this because such windows may | 598 // Explicitly destroy top level windows. We do this because such windows may |
| 621 // query the RootWindow for state. | 599 // query the RootWindow for state. |
| 622 WmWindowTracker non_toplevel_windows; | 600 WmWindowTracker non_toplevel_windows; |
| 623 non_toplevel_windows.Add(root_); | 601 WmWindow* root = GetWindow(); |
| 602 non_toplevel_windows.Add(root); |
| 624 while (!non_toplevel_windows.windows().empty()) { | 603 while (!non_toplevel_windows.windows().empty()) { |
| 625 WmWindow* non_toplevel_window = non_toplevel_windows.Pop(); | 604 WmWindow* non_toplevel_window = non_toplevel_windows.Pop(); |
| 626 WmWindowTracker toplevel_windows; | 605 WmWindowTracker toplevel_windows; |
| 627 for (WmWindow* child : non_toplevel_window->GetChildren()) { | 606 for (WmWindow* child : non_toplevel_window->GetChildren()) { |
| 628 if (!ShouldDestroyWindowInCloseChildWindows(child)) | 607 if (!ShouldDestroyWindowInCloseChildWindows(child)) |
| 629 continue; | 608 continue; |
| 630 if (child->HasNonClientArea()) | 609 if (child->HasNonClientArea()) |
| 631 toplevel_windows.Add(child); | 610 toplevel_windows.Add(child); |
| 632 else | 611 else |
| 633 non_toplevel_windows.Add(child); | 612 non_toplevel_windows.Add(child); |
| 634 } | 613 } |
| 635 while (!toplevel_windows.windows().empty()) | 614 while (!toplevel_windows.windows().empty()) |
| 636 toplevel_windows.Pop()->Destroy(); | 615 toplevel_windows.Pop()->Destroy(); |
| 637 } | 616 } |
| 638 // And then remove the containers. | 617 // And then remove the containers. |
| 639 while (!root_->GetChildren().empty()) { | 618 while (!root->GetChildren().empty()) { |
| 640 WmWindow* child = root_->GetChildren()[0]; | 619 WmWindow* child = root->GetChildren()[0]; |
| 641 if (ShouldDestroyWindowInCloseChildWindows(child)) | 620 if (ShouldDestroyWindowInCloseChildWindows(child)) |
| 642 child->Destroy(); | 621 child->Destroy(); |
| 643 else | 622 else |
| 644 root_->RemoveChild(child); | 623 root->RemoveChild(child); |
| 645 } | 624 } |
| 646 | 625 |
| 647 shelf->DestroyShelfWidget(); | 626 shelf->DestroyShelfWidget(); |
| 648 | 627 |
| 649 // CloseChildWindows() may be called twice during the shutdown of ash | 628 // CloseChildWindows() may be called twice during the shutdown of ash |
| 650 // unittests. Avoid notifying WmShelf that the shelf has been destroyed twice. | 629 // unittests. Avoid notifying WmShelf that the shelf has been destroyed twice. |
| 651 if (shelf->IsShelfInitialized()) | 630 if (shelf->IsShelfInitialized()) |
| 652 shelf->ShutdownShelf(); | 631 shelf->ShutdownShelf(); |
| 653 } | 632 } |
| 654 | 633 |
| 655 bool WmRootWindowController::ShouldDestroyWindowInCloseChildWindows( | 634 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(); | 635 menu_runner_.reset(); |
| 671 menu_model_adapter_.reset(); | 636 menu_model_adapter_.reset(); |
| 672 menu_model_.reset(); | 637 menu_model_.reset(); |
| 673 GetShelf()->UpdateVisibilityState(); | 638 wm_shelf_->UpdateVisibilityState(); |
| 674 } | 639 } |
| 675 | 640 |
| 676 } // namespace ash | 641 } // namespace ash |
| OLD | NEW |