| Index: ash/mus/window_manager.cc
|
| diff --git a/ash/mus/window_manager.cc b/ash/mus/window_manager.cc
|
| index 9605c5c5c76ad8c0202eba03420185046111808b..3be7ba8a1dee8a33e9aca00f3fa46e8ac4e5b951 100644
|
| --- a/ash/mus/window_manager.cc
|
| +++ b/ash/mus/window_manager.cc
|
| @@ -9,12 +9,17 @@
|
| #include <utility>
|
|
|
| #include "ash/common/shell_window_ids.h"
|
| -#include "ash/common/wm/container_finder.h"
|
| +#include "ash/mus/bridge/wm_lookup_mus.h"
|
| +#include "ash/mus/bridge/wm_shell_mus.h"
|
| #include "ash/mus/bridge/wm_window_mus.h"
|
| #include "ash/mus/non_client_frame_controller.h"
|
| #include "ash/mus/property_util.h"
|
| #include "ash/mus/root_window_controller.h"
|
| +#include "ash/mus/root_windows_observer.h"
|
| +#include "ash/mus/shadow_controller.h"
|
| +#include "ash/mus/window_manager_application.h"
|
| #include "ash/public/interfaces/container.mojom.h"
|
| +#include "components/mus/common/event_matcher_util.h"
|
| #include "components/mus/common/types.h"
|
| #include "components/mus/public/cpp/property_type_converters.h"
|
| #include "components/mus/public/cpp/window.h"
|
| @@ -23,52 +28,33 @@
|
| #include "components/mus/public/interfaces/mus_constants.mojom.h"
|
| #include "components/mus/public/interfaces/window_manager.mojom.h"
|
| #include "ui/events/mojo/event.mojom.h"
|
| +#include "ui/views/mus/screen_mus.h"
|
|
|
| namespace ash {
|
| namespace mus {
|
|
|
| -WindowManager::WindowManager()
|
| - : root_controller_(nullptr),
|
| - window_manager_client_(nullptr),
|
| - binding_(this) {}
|
| -
|
| -WindowManager::~WindowManager() {}
|
| -
|
| -void WindowManager::Initialize(RootWindowController* root_controller,
|
| - mash::session::mojom::Session* session) {
|
| - DCHECK(root_controller);
|
| - DCHECK(!root_controller_);
|
| - root_controller_ = root_controller;
|
| -
|
| - // Observe all the containers so that windows can be added to/removed from the
|
| - // |disconnected_app_handler_|.
|
| - WmWindowMus* root = WmWindowMus::Get(root_controller_->root());
|
| - for (int shell_window_id = kShellWindowId_Min;
|
| - shell_window_id < kShellWindowId_Max; ++shell_window_id) {
|
| - // kShellWindowId_VirtualKeyboardContainer is lazily created.
|
| - // TODO(sky): http://crbug.com/616909 .
|
| - // kShellWindowId_PhantomWindow is not a container, but a window.
|
| - if (shell_window_id == kShellWindowId_VirtualKeyboardContainer ||
|
| - shell_window_id == kShellWindowId_PhantomWindow)
|
| - continue;
|
| -
|
| -// kShellWindowId_MouseCursorContainer is chromeos specific.
|
| -#if !defined(OS_CHROMEOS)
|
| - if (shell_window_id == kShellWindowId_MouseCursorContainer)
|
| - continue;
|
| -#endif
|
| -
|
| - WmWindowMus* container = WmWindowMus::AsWmWindowMus(
|
| - root->GetChildByShellWindowId(shell_window_id));
|
| - Add(container->mus_window());
|
| -
|
| - // Add any pre-existing windows in the container to
|
| - // |disconnected_app_handler_|.
|
| - for (::mus::Window* child : container->mus_window()->children()) {
|
| - if (!root_controller_->WindowIsContainer(child))
|
| - disconnected_app_handler_.Add(child);
|
| - }
|
| - }
|
| +const uint32_t kWindowSwitchAccelerator = 1;
|
| +
|
| +void AssertTrue(bool success) {
|
| + DCHECK(success);
|
| +}
|
| +
|
| +WindowManager::WindowManager(WindowManagerApplication* window_manager_app,
|
| + shell::Connector* connector)
|
| + : window_manager_app_(window_manager_app), connector_(connector) {}
|
| +
|
| +WindowManager::~WindowManager() {
|
| + // NOTE: |window_tree_client_| may already be null.
|
| + delete window_tree_client_;
|
| +}
|
| +
|
| +void WindowManager::Init(::mus::WindowTreeClient* window_tree_client) {
|
| + DCHECK(!window_tree_client_);
|
| + window_tree_client_ = window_tree_client;
|
| +
|
| + shadow_controller_.reset(new ShadowController(window_tree_client));
|
| +
|
| + AddAccelerators();
|
|
|
| // The insets are roughly what is needed by CustomFrameView. The expectation
|
| // is at some point we'll write our own NonClientFrameView and get the insets
|
| @@ -84,93 +70,121 @@ void WindowManager::Initialize(RootWindowController* root_controller,
|
| window_manager_client_->SetFrameDecorationValues(
|
| std::move(frame_decoration_values));
|
|
|
| - if (session)
|
| - session->AddScreenlockStateListener(binding_.CreateInterfacePtrAndBind());
|
| + shell_.reset(new WmShellMus(window_tree_client_));
|
| + lookup_.reset(new WmLookupMus);
|
| +}
|
| +
|
| +void WindowManager::SetScreenLocked(bool is_locked) {
|
| + // TODO: screen locked state needs to be persisted for newly added displays.
|
| + for (auto& root_window_controller : root_window_controllers_) {
|
| + WmWindowMus* non_lock_screen_containers_container =
|
| + root_window_controller->GetWindowByShellWindowId(
|
| + kShellWindowId_NonLockScreenContainersContainer);
|
| + non_lock_screen_containers_container->mus_window()->SetVisible(!is_locked);
|
| + }
|
| }
|
|
|
| ::mus::Window* WindowManager::NewTopLevelWindow(
|
| std::map<std::string, std::vector<uint8_t>>* properties) {
|
| - DCHECK(root_controller_);
|
| - ::mus::Window* root = root_controller_->root();
|
| - DCHECK(root);
|
| -
|
| - // TODO(sky): panels need a different frame, http:://crbug.com/614362.
|
| - const bool provide_non_client_frame =
|
| - GetWindowType(*properties) == ::mus::mojom::WindowType::WINDOW ||
|
| - GetWindowType(*properties) == ::mus::mojom::WindowType::PANEL;
|
| - if (provide_non_client_frame)
|
| - (*properties)[::mus::mojom::kWaitForUnderlay_Property].clear();
|
| -
|
| - // TODO(sky): constrain and validate properties before passing to server.
|
| - ::mus::Window* window = root->window_tree()->NewWindow(properties);
|
| - window->SetBounds(CalculateDefaultBounds(window));
|
| -
|
| - ::mus::Window* container_window = nullptr;
|
| - mojom::Container container;
|
| - if (GetRequestedContainer(window, &container)) {
|
| - container_window = root_controller_->GetWindowForContainer(container);
|
| - } else {
|
| - // TODO(sky): window->bounds() isn't quite right.
|
| - container_window = WmWindowMus::GetMusWindow(
|
| - wm::GetDefaultParent(WmWindowMus::Get(root_controller_->root()),
|
| - WmWindowMus::Get(window), window->bounds()));
|
| - }
|
| - DCHECK(root_controller_->WindowIsContainer(container_window));
|
| -
|
| - if (provide_non_client_frame) {
|
| - NonClientFrameController::Create(root_controller_->GetConnector(),
|
| - container_window, window,
|
| - root_controller_->window_manager_client());
|
| - } else {
|
| - container_window->AddChild(window);
|
| + // TODO(sky): need to maintain active as well as allowing specifying display.
|
| + RootWindowController* root_window_controller =
|
| + root_window_controllers_.begin()->get();
|
| + return root_window_controller->NewTopLevelWindow(properties);
|
| +}
|
| +
|
| +std::set<RootWindowController*> WindowManager::GetRootWindowControllers() {
|
| + std::set<RootWindowController*> result;
|
| + for (auto& root_window_controller : root_window_controllers_)
|
| + result.insert(root_window_controller.get());
|
| + return result;
|
| +}
|
| +
|
| +void WindowManager::AddRootWindowsObserver(RootWindowsObserver* observer) {
|
| + root_windows_observers_.AddObserver(observer);
|
| +}
|
| +
|
| +void WindowManager::RemoveRootWindowsObserver(RootWindowsObserver* observer) {
|
| + root_windows_observers_.RemoveObserver(observer);
|
| +}
|
| +
|
| +void WindowManager::AddAccelerators() {
|
| + // TODO(sky): this is broke for multi-display case. Need to fix mus to
|
| + // deal correctly.
|
| + window_manager_client_->AddAccelerator(
|
| + kWindowSwitchAccelerator,
|
| + ::mus::CreateKeyMatcher(ui::mojom::KeyboardCode::TAB,
|
| + ui::mojom::kEventFlagControlDown),
|
| + base::Bind(&AssertTrue));
|
| +}
|
| +
|
| +RootWindowController* WindowManager::CreateRootWindowController(
|
| + ::mus::Window* window,
|
| + const display::Display& display) {
|
| + // TODO(sky): there is timing issues with using ScreenMus.
|
| + if (!screen_) {
|
| + std::unique_ptr<views::ScreenMus> screen(new views::ScreenMus(nullptr));
|
| + screen->Init(connector_);
|
| + screen_ = std::move(screen);
|
| }
|
|
|
| - root_controller_->IncrementWindowCount();
|
| + std::unique_ptr<RootWindowController> root_window_controller_ptr(
|
| + new RootWindowController(this, window, display));
|
| + RootWindowController* root_window_controller =
|
| + root_window_controller_ptr.get();
|
| + root_window_controllers_.insert(std::move(root_window_controller_ptr));
|
| + window->AddObserver(this);
|
|
|
| - return window;
|
| + FOR_EACH_OBSERVER(RootWindowsObserver, root_windows_observers_,
|
| + OnRootWindowControllerAdded(root_window_controller));
|
| + return root_window_controller;
|
| }
|
|
|
| -gfx::Rect WindowManager::CalculateDefaultBounds(::mus::Window* window) const {
|
| - if (window->HasSharedProperty(
|
| - ::mus::mojom::WindowManager::kInitialBounds_Property)) {
|
| - return window->GetSharedProperty<gfx::Rect>(
|
| - ::mus::mojom::WindowManager::kInitialBounds_Property);
|
| +void WindowManager::OnWindowDestroying(::mus::Window* window) {
|
| + for (auto it = root_window_controllers_.begin();
|
| + it != root_window_controllers_.end(); ++it) {
|
| + if ((*it)->root() == window) {
|
| + FOR_EACH_OBSERVER(RootWindowsObserver, root_windows_observers_,
|
| + OnWillDestroyRootWindowController((*it).get()));
|
| + return;
|
| + }
|
| }
|
| + NOTREACHED();
|
| +}
|
|
|
| - DCHECK(root_controller_);
|
| - int width, height;
|
| - const gfx::Size pref = GetWindowPreferredSize(window);
|
| - const ::mus::Window* root = root_controller_->root();
|
| - if (pref.IsEmpty()) {
|
| - width = root->bounds().width() - 240;
|
| - height = root->bounds().height() - 240;
|
| - } else {
|
| - // TODO(sky): likely want to constrain more than root size.
|
| - const gfx::Size max_size = GetMaximizedWindowBounds().size();
|
| - width = std::max(0, std::min(max_size.width(), pref.width()));
|
| - height = std::max(0, std::min(max_size.height(), pref.height()));
|
| +void WindowManager::OnWindowDestroyed(::mus::Window* window) {
|
| + window->RemoveObserver(this);
|
| + for (auto it = root_window_controllers_.begin();
|
| + it != root_window_controllers_.end(); ++it) {
|
| + if ((*it)->root() == window) {
|
| + root_window_controllers_.erase(it);
|
| + return;
|
| + }
|
| }
|
| - return gfx::Rect(40 + (root_controller_->window_count() % 4) * 40,
|
| - 40 + (root_controller_->window_count() % 4) * 40, width,
|
| - height);
|
| + NOTREACHED();
|
| }
|
|
|
| -gfx::Rect WindowManager::GetMaximizedWindowBounds() const {
|
| - DCHECK(root_controller_);
|
| - return gfx::Rect(root_controller_->root()->bounds().size());
|
| +void WindowManager::OnEmbed(::mus::Window* root) {
|
| + // WindowManager should never see this, instead OnWmNewDisplay() is called.
|
| + NOTREACHED();
|
| }
|
|
|
| -void WindowManager::OnTreeChanging(const TreeChangeParams& params) {
|
| - DCHECK(root_controller_);
|
| - if (params.old_parent == params.receiver &&
|
| - root_controller_->WindowIsContainer(params.old_parent))
|
| - disconnected_app_handler_.Remove(params.target);
|
| +void WindowManager::OnWindowTreeClientDestroyed(
|
| + ::mus::WindowTreeClient* client) {
|
| + // Destroying the roots should result in removal from
|
| + // |root_window_controllers_|.
|
| + DCHECK(root_window_controllers_.empty());
|
| +
|
| + lookup_.reset();
|
| + shell_.reset();
|
| + shadow_controller_.reset();
|
|
|
| - if (params.new_parent == params.receiver &&
|
| - root_controller_->WindowIsContainer(params.new_parent))
|
| - disconnected_app_handler_.Add(params.target);
|
| + window_tree_client_ = nullptr;
|
| + // TODO(sky): this should likely shutdown.
|
| +}
|
|
|
| - ::mus::WindowTracker::OnTreeChanging(params);
|
| +void WindowManager::OnEventObserved(const ui::Event& event,
|
| + ::mus::Window* target) {
|
| + // Does not use EventObservers.
|
| }
|
|
|
| void WindowManager::SetWindowManagerClient(::mus::WindowManagerClient* client) {
|
| @@ -210,15 +224,20 @@ void WindowManager::OnWmClientJankinessChanged(
|
| SetWindowIsJanky(window, janky);
|
| }
|
|
|
| -void WindowManager::OnAccelerator(uint32_t id, const ui::Event& event) {
|
| - root_controller_->OnAccelerator(id, std::move(event));
|
| +void WindowManager::OnWmNewDisplay(::mus::Window* window,
|
| + const display::Display& display) {
|
| + CreateRootWindowController(window, display);
|
| }
|
|
|
| -void WindowManager::ScreenlockStateChanged(bool locked) {
|
| - WmWindowMus* non_lock_screen_containers_container =
|
| - root_controller_->GetWindowByShellWindowId(
|
| - kShellWindowId_NonLockScreenContainersContainer);
|
| - non_lock_screen_containers_container->mus_window()->SetVisible(!locked);
|
| +void WindowManager::OnAccelerator(uint32_t id, const ui::Event& event) {
|
| + switch (id) {
|
| + case kWindowSwitchAccelerator:
|
| + window_manager_client()->ActivateNextWindow();
|
| + break;
|
| + default:
|
| + window_manager_app_->OnAccelerator(id, event);
|
| + break;
|
| + }
|
| }
|
|
|
| } // namespace mus
|
|
|