| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 63 |
| 64 bool PropertyConverter::ConvertPropertyForTransport( | 64 bool PropertyConverter::ConvertPropertyForTransport( |
| 65 Window* window, | 65 Window* window, |
| 66 const void* key, | 66 const void* key, |
| 67 std::string* transport_name, | 67 std::string* transport_name, |
| 68 std::unique_ptr<std::vector<uint8_t>>* transport_value) { | 68 std::unique_ptr<std::vector<uint8_t>>* transport_value) { |
| 69 *transport_name = GetTransportNameForPropertyKey(key); | 69 *transport_name = GetTransportNameForPropertyKey(key); |
| 70 if (transport_name->empty()) | 70 if (transport_name->empty()) |
| 71 return false; | 71 return false; |
| 72 | 72 |
| 73 auto image_key = static_cast<const WindowProperty<gfx::ImageSkia*>*>(key); | 73 auto* image_key = static_cast<const WindowProperty<gfx::ImageSkia*>*>(key); |
| 74 if (image_properties_.count(image_key) > 0) { | 74 if (image_properties_.count(image_key) > 0) { |
| 75 const gfx::ImageSkia* value = window->GetProperty(image_key); | 75 const gfx::ImageSkia* value = window->GetProperty(image_key); |
| 76 if (value) { | 76 if (value) { |
| 77 // TODO(crbug.com/667566): Support additional scales or gfx::Image[Skia]. | 77 // TODO(crbug.com/667566): Support additional scales or gfx::Image[Skia]. |
| 78 SkBitmap bitmap = value->GetRepresentation(1.f).sk_bitmap(); | 78 SkBitmap bitmap = value->GetRepresentation(1.f).sk_bitmap(); |
| 79 *transport_value = base::MakeUnique<std::vector<uint8_t>>( | 79 *transport_value = base::MakeUnique<std::vector<uint8_t>>( |
| 80 mojo::ConvertTo<std::vector<uint8_t>>(bitmap)); | 80 mojo::ConvertTo<std::vector<uint8_t>>(bitmap)); |
| 81 } else { | 81 } else { |
| 82 *transport_value = base::MakeUnique<std::vector<uint8_t>>(); | 82 *transport_value = base::MakeUnique<std::vector<uint8_t>>(); |
| 83 } | 83 } |
| 84 return true; | 84 return true; |
| 85 } | 85 } |
| 86 | 86 |
| 87 auto rect_key = static_cast<const WindowProperty<gfx::Rect*>*>(key); | 87 auto* rect_key = static_cast<const WindowProperty<gfx::Rect*>*>(key); |
| 88 if (rect_properties_.count(rect_key) > 0) { | 88 if (rect_properties_.count(rect_key) > 0) { |
| 89 *transport_value = GetArray(window, rect_key); | 89 *transport_value = GetArray(window, rect_key); |
| 90 return true; | 90 return true; |
| 91 } | 91 } |
| 92 | 92 |
| 93 auto size_key = static_cast<const WindowProperty<gfx::Size*>*>(key); | 93 auto* size_key = static_cast<const WindowProperty<gfx::Size*>*>(key); |
| 94 if (size_properties_.count(size_key) > 0) { | 94 if (size_properties_.count(size_key) > 0) { |
| 95 *transport_value = GetArray(window, size_key); | 95 *transport_value = GetArray(window, size_key); |
| 96 return true; | 96 return true; |
| 97 } | 97 } |
| 98 | 98 |
| 99 auto string_key = static_cast<const WindowProperty<std::string*>*>(key); | 99 auto* string_key = static_cast<const WindowProperty<std::string*>*>(key); |
| 100 if (string_properties_.count(string_key) > 0) { | 100 if (string_properties_.count(string_key) > 0) { |
| 101 *transport_value = GetArray(window, string_key); | 101 *transport_value = GetArray(window, string_key); |
| 102 return true; | 102 return true; |
| 103 } | 103 } |
| 104 | 104 |
| 105 auto string16_key = static_cast<const WindowProperty<base::string16*>*>(key); | 105 auto* string16_key = static_cast<const WindowProperty<base::string16*>*>(key); |
| 106 if (string16_properties_.count(string16_key) > 0) { | 106 if (string16_properties_.count(string16_key) > 0) { |
| 107 *transport_value = GetArray(window, string16_key); | 107 *transport_value = GetArray(window, string16_key); |
| 108 return true; | 108 return true; |
| 109 } | 109 } |
| 110 | 110 |
| 111 // Handle primitive property types generically. | 111 // Handle primitive property types generically. |
| 112 DCHECK_GT(primitive_properties_.count(key), 0u); | 112 DCHECK_GT(primitive_properties_.count(key), 0u); |
| 113 PrimitiveType default_value = primitive_properties_[key].default_value; | 113 PrimitiveType default_value = primitive_properties_[key].default_value; |
| 114 // TODO(msw): Using the int64_t accessor is wasteful for smaller types. | 114 // TODO(msw): Using the int64_t accessor is wasteful for smaller types. |
| 115 const PrimitiveType value = window->GetPropertyInternal(key, default_value); | 115 const PrimitiveType value = window->GetPropertyInternal(key, default_value); |
| 116 *transport_value = base::MakeUnique<std::vector<uint8_t>>( | 116 *transport_value = base::MakeUnique<std::vector<uint8_t>>( |
| 117 mojo::ConvertTo<std::vector<uint8_t>>(value)); | 117 mojo::ConvertTo<std::vector<uint8_t>>(value)); |
| 118 return true; | 118 return true; |
| 119 } | 119 } |
| 120 | 120 |
| 121 std::string PropertyConverter::GetTransportNameForPropertyKey(const void* key) { | 121 std::string PropertyConverter::GetTransportNameForPropertyKey(const void* key) { |
| 122 if (primitive_properties_.count(key) > 0) | 122 if (primitive_properties_.count(key) > 0) |
| 123 return primitive_properties_[key].transport_name; | 123 return primitive_properties_[key].transport_name; |
| 124 | 124 |
| 125 auto image_key = static_cast<const WindowProperty<gfx::ImageSkia*>*>(key); | 125 auto* image_key = static_cast<const WindowProperty<gfx::ImageSkia*>*>(key); |
| 126 if (image_properties_.count(image_key) > 0) | 126 if (image_properties_.count(image_key) > 0) |
| 127 return image_properties_[image_key]; | 127 return image_properties_[image_key]; |
| 128 | 128 |
| 129 auto rect_key = static_cast<const WindowProperty<gfx::Rect*>*>(key); | 129 auto* rect_key = static_cast<const WindowProperty<gfx::Rect*>*>(key); |
| 130 if (rect_properties_.count(rect_key) > 0) | 130 if (rect_properties_.count(rect_key) > 0) |
| 131 return rect_properties_[rect_key]; | 131 return rect_properties_[rect_key]; |
| 132 | 132 |
| 133 auto size_key = static_cast<const WindowProperty<gfx::Size*>*>(key); | 133 auto* size_key = static_cast<const WindowProperty<gfx::Size*>*>(key); |
| 134 if (size_properties_.count(size_key) > 0) | 134 if (size_properties_.count(size_key) > 0) |
| 135 return size_properties_[size_key]; | 135 return size_properties_[size_key]; |
| 136 | 136 |
| 137 auto string_key = static_cast<const WindowProperty<std::string*>*>(key); | 137 auto* string_key = static_cast<const WindowProperty<std::string*>*>(key); |
| 138 if (string_properties_.count(string_key) > 0) | 138 if (string_properties_.count(string_key) > 0) |
| 139 return string_properties_[string_key]; | 139 return string_properties_[string_key]; |
| 140 | 140 |
| 141 auto string16_key = static_cast<const WindowProperty<base::string16*>*>(key); | 141 auto* string16_key = static_cast<const WindowProperty<base::string16*>*>(key); |
| 142 if (string16_properties_.count(string16_key) > 0) | 142 if (string16_properties_.count(string16_key) > 0) |
| 143 return string16_properties_[string16_key]; | 143 return string16_properties_[string16_key]; |
| 144 | 144 |
| 145 return std::string(); | 145 return std::string(); |
| 146 } | 146 } |
| 147 | 147 |
| 148 void PropertyConverter::SetPropertyFromTransportValue( | 148 void PropertyConverter::SetPropertyFromTransportValue( |
| 149 Window* window, | 149 Window* window, |
| 150 const std::string& transport_name, | 150 const std::string& transport_name, |
| 151 const std::vector<uint8_t>* data) { | 151 const std::vector<uint8_t>* data) { |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 } | 269 } |
| 270 | 270 |
| 271 void PropertyConverter::RegisterProperty( | 271 void PropertyConverter::RegisterProperty( |
| 272 const WindowProperty<base::string16*>* property, | 272 const WindowProperty<base::string16*>* property, |
| 273 const char* transport_name) { | 273 const char* transport_name) { |
| 274 string16_properties_[property] = transport_name; | 274 string16_properties_[property] = transport_name; |
| 275 transport_names_.insert(transport_name); | 275 transport_names_.insert(transport_name); |
| 276 } | 276 } |
| 277 | 277 |
| 278 } // namespace aura | 278 } // namespace aura |
| OLD | NEW |