OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/aura/mus/property_converter.h" | 5 #include "ui/aura/mus/property_converter.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "mojo/public/cpp/bindings/type_converter.h" | 8 #include "mojo/public/cpp/bindings/type_converter.h" |
9 #include "services/ui/public/cpp/property_type_converters.h" | 9 #include "services/ui/public/cpp/property_type_converters.h" |
10 #include "services/ui/public/interfaces/window_manager.mojom.h" | 10 #include "services/ui/public/interfaces/window_manager.mojom.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 } | 96 } |
97 | 97 |
98 auto string16_key = static_cast<const WindowProperty<base::string16*>*>(key); | 98 auto string16_key = static_cast<const WindowProperty<base::string16*>*>(key); |
99 if (string16_properties_.count(string16_key) > 0) { | 99 if (string16_properties_.count(string16_key) > 0) { |
100 *transport_value = GetArray(window, string16_key); | 100 *transport_value = GetArray(window, string16_key); |
101 return true; | 101 return true; |
102 } | 102 } |
103 | 103 |
104 // Handle primitive property types generically. | 104 // Handle primitive property types generically. |
105 DCHECK_GT(primitive_properties_.count(key), 0u); | 105 DCHECK_GT(primitive_properties_.count(key), 0u); |
106 PrimitiveType default_value = primitive_properties_.at(key).default_value; | |
sky
2017/01/18 04:03:09
primitive_properties_[key].default_value?
msw
2017/01/18 18:00:40
Done.
| |
106 // TODO(msw): Using the int64_t accessor is wasteful for smaller types. | 107 // TODO(msw): Using the int64_t accessor is wasteful for smaller types. |
107 const PrimitiveType value = window->GetPropertyInternal(key, 0); | 108 const PrimitiveType value = window->GetPropertyInternal(key, default_value); |
108 *transport_value = base::MakeUnique<std::vector<uint8_t>>( | 109 *transport_value = base::MakeUnique<std::vector<uint8_t>>( |
109 mojo::ConvertTo<std::vector<uint8_t>>(value)); | 110 mojo::ConvertTo<std::vector<uint8_t>>(value)); |
110 return true; | 111 return true; |
111 } | 112 } |
112 | 113 |
113 std::string PropertyConverter::GetTransportNameForPropertyKey(const void* key) { | 114 std::string PropertyConverter::GetTransportNameForPropertyKey(const void* key) { |
114 if (primitive_properties_.count(key) > 0) | 115 if (primitive_properties_.count(key) > 0) |
115 return primitive_properties_[key].second; | 116 return primitive_properties_.at(key).transport_name; |
sky
2017/01/18 04:03:09
Same comment about using [].
msw
2017/01/18 18:00:40
Done.
| |
116 | 117 |
117 auto image_key = static_cast<const WindowProperty<gfx::ImageSkia*>*>(key); | 118 auto image_key = static_cast<const WindowProperty<gfx::ImageSkia*>*>(key); |
118 if (image_properties_.count(image_key) > 0) | 119 if (image_properties_.count(image_key) > 0) |
119 return image_properties_[image_key]; | 120 return image_properties_[image_key]; |
120 | 121 |
121 auto rect_key = static_cast<const WindowProperty<gfx::Rect*>*>(key); | 122 auto rect_key = static_cast<const WindowProperty<gfx::Rect*>*>(key); |
122 if (rect_properties_.count(rect_key) > 0) | 123 if (rect_properties_.count(rect_key) > 0) |
123 return rect_properties_[rect_key]; | 124 return rect_properties_[rect_key]; |
124 | 125 |
125 auto size_key = static_cast<const WindowProperty<gfx::Size*>*>(key); | 126 auto size_key = static_cast<const WindowProperty<gfx::Size*>*>(key); |
126 if (size_properties_.count(size_key) > 0) | 127 if (size_properties_.count(size_key) > 0) |
127 return size_properties_[size_key]; | 128 return size_properties_[size_key]; |
128 | 129 |
129 auto string_key = static_cast<const WindowProperty<std::string*>*>(key); | 130 auto string_key = static_cast<const WindowProperty<std::string*>*>(key); |
130 if (string_properties_.count(string_key) > 0) | 131 if (string_properties_.count(string_key) > 0) |
131 return string_properties_[string_key]; | 132 return string_properties_[string_key]; |
132 | 133 |
133 auto string16_key = static_cast<const WindowProperty<base::string16*>*>(key); | 134 auto string16_key = static_cast<const WindowProperty<base::string16*>*>(key); |
134 if (string16_properties_.count(string16_key) > 0) | 135 if (string16_properties_.count(string16_key) > 0) |
135 return string16_properties_[string16_key]; | 136 return string16_properties_[string16_key]; |
136 | 137 |
137 return std::string(); | 138 return std::string(); |
138 } | 139 } |
139 | 140 |
140 void PropertyConverter::SetPropertyFromTransportValue( | 141 void PropertyConverter::SetPropertyFromTransportValue( |
141 Window* window, | 142 Window* window, |
142 const std::string& transport_name, | 143 const std::string& transport_name, |
143 const std::vector<uint8_t>* data) { | 144 const std::vector<uint8_t>* data) { |
144 for (const auto& primitive_property : primitive_properties_) { | 145 for (const auto& primitive_property : primitive_properties_) { |
145 if (primitive_property.second.second == transport_name) { | 146 if (primitive_property.second.transport_name == transport_name) { |
146 // aura::Window only supports property types that fit in PrimitiveType. | 147 // aura::Window only supports property types that fit in PrimitiveType. |
147 if (data->size() != 8u) { | 148 if (data->size() != 8u) { |
148 DVLOG(2) << "Property size mismatch (PrimitiveType): " | 149 DVLOG(2) << "Property size mismatch (PrimitiveType): " |
149 << transport_name; | 150 << transport_name; |
150 return; | 151 return; |
151 } | 152 } |
152 const PrimitiveType value = mojo::ConvertTo<PrimitiveType>(*data); | 153 const PrimitiveType value = mojo::ConvertTo<PrimitiveType>(*data); |
153 // TODO(msw): Should aura::Window just store all properties by name? | 154 // TODO(msw): Should aura::Window just store all properties by name? |
154 window->SetPropertyInternal(primitive_property.first, | 155 window->SetPropertyInternal( |
155 primitive_property.second.first, nullptr, | 156 primitive_property.first, primitive_property.second.property_name, |
156 value, 0); | 157 nullptr, value, primitive_property.second.default_value); |
157 return; | 158 return; |
158 } | 159 } |
159 } | 160 } |
160 | 161 |
161 for (const auto& image_property : image_properties_) { | 162 for (const auto& image_property : image_properties_) { |
162 if (image_property.second == transport_name) { | 163 if (image_property.second == transport_name) { |
163 // TODO(msw): Validate the data somehow, before trying to convert? | 164 // TODO(msw): Validate the data somehow, before trying to convert? |
164 // TODO(crbug.com/667566): Support additional scales or gfx::Image[Skia]. | 165 // TODO(crbug.com/667566): Support additional scales or gfx::Image[Skia]. |
165 const SkBitmap bitmap = mojo::ConvertTo<SkBitmap>(*data); | 166 const SkBitmap bitmap = mojo::ConvertTo<SkBitmap>(*data); |
166 const gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); | 167 const gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 bool PropertyConverter::GetPropertyValueFromTransportValue( | 218 bool PropertyConverter::GetPropertyValueFromTransportValue( |
218 const std::string& transport_name, | 219 const std::string& transport_name, |
219 const std::vector<uint8_t>& transport_data, | 220 const std::vector<uint8_t>& transport_data, |
220 PrimitiveType* value) { | 221 PrimitiveType* value) { |
221 // aura::Window only supports property types that fit in PrimitiveType. | 222 // aura::Window only supports property types that fit in PrimitiveType. |
222 if (transport_data.size() != 8u) { | 223 if (transport_data.size() != 8u) { |
223 DVLOG(2) << "Property size mismatch (PrimitiveType): " << transport_name; | 224 DVLOG(2) << "Property size mismatch (PrimitiveType): " << transport_name; |
224 return false; | 225 return false; |
225 } | 226 } |
226 for (const auto& primitive_property : primitive_properties_) { | 227 for (const auto& primitive_property : primitive_properties_) { |
227 if (primitive_property.second.second == transport_name) { | 228 if (primitive_property.second.transport_name == transport_name) { |
228 *value = mojo::ConvertTo<PrimitiveType>(transport_data); | 229 *value = mojo::ConvertTo<PrimitiveType>(transport_data); |
229 return true; | 230 return true; |
230 } | 231 } |
231 } | 232 } |
232 return false; | 233 return false; |
233 } | 234 } |
234 | 235 |
235 void PropertyConverter::RegisterProperty( | 236 void PropertyConverter::RegisterProperty( |
236 const WindowProperty<gfx::ImageSkia*>* property, | 237 const WindowProperty<gfx::ImageSkia*>* property, |
237 const char* transport_name) { | 238 const char* transport_name) { |
(...skipping 17 matching lines...) Expand all Loading... | |
255 const char* transport_name) { | 256 const char* transport_name) { |
256 string_properties_[property] = transport_name; | 257 string_properties_[property] = transport_name; |
257 } | 258 } |
258 | 259 |
259 void PropertyConverter::RegisterProperty( | 260 void PropertyConverter::RegisterProperty( |
260 const WindowProperty<base::string16*>* property, | 261 const WindowProperty<base::string16*>* property, |
261 const char* transport_name) { | 262 const char* transport_name) { |
262 string16_properties_[property] = transport_name; | 263 string16_properties_[property] = transport_name; |
263 } | 264 } |
264 | 265 |
266 PropertyConverter::PrimitiveProperty::PrimitiveProperty( | |
267 const char* property_name, | |
268 const char* transport_name, | |
269 const PrimitiveType default_value) | |
270 : property_name(property_name), | |
271 transport_name(transport_name), | |
272 default_value(default_value) {} | |
273 | |
265 } // namespace aura | 274 } // namespace aura |
OLD | NEW |