Commit 7aec5f84 authored by Mike Wasserman's avatar Mike Wasserman Committed by Commit Bot

ws: Add property support to WindowServiceClient::NewTopLevelWindow

Call CreateAndParentTopLevelWindow from WindowServiceDelegateImpl.
Get the window type like ui/aura/mus/window_tree_client.cc
Pass PropertyConverter, etc. args to avoid ash::WindowManager.
Check access to possibly null WindowManager[Client], etc. ptrs.

Add a unit test, apply properties to windows in test delegates.

Bug: 837695
Change-Id: I9f474c4b2701efc110b0738ae56fb5334d2fa641
Reviewed-on: https://chromium-review.googlesource.com/1055658
Commit-Queue: Michael Wasserman <msw@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#558018}
parent ca6c2430
...@@ -8,9 +8,9 @@ ...@@ -8,9 +8,9 @@
#include "ash/frame/caption_buttons/caption_button_model.h" #include "ash/frame/caption_buttons/caption_button_model.h"
#include "ash/frame/header_view.h" #include "ash/frame/header_view.h"
#include "ash/window_manager.h"
#include "ash/wm/property_util.h" #include "ash/wm/property_util.h"
#include "ash/wm/window_state.h" #include "ash/wm/window_state.h"
#include "services/ui/public/interfaces/window_manager_constants.mojom.h"
#include "ui/aura/client/aura_constants.h" #include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/transient_window_client.h" #include "ui/aura/client/transient_window_client.h"
#include "ui/aura/mus/property_converter.h" #include "ui/aura/mus/property_converter.h"
...@@ -93,8 +93,8 @@ DetachedTitleAreaRendererForInternal::~DetachedTitleAreaRendererForInternal() = ...@@ -93,8 +93,8 @@ DetachedTitleAreaRendererForInternal::~DetachedTitleAreaRendererForInternal() =
DetachedTitleAreaRendererForClient::DetachedTitleAreaRendererForClient( DetachedTitleAreaRendererForClient::DetachedTitleAreaRendererForClient(
aura::Window* parent, aura::Window* parent,
std::map<std::string, std::vector<uint8_t>>* properties, aura::PropertyConverter* property_converter,
WindowManager* window_manager) std::map<std::string, std::vector<uint8_t>>* properties)
: widget_(new views::Widget) { : widget_(new views::Widget) {
std::unique_ptr<views::Widget::InitParams> params = std::unique_ptr<views::Widget::InitParams> params =
CreateInitParams("DetachedTitleAreaRendererForClient"); CreateInitParams("DetachedTitleAreaRendererForClient");
...@@ -104,8 +104,8 @@ DetachedTitleAreaRendererForClient::DetachedTitleAreaRendererForClient( ...@@ -104,8 +104,8 @@ DetachedTitleAreaRendererForClient::DetachedTitleAreaRendererForClient(
aura::client::kEmbedType, aura::client::WindowEmbedType::TOP_LEVEL_IN_WM); aura::client::kEmbedType, aura::client::WindowEmbedType::TOP_LEVEL_IN_WM);
aura::SetWindowType(native_widget->GetNativeWindow(), aura::SetWindowType(native_widget->GetNativeWindow(),
ui::mojom::WindowType::POPUP); ui::mojom::WindowType::POPUP);
ApplyProperties(native_widget->GetNativeWindow(), ApplyProperties(native_widget->GetNativeWindow(), property_converter,
window_manager->property_converter(), *properties); *properties);
native_widget->GetNativeView()->SetProperty(kDetachedTitleAreaRendererKey, native_widget->GetNativeView()->SetProperty(kDetachedTitleAreaRendererKey,
this); this);
params->delegate = this; params->delegate = this;
......
...@@ -15,13 +15,12 @@ ...@@ -15,13 +15,12 @@
#include "ui/views/widget/widget_delegate.h" #include "ui/views/widget/widget_delegate.h"
namespace aura { namespace aura {
class PropertyConverter;
class Window; class Window;
} }
namespace ash { namespace ash {
class WindowManager;
// This class is used to support immersive fullscreen mode. // This class is used to support immersive fullscreen mode.
// //
// Immersive fullscreen is a specialized fullscreen mode. In it the user can // Immersive fullscreen is a specialized fullscreen mode. In it the user can
...@@ -77,8 +76,8 @@ class DetachedTitleAreaRendererForClient : public views::WidgetDelegate { ...@@ -77,8 +76,8 @@ class DetachedTitleAreaRendererForClient : public views::WidgetDelegate {
public: public:
DetachedTitleAreaRendererForClient( DetachedTitleAreaRendererForClient(
aura::Window* parent, aura::Window* parent,
std::map<std::string, std::vector<uint8_t>>* properties, aura::PropertyConverter* property_converter,
WindowManager* window_manager); std::map<std::string, std::vector<uint8_t>>* properties);
static DetachedTitleAreaRendererForClient* ForWindow(aura::Window* window); static DetachedTitleAreaRendererForClient* ForWindow(aura::Window* window);
......
...@@ -281,7 +281,8 @@ std::unique_ptr<aura::Window> AshTestBase::CreateTestWindow( ...@@ -281,7 +281,8 @@ std::unique_ptr<aura::Window> AshTestBase::CreateTestWindow(
WindowManager* window_manager = WindowManager* window_manager =
ash_test_helper_->window_manager_service()->window_manager(); ash_test_helper_->window_manager_service()->window_manager();
aura::Window* window = CreateAndParentTopLevelWindow( aura::Window* window = CreateAndParentTopLevelWindow(
window_manager, mus_window_type, &properties); window_manager, mus_window_type, window_manager->property_converter(),
&properties);
window->set_id(shell_window_id); window->set_id(shell_window_id);
window->Show(); window->Show();
return base::WrapUnique<aura::Window>(window); return base::WrapUnique<aura::Window>(window);
......
...@@ -364,7 +364,8 @@ aura::Window* WindowManager::OnWmCreateTopLevelWindow( ...@@ -364,7 +364,8 @@ aura::Window* WindowManager::OnWmCreateTopLevelWindow(
return nullptr; return nullptr;
} }
return CreateAndParentTopLevelWindow(this, window_type, properties); return CreateAndParentTopLevelWindow(this, window_type,
property_converter_.get(), properties);
} }
void WindowManager::OnWmClientJankinessChanged( void WindowManager::OnWmClientJankinessChanged(
......
...@@ -116,7 +116,9 @@ WorkspaceEventHandlerMash* MoveEventHandler::GetWorkspaceEventHandlerMash() { ...@@ -116,7 +116,9 @@ WorkspaceEventHandlerMash* MoveEventHandler::GetWorkspaceEventHandlerMash() {
void MoveEventHandler::OnMouseEvent(ui::MouseEvent* event) { void MoveEventHandler::OnMouseEvent(ui::MouseEvent* event) {
toplevel_window_event_handler_.OnMouseEvent(event, window_); toplevel_window_event_handler_.OnMouseEvent(event, window_);
// TODO(crbug.com/842295): Add support for window-service as a library.
if (!toplevel_window_event_handler_.is_drag_in_progress() && if (!toplevel_window_event_handler_.is_drag_in_progress() &&
window_manager_client_ &&
(event->type() == ui::ET_POINTER_MOVED || (event->type() == ui::ET_POINTER_MOVED ||
event->type() == ui::ET_MOUSE_MOVED)) { event->type() == ui::ET_MOUSE_MOVED)) {
const int hit_test_location = const int hit_test_location =
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include "ash/public/cpp/ash_constants.h" #include "ash/public/cpp/ash_constants.h"
#include "ash/public/cpp/immersive/immersive_fullscreen_controller_delegate.h" #include "ash/public/cpp/immersive/immersive_fullscreen_controller_delegate.h"
#include "ash/public/cpp/window_properties.h" #include "ash/public/cpp/window_properties.h"
#include "ash/window_manager.h"
#include "ash/wm/move_event_handler.h" #include "ash/wm/move_event_handler.h"
#include "ash/wm/panels/panel_frame_view.h" #include "ash/wm/panels/panel_frame_view.h"
#include "ash/wm/property_util.h" #include "ash/wm/property_util.h"
...@@ -262,8 +261,11 @@ class ClientViewMus : public views::ClientView { ...@@ -262,8 +261,11 @@ class ClientViewMus : public views::ClientView {
// views::ClientView: // views::ClientView:
bool CanClose() override { bool CanClose() override {
if (!frame_controller_->window()) // TODO(crbug.com/842298): Add support for window-service as a library.
if (!frame_controller_->window() ||
!frame_controller_->window_manager_client()) {
return true; return true;
}
frame_controller_->window_manager_client()->RequestClose( frame_controller_->window_manager_client()->RequestClose(
frame_controller_->window()); frame_controller_->window());
...@@ -283,9 +285,10 @@ NonClientFrameController::NonClientFrameController( ...@@ -283,9 +285,10 @@ NonClientFrameController::NonClientFrameController(
aura::Window* context, aura::Window* context,
const gfx::Rect& bounds, const gfx::Rect& bounds,
ui::mojom::WindowType window_type, ui::mojom::WindowType window_type,
aura::PropertyConverter* property_converter,
std::map<std::string, std::vector<uint8_t>>* properties, std::map<std::string, std::vector<uint8_t>>* properties,
WindowManager* window_manager) aura::WindowManagerClient* window_manager_client)
: window_manager_client_(window_manager->window_manager_client()), : window_manager_client_(window_manager_client),
widget_(new views::Widget), widget_(new views::Widget),
window_(nullptr) { window_(nullptr) {
// To simplify things this code creates a Widget. While a Widget is created // To simplify things this code creates a Widget. While a Widget is created
...@@ -318,8 +321,6 @@ NonClientFrameController::NonClientFrameController( ...@@ -318,8 +321,6 @@ NonClientFrameController::NonClientFrameController(
window_->AddObserver(this); window_->AddObserver(this);
params.native_widget = native_widget; params.native_widget = native_widget;
aura::SetWindowType(window_, window_type); aura::SetWindowType(window_, window_type);
aura::PropertyConverter* property_converter =
window_manager->property_converter();
for (auto& property_pair : *properties) { for (auto& property_pair : *properties) {
property_converter->SetPropertyFromTransportValue( property_converter->SetPropertyFromTransportValue(
window_, property_pair.first, &property_pair.second); window_, property_pair.first, &property_pair.second);
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "ui/views/widget/widget_delegate.h" #include "ui/views/widget/widget_delegate.h"
namespace aura { namespace aura {
class PropertyConverter;
class Window; class Window;
class WindowManagerClient; class WindowManagerClient;
} // namespace aura } // namespace aura
...@@ -37,8 +38,6 @@ enum class WindowType; ...@@ -37,8 +38,6 @@ enum class WindowType;
namespace ash { namespace ash {
class WindowManager;
// Provides the non-client frame for mus Windows. // Provides the non-client frame for mus Windows.
class ASH_EXPORT NonClientFrameController class ASH_EXPORT NonClientFrameController
: public views::WidgetDelegateView, : public views::WidgetDelegateView,
...@@ -48,15 +47,17 @@ class ASH_EXPORT NonClientFrameController ...@@ -48,15 +47,17 @@ class ASH_EXPORT NonClientFrameController
// Creates a new NonClientFrameController and window to render the non-client // Creates a new NonClientFrameController and window to render the non-client
// frame decorations. This deletes itself when |window| is destroyed. |parent| // frame decorations. This deletes itself when |window| is destroyed. |parent|
// is the parent to place the newly created window in, and may be null. If // is the parent to place the newly created window in, and may be null. If
// |parent| is null |context| is used to determine the parent Window. One of // |parent| is null, |context| is used to determine the parent Window. One of
// |parent| or |context| must be non-null. // |parent| or |context| must be non-null. |window_manager_client| may be
// null for now.
NonClientFrameController( NonClientFrameController(
aura::Window* parent, aura::Window* parent,
aura::Window* context, aura::Window* context,
const gfx::Rect& bounds, const gfx::Rect& bounds,
ui::mojom::WindowType window_type, ui::mojom::WindowType window_type,
aura::PropertyConverter* property_converter,
std::map<std::string, std::vector<uint8_t>>* properties, std::map<std::string, std::vector<uint8_t>>* properties,
WindowManager* window_manager); aura::WindowManagerClient* window_manager_client);
// Returns the NonClientFrameController for the specified window, null if // Returns the NonClientFrameController for the specified window, null if
// one was not created. // one was not created.
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "ash/ash_layout_constants.h" #include "ash/ash_layout_constants.h"
#include "ash/test/ash_test_base.h" #include "ash/test/ash_test_base.h"
#include "ash/test/ash_test_helper.h" #include "ash/test/ash_test_helper.h"
#include "ash/window_manager.h"
#include "ash/window_manager_service.h" #include "ash/window_manager_service.h"
#include "ash/wm/top_level_window_factory.h" #include "ash/wm/top_level_window_factory.h"
#include "cc/base/math_util.h" #include "cc/base/math_util.h"
...@@ -105,9 +106,11 @@ class NonClientFrameControllerTest : public AshTestBase { ...@@ -105,9 +106,11 @@ class NonClientFrameControllerTest : public AshTestBase {
TEST_F(NonClientFrameControllerTest, ContentRegionNotDrawnForClient) { TEST_F(NonClientFrameControllerTest, ContentRegionNotDrawnForClient) {
std::map<std::string, std::vector<uint8_t>> properties; std::map<std::string, std::vector<uint8_t>> properties;
auto* window_manager =
ash_test_helper()->window_manager_service()->window_manager();
std::unique_ptr<aura::Window> window(CreateAndParentTopLevelWindow( std::unique_ptr<aura::Window> window(CreateAndParentTopLevelWindow(
ash_test_helper()->window_manager_service()->window_manager(), window_manager, ui::mojom::WindowType::WINDOW,
ui::mojom::WindowType::WINDOW, &properties)); window_manager->property_converter(), &properties));
ASSERT_TRUE(window); ASSERT_TRUE(window);
NonClientFrameController* controller = NonClientFrameController* controller =
......
...@@ -77,9 +77,9 @@ RootWindowController* GetRootWindowControllerForNewTopLevelWindow( ...@@ -77,9 +77,9 @@ RootWindowController* GetRootWindowControllerForNewTopLevelWindow(
// Returns the bounds for the new window. // Returns the bounds for the new window.
gfx::Rect CalculateDefaultBounds( gfx::Rect CalculateDefaultBounds(
WindowManager* window_manager,
RootWindowController* root_window_controller, RootWindowController* root_window_controller,
aura::Window* container_window, aura::Window* container_window,
aura::PropertyConverter* property_converter,
const std::map<std::string, std::vector<uint8_t>>* properties) { const std::map<std::string, std::vector<uint8_t>>* properties) {
gfx::Rect requested_bounds; gfx::Rect requested_bounds;
if (GetInitialBounds(*properties, &requested_bounds)) if (GetInitialBounds(*properties, &requested_bounds))
...@@ -90,8 +90,7 @@ gfx::Rect CalculateDefaultBounds( ...@@ -90,8 +90,7 @@ gfx::Rect CalculateDefaultBounds(
auto show_state_iter = auto show_state_iter =
properties->find(ui::mojom::WindowManager::kShowState_Property); properties->find(ui::mojom::WindowManager::kShowState_Property);
if (show_state_iter != properties->end()) { if (show_state_iter != properties->end()) {
if (IsFullscreen(window_manager->property_converter(), if (IsFullscreen(property_converter, show_state_iter->second)) {
show_state_iter->second)) {
gfx::Rect bounds(root_size); gfx::Rect bounds(root_size);
if (!container_window) { if (!container_window) {
const display::Display display = const display::Display display =
...@@ -121,9 +120,10 @@ gfx::Rect CalculateDefaultBounds( ...@@ -121,9 +120,10 @@ gfx::Rect CalculateDefaultBounds(
// Does the real work of CreateAndParentTopLevelWindow() once the appropriate // Does the real work of CreateAndParentTopLevelWindow() once the appropriate
// RootWindowController was found. // RootWindowController was found.
aura::Window* CreateAndParentTopLevelWindowInRoot( aura::Window* CreateAndParentTopLevelWindowInRoot(
WindowManager* window_manager, aura::WindowManagerClient* window_manager_client,
RootWindowController* root_window_controller, RootWindowController* root_window_controller,
ui::mojom::WindowType window_type, ui::mojom::WindowType window_type,
aura::PropertyConverter* property_converter,
std::map<std::string, std::vector<uint8_t>>* properties) { std::map<std::string, std::vector<uint8_t>>* properties) {
// TODO(sky): constrain and validate properties. // TODO(sky): constrain and validate properties.
...@@ -138,7 +138,7 @@ aura::Window* CreateAndParentTopLevelWindowInRoot( ...@@ -138,7 +138,7 @@ aura::Window* CreateAndParentTopLevelWindowInRoot(
} }
gfx::Rect bounds = CalculateDefaultBounds( gfx::Rect bounds = CalculateDefaultBounds(
window_manager, root_window_controller, container_window, properties); root_window_controller, container_window, property_converter, properties);
const bool provide_non_client_frame = const bool provide_non_client_frame =
window_type == ui::mojom::WindowType::WINDOW || window_type == ui::mojom::WindowType::WINDOW ||
...@@ -147,13 +147,11 @@ aura::Window* CreateAndParentTopLevelWindowInRoot( ...@@ -147,13 +147,11 @@ aura::Window* CreateAndParentTopLevelWindowInRoot(
// See NonClientFrameController for details on lifetime. // See NonClientFrameController for details on lifetime.
NonClientFrameController* non_client_frame_controller = NonClientFrameController* non_client_frame_controller =
new NonClientFrameController(container_window, context, bounds, new NonClientFrameController(container_window, context, bounds,
window_type, properties, window_manager); window_type, property_converter,
properties, window_manager_client);
return non_client_frame_controller->window(); return non_client_frame_controller->window();
} }
aura::PropertyConverter* property_converter =
window_manager->property_converter();
if (window_type == ui::mojom::WindowType::POPUP && if (window_type == ui::mojom::WindowType::POPUP &&
ShouldRenderTitleArea(property_converter, *properties)) { ShouldRenderTitleArea(property_converter, *properties)) {
// Pick a parent so display information is obtained. Will pick the real one // Pick a parent so display information is obtained. Will pick the real one
...@@ -164,7 +162,7 @@ aura::Window* CreateAndParentTopLevelWindowInRoot( ...@@ -164,7 +162,7 @@ aura::Window* CreateAndParentTopLevelWindowInRoot(
// DetachedTitleAreaRendererForClient is owned by the client. // DetachedTitleAreaRendererForClient is owned by the client.
DetachedTitleAreaRendererForClient* renderer = DetachedTitleAreaRendererForClient* renderer =
new DetachedTitleAreaRendererForClient(unparented_control_container, new DetachedTitleAreaRendererForClient(unparented_control_container,
properties, window_manager); property_converter, properties);
return renderer->widget()->GetNativeView(); return renderer->widget()->GetNativeView();
} }
...@@ -197,11 +195,13 @@ aura::Window* CreateAndParentTopLevelWindowInRoot( ...@@ -197,11 +195,13 @@ aura::Window* CreateAndParentTopLevelWindowInRoot(
aura::Window* CreateAndParentTopLevelWindow( aura::Window* CreateAndParentTopLevelWindow(
WindowManager* window_manager, WindowManager* window_manager,
ui::mojom::WindowType window_type, ui::mojom::WindowType window_type,
aura::PropertyConverter* property_converter,
std::map<std::string, std::vector<uint8_t>>* properties) { std::map<std::string, std::vector<uint8_t>>* properties) {
RootWindowController* root_window_controller = RootWindowController* root_window_controller =
GetRootWindowControllerForNewTopLevelWindow(properties); GetRootWindowControllerForNewTopLevelWindow(properties);
aura::Window* window = CreateAndParentTopLevelWindowInRoot( aura::Window* window = CreateAndParentTopLevelWindowInRoot(
window_manager, root_window_controller, window_type, properties); window_manager ? window_manager->window_manager_client() : nullptr,
root_window_controller, window_type, property_converter, properties);
DisconnectedAppHandler::Create(window); DisconnectedAppHandler::Create(window);
auto ignored_by_shelf_iter = properties->find( auto ignored_by_shelf_iter = properties->find(
...@@ -218,7 +218,9 @@ aura::Window* CreateAndParentTopLevelWindow( ...@@ -218,7 +218,9 @@ aura::Window* CreateAndParentTopLevelWindow(
properties->find(ui::mojom::WindowManager::kFocusable_InitProperty); properties->find(ui::mojom::WindowManager::kFocusable_InitProperty);
if (focusable_iter != properties->end()) { if (focusable_iter != properties->end()) {
bool can_focus = mojo::ConvertTo<bool>(focusable_iter->second); bool can_focus = mojo::ConvertTo<bool>(focusable_iter->second);
window_manager->window_tree_client()->SetCanFocus(window, can_focus); // TODO(crbug.com/842301): Add support for window-service as a library.
if (window_manager)
window_manager->window_tree_client()->SetCanFocus(window, can_focus);
NonClientFrameController* non_client_frame_controller = NonClientFrameController* non_client_frame_controller =
NonClientFrameController::Get(window); NonClientFrameController::Get(window);
if (non_client_frame_controller) if (non_client_frame_controller)
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "ash/ash_export.h" #include "ash/ash_export.h"
namespace aura { namespace aura {
class PropertyConverter;
class Window; class Window;
} }
...@@ -29,9 +30,11 @@ class WindowManager; ...@@ -29,9 +30,11 @@ class WindowManager;
// Creates and parents a new top-level window and returns it. The returned // Creates and parents a new top-level window and returns it. The returned
// aura::Window is owned by its parent. // aura::Window is owned by its parent.
// TODO(ws): Refine this for the Window Service as-a-library (no WindowManager).
ASH_EXPORT aura::Window* CreateAndParentTopLevelWindow( ASH_EXPORT aura::Window* CreateAndParentTopLevelWindow(
WindowManager* window_manager, WindowManager* window_manager,
ui::mojom::WindowType window_type, ui::mojom::WindowType window_type,
aura::PropertyConverter* property_converter,
std::map<std::string, std::vector<uint8_t>>* properties); std::map<std::string, std::vector<uint8_t>>* properties);
} // namespace ash } // namespace ash
......
...@@ -44,7 +44,8 @@ aura::Window* CreateFullscreenTestWindow(WindowManager* window_manager, ...@@ -44,7 +44,8 @@ aura::Window* CreateFullscreenTestWindow(WindowManager* window_manager,
mojo::ConvertTo<std::vector<uint8_t>>(display_id); mojo::ConvertTo<std::vector<uint8_t>>(display_id);
} }
aura::Window* window = CreateAndParentTopLevelWindow( aura::Window* window = CreateAndParentTopLevelWindow(
window_manager, ui::mojom::WindowType::WINDOW, &properties); window_manager, ui::mojom::WindowType::WINDOW,
window_manager->property_converter(), &properties);
window->Show(); window->Show();
return window; return window;
} }
...@@ -84,9 +85,11 @@ using TopLevelWindowFactoryAshTest = AshTestBase; ...@@ -84,9 +85,11 @@ using TopLevelWindowFactoryAshTest = AshTestBase;
TEST_F(TopLevelWindowFactoryAshTest, TopLevelNotShownOnCreate) { TEST_F(TopLevelWindowFactoryAshTest, TopLevelNotShownOnCreate) {
std::map<std::string, std::vector<uint8_t>> properties; std::map<std::string, std::vector<uint8_t>> properties;
auto* window_manager =
ash_test_helper()->window_manager_service()->window_manager();
std::unique_ptr<aura::Window> window(CreateAndParentTopLevelWindow( std::unique_ptr<aura::Window> window(CreateAndParentTopLevelWindow(
ash_test_helper()->window_manager_service()->window_manager(), window_manager, ui::mojom::WindowType::WINDOW,
ui::mojom::WindowType::WINDOW, &properties)); window_manager->property_converter(), &properties));
ASSERT_TRUE(window); ASSERT_TRUE(window);
EXPECT_FALSE(window->IsVisible()); EXPECT_FALSE(window->IsVisible());
} }
...@@ -106,7 +109,8 @@ TEST_F(TopLevelWindowFactoryAshTest, CreateTopLevelWindow) { ...@@ -106,7 +109,8 @@ TEST_F(TopLevelWindowFactoryAshTest, CreateTopLevelWindow) {
ash_test_helper()->window_manager_service()->window_manager(); ash_test_helper()->window_manager_service()->window_manager();
// |window| is owned by its parent. // |window| is owned by its parent.
aura::Window* window = CreateAndParentTopLevelWindow( aura::Window* window = CreateAndParentTopLevelWindow(
window_manager, ui::mojom::WindowType::WINDOW, &properties); window_manager, ui::mojom::WindowType::WINDOW,
window_manager->property_converter(), &properties);
ASSERT_TRUE(window->parent()); ASSERT_TRUE(window->parent());
EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id()); EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
EXPECT_EQ(bounds, window->bounds()); EXPECT_EQ(bounds, window->bounds());
......
...@@ -5,6 +5,11 @@ ...@@ -5,6 +5,11 @@
#include "ash/ws/window_service_delegate_impl.h" #include "ash/ws/window_service_delegate_impl.h"
#include "ash/wm/container_finder.h" #include "ash/wm/container_finder.h"
#include "ash/wm/top_level_window_factory.h"
#include "mojo/public/cpp/bindings/map.h"
#include "services/ui/public/cpp/property_type_converters.h"
#include "services/ui/public/interfaces/window_manager.mojom.h"
#include "services/ui/public/interfaces/window_manager_constants.mojom.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
namespace ash { namespace ash {
...@@ -14,15 +19,22 @@ WindowServiceDelegateImpl::WindowServiceDelegateImpl() = default; ...@@ -14,15 +19,22 @@ WindowServiceDelegateImpl::WindowServiceDelegateImpl() = default;
WindowServiceDelegateImpl::~WindowServiceDelegateImpl() = default; WindowServiceDelegateImpl::~WindowServiceDelegateImpl() = default;
std::unique_ptr<aura::Window> WindowServiceDelegateImpl::NewTopLevel( std::unique_ptr<aura::Window> WindowServiceDelegateImpl::NewTopLevel(
aura::PropertyConverter* property_converter,
const base::flat_map<std::string, std::vector<uint8_t>>& properties) { const base::flat_map<std::string, std::vector<uint8_t>>& properties) {
// TODO: this needs to call CreateAndParentTopLevelWindow(); std::map<std::string, std::vector<uint8_t>> property_map =
std::unique_ptr<aura::Window> window = mojo::FlatMapToMap(properties);
std::make_unique<aura::Window>(nullptr); ui::mojom::WindowType window_type = ui::mojom::WindowType::UNKNOWN;
window->SetType(aura::client::WINDOW_TYPE_NORMAL); auto type_iter =
window->Init(ui::LAYER_NOT_DRAWN); property_map.find(ui::mojom::WindowManager::kWindowType_InitProperty);
ash::wm::GetDefaultParent(window.get(), gfx::Rect())->AddChild(window.get()); if (type_iter != property_map.end()) {
// TODO(crbug.com/837695): Apply |properties|. window_type = static_cast<ui::mojom::WindowType>(
return window; mojo::ConvertTo<int32_t>(type_iter->second));
}
auto* window =
CreateAndParentTopLevelWindow(nullptr /* window_manager */, window_type,
property_converter, &property_map);
return base::WrapUnique<aura::Window>(window);
} }
} // namespace ash } // namespace ash
...@@ -18,6 +18,7 @@ class WindowServiceDelegateImpl : public ui::ws2::WindowServiceDelegate { ...@@ -18,6 +18,7 @@ class WindowServiceDelegateImpl : public ui::ws2::WindowServiceDelegate {
// ui::ws2::WindowServiceDelegate: // ui::ws2::WindowServiceDelegate:
std::unique_ptr<aura::Window> NewTopLevel( std::unique_ptr<aura::Window> NewTopLevel(
aura::PropertyConverter* property_converter,
const base::flat_map<std::string, std::vector<uint8_t>>& properties) const base::flat_map<std::string, std::vector<uint8_t>>& properties)
override; override;
......
...@@ -122,11 +122,16 @@ class TestWindowService : public service_manager::Service, ...@@ -122,11 +122,16 @@ class TestWindowService : public service_manager::Service,
private: private:
// WindowServiceDelegate: // WindowServiceDelegate:
std::unique_ptr<aura::Window> NewTopLevel( std::unique_ptr<aura::Window> NewTopLevel(
aura::PropertyConverter* property_converter,
const base::flat_map<std::string, std::vector<uint8_t>>& properties) const base::flat_map<std::string, std::vector<uint8_t>>& properties)
override { override {
std::unique_ptr<aura::Window> top_level = std::unique_ptr<aura::Window> top_level =
std::make_unique<aura::Window>(nullptr); std::make_unique<aura::Window>(nullptr);
top_level->Init(LAYER_NOT_DRAWN); top_level->Init(LAYER_NOT_DRAWN);
for (auto property : properties) {
property_converter->SetPropertyFromTransportValue(
top_level.get(), property.first, &property.second);
}
return top_level; return top_level;
} }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "services/ui/ws2/test_window_service_delegate.h" #include "services/ui/ws2/test_window_service_delegate.h"
#include "ui/aura/mus/property_converter.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
namespace ui { namespace ui {
...@@ -16,12 +17,17 @@ TestWindowServiceDelegate::TestWindowServiceDelegate( ...@@ -16,12 +17,17 @@ TestWindowServiceDelegate::TestWindowServiceDelegate(
TestWindowServiceDelegate::~TestWindowServiceDelegate() = default; TestWindowServiceDelegate::~TestWindowServiceDelegate() = default;
std::unique_ptr<aura::Window> TestWindowServiceDelegate::NewTopLevel( std::unique_ptr<aura::Window> TestWindowServiceDelegate::NewTopLevel(
aura::PropertyConverter* property_converter,
const base::flat_map<std::string, std::vector<uint8_t>>& properties) { const base::flat_map<std::string, std::vector<uint8_t>>& properties) {
std::unique_ptr<aura::Window> window = std::unique_ptr<aura::Window> window =
std::make_unique<aura::Window>(nullptr); std::make_unique<aura::Window>(nullptr);
window->Init(LAYER_NOT_DRAWN); window->Init(LAYER_NOT_DRAWN);
if (top_level_parent_) if (top_level_parent_)
top_level_parent_->AddChild(window.get()); top_level_parent_->AddChild(window.get());
for (auto property : properties) {
property_converter->SetPropertyFromTransportValue(
window.get(), property.first, &property.second);
}
return window; return window;
} }
......
...@@ -24,6 +24,7 @@ class TestWindowServiceDelegate : public WindowServiceDelegate { ...@@ -24,6 +24,7 @@ class TestWindowServiceDelegate : public WindowServiceDelegate {
// WindowServiceDelegate: // WindowServiceDelegate:
std::unique_ptr<aura::Window> NewTopLevel( std::unique_ptr<aura::Window> NewTopLevel(
aura::PropertyConverter* property_converter,
const base::flat_map<std::string, std::vector<uint8_t>>& properties) const base::flat_map<std::string, std::vector<uint8_t>>& properties)
override; override;
......
...@@ -697,7 +697,8 @@ void WindowServiceClient::NewTopLevelWindow( ...@@ -697,7 +697,8 @@ void WindowServiceClient::NewTopLevelWindow(
return; return;
} }
std::unique_ptr<aura::Window> top_level_ptr = std::unique_ptr<aura::Window> top_level_ptr =
window_service_->delegate()->NewTopLevel(properties); window_service_->delegate()->NewTopLevel(
window_service_->property_converter(), properties);
if (!top_level_ptr) { if (!top_level_ptr) {
DVLOG(1) << "NewTopLevelWindow failed (delegate window creation failed)"; DVLOG(1) << "NewTopLevelWindow failed (delegate window creation failed)";
window_tree_client_->OnChangeCompleted(change_id, false); window_tree_client_->OnChangeCompleted(change_id, false);
......
...@@ -20,8 +20,8 @@ mojom::WindowTree* WindowServiceClientTestHelper::window_tree() { ...@@ -20,8 +20,8 @@ mojom::WindowTree* WindowServiceClientTestHelper::window_tree() {
} }
aura::Window* WindowServiceClientTestHelper::NewTopLevelWindow( aura::Window* WindowServiceClientTestHelper::NewTopLevelWindow(
Id transport_window_id) { Id transport_window_id,
base::flat_map<std::string, std::vector<uint8_t>> properties; base::flat_map<std::string, std::vector<uint8_t>> properties) {
const uint32_t change_id = 1u; const uint32_t change_id = 1u;
window_service_client_->NewTopLevelWindow(change_id, transport_window_id, window_service_client_->NewTopLevelWindow(change_id, transport_window_id,
properties); properties);
......
...@@ -5,8 +5,10 @@ ...@@ -5,8 +5,10 @@
#ifndef SERVICES_UI_WS2_WINDOW_SERVICE_CLIENT_TEST_HELPER_H_ #ifndef SERVICES_UI_WS2_WINDOW_SERVICE_CLIENT_TEST_HELPER_H_
#define SERVICES_UI_WS2_WINDOW_SERVICE_CLIENT_TEST_HELPER_H_ #define SERVICES_UI_WS2_WINDOW_SERVICE_CLIENT_TEST_HELPER_H_
#include <string>
#include <vector> #include <vector>
#include "base/containers/flat_map.h"
#include "base/macros.h" #include "base/macros.h"
#include "services/ui/ws2/ids.h" #include "services/ui/ws2/ids.h"
...@@ -39,7 +41,9 @@ class WindowServiceClientTestHelper { ...@@ -39,7 +41,9 @@ class WindowServiceClientTestHelper {
mojom::WindowTree* window_tree(); mojom::WindowTree* window_tree();
aura::Window* NewTopLevelWindow(Id transport_window_id); aura::Window* NewTopLevelWindow(
Id transport_window_id,
base::flat_map<std::string, std::vector<uint8_t>> properties = {});
void SetWindowBounds(aura::Window* window, void SetWindowBounds(aura::Window* window,
const gfx::Rect& bounds, const gfx::Rect& bounds,
uint32_t change_id = 1); uint32_t change_id = 1);
......
...@@ -66,13 +66,12 @@ class WindowServiceTestHelper { ...@@ -66,13 +66,12 @@ class WindowServiceTestHelper {
aura::Window* root() { return aura_test_helper_.root_window(); } aura::Window* root() { return aura_test_helper_.root_window(); }
TestWindowServiceDelegate* delegate() { return &delegate_; } TestWindowServiceDelegate* delegate() { return &delegate_; }
TestWindowTreeClient* window_tree_client() { return &window_tree_client_; } TestWindowTreeClient* window_tree_client() { return &window_tree_client_; }
WindowServiceClientTestHelper* helper() { return helper_.get(); }
std::vector<Change>* changes() { std::vector<Change>* changes() {
return window_tree_client_.tracker()->changes(); return window_tree_client_.tracker()->changes();
} }
std::unique_ptr<WindowServiceClientTestHelper> helper_;
private: private:
base::test::ScopedTaskEnvironment task_environment_{ base::test::ScopedTaskEnvironment task_environment_{
base::test::ScopedTaskEnvironment::MainThreadType::UI}; base::test::ScopedTaskEnvironment::MainThreadType::UI};
...@@ -81,6 +80,7 @@ class WindowServiceTestHelper { ...@@ -81,6 +80,7 @@ class WindowServiceTestHelper {
std::unique_ptr<WindowService> service_; std::unique_ptr<WindowService> service_;
TestWindowTreeClient window_tree_client_; TestWindowTreeClient window_tree_client_;
std::unique_ptr<WindowServiceClient> window_service_client_; std::unique_ptr<WindowServiceClient> window_service_client_;
std::unique_ptr<WindowServiceClientTestHelper> helper_;
DISALLOW_COPY_AND_ASSIGN(WindowServiceTestHelper); DISALLOW_COPY_AND_ASSIGN(WindowServiceTestHelper);
}; };
...@@ -118,20 +118,34 @@ class TestLayoutManager : public aura::LayoutManager { ...@@ -118,20 +118,34 @@ class TestLayoutManager : public aura::LayoutManager {
TEST(WindowServiceClientTest, CreateTopLevel) { TEST(WindowServiceClientTest, CreateTopLevel) {
WindowServiceTestHelper helper; WindowServiceTestHelper helper;
EXPECT_TRUE(helper.changes()->empty()); EXPECT_TRUE(helper.changes()->empty());
aura::Window* top_level = helper.helper_->NewTopLevelWindow(1); aura::Window* top_level = helper.helper()->NewTopLevelWindow(1);
ASSERT_TRUE(top_level);
EXPECT_EQ("TopLevelCreated id=1 window_id=0,1 drawn=false",
SingleChangeToDescription(*helper.changes()));
helper.changes()->clear();
}
TEST(WindowServiceClientTest, CreateTopLevelWithProperties) {
WindowServiceTestHelper helper;
EXPECT_TRUE(helper.changes()->empty());
aura::PropertyConverter::PrimitiveType value = true;
std::vector<uint8_t> transport = mojo::ConvertTo<std::vector<uint8_t>>(value);
aura::Window* top_level = helper.helper()->NewTopLevelWindow(
1, {{ui::mojom::WindowManager::kAlwaysOnTop_Property, transport}});
ASSERT_TRUE(top_level); ASSERT_TRUE(top_level);
EXPECT_EQ("TopLevelCreated id=1 window_id=0,1 drawn=false", EXPECT_EQ("TopLevelCreated id=1 window_id=0,1 drawn=false",
SingleChangeToDescription(*helper.changes())); SingleChangeToDescription(*helper.changes()));
EXPECT_TRUE(top_level->GetProperty(aura::client::kAlwaysOnTopKey));
helper.changes()->clear(); helper.changes()->clear();
} }
TEST(WindowServiceClientTest, SetBounds) { TEST(WindowServiceClientTest, SetBounds) {
WindowServiceTestHelper helper; WindowServiceTestHelper helper;
aura::Window* top_level = helper.helper_->NewTopLevelWindow(1); aura::Window* top_level = helper.helper()->NewTopLevelWindow(1);
helper.changes()->clear(); helper.changes()->clear();
const gfx::Rect bounds_from_client = gfx::Rect(1, 2, 300, 400); const gfx::Rect bounds_from_client = gfx::Rect(1, 2, 300, 400);
helper.helper_->SetWindowBounds(top_level, bounds_from_client, 2); helper.helper()->SetWindowBounds(top_level, bounds_from_client, 2);
EXPECT_EQ(bounds_from_client, top_level->bounds()); EXPECT_EQ(bounds_from_client, top_level->bounds());
EXPECT_EQ("ChangeCompleted id=2 sucess=true", EXPECT_EQ("ChangeCompleted id=2 sucess=true",
SingleChangeToDescription(*helper.changes())); SingleChangeToDescription(*helper.changes()));
...@@ -151,7 +165,7 @@ TEST(WindowServiceClientTest, SetBounds) { ...@@ -151,7 +165,7 @@ TEST(WindowServiceClientTest, SetBounds) {
const gfx::Rect restricted_bounds = gfx::Rect(401, 405, 406, 407); const gfx::Rect restricted_bounds = gfx::Rect(401, 405, 406, 407);
layout_manager->set_next_bounds(restricted_bounds); layout_manager->set_next_bounds(restricted_bounds);
top_level->parent()->SetLayoutManager(layout_manager); top_level->parent()->SetLayoutManager(layout_manager);
helper.helper_->SetWindowBounds(top_level, bounds_from_client, 3); helper.helper()->SetWindowBounds(top_level, bounds_from_client, 3);
ASSERT_EQ(2u, helper.changes()->size()); ASSERT_EQ(2u, helper.changes()->size());
// The layout manager changes the bounds to a different value than the client // The layout manager changes the bounds to a different value than the client
// requested, so the client should get OnWindowBoundsChanged() with // requested, so the client should get OnWindowBoundsChanged() with
...@@ -167,13 +181,13 @@ TEST(WindowServiceClientTest, SetBounds) { ...@@ -167,13 +181,13 @@ TEST(WindowServiceClientTest, SetBounds) {
TEST(WindowServiceClientTest, SetProperty) { TEST(WindowServiceClientTest, SetProperty) {
WindowServiceTestHelper helper; WindowServiceTestHelper helper;
aura::Window* top_level = helper.helper_->NewTopLevelWindow(1); aura::Window* top_level = helper.helper()->NewTopLevelWindow(1);
helper.changes()->clear(); helper.changes()->clear();
EXPECT_FALSE(top_level->GetProperty(aura::client::kAlwaysOnTopKey)); EXPECT_FALSE(top_level->GetProperty(aura::client::kAlwaysOnTopKey));
aura::PropertyConverter::PrimitiveType value = true; aura::PropertyConverter::PrimitiveType value = true;
std::vector<uint8_t> transport = mojo::ConvertTo<std::vector<uint8_t>>(value); std::vector<uint8_t> transport = mojo::ConvertTo<std::vector<uint8_t>>(value);
helper.helper_->SetWindowProperty( helper.helper()->SetWindowProperty(
top_level, ui::mojom::WindowManager::kAlwaysOnTop_Property, transport, 2); top_level, ui::mojom::WindowManager::kAlwaysOnTop_Property, transport, 2);
EXPECT_EQ("ChangeCompleted id=2 sucess=true", EXPECT_EQ("ChangeCompleted id=2 sucess=true",
SingleChangeToDescription(*helper.changes())); SingleChangeToDescription(*helper.changes()));
...@@ -184,14 +198,14 @@ TEST(WindowServiceClientTest, SetProperty) { ...@@ -184,14 +198,14 @@ TEST(WindowServiceClientTest, SetProperty) {
TEST(WindowServiceClientTest, PointerWatcher) { TEST(WindowServiceClientTest, PointerWatcher) {
WindowServiceTestHelper helper; WindowServiceTestHelper helper;
TestWindowTreeClient* window_tree_client = helper.window_tree_client(); TestWindowTreeClient* window_tree_client = helper.window_tree_client();
aura::Window* top_level = helper.helper_->NewTopLevelWindow(1); aura::Window* top_level = helper.helper()->NewTopLevelWindow(1);
ASSERT_TRUE(top_level); ASSERT_TRUE(top_level);
helper.helper_->SetEventTargetingPolicy(top_level, helper.helper()->SetEventTargetingPolicy(top_level,
mojom::EventTargetingPolicy::NONE); mojom::EventTargetingPolicy::NONE);
EXPECT_EQ(mojom::EventTargetingPolicy::NONE, EXPECT_EQ(mojom::EventTargetingPolicy::NONE,
top_level->event_targeting_policy()); top_level->event_targeting_policy());
// Start the pointer watcher only for pointer down/up. // Start the pointer watcher only for pointer down/up.
helper.helper_->window_tree()->StartPointerWatcher(false); helper.helper()->window_tree()->StartPointerWatcher(false);
top_level->Show(); top_level->Show();
top_level->SetBounds(gfx::Rect(10, 10, 100, 100)); top_level->SetBounds(gfx::Rect(10, 10, 100, 100));
...@@ -222,7 +236,7 @@ TEST(WindowServiceClientTest, PointerWatcher) { ...@@ -222,7 +236,7 @@ TEST(WindowServiceClientTest, PointerWatcher) {
} }
// Enable observing move events. // Enable observing move events.
helper.helper_->window_tree()->StartPointerWatcher(true); helper.helper()->window_tree()->StartPointerWatcher(true);
event_generator.MoveMouseTo(8, 9); event_generator.MoveMouseTo(8, 9);
{ {
ASSERT_EQ(1u, window_tree_client->observed_pointer_events().size()); ASSERT_EQ(1u, window_tree_client->observed_pointer_events().size());
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "base/containers/flat_map.h" #include "base/containers/flat_map.h"
namespace aura { namespace aura {
class PropertyConverter;
class Window; class Window;
} }
...@@ -28,6 +29,7 @@ class COMPONENT_EXPORT(WINDOW_SERVICE) WindowServiceDelegate { ...@@ -28,6 +29,7 @@ class COMPONENT_EXPORT(WINDOW_SERVICE) WindowServiceDelegate {
// new window, parenting it in the appropriate container. Return null to // new window, parenting it in the appropriate container. Return null to
// reject the request. // reject the request.
virtual std::unique_ptr<aura::Window> NewTopLevel( virtual std::unique_ptr<aura::Window> NewTopLevel(
aura::PropertyConverter* property_converter,
const base::flat_map<std::string, std::vector<uint8_t>>& properties) = 0; const base::flat_map<std::string, std::vector<uint8_t>>& properties) = 0;
protected: protected:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment