Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Unified Diff: ui/aura/mus/property_converter.cc

Issue 2538633002: Adds a couple more properties to the property converter (Closed)
Patch Set: merge again Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/aura/mus/property_converter.h ('k') | ui/aura/mus/property_converter_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..966b615c24389986e8b07eeb51d4bcde904d8926 100644
--- a/ui/aura/mus/property_converter.cc
+++ b/ui/aura/mus/property_converter.cc
@@ -37,8 +37,12 @@ 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);
}
@@ -74,6 +78,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 +99,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 +117,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 +138,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 +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_) {
if (string_property.second == transport_name) {
// TODO(msw): Validate the data somehow, before trying to convert?
@@ -182,6 +209,24 @@ void PropertyConverter::SetPropertyFromTransportValue(
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(
const WindowProperty<gfx::ImageSkia*>* property,
const char* transport_name) {
@@ -195,6 +240,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;
« no previous file with comments | « ui/aura/mus/property_converter.h ('k') | ui/aura/mus/property_converter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698