| Index: ash/mus/window_manager.cc
|
| diff --git a/ash/mus/window_manager.cc b/ash/mus/window_manager.cc
|
| index b27154446694906453cb95f1541eb088d1fb6e43..fcdced5651970f2aa4577aa2e4944993f10aa8aa 100644
|
| --- a/ash/mus/window_manager.cc
|
| +++ b/ash/mus/window_manager.cc
|
| @@ -9,10 +9,10 @@
|
| #include <utility>
|
|
|
| #include "ash/common/session/session_controller.h"
|
| +#include "ash/common/system/tray/system_tray_delegate.h"
|
| #include "ash/common/wm/container_finder.h"
|
| #include "ash/common/wm/window_state.h"
|
| #include "ash/common/wm_window.h"
|
| -#include "ash/display/screen_position_controller.h"
|
| #include "ash/mus/accelerators/accelerator_handler.h"
|
| #include "ash/mus/accelerators/accelerator_ids.h"
|
| #include "ash/mus/bridge/wm_lookup_mus.h"
|
| @@ -24,13 +24,12 @@
|
| #include "ash/mus/screen_mus.h"
|
| #include "ash/mus/shadow_controller.h"
|
| #include "ash/mus/shell_delegate_mus.h"
|
| -#include "ash/mus/window_manager_observer.h"
|
| #include "ash/mus/window_properties.h"
|
| #include "ash/public/cpp/shell_window_ids.h"
|
| #include "ash/root_window_controller.h"
|
| #include "ash/shell.h"
|
| +#include "ash/shell_init_params.h"
|
| #include "ash/wm/ash_focus_rules.h"
|
| -#include "ash/wm/event_client_impl.h"
|
| #include "ash/wm/window_properties.h"
|
| #include "base/memory/ptr_util.h"
|
| #include "services/service_manager/public/cpp/connector.h"
|
| @@ -52,39 +51,17 @@
|
| #include "ui/views/mus/pointer_watcher_event_router.h"
|
| #include "ui/views/mus/screen_mus.h"
|
| #include "ui/wm/core/capture_controller.h"
|
| -#include "ui/wm/core/focus_controller.h"
|
| #include "ui/wm/core/wm_state.h"
|
| +#include "ui/wm/public/activation_client.h"
|
|
|
| namespace ash {
|
| namespace mus {
|
| -namespace {
|
| -
|
| -// TODO: this is temporary until WindowManager create the real Shell (which is
|
| -// the event target). http://crbug.com/670744.
|
| -class EventClientImplMus : public EventClientImpl {
|
| - public:
|
| - EventClientImplMus() = default;
|
| - ~EventClientImplMus() override = default;
|
| -
|
| - // EventClientImpl:
|
| - ui::EventTarget* GetToplevelEventTarget() override { return nullptr; }
|
| -
|
| - private:
|
| - DISALLOW_COPY_AND_ASSIGN(EventClientImplMus);
|
| -};
|
| -
|
| -} // namespace
|
|
|
| // TODO: need to register OSExchangeDataProviderMus. http://crbug.com/665077.
|
| WindowManager::WindowManager(service_manager::Connector* connector)
|
| : connector_(connector),
|
| - focus_controller_(base::MakeUnique<::wm::FocusController>(
|
| - new ::ash::wm::AshFocusRules())),
|
| wm_state_(base::MakeUnique<::wm::WMState>()),
|
| - property_converter_(base::MakeUnique<aura::PropertyConverter>()),
|
| - event_client_(base::MakeUnique<EventClientImplMus>()),
|
| - screen_position_controller_(
|
| - base::MakeUnique<ScreenPositionController>()) {
|
| + property_converter_(base::MakeUnique<aura::PropertyConverter>()) {
|
| property_converter_->RegisterProperty(
|
| kPanelAttachedKey, ui::mojom::WindowManager::kPanelAttached_Property);
|
| property_converter_->RegisterProperty(
|
| @@ -103,6 +80,7 @@ WindowManager::~WindowManager() {
|
| void WindowManager::Init(
|
| std::unique_ptr<aura::WindowTreeClient> window_tree_client,
|
| const scoped_refptr<base::SequencedWorkerPool>& blocking_pool) {
|
| + blocking_pool_ = blocking_pool;
|
| DCHECK(window_manager_client_);
|
| DCHECK(!window_tree_client_);
|
| window_tree_client_ = std::move(window_tree_client);
|
| @@ -134,14 +112,28 @@ void WindowManager::Init(
|
| window_manager_client_->SetFrameDecorationValues(
|
| std::move(frame_decoration_values));
|
|
|
| - shell_.reset(new WmShellMus(base::MakeUnique<ShellDelegateMus>(connector_),
|
| - this, pointer_watcher_event_router_.get()));
|
| - shell_->Initialize(blocking_pool);
|
| lookup_.reset(new WmLookupMus);
|
| }
|
|
|
| -aura::client::ActivationClient* WindowManager::activation_client() {
|
| - return focus_controller_.get();
|
| +void WindowManager::DeleteAllRootWindowControllers() {
|
| + // Primary RootWindowController must be destroyed last.
|
| + RootWindowController* primary_root_window_controller =
|
| + GetPrimaryRootWindowController();
|
| + std::set<RootWindowController*> secondary_root_window_controllers;
|
| + for (auto& root_window_controller_ptr : root_window_controllers_) {
|
| + if (root_window_controller_ptr.get() != primary_root_window_controller) {
|
| + secondary_root_window_controllers.insert(
|
| + root_window_controller_ptr.get());
|
| + }
|
| + }
|
| + const bool in_shutdown = true;
|
| + for (RootWindowController* root_window_controller :
|
| + secondary_root_window_controllers) {
|
| + DestroyRootWindowController(root_window_controller, in_shutdown);
|
| + }
|
| + if (primary_root_window_controller)
|
| + DestroyRootWindowController(primary_root_window_controller, in_shutdown);
|
| + DCHECK(root_window_controllers_.empty());
|
| }
|
|
|
| aura::Window* WindowManager::NewTopLevelWindow(
|
| @@ -190,55 +182,68 @@ void WindowManager::RemoveAcceleratorHandler(uint16_t id_namespace) {
|
| accelerator_handlers_.erase(id_namespace);
|
| }
|
|
|
| -void WindowManager::AddObserver(WindowManagerObserver* observer) {
|
| - observers_.AddObserver(observer);
|
| -}
|
| -
|
| -void WindowManager::RemoveObserver(WindowManagerObserver* observer) {
|
| - observers_.RemoveObserver(observer);
|
| -}
|
| -
|
| display::mojom::DisplayController* WindowManager::GetDisplayController() {
|
| return display_controller_ ? display_controller_.get() : nullptr;
|
| }
|
|
|
| -RootWindowController* WindowManager::CreateRootWindowController(
|
| +void WindowManager::CreatePrimaryRootWindowController(
|
| + std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) {
|
| + // See comment in CreateRootWindowController().
|
| + DCHECK(created_shell_);
|
| + std::unique_ptr<RootWindowController> root_window_controller_ptr(
|
| + new RootWindowController(
|
| + this, std::move(window_tree_host), screen_->GetAllDisplays()[0],
|
| + ash::RootWindowController::RootWindowType::PRIMARY));
|
| + root_window_controllers_.insert(std::move(root_window_controller_ptr));
|
| +}
|
| +
|
| +void WindowManager::CreateShell(
|
| + std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) {
|
| + DCHECK(!created_shell_);
|
| + created_shell_ = true;
|
| + ShellInitParams init_params;
|
| + WmShellMus* wm_shell =
|
| + new WmShellMus(WmWindow::Get(window_tree_host->window()),
|
| + base::MakeUnique<ShellDelegateMus>(
|
| + connector_, std::move(system_tray_delegate_for_test_)),
|
| + this, pointer_watcher_event_router_.get());
|
| + init_params.primary_window_tree_host = window_tree_host.release();
|
| + init_params.wm_shell = wm_shell;
|
| + init_params.blocking_pool = blocking_pool_.get();
|
| + Shell::CreateInstance(init_params);
|
| +}
|
| +
|
| +void WindowManager::CreateRootWindowController(
|
| std::unique_ptr<aura::WindowTreeHostMus> window_tree_host,
|
| const display::Display& display,
|
| ash::RootWindowController::RootWindowType root_window_type) {
|
| - // TODO(sky): all of these calls to SetFooClient() are done in
|
| - // Shell::InitRootWindow(). When Shell is used these can be removed.
|
| - aura::client::SetFocusClient(window_tree_host->window(),
|
| - focus_controller_.get());
|
| - aura::client::SetActivationClient(window_tree_host->window(),
|
| - focus_controller_.get());
|
| - aura::client::SetEventClient(window_tree_host->window(), event_client_.get());
|
| - aura::client::SetScreenPositionClient(window_tree_host->window(),
|
| - screen_position_controller_.get());
|
| -
|
| + // The ash startup sequence creates the Shell, which creates
|
| + // WindowTreeHostManager, which creates the WindowTreeHosts and
|
| + // RootWindowControllers. For mash we are supplied the WindowTreeHost when
|
| + // a display is added (and WindowTreeHostManager is not used in mash). Mash
|
| + // waits for the first WindowTreeHost, then creates the shell. As there are
|
| + // order dependencies we have to create the RootWindowController at a similar
|
| + // time as cash, to do that we inject the WindowTreeHost into ShellInitParams.
|
| + // Shell calls to WmShell::InitHosts(), which calls back to
|
| + // CreatePrimaryRootWindowController().
|
| + if (!created_shell_) {
|
| + CreateShell(std::move(window_tree_host));
|
| + return;
|
| + }
|
| std::unique_ptr<RootWindowController> root_window_controller_ptr(
|
| - new RootWindowController(this, std::move(window_tree_host), display,
|
| - root_window_type));
|
| - RootWindowController* root_window_controller =
|
| - root_window_controller_ptr.get();
|
| + new RootWindowController(
|
| + this, std::move(window_tree_host), display,
|
| + ash::RootWindowController::RootWindowType::SECONDARY));
|
| root_window_controllers_.insert(std::move(root_window_controller_ptr));
|
|
|
| - // Create a shelf if a user is already logged in.
|
| - if (shell_->session_controller()->NumberOfLoggedInUsers())
|
| - root_window_controller->ash_root_window_controller()->CreateShelf();
|
| -
|
| - for (auto& observer : observers_)
|
| - observer.OnRootWindowControllerAdded(root_window_controller);
|
| -
|
| for (auto& observer : *screen_->display_list().observers())
|
| - observer.OnDisplayAdded(root_window_controller->display());
|
| -
|
| - return root_window_controller;
|
| + observer.OnDisplayAdded(display);
|
| }
|
|
|
| void WindowManager::DestroyRootWindowController(
|
| - RootWindowController* root_window_controller) {
|
| - if (root_window_controllers_.size() > 1) {
|
| + RootWindowController* root_window_controller,
|
| + bool in_shutdown) {
|
| + if (!in_shutdown && root_window_controllers_.size() > 1) {
|
| DCHECK_NE(root_window_controller, GetPrimaryRootWindowController());
|
| root_window_controller->ash_root_window_controller()->MoveWindowsTo(
|
| GetPrimaryRootWindowController()->root());
|
| @@ -246,8 +251,6 @@ void WindowManager::DestroyRootWindowController(
|
|
|
| root_window_controller->Shutdown();
|
|
|
| - // NOTE: classic ash deleted RootWindowController after a delay (DeleteSoon())
|
| - // this may need to change to mirror that.
|
| for (auto iter = root_window_controllers_.begin();
|
| iter != root_window_controllers_.end(); ++iter) {
|
| if (iter->get() == root_window_controller) {
|
| @@ -261,47 +264,15 @@ void WindowManager::Shutdown() {
|
| if (!window_tree_client_)
|
| return;
|
|
|
| - // Remove the focus from any window. This will prevent overhead and side
|
| - // effects (e.g. crashes) from changing focus during shutdown.
|
| - // See bug crbug.com/134502.
|
| - static_cast<aura::client::FocusClient*>(focus_controller_.get())
|
| - ->FocusWindow(nullptr);
|
| -
|
| - // Observers can rely on WmShell from the callback. So notify the observers
|
| - // before destroying it.
|
| - for (auto& observer : observers_)
|
| - observer.OnWindowTreeClientDestroyed();
|
| -
|
| - // Primary RootWindowController must be destroyed last.
|
| - RootWindowController* primary_root_window_controller =
|
| - GetPrimaryRootWindowController();
|
| - std::set<RootWindowController*> secondary_root_window_controllers;
|
| - for (auto& root_window_controller_ptr : root_window_controllers_) {
|
| - if (root_window_controller_ptr.get() != primary_root_window_controller)
|
| - secondary_root_window_controllers.insert(
|
| - root_window_controller_ptr.get());
|
| - }
|
| - for (RootWindowController* root_window_controller :
|
| - secondary_root_window_controllers) {
|
| - DestroyRootWindowController(root_window_controller);
|
| - }
|
| - if (primary_root_window_controller)
|
| - DestroyRootWindowController(primary_root_window_controller);
|
| -
|
| - DCHECK(root_window_controllers_.empty());
|
| + Shell::DeleteInstance();
|
|
|
| lookup_.reset();
|
| - shell_->Shutdown();
|
| - shell_.reset();
|
| shadow_controller_.reset();
|
|
|
| pointer_watcher_event_router_.reset();
|
|
|
| window_tree_client_.reset();
|
| window_manager_client_ = nullptr;
|
| -
|
| - DCHECK_EQ(screen_.get(), display::Screen::GetScreen());
|
| - display::Screen::SetScreenInstance(nullptr);
|
| }
|
|
|
| RootWindowController* WindowManager::GetPrimaryRootWindowController() {
|
| @@ -439,7 +410,9 @@ void WindowManager::OnWmDisplayRemoved(
|
| aura::WindowTreeHostMus* window_tree_host) {
|
| for (auto& root_window_controller_ptr : root_window_controllers_) {
|
| if (root_window_controller_ptr->window_tree_host() == window_tree_host) {
|
| - DestroyRootWindowController(root_window_controller_ptr.get());
|
| + const bool in_shutdown = false;
|
| + DestroyRootWindowController(root_window_controller_ptr.get(),
|
| + in_shutdown);
|
| break;
|
| }
|
| }
|
| @@ -505,11 +478,11 @@ void WindowManager::OnWmSetClientArea(
|
| }
|
|
|
| bool WindowManager::IsWindowActive(aura::Window* window) {
|
| - return activation_client()->GetActiveWindow() == window;
|
| + return Shell::GetInstance()->activation_client()->GetActiveWindow() == window;
|
| }
|
|
|
| void WindowManager::OnWmDeactivateWindow(aura::Window* window) {
|
| - activation_client()->DeactivateWindow(window);
|
| + Shell::GetInstance()->activation_client()->DeactivateWindow(window);
|
| }
|
|
|
| } // namespace mus
|
|
|