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