Chromium Code Reviews| 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..d243eb498aca9234e0423ccc22512d9be851072d 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,24 @@ |
| #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 { |
| -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 +60,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 +72,15 @@ 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(); |
| + wm_shelf_.reset(); |
|
James Cook
2016/12/05 19:21:44
I presume there's an ordering dependency in destru
sky
2016/12/05 21:39:20
Done.
|
| + wm_root_window_controller_.reset(); |
| + window_tree_host_.reset(); |
| } |
| void RootWindowController::Shutdown() { |
| @@ -85,46 +93,75 @@ service_manager::Connector* RootWindowController::GetConnector() { |
| return window_manager_->connector(); |
| } |
| -ui::Window* RootWindowController::NewTopLevelWindow( |
| - 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(); |
| +aura::Window* RootWindowController::root() { |
| + return window_tree_host_->window(); |
| +} |
| - // TODO(sky): constrain and validate properties before passing to server. |
| - ui::Window* window = root_->window_tree()->NewWindow(properties); |
| - window->SetBounds(CalculateDefaultBounds(window)); |
| +const aura::Window* RootWindowController::root() const { |
| + return window_tree_host_->window(); |
| +} |
| - ui::Window* container_window = nullptr; |
| - int container_id = kShellWindowId_Invalid; |
| - if (GetRequestedContainer(window, &container_id)) { |
| - container_window = GetWindowByShellWindowId(container_id)->mus_window(); |
| +aura::Window* RootWindowController::NewTopLevelWindow( |
| + ui::mojom::WindowType window_type, |
| + std::map<std::string, std::vector<uint8_t>>* properties) { |
| + // TODO(sky): constrain and validate properties. |
| + |
| + 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 { |
| - 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)); |
| + context = window_tree_host_->window(); |
|
James Cook
2016/12/05 19:21:44
Using root() here might be a little clearer.
sky
2016/12/05 21:39:19
Done.
|
| } |
| - 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(); |
|
James Cook
2016/12/05 19:21:44
I know you didn't change this, but what's it for /
sky
2016/12/05 21:39:20
It's for mus to make sure mus has both parts of th
|
| + // 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(window_tree_host_->window()); |
|
James Cook
2016/12/05 19:21:44
ditto, might be clearer to call root()
sky
2016/12/05 21:39:19
Done.
|
| + 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 +187,46 @@ 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()) { |
| + aura::PropertyConverter::PrimitiveType show_state = 0; |
| + if (window_manager_->property_converter() |
| + ->GetPropertyValueFromTransportValue( |
| + ui::mojom::WindowManager::kShowState_Property, |
| + show_state_iter->second, &show_state) && |
| + static_cast<ui::WindowShowState>(show_state) == |
| + ui::SHOW_STATE_FULLSCREEN) { |
|
James Cook
2016/12/05 19:21:44
nit: This if() is ugly. Would it help to cache pro
sky
2016/12/05 21:39:19
Well, I made this function easier to parse, but I'
James Cook
2016/12/05 22:56:34
Better, one other idea above.
|
| + gfx::Rect bounds(0, 0, root()->bounds().width(), |
| + root()->bounds().height()); |
| + if (!container_window) { |
|
James Cook
2016/12/05 19:21:44
Why is fullscreen not using the root window bounds
sky
2016/12/05 21:39:19
It's because of differences in how NativeWidgetAur
|
| + 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 |