Commit 72c2bf6c authored by Mike Wasserman's avatar Mike Wasserman Committed by Commit Bot

ws: Add property support to WindowServiceClient::NewWindow

Make a shared helper for getting the window type from properties.
Apply properties to the window like the old WindowTreeClient.

Bug: 837695
Change-Id: Icfe1efcddb52b2c3ef9d3ed218e02c105885e230
Reviewed-on: https://chromium-review.googlesource.com/1056349
Commit-Queue: Michael Wasserman <msw@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#558209}
parent 7f917836
...@@ -7,9 +7,9 @@ ...@@ -7,9 +7,9 @@
#include "ash/wm/container_finder.h" #include "ash/wm/container_finder.h"
#include "ash/wm/top_level_window_factory.h" #include "ash/wm/top_level_window_factory.h"
#include "mojo/public/cpp/bindings/map.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.mojom.h"
#include "services/ui/public/interfaces/window_manager_constants.mojom.h" #include "services/ui/public/interfaces/window_manager_constants.mojom.h"
#include "ui/aura/mus/property_utils.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
namespace ash { namespace ash {
...@@ -23,13 +23,8 @@ std::unique_ptr<aura::Window> WindowServiceDelegateImpl::NewTopLevel( ...@@ -23,13 +23,8 @@ std::unique_ptr<aura::Window> WindowServiceDelegateImpl::NewTopLevel(
const base::flat_map<std::string, std::vector<uint8_t>>& properties) { const base::flat_map<std::string, std::vector<uint8_t>>& properties) {
std::map<std::string, std::vector<uint8_t>> property_map = std::map<std::string, std::vector<uint8_t>> property_map =
mojo::FlatMapToMap(properties); mojo::FlatMapToMap(properties);
ui::mojom::WindowType window_type = ui::mojom::WindowType::UNKNOWN; ui::mojom::WindowType window_type =
auto type_iter = aura::GetWindowTypeFromProperties(property_map);
property_map.find(ui::mojom::WindowManager::kWindowType_InitProperty);
if (type_iter != property_map.end()) {
window_type = static_cast<ui::mojom::WindowType>(
mojo::ConvertTo<int32_t>(type_iter->second));
}
auto* window = auto* window =
CreateAndParentTopLevelWindow(nullptr /* window_manager */, window_type, CreateAndParentTopLevelWindow(nullptr /* window_manager */, window_type,
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "ui/aura/client/transient_window_client.h" #include "ui/aura/client/transient_window_client.h"
#include "ui/aura/env.h" #include "ui/aura/env.h"
#include "ui/aura/mus/property_converter.h" #include "ui/aura/mus/property_converter.h"
#include "ui/aura/mus/property_utils.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/aura/window_observer.h" #include "ui/aura/window_observer.h"
#include "ui/aura/window_tree_host.h" #include "ui/aura/window_tree_host.h"
...@@ -375,10 +376,15 @@ bool WindowServiceClient::NewWindowImpl( ...@@ -375,10 +376,15 @@ bool WindowServiceClient::NewWindowImpl(
} }
aura::Window* window = AddClientCreatedWindow( aura::Window* window = AddClientCreatedWindow(
client_window_id, std::make_unique<aura::Window>(nullptr)); client_window_id, std::make_unique<aura::Window>(nullptr));
SetWindowType(window, aura::GetWindowTypeFromProperties(properties));
for (auto& pair : properties) {
window_service_->property_converter()->SetPropertyFromTransportValue(
window, pair.first, &pair.second);
}
window->Init(LAYER_NOT_DRAWN); window->Init(LAYER_NOT_DRAWN);
// Windows created by the client should only be destroyed by the client. // Windows created by the client should only be destroyed by the client.
window->set_owned_by_parent(false); window->set_owned_by_parent(false);
// TODO(crbug.com/837695): Apply |properties|.
return true; return true;
} }
...@@ -668,9 +674,9 @@ void WindowServiceClient::NewWindow( ...@@ -668,9 +674,9 @@ void WindowServiceClient::NewWindow(
Id transport_window_id, Id transport_window_id,
const base::Optional<base::flat_map<std::string, std::vector<uint8_t>>>& const base::Optional<base::flat_map<std::string, std::vector<uint8_t>>>&
transport_properties) { transport_properties) {
// TODO(crbug.com/837695): Map and validate |transport_properties|.
std::map<std::string, std::vector<uint8_t>> properties; std::map<std::string, std::vector<uint8_t>> properties;
if (transport_properties.has_value())
properties = mojo::FlatMapToMap(transport_properties.value());
window_tree_client_->OnChangeCompleted( window_tree_client_->OnChangeCompleted(
change_id, change_id,
NewWindowImpl(MakeClientWindowId(transport_window_id), properties)); NewWindowImpl(MakeClientWindowId(transport_window_id), properties));
......
...@@ -19,6 +19,15 @@ mojom::WindowTree* WindowServiceClientTestHelper::window_tree() { ...@@ -19,6 +19,15 @@ mojom::WindowTree* WindowServiceClientTestHelper::window_tree() {
return static_cast<mojom::WindowTree*>(window_service_client_); return static_cast<mojom::WindowTree*>(window_service_client_);
} }
aura::Window* WindowServiceClientTestHelper::NewWindow(
Id transport_window_id,
base::flat_map<std::string, std::vector<uint8_t>> properties) {
const uint32_t change_id = 1u;
window_service_client_->NewWindow(change_id, transport_window_id, properties);
return window_service_client_->GetWindowByClientId(
window_service_client_->MakeClientWindowId(transport_window_id));
}
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) {
......
...@@ -41,6 +41,9 @@ class WindowServiceClientTestHelper { ...@@ -41,6 +41,9 @@ class WindowServiceClientTestHelper {
mojom::WindowTree* window_tree(); mojom::WindowTree* window_tree();
aura::Window* NewWindow(
Id transport_window_id,
base::flat_map<std::string, std::vector<uint8_t>> properties = {});
aura::Window* NewTopLevelWindow( aura::Window* 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 = {});
......
...@@ -115,7 +115,31 @@ class TestLayoutManager : public aura::LayoutManager { ...@@ -115,7 +115,31 @@ class TestLayoutManager : public aura::LayoutManager {
DISALLOW_COPY_AND_ASSIGN(TestLayoutManager); DISALLOW_COPY_AND_ASSIGN(TestLayoutManager);
}; };
TEST(WindowServiceClientTest, CreateTopLevel) { TEST(WindowServiceClientTest, NewWindow) {
WindowServiceTestHelper helper;
EXPECT_TRUE(helper.changes()->empty());
aura::Window* top_level = helper.helper()->NewWindow(1);
ASSERT_TRUE(top_level);
EXPECT_EQ("ChangeCompleted id=1 sucess=true",
SingleChangeToDescription(*helper.changes()));
helper.changes()->clear();
}
TEST(WindowServiceClientTest, NewWindowWithProperties) {
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()->NewWindow(
1, {{ui::mojom::WindowManager::kAlwaysOnTop_Property, transport}});
ASSERT_TRUE(top_level);
EXPECT_EQ("ChangeCompleted id=1 sucess=true",
SingleChangeToDescription(*helper.changes()));
EXPECT_TRUE(top_level->GetProperty(aura::client::kAlwaysOnTopKey));
helper.changes()->clear();
}
TEST(WindowServiceClientTest, NewTopLevelWindow) {
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);
...@@ -125,7 +149,7 @@ TEST(WindowServiceClientTest, CreateTopLevel) { ...@@ -125,7 +149,7 @@ TEST(WindowServiceClientTest, CreateTopLevel) {
helper.changes()->clear(); helper.changes()->clear();
} }
TEST(WindowServiceClientTest, CreateTopLevelWithProperties) { TEST(WindowServiceClientTest, NewTopLevelWindowWithProperties) {
WindowServiceTestHelper helper; WindowServiceTestHelper helper;
EXPECT_TRUE(helper.changes()->empty()); EXPECT_TRUE(helper.changes()->empty());
aura::PropertyConverter::PrimitiveType value = true; aura::PropertyConverter::PrimitiveType value = true;
...@@ -139,7 +163,7 @@ TEST(WindowServiceClientTest, CreateTopLevelWithProperties) { ...@@ -139,7 +163,7 @@ TEST(WindowServiceClientTest, CreateTopLevelWithProperties) {
helper.changes()->clear(); helper.changes()->clear();
} }
TEST(WindowServiceClientTest, SetBounds) { TEST(WindowServiceClientTest, SetWindowBounds) {
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();
...@@ -179,7 +203,7 @@ TEST(WindowServiceClientTest, SetBounds) { ...@@ -179,7 +203,7 @@ TEST(WindowServiceClientTest, SetBounds) {
helper.changes()->clear(); helper.changes()->clear();
} }
TEST(WindowServiceClientTest, SetProperty) { TEST(WindowServiceClientTest, SetWindowProperty) {
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();
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "ui/aura/mus/property_utils.h" #include "ui/aura/mus/property_utils.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 "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/window_types.h" #include "ui/aura/client/window_types.h"
...@@ -39,8 +41,20 @@ client::WindowType UiWindowTypeToWindowType(ui::mojom::WindowType type) { ...@@ -39,8 +41,20 @@ client::WindowType UiWindowTypeToWindowType(ui::mojom::WindowType type) {
} // namespace } // namespace
void SetWindowType(Window* window, ui::mojom::WindowType window_type) { void SetWindowType(Window* window, ui::mojom::WindowType window_type) {
if (window_type == ui::mojom::WindowType::UNKNOWN)
return;
window->SetProperty(client::kWindowTypeKey, window_type); window->SetProperty(client::kWindowTypeKey, window_type);
window->SetType(UiWindowTypeToWindowType(window_type)); window->SetType(UiWindowTypeToWindowType(window_type));
} }
ui::mojom::WindowType GetWindowTypeFromProperties(
const std::map<std::string, std::vector<uint8_t>>& properties) {
auto iter =
properties.find(ui::mojom::WindowManager::kWindowType_InitProperty);
if (iter == properties.end())
return ui::mojom::WindowType::UNKNOWN;
return static_cast<ui::mojom::WindowType>(
mojo::ConvertTo<int32_t>(iter->second));
}
} // namespace aura } // namespace aura
...@@ -6,6 +6,9 @@ ...@@ -6,6 +6,9 @@
#define UI_AURA_MUS_PROPERTY_UTILS_H_ #define UI_AURA_MUS_PROPERTY_UTILS_H_
#include <stdint.h> #include <stdint.h>
#include <map>
#include <string>
#include <vector>
#include "ui/aura/aura_export.h" #include "ui/aura/aura_export.h"
...@@ -21,10 +24,14 @@ class Window; ...@@ -21,10 +24,14 @@ class Window;
// Configures the two window type properties on |window|. Specifically this // Configures the two window type properties on |window|. Specifically this
// sets the property client::kWindowTypeKey as well as calling SetType(). // sets the property client::kWindowTypeKey as well as calling SetType().
// This *must* be called before Init(). // This *must* be called before Init(). No-op for WindowType::UNKNOWN.
AURA_EXPORT void SetWindowType(Window* window, AURA_EXPORT void SetWindowType(Window* window,
ui::mojom::WindowType window_type); ui::mojom::WindowType window_type);
// Returns the window type specified in |properties|, or WindowType::UNKNOWN.
AURA_EXPORT ui::mojom::WindowType GetWindowTypeFromProperties(
const std::map<std::string, std::vector<uint8_t>>& properties);
} // namespace aura } // namespace aura
#endif // UI_AURA_MUS_PROPERTY_UTILS_H_ #endif // UI_AURA_MUS_PROPERTY_UTILS_H_
...@@ -153,20 +153,6 @@ bool IsInternalProperty(const void* key) { ...@@ -153,20 +153,6 @@ bool IsInternalProperty(const void* key) {
return key == client::kModalKey || key == client::kChildModalParentKey; return key == client::kModalKey || key == client::kChildModalParentKey;
} }
void SetWindowTypeFromProperties(
Window* window,
const base::flat_map<std::string, std::vector<uint8_t>>& properties) {
auto type_iter =
properties.find(ui::mojom::WindowManager::kWindowType_InitProperty);
if (type_iter == properties.end())
return;
// TODO: need to validate type! http://crbug.com/654924.
ui::mojom::WindowType window_type = static_cast<ui::mojom::WindowType>(
mojo::ConvertTo<int32_t>(type_iter->second));
SetWindowType(window, window_type);
}
// Create and return a MouseEvent or TouchEvent from |event| if |event| is a // Create and return a MouseEvent or TouchEvent from |event| if |event| is a
// PointerEvent, otherwise return the copy of |event|. // PointerEvent, otherwise return the copy of |event|.
std::unique_ptr<ui::Event> MapEvent(const ui::Event& event) { std::unique_ptr<ui::Event> MapEvent(const ui::Event& event) {
...@@ -752,7 +738,9 @@ WindowMus* WindowTreeClient::NewWindowFromWindowData( ...@@ -752,7 +738,9 @@ WindowMus* WindowTreeClient::NewWindowFromWindowData(
window_port_mus_ptr->should_restack_transient_children_ = false; window_port_mus_ptr->should_restack_transient_children_ = false;
Window* window = new Window(nullptr, std::move(window_port_mus)); Window* window = new Window(nullptr, std::move(window_port_mus));
WindowMus* window_mus = window_port_mus_ptr; WindowMus* window_mus = window_port_mus_ptr;
SetWindowTypeFromProperties(window, window_data.properties); std::map<std::string, std::vector<uint8_t>> properties =
mojo::FlatMapToMap(window_data.properties);
SetWindowType(window, GetWindowTypeFromProperties(properties));
window->Init(ui::LAYER_NOT_DRAWN); window->Init(ui::LAYER_NOT_DRAWN);
SetLocalPropertiesFromServerProperties(window_mus, window_data); SetLocalPropertiesFromServerProperties(window_mus, window_data);
window_mus->SetBoundsFromServer( window_mus->SetBoundsFromServer(
...@@ -2011,14 +1999,7 @@ void WindowTreeClient::WmCreateTopLevelWindow( ...@@ -2011,14 +1999,7 @@ void WindowTreeClient::WmCreateTopLevelWindow(
DCHECK(frame_sink_id.is_valid()); DCHECK(frame_sink_id.is_valid());
std::map<std::string, std::vector<uint8_t>> properties = std::map<std::string, std::vector<uint8_t>> properties =
mojo::FlatMapToMap(transport_properties); mojo::FlatMapToMap(transport_properties);
ui::mojom::WindowType window_type = ui::mojom::WindowType::UNKNOWN; ui::mojom::WindowType window_type = GetWindowTypeFromProperties(properties);
auto type_iter =
properties.find(ui::mojom::WindowManager::kWindowType_InitProperty);
if (type_iter != properties.end()) {
// TODO: validation! http://crbug.com/654924.
window_type = static_cast<ui::mojom::WindowType>(
mojo::ConvertTo<int32_t>(type_iter->second));
}
Window* window = window_manager_delegate_->OnWmCreateTopLevelWindow( Window* window = window_manager_delegate_->OnWmCreateTopLevelWindow(
window_type, &properties); window_type, &properties);
if (!window) { if (!window) {
......
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