| Index: ash/mus/root_window_controller.cc
|
| diff --git a/ash/mus/root_window_controller.cc b/ash/mus/root_window_controller.cc
|
| index d81f7f4ec5c5dc600d9307c79c3689888ba67ec3..61ae21e2fef4ff35369998a967c49e092f75f3e0 100644
|
| --- a/ash/mus/root_window_controller.cc
|
| +++ b/ash/mus/root_window_controller.cc
|
| @@ -24,9 +24,10 @@
|
| #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/screenlock_layout.h"
|
| +#include "ash/mus/screen_mus.h"
|
| #include "ash/mus/window_manager.h"
|
| #include "ash/public/cpp/shell_window_ids.h"
|
| +#include "ash/wm/stacking_controller.h"
|
| #include "base/bind.h"
|
| #include "base/command_line.h"
|
| #include "base/memory/ptr_util.h"
|
| @@ -34,21 +35,37 @@
|
| #include "services/service_manager/public/cpp/connector.h"
|
| #include "services/ui/common/switches.h"
|
| #include "services/ui/common/util.h"
|
| -#include "services/ui/public/cpp/property_type_converters.h"
|
| -#include "services/ui/public/cpp/window.h"
|
| -#include "services/ui/public/cpp/window_property.h"
|
| -#include "services/ui/public/cpp/window_tree_client.h"
|
| +#include "ui/aura/client/aura_constants.h"
|
| +#include "ui/aura/mus/property_converter.h"
|
| +#include "ui/aura/mus/property_utils.h"
|
| +#include "ui/aura/mus/window_tree_client.h"
|
| +#include "ui/aura/mus/window_tree_host_mus.h"
|
| +#include "ui/aura/window.h"
|
| +#include "ui/base/ui_base_types.h"
|
| #include "ui/display/display_list.h"
|
| -#include "ui/display/screen_base.h"
|
|
|
| namespace ash {
|
| namespace mus {
|
| +namespace {
|
| +
|
| +bool IsFullscreen(aura::PropertyConverter* property_converter,
|
| + const std::vector<uint8_t>& transport_data) {
|
| + using ui::mojom::WindowManager;
|
| + aura::PropertyConverter::PrimitiveType show_state = 0;
|
| + return property_converter->GetPropertyValueFromTransportValue(
|
| + WindowManager::kShowState_Property, transport_data, &show_state) &&
|
| + (static_cast<ui::WindowShowState>(show_state) ==
|
| + ui::SHOW_STATE_FULLSCREEN);
|
| +}
|
| +
|
| +} // namespace
|
|
|
| -RootWindowController::RootWindowController(WindowManager* window_manager,
|
| - ui::Window* root,
|
| - const display::Display& display)
|
| +RootWindowController::RootWindowController(
|
| + WindowManager* window_manager,
|
| + std::unique_ptr<aura::WindowTreeHostMus> window_tree_host,
|
| + const display::Display& display)
|
| : window_manager_(window_manager),
|
| - root_(root),
|
| + window_tree_host_(std::move(window_tree_host)),
|
| window_count_(0),
|
| display_(display),
|
| wm_shelf_(base::MakeUnique<WmShelfMus>()) {
|
| @@ -56,9 +73,11 @@ RootWindowController::RootWindowController(WindowManager* window_manager,
|
| window_manager_->shell(), this);
|
| wm_root_window_controller_->CreateContainers();
|
| wm_root_window_controller_->CreateLayoutManagers();
|
| - CreateLayoutManagers();
|
|
|
| - disconnected_app_handler_.reset(new DisconnectedAppHandler(root));
|
| + parenting_client_ = base::MakeUnique<StackingController>();
|
| + aura::client::SetWindowParentingClient(root(), parenting_client_.get());
|
| +
|
| + disconnected_app_handler_.reset(new DisconnectedAppHandler(root()));
|
|
|
| // Force a layout of the root, and its children, RootWindowLayout handles
|
| // both.
|
| @@ -66,13 +85,16 @@ RootWindowController::RootWindowController(WindowManager* window_manager,
|
|
|
| for (size_t i = 0; i < kNumActivatableShellWindowIds; ++i) {
|
| window_manager_->window_manager_client()->AddActivationParent(
|
| - GetWindowByShellWindowId(kActivatableShellWindowIds[i])->mus_window());
|
| + GetWindowByShellWindowId(kActivatableShellWindowIds[i])->aura_window());
|
| }
|
| }
|
|
|
| RootWindowController::~RootWindowController() {
|
| Shutdown();
|
| - root_->Destroy();
|
| + // Destroy WindowTreeHost last as it owns the root Window.
|
| + wm_shelf_.reset();
|
| + wm_root_window_controller_.reset();
|
| + window_tree_host_.reset();
|
| }
|
|
|
| void RootWindowController::Shutdown() {
|
| @@ -85,46 +107,74 @@ service_manager::Connector* RootWindowController::GetConnector() {
|
| return window_manager_->connector();
|
| }
|
|
|
| -ui::Window* RootWindowController::NewTopLevelWindow(
|
| +aura::Window* RootWindowController::root() {
|
| + return window_tree_host_->window();
|
| +}
|
| +
|
| +const aura::Window* RootWindowController::root() const {
|
| + return window_tree_host_->window();
|
| +}
|
| +
|
| +aura::Window* RootWindowController::NewTopLevelWindow(
|
| + ui::mojom::WindowType window_type,
|
| std::map<std::string, std::vector<uint8_t>>* properties) {
|
| - const bool provide_non_client_frame =
|
| - GetWindowType(*properties) == ui::mojom::WindowType::WINDOW ||
|
| - GetWindowType(*properties) == ui::mojom::WindowType::PANEL;
|
| - if (provide_non_client_frame)
|
| - (*properties)[ui::mojom::kWaitForUnderlay_Property].clear();
|
| + // TODO(sky): constrain and validate properties.
|
|
|
| - // TODO(sky): constrain and validate properties before passing to server.
|
| - ui::Window* window = root_->window_tree()->NewWindow(properties);
|
| - window->SetBounds(CalculateDefaultBounds(window));
|
| + int32_t container_id = kShellWindowId_Invalid;
|
| + aura::Window* context = nullptr;
|
| + aura::Window* container_window = nullptr;
|
| + if (GetInitialContainerId(*properties, &container_id))
|
| + container_window = GetWindowByShellWindowId(container_id)->aura_window();
|
| + else
|
| + context = root();
|
|
|
| - ui::Window* container_window = nullptr;
|
| - int container_id = kShellWindowId_Invalid;
|
| - if (GetRequestedContainer(window, &container_id)) {
|
| - container_window = GetWindowByShellWindowId(container_id)->mus_window();
|
| - } else {
|
| - gfx::Point origin = wm_root_window_controller_->ConvertPointToScreen(
|
| - WmWindowMus::Get(root_), gfx::Point());
|
| - gfx::Rect bounds_in_screen(origin, window->bounds().size());
|
| - container_window = WmWindowMus::GetMusWindow(wm::GetDefaultParent(
|
| - WmWindowMus::Get(root_), WmWindowMus::Get(window), bounds_in_screen));
|
| - }
|
| - DCHECK(WmWindowMus::Get(container_window)->IsContainer());
|
| + gfx::Rect bounds = CalculateDefaultBounds(container_window, properties);
|
| + window_count_++;
|
|
|
| + const bool provide_non_client_frame =
|
| + window_type == ui::mojom::WindowType::WINDOW ||
|
| + window_type == ui::mojom::WindowType::PANEL;
|
| if (provide_non_client_frame) {
|
| - NonClientFrameController::Create(container_window, window,
|
| - window_manager_->window_manager_client());
|
| - } else {
|
| - container_window->AddChild(window);
|
| + (*properties)[ui::mojom::kWaitForUnderlay_Property].clear();
|
| + // See NonClientFrameController for details on lifetime.
|
| + NonClientFrameController* non_client_frame_controller =
|
| + new NonClientFrameController(container_window, context, bounds,
|
| + window_type, properties, window_manager_);
|
| + return non_client_frame_controller->window();
|
| }
|
|
|
| - window_count_++;
|
| + aura::Window* window = new aura::Window(nullptr);
|
| + aura::SetWindowType(window, window_type);
|
| + // Apply properties before Init(), that way they are sent to the server at
|
| + // the time the window is created.
|
| + aura::PropertyConverter* property_converter =
|
| + window_manager_->property_converter();
|
| + for (auto& property_pair : *properties) {
|
| + property_converter->SetPropertyFromTransportValue(
|
| + window, property_pair.first, &property_pair.second);
|
| + }
|
| + window->Init(ui::LAYER_TEXTURED);
|
| + window->SetBounds(bounds);
|
|
|
| + if (container_window) {
|
| + container_window->AddChild(window);
|
| + } else {
|
| + WmWindowMus* root = WmWindowMus::Get(this->root());
|
| + gfx::Point origin =
|
| + wm_root_window_controller_->ConvertPointToScreen(root, gfx::Point());
|
| + gfx::Rect bounds_in_screen(origin, bounds.size());
|
| + static_cast<WmWindowMus*>(
|
| + ash::wm::GetDefaultParent(WmWindowMus::Get(context),
|
| + WmWindowMus::Get(window), bounds_in_screen))
|
| + ->aura_window()
|
| + ->AddChild(window);
|
| + }
|
| return window;
|
| }
|
|
|
| WmWindowMus* RootWindowController::GetWindowByShellWindowId(int id) {
|
| return WmWindowMus::AsWmWindowMus(
|
| - WmWindowMus::Get(root_)->GetChildByShellWindowId(id));
|
| + WmWindowMus::Get(root())->GetChildByShellWindowId(id));
|
| }
|
|
|
| void RootWindowController::SetWorkAreaInests(const gfx::Insets& insets) {
|
| @@ -150,39 +200,41 @@ void RootWindowController::SetDisplay(const display::Display& display) {
|
| }
|
|
|
| gfx::Rect RootWindowController::CalculateDefaultBounds(
|
| - ui::Window* window) const {
|
| - if (window->HasSharedProperty(
|
| - ui::mojom::WindowManager::kInitialBounds_Property)) {
|
| - return window->GetSharedProperty<gfx::Rect>(
|
| - ui::mojom::WindowManager::kInitialBounds_Property);
|
| - }
|
| -
|
| - if (GetWindowShowState(window) == ui::mojom::ShowState::FULLSCREEN) {
|
| - return gfx::Rect(0, 0, root_->bounds().width(), root_->bounds().height());
|
| + aura::Window* container_window,
|
| + const std::map<std::string, std::vector<uint8_t>>* properties) const {
|
| + gfx::Rect requested_bounds;
|
| + if (GetInitialBounds(*properties, &requested_bounds))
|
| + return requested_bounds;
|
| +
|
| + auto show_state_iter =
|
| + properties->find(ui::mojom::WindowManager::kShowState_Property);
|
| + if (show_state_iter != properties->end()) {
|
| + if (IsFullscreen(window_manager_->property_converter(),
|
| + show_state_iter->second)) {
|
| + gfx::Rect bounds(0, 0, root()->bounds().width(),
|
| + root()->bounds().height());
|
| + if (!container_window) {
|
| + bounds.Offset(display_.bounds().origin().x(),
|
| + display_.bounds().origin().y());
|
| + }
|
| + return bounds;
|
| + }
|
| }
|
|
|
| int width, height;
|
| - const gfx::Size pref = GetWindowPreferredSize(window);
|
| - if (pref.IsEmpty()) {
|
| - width = root_->bounds().width() - 240;
|
| - height = root_->bounds().height() - 240;
|
| - } else {
|
| + gfx::Size pref;
|
| + if (GetWindowPreferredSize(*properties, &pref) && !pref.IsEmpty()) {
|
| // TODO(sky): likely want to constrain more than root size.
|
| - const gfx::Size max_size = root_->bounds().size();
|
| + const gfx::Size max_size = root()->bounds().size();
|
| width = std::max(0, std::min(max_size.width(), pref.width()));
|
| height = std::max(0, std::min(max_size.height(), pref.height()));
|
| + } else {
|
| + width = root()->bounds().width() - 240;
|
| + height = root()->bounds().height() - 240;
|
| }
|
| return gfx::Rect(40 + (window_count_ % 4) * 40, 40 + (window_count_ % 4) * 40,
|
| width, height);
|
| }
|
|
|
| -void RootWindowController::CreateLayoutManagers() {
|
| - // Override the default layout managers for certain containers.
|
| - WmWindowMus* lock_screen_container =
|
| - GetWindowByShellWindowId(kShellWindowId_LockScreenContainer);
|
| - layout_managers_[lock_screen_container->mus_window()].reset(
|
| - new ScreenlockLayout(lock_screen_container->mus_window()));
|
| -}
|
| -
|
| } // namespace mus
|
| } // namespace ash
|
|
|