Commit 153f6770 authored by sky's avatar sky Committed by Commit bot

Adds a couple more properties to the property converter

This also adds PropertyConverter::GetPropertyValueFromTransformValue()
which I need in ash for values used in creation of the window but
don't make their way into real properties.

BUG=664625
TEST=none
R=msw@chromium.org

Review-Url: https://codereview.chromium.org/2538633002
Cr-Commit-Position: refs/heads/master@{#435026}
parent 2d5570df
...@@ -13,8 +13,8 @@ DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(AURA_EXPORT, base::string16*) ...@@ -13,8 +13,8 @@ DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(AURA_EXPORT, base::string16*)
DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(AURA_EXPORT, ui::ModalType) DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(AURA_EXPORT, ui::ModalType)
DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(AURA_EXPORT, gfx::ImageSkia*) DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(AURA_EXPORT, gfx::ImageSkia*)
DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(AURA_EXPORT, gfx::Rect*) DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(AURA_EXPORT, gfx::Rect*)
DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(AURA_EXPORT, gfx::Size*)
DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(AURA_EXPORT, std::string*) DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(AURA_EXPORT, std::string*)
DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(AURA_EXPORT, ui::InputMethod*)
DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(AURA_EXPORT, ui::WindowShowState) DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(AURA_EXPORT, ui::WindowShowState)
DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(AURA_EXPORT, ui::mojom::WindowType); DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(AURA_EXPORT, ui::mojom::WindowType);
DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(AURA_EXPORT, void*) DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(AURA_EXPORT, void*)
...@@ -42,8 +42,10 @@ DEFINE_WINDOW_PROPERTY_KEY(bool, kMirroringEnabledKey, false); ...@@ -42,8 +42,10 @@ DEFINE_WINDOW_PROPERTY_KEY(bool, kMirroringEnabledKey, false);
DEFINE_WINDOW_PROPERTY_KEY(Window*, kHostWindowKey, nullptr); DEFINE_WINDOW_PROPERTY_KEY(Window*, kHostWindowKey, nullptr);
DEFINE_WINDOW_PROPERTY_KEY(ui::ModalType, kModalKey, ui::MODAL_TYPE_NONE); DEFINE_WINDOW_PROPERTY_KEY(ui::ModalType, kModalKey, ui::MODAL_TYPE_NONE);
DEFINE_OWNED_WINDOW_PROPERTY_KEY(std::string, kNameKey, nullptr); DEFINE_OWNED_WINDOW_PROPERTY_KEY(std::string, kNameKey, nullptr);
// gfx::Rect object for RestoreBoundsKey property is owned by the window DEFINE_OWNED_WINDOW_PROPERTY_KEY(gfx::Size, kPreferredSize, nullptr);
// and will be freed automatically. DEFINE_WINDOW_PROPERTY_KEY(int32_t,
kResizeBehaviorKey,
ui::mojom::kResizeBehaviorNone);
DEFINE_OWNED_WINDOW_PROPERTY_KEY(gfx::Rect, kRestoreBoundsKey, nullptr); DEFINE_OWNED_WINDOW_PROPERTY_KEY(gfx::Rect, kRestoreBoundsKey, nullptr);
DEFINE_WINDOW_PROPERTY_KEY( DEFINE_WINDOW_PROPERTY_KEY(
ui::WindowShowState, kRestoreShowStateKey, ui::SHOW_STATE_DEFAULT); ui::WindowShowState, kRestoreShowStateKey, ui::SHOW_STATE_DEFAULT);
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "ui/base/ui_base_types.h" #include "ui/base/ui_base_types.h"
namespace ui { namespace ui {
class InputMethod;
namespace mojom { namespace mojom {
enum class WindowType; enum class WindowType;
} }
...@@ -76,6 +75,13 @@ AURA_EXPORT extern const WindowProperty<ui::ModalType>* const kModalKey; ...@@ -76,6 +75,13 @@ AURA_EXPORT extern const WindowProperty<ui::ModalType>* const kModalKey;
// A property key to store the name of the window; mostly used for debugging. // A property key to store the name of the window; mostly used for debugging.
AURA_EXPORT extern const WindowProperty<std::string*>* const kNameKey; AURA_EXPORT extern const WindowProperty<std::string*>* const kNameKey;
// A property key to store the preferred size of the window.
AURA_EXPORT extern const WindowProperty<gfx::Size*>* const kPreferredSize;
// A property key to store the resize behavior, which is a bitmask of the
// ui::mojom::kResizeBehavior values.
AURA_EXPORT extern const WindowProperty<int32_t>* const kResizeBehaviorKey;
// A property key to store the restore bounds for a window. // A property key to store the restore bounds for a window.
AURA_EXPORT extern const WindowProperty<gfx::Rect*>* const kRestoreBoundsKey; AURA_EXPORT extern const WindowProperty<gfx::Rect*>* const kRestoreBoundsKey;
......
...@@ -37,8 +37,12 @@ PropertyConverter::PropertyConverter() { ...@@ -37,8 +37,12 @@ PropertyConverter::PropertyConverter() {
RegisterProperty(client::kExcludeFromMruKey, RegisterProperty(client::kExcludeFromMruKey,
ui::mojom::WindowManager::kExcludeFromMru_Property); ui::mojom::WindowManager::kExcludeFromMru_Property);
RegisterProperty(client::kNameKey, ui::mojom::WindowManager::kName_Property); RegisterProperty(client::kNameKey, ui::mojom::WindowManager::kName_Property);
RegisterProperty(client::kPreferredSize,
ui::mojom::WindowManager::kPreferredSize_Property);
RegisterProperty(client::kRestoreBoundsKey, RegisterProperty(client::kRestoreBoundsKey,
ui::mojom::WindowManager::kRestoreBounds_Property); ui::mojom::WindowManager::kRestoreBounds_Property);
RegisterProperty(client::kShowStateKey,
ui::mojom::WindowManager::kShowState_Property);
RegisterProperty(client::kTitleKey, RegisterProperty(client::kTitleKey,
ui::mojom::WindowManager::kWindowTitle_Property); ui::mojom::WindowManager::kWindowTitle_Property);
} }
...@@ -74,6 +78,12 @@ bool PropertyConverter::ConvertPropertyForTransport( ...@@ -74,6 +78,12 @@ bool PropertyConverter::ConvertPropertyForTransport(
return true; return true;
} }
auto size_key = static_cast<const WindowProperty<gfx::Size*>*>(key);
if (size_properties_.count(size_key) > 0) {
*transport_value = GetArray(window, size_key);
return true;
}
auto string_key = static_cast<const WindowProperty<std::string*>*>(key); auto string_key = static_cast<const WindowProperty<std::string*>*>(key);
if (string_properties_.count(string_key) > 0) { if (string_properties_.count(string_key) > 0) {
*transport_value = GetArray(window, string_key); *transport_value = GetArray(window, string_key);
...@@ -89,7 +99,7 @@ bool PropertyConverter::ConvertPropertyForTransport( ...@@ -89,7 +99,7 @@ bool PropertyConverter::ConvertPropertyForTransport(
// Handle primitive property types generically. // Handle primitive property types generically.
DCHECK_GT(primitive_properties_.count(key), 0u); DCHECK_GT(primitive_properties_.count(key), 0u);
// TODO(msw): Using the int64_t accessor is wasteful for smaller types. // TODO(msw): Using the int64_t accessor is wasteful for smaller types.
const int64_t value = window->GetPropertyInternal(key, 0); const PrimitiveType value = window->GetPropertyInternal(key, 0);
*transport_value = base::MakeUnique<std::vector<uint8_t>>( *transport_value = base::MakeUnique<std::vector<uint8_t>>(
mojo::ConvertTo<std::vector<uint8_t>>(value)); mojo::ConvertTo<std::vector<uint8_t>>(value));
return true; return true;
...@@ -107,6 +117,10 @@ std::string PropertyConverter::GetTransportNameForPropertyKey(const void* key) { ...@@ -107,6 +117,10 @@ std::string PropertyConverter::GetTransportNameForPropertyKey(const void* key) {
if (rect_properties_.count(rect_key) > 0) if (rect_properties_.count(rect_key) > 0)
return rect_properties_[rect_key]; return rect_properties_[rect_key];
auto size_key = static_cast<const WindowProperty<gfx::Size*>*>(key);
if (size_properties_.count(size_key) > 0)
return size_properties_[size_key];
auto string_key = static_cast<const WindowProperty<std::string*>*>(key); auto string_key = static_cast<const WindowProperty<std::string*>*>(key);
if (string_properties_.count(string_key) > 0) if (string_properties_.count(string_key) > 0)
return string_properties_[string_key]; return string_properties_[string_key];
...@@ -124,12 +138,13 @@ void PropertyConverter::SetPropertyFromTransportValue( ...@@ -124,12 +138,13 @@ void PropertyConverter::SetPropertyFromTransportValue(
const std::vector<uint8_t>* data) { const std::vector<uint8_t>* data) {
for (const auto& primitive_property : primitive_properties_) { for (const auto& primitive_property : primitive_properties_) {
if (primitive_property.second.second == transport_name) { if (primitive_property.second.second == transport_name) {
// aura::Window only supports property types that fit in int64_t. // aura::Window only supports property types that fit in PrimitiveType.
if (data->size() != 8u) { if (data->size() != 8u) {
DVLOG(2) << "Property size mismatch (int64_t): " << transport_name; DVLOG(2) << "Property size mismatch (PrimitiveType): "
<< transport_name;
return; return;
} }
const int64_t value = mojo::ConvertTo<int64_t>(*data); const PrimitiveType value = mojo::ConvertTo<PrimitiveType>(*data);
// TODO(msw): Should aura::Window just store all properties by name? // TODO(msw): Should aura::Window just store all properties by name?
window->SetPropertyInternal(primitive_property.first, window->SetPropertyInternal(primitive_property.first,
primitive_property.second.first, nullptr, primitive_property.second.first, nullptr,
...@@ -161,6 +176,18 @@ void PropertyConverter::SetPropertyFromTransportValue( ...@@ -161,6 +176,18 @@ void PropertyConverter::SetPropertyFromTransportValue(
} }
} }
for (const auto& size_property : size_properties_) {
if (size_property.second == transport_name) {
if (data->size() != 8u) {
DVLOG(2) << "Property size mismatch (gfx::Size): " << transport_name;
return;
}
const gfx::Size value = mojo::ConvertTo<gfx::Size>(*data);
window->SetProperty(size_property.first, new gfx::Size(value));
return;
}
}
for (const auto& string_property : string_properties_) { for (const auto& string_property : string_properties_) {
if (string_property.second == transport_name) { if (string_property.second == transport_name) {
// TODO(msw): Validate the data somehow, before trying to convert? // TODO(msw): Validate the data somehow, before trying to convert?
...@@ -182,6 +209,24 @@ void PropertyConverter::SetPropertyFromTransportValue( ...@@ -182,6 +209,24 @@ void PropertyConverter::SetPropertyFromTransportValue(
DVLOG(2) << "Unknown mus property name: " << transport_name; DVLOG(2) << "Unknown mus property name: " << transport_name;
} }
bool PropertyConverter::GetPropertyValueFromTransportValue(
const std::string& transport_name,
const std::vector<uint8_t>& transport_data,
PrimitiveType* value) {
// aura::Window only supports property types that fit in PrimitiveType.
if (transport_data.size() != 8u) {
DVLOG(2) << "Property size mismatch (PrimitiveType): " << transport_name;
return false;
}
for (const auto& primitive_property : primitive_properties_) {
if (primitive_property.second.second == transport_name) {
*value = mojo::ConvertTo<PrimitiveType>(transport_data);
return true;
}
}
return false;
}
void PropertyConverter::RegisterProperty( void PropertyConverter::RegisterProperty(
const WindowProperty<gfx::ImageSkia*>* property, const WindowProperty<gfx::ImageSkia*>* property,
const char* transport_name) { const char* transport_name) {
...@@ -194,6 +239,12 @@ void PropertyConverter::RegisterProperty( ...@@ -194,6 +239,12 @@ void PropertyConverter::RegisterProperty(
rect_properties_[property] = transport_name; rect_properties_[property] = transport_name;
} }
void PropertyConverter::RegisterProperty(
const WindowProperty<gfx::Size*>* property,
const char* transport_name) {
size_properties_[property] = transport_name;
}
void PropertyConverter::RegisterProperty( void PropertyConverter::RegisterProperty(
const WindowProperty<std::string*>* property, const WindowProperty<std::string*>* property,
const char* transport_name) { const char* transport_name) {
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
namespace gfx { namespace gfx {
class Rect; class Rect;
class Size;
} }
namespace aura { namespace aura {
...@@ -29,6 +30,9 @@ namespace aura { ...@@ -29,6 +30,9 @@ namespace aura {
// Window properties. // Window properties.
class AURA_EXPORT PropertyConverter { class AURA_EXPORT PropertyConverter {
public: public:
// All primitive values are stored using this type.
using PrimitiveType = int64_t;
PropertyConverter(); PropertyConverter();
~PropertyConverter(); ~PropertyConverter();
...@@ -52,6 +56,16 @@ class AURA_EXPORT PropertyConverter { ...@@ -52,6 +56,16 @@ class AURA_EXPORT PropertyConverter {
const std::string& transport_name, const std::string& transport_name,
const std::vector<uint8_t>* transport_data); const std::vector<uint8_t>* transport_data);
// Returns the value for a particular transport value. All primitives are
// serialized as a PrimitiveType, so this function may be used for any
// primitive. Returns true on success and sets |value| accordingly. A return
// value of false indicates the value isn't known or the property type isn't
// primitive.
bool GetPropertyValueFromTransportValue(
const std::string& transport_name,
const std::vector<uint8_t>& transport_data,
PrimitiveType* value);
// Register a property to support conversion between mus and aura. // Register a property to support conversion between mus and aura.
template<typename T> template<typename T>
void RegisterProperty(const WindowProperty<T>* property, void RegisterProperty(const WindowProperty<T>* property,
...@@ -65,6 +79,8 @@ class AURA_EXPORT PropertyConverter { ...@@ -65,6 +79,8 @@ class AURA_EXPORT PropertyConverter {
const char* transport_name); const char* transport_name);
void RegisterProperty(const WindowProperty<gfx::Rect*>* property, void RegisterProperty(const WindowProperty<gfx::Rect*>* property,
const char* transport_name); const char* transport_name);
void RegisterProperty(const WindowProperty<gfx::Size*>* property,
const char* transport_name);
void RegisterProperty(const WindowProperty<std::string*>* property, void RegisterProperty(const WindowProperty<std::string*>* property,
const char* transport_name); const char* transport_name);
void RegisterProperty(const WindowProperty<base::string16*>* property, void RegisterProperty(const WindowProperty<base::string16*>* property,
...@@ -82,6 +98,7 @@ class AURA_EXPORT PropertyConverter { ...@@ -82,6 +98,7 @@ class AURA_EXPORT PropertyConverter {
std::map<const WindowProperty<gfx::ImageSkia*>*, const char*> std::map<const WindowProperty<gfx::ImageSkia*>*, const char*>
image_properties_; image_properties_;
std::map<const WindowProperty<gfx::Rect*>*, const char*> rect_properties_; std::map<const WindowProperty<gfx::Rect*>*, const char*> rect_properties_;
std::map<const WindowProperty<gfx::Size*>*, const char*> size_properties_;
std::map<const WindowProperty<std::string*>*, const char*> string_properties_; std::map<const WindowProperty<std::string*>*, const char*> string_properties_;
std::map<const WindowProperty<base::string16*>*, const char*> std::map<const WindowProperty<base::string16*>*, const char*>
string16_properties_; string16_properties_;
......
...@@ -45,6 +45,7 @@ DEFINE_WINDOW_PROPERTY_KEY(int64_t, kTestPropertyKey8, 0); ...@@ -45,6 +45,7 @@ DEFINE_WINDOW_PROPERTY_KEY(int64_t, kTestPropertyKey8, 0);
DEFINE_OWNED_WINDOW_PROPERTY_KEY(gfx::ImageSkia, kTestImagePropertyKey, DEFINE_OWNED_WINDOW_PROPERTY_KEY(gfx::ImageSkia, kTestImagePropertyKey,
nullptr); nullptr);
DEFINE_OWNED_WINDOW_PROPERTY_KEY(gfx::Rect, kTestRectPropertyKey, nullptr); DEFINE_OWNED_WINDOW_PROPERTY_KEY(gfx::Rect, kTestRectPropertyKey, nullptr);
DEFINE_OWNED_WINDOW_PROPERTY_KEY(gfx::Size, kTestSizePropertyKey, nullptr);
DEFINE_OWNED_WINDOW_PROPERTY_KEY(std::string, kTestStringPropertyKey, nullptr); DEFINE_OWNED_WINDOW_PROPERTY_KEY(std::string, kTestStringPropertyKey, nullptr);
DEFINE_OWNED_WINDOW_PROPERTY_KEY(base::string16, kTestString16PropertyKey, DEFINE_OWNED_WINDOW_PROPERTY_KEY(base::string16, kTestString16PropertyKey,
nullptr); nullptr);
...@@ -61,6 +62,7 @@ const char kTestPropertyServerKey8[] = "test-property-server8"; ...@@ -61,6 +62,7 @@ const char kTestPropertyServerKey8[] = "test-property-server8";
const char kTestImagePropertyServerKey[] = "test-image-property-server"; const char kTestImagePropertyServerKey[] = "test-image-property-server";
const char kTestRectPropertyServerKey[] = "test-rect-property-server"; const char kTestRectPropertyServerKey[] = "test-rect-property-server";
const char kTestSizePropertyServerKey[] = "test-size-property-server";
const char kTestStringPropertyServerKey[] = "test-string-property-server"; const char kTestStringPropertyServerKey[] = "test-string-property-server";
const char kTestString16PropertyServerKey[] = "test-string16-property-server"; const char kTestString16PropertyServerKey[] = "test-string16-property-server";
...@@ -89,12 +91,21 @@ void TestPrimitiveProperty(PropertyConverter* property_converter, ...@@ -89,12 +91,21 @@ void TestPrimitiveProperty(PropertyConverter* property_converter,
mojo::ConvertTo<std::vector<uint8_t>>(storage_value_1); mojo::ConvertTo<std::vector<uint8_t>>(storage_value_1);
EXPECT_EQ(transport_value1, *transport_value_out.get()); EXPECT_EQ(transport_value1, *transport_value_out.get());
int64_t decoded_value_1 = 0;
EXPECT_TRUE(property_converter->GetPropertyValueFromTransportValue(
transport_name, *transport_value_out, &decoded_value_1));
EXPECT_EQ(value_1, static_cast<T>(decoded_value_1));
const int64_t storage_value_2 = static_cast<int64_t>(value_2); const int64_t storage_value_2 = static_cast<int64_t>(value_2);
std::vector<uint8_t> transport_value2 = std::vector<uint8_t> transport_value2 =
mojo::ConvertTo<std::vector<uint8_t>>(storage_value_2); mojo::ConvertTo<std::vector<uint8_t>>(storage_value_2);
property_converter->SetPropertyFromTransportValue(window, transport_name, property_converter->SetPropertyFromTransportValue(window, transport_name,
&transport_value2); &transport_value2);
EXPECT_EQ(value_2, window->GetProperty(key)); EXPECT_EQ(value_2, window->GetProperty(key));
int64_t decoded_value_2 = 0;
EXPECT_TRUE(property_converter->GetPropertyValueFromTransportValue(
transport_name, transport_value2, &decoded_value_2));
EXPECT_EQ(value_2, static_cast<T>(decoded_value_2));
} }
} // namespace } // namespace
...@@ -214,6 +225,37 @@ TEST_F(PropertyConverterTest, RectProperty) { ...@@ -214,6 +225,37 @@ TEST_F(PropertyConverterTest, RectProperty) {
EXPECT_EQ(value_2, *window->GetProperty(kTestRectPropertyKey)); EXPECT_EQ(value_2, *window->GetProperty(kTestRectPropertyKey));
} }
// Verifies property setting behavior for a gfx::Size* property.
TEST_F(PropertyConverterTest, SizeProperty) {
PropertyConverter property_converter;
property_converter.RegisterProperty(kTestSizePropertyKey,
kTestSizePropertyServerKey);
EXPECT_EQ(
kTestSizePropertyServerKey,
property_converter.GetTransportNameForPropertyKey(kTestSizePropertyKey));
gfx::Size value_1(1, 2);
std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr));
window->SetProperty(kTestSizePropertyKey, new gfx::Size(value_1));
EXPECT_EQ(value_1, *window->GetProperty(kTestSizePropertyKey));
std::string transport_name_out;
std::unique_ptr<std::vector<uint8_t>> transport_value_out;
EXPECT_TRUE(property_converter.ConvertPropertyForTransport(
window.get(), kTestSizePropertyKey, &transport_name_out,
&transport_value_out));
EXPECT_EQ(kTestSizePropertyServerKey, transport_name_out);
EXPECT_EQ(mojo::ConvertTo<std::vector<uint8_t>>(value_1),
*transport_value_out.get());
gfx::Size value_2(1, 3);
std::vector<uint8_t> transport_value =
mojo::ConvertTo<std::vector<uint8_t>>(value_2);
property_converter.SetPropertyFromTransportValue(
window.get(), kTestSizePropertyServerKey, &transport_value);
EXPECT_EQ(value_2, *window->GetProperty(kTestSizePropertyKey));
}
// Verifies property setting behavior for a std::string* property. // Verifies property setting behavior for a std::string* property.
TEST_F(PropertyConverterTest, StringProperty) { TEST_F(PropertyConverterTest, StringProperty) {
PropertyConverter property_converter; PropertyConverter property_converter;
......
...@@ -130,6 +130,22 @@ DesktopWindowTreeHostMus::~DesktopWindowTreeHostMus() { ...@@ -130,6 +130,22 @@ DesktopWindowTreeHostMus::~DesktopWindowTreeHostMus() {
desktop_native_widget_aura_->OnDesktopWindowTreeHostDestroyed(this); desktop_native_widget_aura_->OnDesktopWindowTreeHostDestroyed(this);
} }
// static
int DesktopWindowTreeHostMus::GetResizeBehaviorFromDelegate(
WidgetDelegate* delegate) {
if (!delegate)
return ui::mojom::kResizeBehaviorNone;
int32_t behavior = ui::mojom::kResizeBehaviorNone;
if (delegate->CanResize())
behavior |= ui::mojom::kResizeBehaviorCanResize;
if (delegate->CanMaximize())
behavior |= ui::mojom::kResizeBehaviorCanMaximize;
if (delegate->CanMinimize())
behavior |= ui::mojom::kResizeBehaviorCanMinimize;
return behavior;
}
bool DesktopWindowTreeHostMus::IsDocked() const { bool DesktopWindowTreeHostMus::IsDocked() const {
return window()->GetProperty(aura::client::kShowStateKey) == return window()->GetProperty(aura::client::kShowStateKey) ==
ui::SHOW_STATE_DOCKED; ui::SHOW_STATE_DOCKED;
...@@ -541,6 +557,10 @@ void DesktopWindowTreeHostMus::SizeConstraintsChanged() { ...@@ -541,6 +557,10 @@ void DesktopWindowTreeHostMus::SizeConstraintsChanged() {
widget->widget_delegate()->CanMinimize()); widget->widget_delegate()->CanMinimize());
window()->SetProperty(aura::client::kCanResizeKey, window()->SetProperty(aura::client::kCanResizeKey,
widget->widget_delegate()->CanResize()); widget->widget_delegate()->CanResize());
// TODO: replace above keys with kResizeBehaviorKey. http://crbug.com/669290.
window()->SetProperty(
aura::client::kResizeBehaviorKey,
GetResizeBehaviorFromDelegate(widget->widget_delegate()));
} }
void DesktopWindowTreeHostMus::OnWindowManagerFrameValuesChanged() { void DesktopWindowTreeHostMus::OnWindowManagerFrameValuesChanged() {
......
...@@ -30,6 +30,10 @@ class VIEWS_MUS_EXPORT DesktopWindowTreeHostMus ...@@ -30,6 +30,10 @@ class VIEWS_MUS_EXPORT DesktopWindowTreeHostMus
const std::map<std::string, std::vector<uint8_t>>* mus_properties); const std::map<std::string, std::vector<uint8_t>>* mus_properties);
~DesktopWindowTreeHostMus() override; ~DesktopWindowTreeHostMus() override;
// Returns a bitmask of the resize types. See ui::mojom::kResizeBehavior.
// |delegate| may be null.
static int32_t GetResizeBehaviorFromDelegate(WidgetDelegate* delegate);
private: private:
bool IsDocked() const; bool IsDocked() const;
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "ui/views/mus/screen_mus.h" #include "ui/views/mus/screen_mus.h"
#include "ui/views/views_delegate.h" #include "ui/views/views_delegate.h"
#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
#include "ui/views/widget/widget_delegate.h"
#include "ui/wm/core/capture_controller.h" #include "ui/wm/core/capture_controller.h"
#include "ui/wm/core/wm_state.h" #include "ui/wm/core/wm_state.h"
...@@ -83,13 +84,58 @@ bool MusClient::ShouldCreateDesktopNativeWidgetAura( ...@@ -83,13 +84,58 @@ bool MusClient::ShouldCreateDesktopNativeWidgetAura(
std::map<std::string, std::vector<uint8_t>> std::map<std::string, std::vector<uint8_t>>
MusClient::ConfigurePropertiesFromParams( MusClient::ConfigurePropertiesFromParams(
const Widget::InitParams& init_params) { const Widget::InitParams& init_params) {
std::map<std::string, std::vector<uint8_t>> mus_properties = using PrimitiveType = aura::PropertyConverter::PrimitiveType;
std::map<std::string, std::vector<uint8_t>> properties =
init_params.mus_properties; init_params.mus_properties;
// Widget::InitParams::Type matches ui::mojom::WindowType. // Widget::InitParams::Type matches ui::mojom::WindowType.
mus_properties[ui::mojom::WindowManager::kWindowType_Property] = properties[ui::mojom::WindowManager::kWindowType_Property] =
mojo::ConvertTo<std::vector<uint8_t>>( mojo::ConvertTo<std::vector<uint8_t>>(
static_cast<int32_t>(init_params.type)); static_cast<int32_t>(init_params.type));
return mus_properties;
if (!init_params.bounds.IsEmpty()) {
properties[ui::mojom::WindowManager::kInitialBounds_Property] =
mojo::ConvertTo<std::vector<uint8_t>>(init_params.bounds);
}
if (!init_params.name.empty()) {
properties[ui::mojom::WindowManager::kName_Property] =
mojo::ConvertTo<std::vector<uint8_t>>(init_params.name);
}
properties[ui::mojom::WindowManager::kAlwaysOnTop_Property] =
mojo::ConvertTo<std::vector<uint8_t>>(
static_cast<PrimitiveType>(init_params.keep_on_top));
if (!Widget::RequiresNonClientView(init_params.type))
return properties;
if (init_params.delegate) {
if (properties.count(ui::mojom::WindowManager::kResizeBehavior_Property) ==
0) {
properties[ui::mojom::WindowManager::kResizeBehavior_Property] =
mojo::ConvertTo<std::vector<uint8_t>>(static_cast<PrimitiveType>(
DesktopWindowTreeHostMus::GetResizeBehaviorFromDelegate(
init_params.delegate)));
}
// TODO(crbug.com/667566): Support additional scales or gfx::Image[Skia].
gfx::ImageSkia app_icon = init_params.delegate->GetWindowAppIcon();
SkBitmap app_bitmap = app_icon.GetRepresentation(1.f).sk_bitmap();
if (!app_bitmap.isNull()) {
properties[ui::mojom::WindowManager::kAppIcon_Property] =
mojo::ConvertTo<std::vector<uint8_t>>(app_bitmap);
}
// TODO(crbug.com/667566): Support additional scales or gfx::Image[Skia].
gfx::ImageSkia window_icon = init_params.delegate->GetWindowIcon();
SkBitmap window_bitmap = window_icon.GetRepresentation(1.f).sk_bitmap();
if (!window_bitmap.isNull()) {
properties[ui::mojom::WindowManager::kWindowIcon_Property] =
mojo::ConvertTo<std::vector<uint8_t>>(window_bitmap);
}
}
return properties;
} }
NativeWidget* MusClient::CreateNativeWidget( NativeWidget* MusClient::CreateNativeWidget(
......
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
#include "ui/views/corewm/tooltip_aura.h" #include "ui/views/corewm/tooltip_aura.h"
#include "ui/views/corewm/tooltip_controller.h" #include "ui/views/corewm/tooltip_controller.h"
#include "ui/views/drag_utils.h" #include "ui/views/drag_utils.h"
#include "ui/views/mus/desktop_window_tree_host_mus.h"
#include "ui/views/mus/drag_drop_client_mus.h" #include "ui/views/mus/drag_drop_client_mus.h"
#include "ui/views/mus/drop_target_mus.h" #include "ui/views/mus/drop_target_mus.h"
#include "ui/views/mus/input_method_mus.h" #include "ui/views/mus/input_method_mus.h"
...@@ -323,20 +324,6 @@ class ClientSideNonClientFrameView : public NonClientFrameView { ...@@ -323,20 +324,6 @@ class ClientSideNonClientFrameView : public NonClientFrameView {
DISALLOW_COPY_AND_ASSIGN(ClientSideNonClientFrameView); DISALLOW_COPY_AND_ASSIGN(ClientSideNonClientFrameView);
}; };
int ResizeBehaviorFromDelegate(WidgetDelegate* delegate) {
if (!delegate)
return ui::mojom::kResizeBehaviorNone;
int32_t behavior = ui::mojom::kResizeBehaviorNone;
if (delegate->CanResize())
behavior |= ui::mojom::kResizeBehaviorCanResize;
if (delegate->CanMaximize())
behavior |= ui::mojom::kResizeBehaviorCanMaximize;
if (delegate->CanMinimize())
behavior |= ui::mojom::kResizeBehaviorCanMinimize;
return behavior;
}
// Handles acknowledgment of an input event, either immediately when a nested // Handles acknowledgment of an input event, either immediately when a nested
// message loop starts, or upon destruction. // message loop starts, or upon destruction.
class EventAckHandler : public base::MessageLoop::NestingObserver { class EventAckHandler : public base::MessageLoop::NestingObserver {
...@@ -691,7 +678,8 @@ void NativeWidgetMus::ConfigurePropertiesForNewWindow( ...@@ -691,7 +678,8 @@ void NativeWidgetMus::ConfigurePropertiesForNewWindow(
0) { 0) {
(*properties)[ui::mojom::WindowManager::kResizeBehavior_Property] = (*properties)[ui::mojom::WindowManager::kResizeBehavior_Property] =
mojo::ConvertTo<std::vector<uint8_t>>( mojo::ConvertTo<std::vector<uint8_t>>(
ResizeBehaviorFromDelegate(init_params.delegate)); DesktopWindowTreeHostMus::GetResizeBehaviorFromDelegate(
init_params.delegate));
} }
if (init_params.delegate) { if (init_params.delegate) {
...@@ -1339,7 +1327,8 @@ void NativeWidgetMus::OnSizeConstraintsChanged() { ...@@ -1339,7 +1327,8 @@ void NativeWidgetMus::OnSizeConstraintsChanged() {
window_->SetSharedProperty<int32_t>( window_->SetSharedProperty<int32_t>(
ui::mojom::WindowManager::kResizeBehavior_Property, ui::mojom::WindowManager::kResizeBehavior_Property,
ResizeBehaviorFromDelegate(GetWidget()->widget_delegate())); DesktopWindowTreeHostMus::GetResizeBehaviorFromDelegate(
GetWidget()->widget_delegate()));
} }
void NativeWidgetMus::RepostNativeEvent(gfx::NativeEvent native_event) { void NativeWidgetMus::RepostNativeEvent(gfx::NativeEvent native_event) {
......
...@@ -29,7 +29,7 @@ NativeWidget* CreatePlatformNativeWidgetImplAuraMus( ...@@ -29,7 +29,7 @@ NativeWidget* CreatePlatformNativeWidgetImplAuraMus(
new TestPlatformNativeWidget<DesktopNativeWidgetAura>( new TestPlatformNativeWidget<DesktopNativeWidgetAura>(
widget, type == kStubCapture, destroyed); widget, type == kStubCapture, destroyed);
std::map<std::string, std::vector<uint8_t>> mus_properties = std::map<std::string, std::vector<uint8_t>> mus_properties =
MusClient::ConfigurePropertiesFromParams(init_params); MusClient::Get()->ConfigurePropertiesFromParams(init_params);
desktop_native_widget_aura->SetDesktopWindowTreeHost( desktop_native_widget_aura->SetDesktopWindowTreeHost(
base::MakeUnique<DesktopWindowTreeHostMus>( base::MakeUnique<DesktopWindowTreeHostMus>(
widget, desktop_native_widget_aura, &mus_properties)); widget, desktop_native_widget_aura, &mus_properties));
......
...@@ -317,6 +317,8 @@ void NativeWidgetAura::CenterWindow(const gfx::Size& size) { ...@@ -317,6 +317,8 @@ void NativeWidgetAura::CenterWindow(const gfx::Size& size) {
if (!window_ || is_parallel_widget_in_window_manager_) if (!window_ || is_parallel_widget_in_window_manager_)
return; return;
window_->SetProperty(aura::client::kPreferredSize, new gfx::Size(size));
gfx::Rect parent_bounds(window_->parent()->GetBoundsInRootWindow()); gfx::Rect parent_bounds(window_->parent()->GetBoundsInRootWindow());
// When centering window, we take the intersection of the host and // When centering window, we take the intersection of the host and
// the parent. We assume the root window represents the visible // the parent. We assume the root window represents the visible
......
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