| 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 "mojo/public/cpp/bindings/type_converter.h" | 7 #include "mojo/public/cpp/bindings/type_converter.h" |
| 8 #include "services/ui/public/cpp/property_type_converters.h" | 8 #include "services/ui/public/cpp/property_type_converters.h" |
| 9 #include "services/ui/public/interfaces/window_manager.mojom.h" | 9 #include "services/ui/public/interfaces/window_manager.mojom.h" |
| 10 #include "ui/aura/client/aura_constants.h" | 10 #include "ui/aura/client/aura_constants.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 | 47 |
| 48 bool PropertyConverter::ConvertPropertyForTransport( | 48 bool PropertyConverter::ConvertPropertyForTransport( |
| 49 Window* window, | 49 Window* window, |
| 50 const void* key, | 50 const void* key, |
| 51 std::string* transport_name, | 51 std::string* transport_name, |
| 52 std::unique_ptr<std::vector<uint8_t>>* transport_value) { | 52 std::unique_ptr<std::vector<uint8_t>>* transport_value) { |
| 53 *transport_name = GetTransportNameForPropertyKey(key); | 53 *transport_name = GetTransportNameForPropertyKey(key); |
| 54 if (transport_name->empty()) | 54 if (transport_name->empty()) |
| 55 return false; | 55 return false; |
| 56 | 56 |
| 57 auto image_key = static_cast<const WindowProperty<gfx::ImageSkia*>*>(key); |
| 58 if (image_properties_.count(image_key) > 0) { |
| 59 const gfx::ImageSkia* value = window->GetProperty(image_key); |
| 60 if (value) { |
| 61 // TODO(crbug.com/667566): Support additional scales or gfx::Image[Skia]. |
| 62 SkBitmap bitmap = value->GetRepresentation(1.f).sk_bitmap(); |
| 63 *transport_value = base::MakeUnique<std::vector<uint8_t>>( |
| 64 mojo::ConvertTo<std::vector<uint8_t>>(bitmap)); |
| 65 } else { |
| 66 *transport_value = base::MakeUnique<std::vector<uint8_t>>(); |
| 67 } |
| 68 return true; |
| 69 } |
| 70 |
| 57 auto rect_key = static_cast<const WindowProperty<gfx::Rect*>*>(key); | 71 auto rect_key = static_cast<const WindowProperty<gfx::Rect*>*>(key); |
| 58 if (rect_properties_.count(rect_key) > 0) { | 72 if (rect_properties_.count(rect_key) > 0) { |
| 59 *transport_value = GetArray(window, rect_key); | 73 *transport_value = GetArray(window, rect_key); |
| 60 return true; | 74 return true; |
| 61 } | 75 } |
| 62 | 76 |
| 63 auto string_key = static_cast<const WindowProperty<std::string*>*>(key); | 77 auto string_key = static_cast<const WindowProperty<std::string*>*>(key); |
| 64 if (string_properties_.count(string_key) > 0) { | 78 if (string_properties_.count(string_key) > 0) { |
| 65 *transport_value = GetArray(window, string_key); | 79 *transport_value = GetArray(window, string_key); |
| 66 return true; | 80 return true; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 78 const int64_t value = window->GetPropertyInternal(key, 0); | 92 const int64_t value = window->GetPropertyInternal(key, 0); |
| 79 *transport_value = base::MakeUnique<std::vector<uint8_t>>( | 93 *transport_value = base::MakeUnique<std::vector<uint8_t>>( |
| 80 mojo::ConvertTo<std::vector<uint8_t>>(value)); | 94 mojo::ConvertTo<std::vector<uint8_t>>(value)); |
| 81 return true; | 95 return true; |
| 82 } | 96 } |
| 83 | 97 |
| 84 std::string PropertyConverter::GetTransportNameForPropertyKey(const void* key) { | 98 std::string PropertyConverter::GetTransportNameForPropertyKey(const void* key) { |
| 85 if (primitive_properties_.count(key) > 0) | 99 if (primitive_properties_.count(key) > 0) |
| 86 return primitive_properties_[key].second; | 100 return primitive_properties_[key].second; |
| 87 | 101 |
| 102 auto image_key = static_cast<const WindowProperty<gfx::ImageSkia*>*>(key); |
| 103 if (image_properties_.count(image_key) > 0) |
| 104 return image_properties_[image_key]; |
| 105 |
| 88 auto rect_key = static_cast<const WindowProperty<gfx::Rect*>*>(key); | 106 auto rect_key = static_cast<const WindowProperty<gfx::Rect*>*>(key); |
| 89 if (rect_properties_.count(rect_key) > 0) | 107 if (rect_properties_.count(rect_key) > 0) |
| 90 return rect_properties_[rect_key]; | 108 return rect_properties_[rect_key]; |
| 91 | 109 |
| 92 auto string_key = static_cast<const WindowProperty<std::string*>*>(key); | 110 auto string_key = static_cast<const WindowProperty<std::string*>*>(key); |
| 93 if (string_properties_.count(string_key) > 0) | 111 if (string_properties_.count(string_key) > 0) |
| 94 return string_properties_[string_key]; | 112 return string_properties_[string_key]; |
| 95 | 113 |
| 96 auto string16_key = static_cast<const WindowProperty<base::string16*>*>(key); | 114 auto string16_key = static_cast<const WindowProperty<base::string16*>*>(key); |
| 97 if (string16_properties_.count(string16_key) > 0) | 115 if (string16_properties_.count(string16_key) > 0) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 113 } | 131 } |
| 114 const int64_t value = mojo::ConvertTo<int64_t>(*data); | 132 const int64_t value = mojo::ConvertTo<int64_t>(*data); |
| 115 // TODO(msw): Should aura::Window just store all properties by name? | 133 // TODO(msw): Should aura::Window just store all properties by name? |
| 116 window->SetPropertyInternal(primitive_property.first, | 134 window->SetPropertyInternal(primitive_property.first, |
| 117 primitive_property.second.first, nullptr, | 135 primitive_property.second.first, nullptr, |
| 118 value, 0); | 136 value, 0); |
| 119 return; | 137 return; |
| 120 } | 138 } |
| 121 } | 139 } |
| 122 | 140 |
| 141 for (const auto& image_property : image_properties_) { |
| 142 if (image_property.second == transport_name) { |
| 143 // TODO(msw): Validate the data somehow, before trying to convert? |
| 144 // TODO(crbug.com/667566): Support additional scales or gfx::Image[Skia]. |
| 145 const SkBitmap bitmap = mojo::ConvertTo<SkBitmap>(*data); |
| 146 const gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); |
| 147 window->SetProperty(image_property.first, new gfx::ImageSkia(image)); |
| 148 return; |
| 149 } |
| 150 } |
| 151 |
| 123 for (const auto& rect_property : rect_properties_) { | 152 for (const auto& rect_property : rect_properties_) { |
| 124 if (rect_property.second == transport_name) { | 153 if (rect_property.second == transport_name) { |
| 125 if (data->size() != 16u) { | 154 if (data->size() != 16u) { |
| 126 DVLOG(2) << "Property size mismatch (gfx::Rect): " << transport_name; | 155 DVLOG(2) << "Property size mismatch (gfx::Rect): " << transport_name; |
| 127 return; | 156 return; |
| 128 } | 157 } |
| 129 const gfx::Rect value = mojo::ConvertTo<gfx::Rect>(*data); | 158 const gfx::Rect value = mojo::ConvertTo<gfx::Rect>(*data); |
| 130 window->SetProperty(rect_property.first, new gfx::Rect(value)); | 159 window->SetProperty(rect_property.first, new gfx::Rect(value)); |
| 131 return; | 160 return; |
| 132 } | 161 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 147 const base::string16 value = mojo::ConvertTo<base::string16>(*data); | 176 const base::string16 value = mojo::ConvertTo<base::string16>(*data); |
| 148 window->SetProperty(string16_property.first, new base::string16(value)); | 177 window->SetProperty(string16_property.first, new base::string16(value)); |
| 149 return; | 178 return; |
| 150 } | 179 } |
| 151 } | 180 } |
| 152 | 181 |
| 153 DVLOG(2) << "Unknown mus property name: " << transport_name; | 182 DVLOG(2) << "Unknown mus property name: " << transport_name; |
| 154 } | 183 } |
| 155 | 184 |
| 156 void PropertyConverter::RegisterProperty( | 185 void PropertyConverter::RegisterProperty( |
| 186 const WindowProperty<gfx::ImageSkia*>* property, |
| 187 const char* transport_name) { |
| 188 image_properties_[property] = transport_name; |
| 189 } |
| 190 |
| 191 void PropertyConverter::RegisterProperty( |
| 157 const WindowProperty<gfx::Rect*>* property, | 192 const WindowProperty<gfx::Rect*>* property, |
| 158 const char* transport_name) { | 193 const char* transport_name) { |
| 159 rect_properties_[property] = transport_name; | 194 rect_properties_[property] = transport_name; |
| 160 } | 195 } |
| 161 | 196 |
| 162 void PropertyConverter::RegisterProperty( | 197 void PropertyConverter::RegisterProperty( |
| 163 const WindowProperty<std::string*>* property, | 198 const WindowProperty<std::string*>* property, |
| 164 const char* transport_name) { | 199 const char* transport_name) { |
| 165 string_properties_[property] = transport_name; | 200 string_properties_[property] = transport_name; |
| 166 } | 201 } |
| 167 | 202 |
| 168 void PropertyConverter::RegisterProperty( | 203 void PropertyConverter::RegisterProperty( |
| 169 const WindowProperty<base::string16*>* property, | 204 const WindowProperty<base::string16*>* property, |
| 170 const char* transport_name) { | 205 const char* transport_name) { |
| 171 string16_properties_[property] = transport_name; | 206 string16_properties_[property] = transport_name; |
| 172 } | 207 } |
| 173 | 208 |
| 174 } // namespace aura | 209 } // namespace aura |
| OLD | NEW |