| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/mus/window_manager.h" | 5 #include "ash/mus/window_manager.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "ash/common/wm/container_finder.h" | 11 #include "ash/common/wm/container_finder.h" |
| 12 #include "ash/common/wm/window_state.h" | 12 #include "ash/common/wm/window_state.h" |
| 13 #include "ash/common/wm_root_window_controller.h" |
| 13 #include "ash/display/screen_position_controller.h" | 14 #include "ash/display/screen_position_controller.h" |
| 14 #include "ash/mus/accelerators/accelerator_handler.h" | 15 #include "ash/mus/accelerators/accelerator_handler.h" |
| 15 #include "ash/mus/accelerators/accelerator_ids.h" | 16 #include "ash/mus/accelerators/accelerator_ids.h" |
| 16 #include "ash/mus/bridge/wm_lookup_mus.h" | 17 #include "ash/mus/bridge/wm_lookup_mus.h" |
| 17 #include "ash/mus/bridge/wm_root_window_controller_mus.h" | |
| 18 #include "ash/mus/bridge/wm_shell_mus.h" | 18 #include "ash/mus/bridge/wm_shell_mus.h" |
| 19 #include "ash/mus/bridge/wm_window_mus.h" | 19 #include "ash/mus/bridge/wm_window_mus.h" |
| 20 #include "ash/mus/move_event_handler.h" | 20 #include "ash/mus/move_event_handler.h" |
| 21 #include "ash/mus/non_client_frame_controller.h" | 21 #include "ash/mus/non_client_frame_controller.h" |
| 22 #include "ash/mus/property_util.h" | 22 #include "ash/mus/property_util.h" |
| 23 #include "ash/mus/root_window_controller.h" | 23 #include "ash/mus/root_window_controller.h" |
| 24 #include "ash/mus/screen_mus.h" | 24 #include "ash/mus/screen_mus.h" |
| 25 #include "ash/mus/shadow_controller.h" | 25 #include "ash/mus/shadow_controller.h" |
| 26 #include "ash/mus/shell_delegate_mus.h" | 26 #include "ash/mus/shell_delegate_mus.h" |
| 27 #include "ash/mus/window_manager_observer.h" | 27 #include "ash/mus/window_manager_observer.h" |
| 28 #include "ash/mus/window_properties.h" | 28 #include "ash/mus/window_properties.h" |
| 29 #include "ash/public/cpp/shell_window_ids.h" | 29 #include "ash/public/cpp/shell_window_ids.h" |
| 30 #include "ash/shell.h" |
| 30 #include "ash/wm/ash_focus_rules.h" | 31 #include "ash/wm/ash_focus_rules.h" |
| 31 #include "ash/wm/event_client_impl.h" | 32 #include "ash/wm/event_client_impl.h" |
| 32 #include "ash/wm/window_properties.h" | 33 #include "ash/wm/window_properties.h" |
| 33 #include "base/memory/ptr_util.h" | 34 #include "base/memory/ptr_util.h" |
| 34 #include "services/service_manager/public/cpp/connector.h" | 35 #include "services/service_manager/public/cpp/connector.h" |
| 35 #include "services/ui/common/accelerator_util.h" | 36 #include "services/ui/common/accelerator_util.h" |
| 36 #include "services/ui/common/types.h" | 37 #include "services/ui/common/types.h" |
| 37 #include "services/ui/public/cpp/property_type_converters.h" | 38 #include "services/ui/public/cpp/property_type_converters.h" |
| 38 #include "services/ui/public/interfaces/constants.mojom.h" | 39 #include "services/ui/public/interfaces/constants.mojom.h" |
| 39 #include "services/ui/public/interfaces/window_manager.mojom.h" | 40 #include "services/ui/public/interfaces/window_manager.mojom.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 property_converter_->RegisterProperty( | 89 property_converter_->RegisterProperty( |
| 89 kRenderTitleAreaProperty, | 90 kRenderTitleAreaProperty, |
| 90 ui::mojom::WindowManager::kRenderParentTitleArea_Property); | 91 ui::mojom::WindowManager::kRenderParentTitleArea_Property); |
| 91 property_converter_->RegisterProperty( | 92 property_converter_->RegisterProperty( |
| 92 kShelfItemTypeKey, ui::mojom::WindowManager::kShelfItemType_Property); | 93 kShelfItemTypeKey, ui::mojom::WindowManager::kShelfItemType_Property); |
| 93 } | 94 } |
| 94 | 95 |
| 95 WindowManager::~WindowManager() { | 96 WindowManager::~WindowManager() { |
| 96 Shutdown(); | 97 Shutdown(); |
| 97 aura::Env::GetInstance()->RemoveObserver(this); | 98 aura::Env::GetInstance()->RemoveObserver(this); |
| 99 ash::Shell::set_window_tree_client(nullptr); |
| 98 } | 100 } |
| 99 | 101 |
| 100 void WindowManager::Init( | 102 void WindowManager::Init( |
| 101 std::unique_ptr<aura::WindowTreeClient> window_tree_client, | 103 std::unique_ptr<aura::WindowTreeClient> window_tree_client, |
| 102 const scoped_refptr<base::SequencedWorkerPool>& blocking_pool) { | 104 const scoped_refptr<base::SequencedWorkerPool>& blocking_pool) { |
| 103 DCHECK(window_manager_client_); | 105 DCHECK(window_manager_client_); |
| 104 DCHECK(!window_tree_client_); | 106 DCHECK(!window_tree_client_); |
| 105 window_tree_client_ = std::move(window_tree_client); | 107 window_tree_client_ = std::move(window_tree_client); |
| 106 | 108 |
| 109 DCHECK_EQ(nullptr, ash::Shell::window_tree_client()); |
| 110 ash::Shell::set_window_tree_client(window_tree_client_.get()); |
| 111 |
| 107 aura::Env::GetInstance()->AddObserver(this); | 112 aura::Env::GetInstance()->AddObserver(this); |
| 108 | 113 |
| 109 // |connector_| will be null in some tests. | 114 // |connector_| will be null in some tests. |
| 110 if (connector_) | 115 if (connector_) |
| 111 connector_->BindInterface(ui::mojom::kServiceName, &display_controller_); | 116 connector_->BindInterface(ui::mojom::kServiceName, &display_controller_); |
| 112 | 117 |
| 113 screen_ = base::MakeUnique<ScreenMus>(); | 118 screen_ = base::MakeUnique<ScreenMus>(); |
| 114 display::Screen::SetScreenInstance(screen_.get()); | 119 display::Screen::SetScreenInstance(screen_.get()); |
| 115 | 120 |
| 116 pointer_watcher_event_router_ = | 121 pointer_watcher_event_router_ = |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 void WindowManager::RemoveObserver(WindowManagerObserver* observer) { | 202 void WindowManager::RemoveObserver(WindowManagerObserver* observer) { |
| 198 observers_.RemoveObserver(observer); | 203 observers_.RemoveObserver(observer); |
| 199 } | 204 } |
| 200 | 205 |
| 201 display::mojom::DisplayController* WindowManager::GetDisplayController() { | 206 display::mojom::DisplayController* WindowManager::GetDisplayController() { |
| 202 return display_controller_ ? display_controller_.get() : nullptr; | 207 return display_controller_ ? display_controller_.get() : nullptr; |
| 203 } | 208 } |
| 204 | 209 |
| 205 RootWindowController* WindowManager::CreateRootWindowController( | 210 RootWindowController* WindowManager::CreateRootWindowController( |
| 206 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host, | 211 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host, |
| 207 const display::Display& display) { | 212 const display::Display& display, |
| 208 // TODO(sky): this is temporary, should use RootWindowController directly. | 213 ash::RootWindowController::RootWindowType root_window_type) { |
| 209 aura::client::SetCaptureClient(window_tree_host->window(), | 214 // TODO(sky): all of these calls to SetFooClient() are done in |
| 210 wm_state_->capture_controller()); | 215 // Shell::InitRootWindow(). When Shell is used these can be removed. |
| 211 aura::client::SetFocusClient(window_tree_host->window(), | 216 aura::client::SetFocusClient(window_tree_host->window(), |
| 212 focus_controller_.get()); | 217 focus_controller_.get()); |
| 213 aura::client::SetActivationClient(window_tree_host->window(), | 218 aura::client::SetActivationClient(window_tree_host->window(), |
| 214 focus_controller_.get()); | 219 focus_controller_.get()); |
| 215 aura::client::SetEventClient(window_tree_host->window(), event_client_.get()); | 220 aura::client::SetEventClient(window_tree_host->window(), event_client_.get()); |
| 216 aura::client::SetScreenPositionClient(window_tree_host->window(), | 221 aura::client::SetScreenPositionClient(window_tree_host->window(), |
| 217 screen_position_controller_.get()); | 222 screen_position_controller_.get()); |
| 218 | 223 |
| 219 std::unique_ptr<RootWindowController> root_window_controller_ptr( | 224 std::unique_ptr<RootWindowController> root_window_controller_ptr( |
| 220 new RootWindowController(this, std::move(window_tree_host), display)); | 225 new RootWindowController(this, std::move(window_tree_host), display, |
| 226 root_window_type)); |
| 221 RootWindowController* root_window_controller = | 227 RootWindowController* root_window_controller = |
| 222 root_window_controller_ptr.get(); | 228 root_window_controller_ptr.get(); |
| 223 root_window_controllers_.insert(std::move(root_window_controller_ptr)); | 229 root_window_controllers_.insert(std::move(root_window_controller_ptr)); |
| 224 | 230 |
| 225 // TODO: this should be called when logged in. See http://crbug.com/654606. | 231 // TODO: this should be called when logged in. See http://crbug.com/654606. |
| 226 root_window_controller->wm_root_window_controller()->CreateShelf(); | 232 root_window_controller->ash_root_window_controller() |
| 233 ->wm_root_window_controller() |
| 234 ->CreateShelf(); |
| 227 | 235 |
| 228 for (auto& observer : observers_) | 236 for (auto& observer : observers_) |
| 229 observer.OnRootWindowControllerAdded(root_window_controller); | 237 observer.OnRootWindowControllerAdded(root_window_controller); |
| 230 | 238 |
| 231 for (auto& observer : *screen_->display_list().observers()) | 239 for (auto& observer : *screen_->display_list().observers()) |
| 232 observer.OnDisplayAdded(root_window_controller->display()); | 240 observer.OnDisplayAdded(root_window_controller->display()); |
| 233 | 241 |
| 234 return root_window_controller; | 242 return root_window_controller; |
| 235 } | 243 } |
| 236 | 244 |
| 237 void WindowManager::DestroyRootWindowController( | 245 void WindowManager::DestroyRootWindowController( |
| 238 RootWindowController* root_window_controller) { | 246 RootWindowController* root_window_controller) { |
| 239 if (root_window_controllers_.size() > 1) { | 247 if (root_window_controllers_.size() > 1) { |
| 240 DCHECK_NE(root_window_controller, GetPrimaryRootWindowController()); | 248 DCHECK_NE(root_window_controller, GetPrimaryRootWindowController()); |
| 241 root_window_controller->wm_root_window_controller()->MoveWindowsTo( | 249 root_window_controller->ash_root_window_controller()->MoveWindowsTo( |
| 242 WmWindowMus::Get(GetPrimaryRootWindowController()->root())); | 250 GetPrimaryRootWindowController()->root()); |
| 243 } | 251 } |
| 244 | 252 |
| 245 root_window_controller->Shutdown(); | 253 root_window_controller->Shutdown(); |
| 246 | 254 |
| 247 // NOTE: classic ash deleted RootWindowController after a delay (DeleteSoon()) | 255 // NOTE: classic ash deleted RootWindowController after a delay (DeleteSoon()) |
| 248 // this may need to change to mirror that. | 256 // this may need to change to mirror that. |
| 249 for (auto iter = root_window_controllers_.begin(); | 257 for (auto iter = root_window_controllers_.begin(); |
| 250 iter != root_window_controllers_.end(); ++iter) { | 258 iter != root_window_controllers_.end(); ++iter) { |
| 251 if (iter->get() == root_window_controller) { | 259 if (iter->get() == root_window_controller) { |
| 252 root_window_controllers_.erase(iter); | 260 root_window_controllers_.erase(iter); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 pointer_watcher_event_router_.reset(); | 304 pointer_watcher_event_router_.reset(); |
| 297 | 305 |
| 298 window_tree_client_.reset(); | 306 window_tree_client_.reset(); |
| 299 window_manager_client_ = nullptr; | 307 window_manager_client_ = nullptr; |
| 300 | 308 |
| 301 DCHECK_EQ(screen_.get(), display::Screen::GetScreen()); | 309 DCHECK_EQ(screen_.get(), display::Screen::GetScreen()); |
| 302 display::Screen::SetScreenInstance(nullptr); | 310 display::Screen::SetScreenInstance(nullptr); |
| 303 } | 311 } |
| 304 | 312 |
| 305 RootWindowController* WindowManager::GetPrimaryRootWindowController() { | 313 RootWindowController* WindowManager::GetPrimaryRootWindowController() { |
| 306 return static_cast<WmRootWindowControllerMus*>( | 314 return RootWindowController::ForWindow( |
| 307 WmShell::Get()->GetPrimaryRootWindowController()) | 315 static_cast<WmWindowMus*>( |
| 308 ->root_window_controller(); | 316 WmShell::Get()->GetPrimaryRootWindowController()->GetWindow()) |
| 317 ->aura_window()); |
| 309 } | 318 } |
| 310 | 319 |
| 311 RootWindowController* | 320 RootWindowController* |
| 312 WindowManager::GetRootWindowControllerForNewTopLevelWindow( | 321 WindowManager::GetRootWindowControllerForNewTopLevelWindow( |
| 313 std::map<std::string, std::vector<uint8_t>>* properties) { | 322 std::map<std::string, std::vector<uint8_t>>* properties) { |
| 314 // If a specific display was requested, use it. | 323 // If a specific display was requested, use it. |
| 315 const int64_t display_id = GetInitialDisplayId(*properties); | 324 const int64_t display_id = GetInitialDisplayId(*properties); |
| 316 for (auto& root_window_controller_ptr : root_window_controllers_) { | 325 for (auto& root_window_controller_ptr : root_window_controllers_) { |
| 317 if (root_window_controller_ptr->display().id() == display_id) | 326 if (root_window_controller_ptr->display().id() == display_id) |
| 318 return root_window_controller_ptr.get(); | 327 return root_window_controller_ptr.get(); |
| 319 } | 328 } |
| 320 | 329 |
| 321 return static_cast<WmRootWindowControllerMus*>( | 330 return RootWindowController::ForWindow( |
| 322 WmShellMus::Get() | 331 static_cast<WmWindowMus*>(WmShellMus::Get()->GetRootWindowForNewWindows()) |
| 323 ->GetRootWindowForNewWindows() | 332 ->aura_window()); |
| 324 ->GetRootWindowController()) | |
| 325 ->root_window_controller(); | |
| 326 } | 333 } |
| 327 | 334 |
| 328 void WindowManager::OnEmbed( | 335 void WindowManager::OnEmbed( |
| 329 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) { | 336 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) { |
| 330 // WindowManager should never see this, instead OnWmNewDisplay() is called. | 337 // WindowManager should never see this, instead OnWmNewDisplay() is called. |
| 331 NOTREACHED(); | 338 NOTREACHED(); |
| 332 } | 339 } |
| 333 | 340 |
| 334 void WindowManager::OnEmbedRootDestroyed( | 341 void WindowManager::OnEmbedRootDestroyed( |
| 335 aura::WindowTreeHostMus* window_tree_host) { | 342 aura::WindowTreeHostMus* window_tree_host) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 const bool is_first_display = screen_->display_list().displays().empty(); | 427 const bool is_first_display = screen_->display_list().displays().empty(); |
| 421 // TODO(sky): should be passed whether display is primary. | 428 // TODO(sky): should be passed whether display is primary. |
| 422 screen_->display_list().AddDisplay( | 429 screen_->display_list().AddDisplay( |
| 423 display, is_first_display ? display::DisplayList::Type::PRIMARY | 430 display, is_first_display ? display::DisplayList::Type::PRIMARY |
| 424 : display::DisplayList::Type::NOT_PRIMARY); | 431 : display::DisplayList::Type::NOT_PRIMARY); |
| 425 } | 432 } |
| 426 | 433 |
| 427 void WindowManager::OnWmNewDisplay( | 434 void WindowManager::OnWmNewDisplay( |
| 428 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host, | 435 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host, |
| 429 const display::Display& display) { | 436 const display::Display& display) { |
| 430 CreateRootWindowController(std::move(window_tree_host), display); | 437 ash::RootWindowController::RootWindowType root_window_type = |
| 438 screen_->display_list().displays().size() == 1 |
| 439 ? ash::RootWindowController::RootWindowType::PRIMARY |
| 440 : ash::RootWindowController::RootWindowType::SECONDARY; |
| 441 CreateRootWindowController(std::move(window_tree_host), display, |
| 442 root_window_type); |
| 431 } | 443 } |
| 432 | 444 |
| 433 void WindowManager::OnWmDisplayRemoved( | 445 void WindowManager::OnWmDisplayRemoved( |
| 434 aura::WindowTreeHostMus* window_tree_host) { | 446 aura::WindowTreeHostMus* window_tree_host) { |
| 435 for (auto& root_window_controller_ptr : root_window_controllers_) { | 447 for (auto& root_window_controller_ptr : root_window_controllers_) { |
| 436 if (root_window_controller_ptr->window_tree_host() == window_tree_host) { | 448 if (root_window_controller_ptr->window_tree_host() == window_tree_host) { |
| 437 DestroyRootWindowController(root_window_controller_ptr.get()); | 449 DestroyRootWindowController(root_window_controller_ptr.get()); |
| 438 break; | 450 break; |
| 439 } | 451 } |
| 440 } | 452 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 | 513 |
| 502 void WindowManager::OnWindowInitialized(aura::Window* window) { | 514 void WindowManager::OnWindowInitialized(aura::Window* window) { |
| 503 // This ensures WmWindowAura won't be called before WmWindowMus. This is | 515 // This ensures WmWindowAura won't be called before WmWindowMus. This is |
| 504 // important as if WmWindowAura::Get() is called first, then WmWindowAura | 516 // important as if WmWindowAura::Get() is called first, then WmWindowAura |
| 505 // would be created, not WmWindowMus. | 517 // would be created, not WmWindowMus. |
| 506 WmWindowMus::Get(window); | 518 WmWindowMus::Get(window); |
| 507 } | 519 } |
| 508 | 520 |
| 509 } // namespace mus | 521 } // namespace mus |
| 510 } // namespace ash | 522 } // namespace ash |
| OLD | NEW |