Chromium Code Reviews| Index: ui/aura/mus/property_converter.cc |
| diff --git a/ui/aura/mus/property_converter.cc b/ui/aura/mus/property_converter.cc |
| index 151e480c776112bb72b6e06fa9c81226bfa9973b..cdf9022b0042cf9535fb329a8f493c8d7bb854a7 100644 |
| --- a/ui/aura/mus/property_converter.cc |
| +++ b/ui/aura/mus/property_converter.cc |
| @@ -37,14 +37,25 @@ PropertyConverter::PropertyConverter() { |
| RegisterProperty(client::kExcludeFromMruKey, |
| ui::mojom::WindowManager::kExcludeFromMru_Property); |
| RegisterProperty(client::kNameKey, ui::mojom::WindowManager::kName_Property); |
| + RegisterProperty(client::kPreferredSize, |
| + ui::mojom::WindowManager::kPreferredSize_Property); |
| RegisterProperty(client::kRestoreBoundsKey, |
| ui::mojom::WindowManager::kRestoreBounds_Property); |
| + RegisterProperty(client::kShowStateKey, |
| + ui::mojom::WindowManager::kShowState_Property); |
| RegisterProperty(client::kTitleKey, |
| ui::mojom::WindowManager::kWindowTitle_Property); |
| } |
| PropertyConverter::~PropertyConverter() {} |
| +void PropertyConverter::ApplyAllTransportProperties( |
| + Window* window, |
| + const std::map<std::string, std::vector<uint8_t>>& properties) { |
| + for (auto& pair : properties) |
|
msw
2016/11/29 01:15:45
It seems easy for a client to inline this; why add
sky
2016/11/29 04:19:36
I need to call it a couple of times, but it's not
|
| + SetPropertyFromTransportValue(window, pair.first, &pair.second); |
| +} |
| + |
| bool PropertyConverter::ConvertPropertyForTransport( |
| Window* window, |
| const void* key, |
| @@ -74,6 +85,12 @@ bool PropertyConverter::ConvertPropertyForTransport( |
| 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); |
| if (string_properties_.count(string_key) > 0) { |
| *transport_value = GetArray(window, string_key); |
| @@ -89,7 +106,7 @@ bool PropertyConverter::ConvertPropertyForTransport( |
| // Handle primitive property types generically. |
| DCHECK_GT(primitive_properties_.count(key), 0u); |
| // 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>>( |
| mojo::ConvertTo<std::vector<uint8_t>>(value)); |
| return true; |
| @@ -107,6 +124,10 @@ std::string PropertyConverter::GetTransportNameForPropertyKey(const void* key) { |
| if (rect_properties_.count(rect_key) > 0) |
| 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); |
| if (string_properties_.count(string_key) > 0) |
| return string_properties_[string_key]; |
| @@ -124,12 +145,13 @@ void PropertyConverter::SetPropertyFromTransportValue( |
| const std::vector<uint8_t>* data) { |
| for (const auto& primitive_property : primitive_properties_) { |
| 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) { |
| - DVLOG(2) << "Property size mismatch (int64_t): " << transport_name; |
| + DVLOG(2) << "Property size mismatch (PrimitiveType): " |
| + << transport_name; |
| 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? |
| window->SetPropertyInternal(primitive_property.first, |
| primitive_property.second.first, nullptr, |
| @@ -161,6 +183,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_) { |
| if (string_property.second == transport_name) { |
| // TODO(msw): Validate the data somehow, before trying to convert? |
| @@ -182,6 +216,24 @@ void PropertyConverter::SetPropertyFromTransportValue( |
| DVLOG(2) << "Unknown mus property name: " << transport_name; |
| } |
| +bool PropertyConverter::GetPropertyValueFromTransformValue( |
| + 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( |
| const WindowProperty<gfx::ImageSkia*>* property, |
| const char* transport_name) { |
| @@ -195,6 +247,12 @@ void PropertyConverter::RegisterProperty( |
| } |
| void PropertyConverter::RegisterProperty( |
| + const WindowProperty<gfx::Size*>* property, |
| + const char* transport_name) { |
| + size_properties_[property] = transport_name; |
| +} |
| + |
| +void PropertyConverter::RegisterProperty( |
| const WindowProperty<std::string*>* property, |
| const char* transport_name) { |
| string_properties_[property] = transport_name; |