| 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 #ifndef UI_AURA_MUS_PROPERTY_CONVERTER_H_ | 5 #ifndef UI_AURA_MUS_PROPERTY_CONVERTER_H_ |
| 6 #define UI_AURA_MUS_PROPERTY_CONVERTER_H_ | 6 #define UI_AURA_MUS_PROPERTY_CONVERTER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 // primitive. | 63 // primitive. |
| 64 bool GetPropertyValueFromTransportValue( | 64 bool GetPropertyValueFromTransportValue( |
| 65 const std::string& transport_name, | 65 const std::string& transport_name, |
| 66 const std::vector<uint8_t>& transport_data, | 66 const std::vector<uint8_t>& transport_data, |
| 67 PrimitiveType* value); | 67 PrimitiveType* value); |
| 68 | 68 |
| 69 // Register a property to support conversion between mus and aura. | 69 // Register a property to support conversion between mus and aura. |
| 70 template<typename T> | 70 template<typename T> |
| 71 void RegisterProperty(const WindowProperty<T>* property, | 71 void RegisterProperty(const WindowProperty<T>* property, |
| 72 const char* transport_name) { | 72 const char* transport_name) { |
| 73 primitive_properties_[property] = | 73 PrimitiveProperty primitive_property; |
| 74 PropertyNames(property->name, transport_name); | 74 primitive_property.property_name = property->name; |
| 75 primitive_property.transport_name = transport_name; |
| 76 primitive_property.default_value = property->default_value; |
| 77 primitive_properties_[property] = primitive_property; |
| 75 } | 78 } |
| 76 | 79 |
| 77 // Specializations for properties to pointer types supporting mojo conversion. | 80 // Specializations for properties to pointer types supporting mojo conversion. |
| 78 void RegisterProperty(const WindowProperty<gfx::ImageSkia*>* property, | 81 void RegisterProperty(const WindowProperty<gfx::ImageSkia*>* property, |
| 79 const char* transport_name); | 82 const char* transport_name); |
| 80 void RegisterProperty(const WindowProperty<gfx::Rect*>* property, | 83 void RegisterProperty(const WindowProperty<gfx::Rect*>* property, |
| 81 const char* transport_name); | 84 const char* transport_name); |
| 82 void RegisterProperty(const WindowProperty<gfx::Size*>* property, | 85 void RegisterProperty(const WindowProperty<gfx::Size*>* property, |
| 83 const char* transport_name); | 86 const char* transport_name); |
| 84 void RegisterProperty(const WindowProperty<std::string*>* property, | 87 void RegisterProperty(const WindowProperty<std::string*>* property, |
| 85 const char* transport_name); | 88 const char* transport_name); |
| 86 void RegisterProperty(const WindowProperty<base::string16*>* property, | 89 void RegisterProperty(const WindowProperty<base::string16*>* property, |
| 87 const char* transport_name); | 90 const char* transport_name); |
| 88 | 91 |
| 89 private: | 92 private: |
| 90 // A pair with the aura::WindowProperty::name and the mus property name. | 93 // Contains data needed to store and convert primitive-type properties. |
| 91 using PropertyNames = std::pair<const char*, const char*>; | 94 struct PrimitiveProperty { |
| 92 // A map of aura::WindowProperty<T> to its aura and mus property names. | 95 // The aura::WindowProperty::name used for storage. |
| 96 const char* property_name = nullptr; |
| 97 // The mus property name used for transport. |
| 98 const char* transport_name = nullptr; |
| 99 // The aura::WindowProperty::default_value stored using PrimitiveType. |
| 100 PrimitiveType default_value = 0; |
| 101 }; |
| 102 |
| 103 // A map of aura::WindowProperty<T> to PrimitiveProperty structs. |
| 93 // This supports the internal codepaths for primitive types, eg. T=bool. | 104 // This supports the internal codepaths for primitive types, eg. T=bool. |
| 94 std::map<const void*, PropertyNames> primitive_properties_; | 105 std::map<const void*, PrimitiveProperty> primitive_properties_; |
| 95 | 106 |
| 96 // Maps of aura::WindowProperty<T> to their mus property names. | 107 // Maps of aura::WindowProperty<T> to their mus property names. |
| 97 // This supports types that can be serialized for Mojo, eg. T=std::string*. | 108 // This supports types that can be serialized for Mojo, eg. T=std::string*. |
| 98 std::map<const WindowProperty<gfx::ImageSkia*>*, const char*> | 109 std::map<const WindowProperty<gfx::ImageSkia*>*, const char*> |
| 99 image_properties_; | 110 image_properties_; |
| 100 std::map<const WindowProperty<gfx::Rect*>*, const char*> rect_properties_; | 111 std::map<const WindowProperty<gfx::Rect*>*, const char*> rect_properties_; |
| 101 std::map<const WindowProperty<gfx::Size*>*, const char*> size_properties_; | 112 std::map<const WindowProperty<gfx::Size*>*, const char*> size_properties_; |
| 102 std::map<const WindowProperty<std::string*>*, const char*> string_properties_; | 113 std::map<const WindowProperty<std::string*>*, const char*> string_properties_; |
| 103 std::map<const WindowProperty<base::string16*>*, const char*> | 114 std::map<const WindowProperty<base::string16*>*, const char*> |
| 104 string16_properties_; | 115 string16_properties_; |
| 105 | 116 |
| 106 DISALLOW_COPY_AND_ASSIGN(PropertyConverter); | 117 DISALLOW_COPY_AND_ASSIGN(PropertyConverter); |
| 107 }; | 118 }; |
| 108 | 119 |
| 109 } // namespace aura | 120 } // namespace aura |
| 110 | 121 |
| 111 #endif // UI_AURA_MUS_PROPERTY_CONVERTER_H_ | 122 #endif // UI_AURA_MUS_PROPERTY_CONVERTER_H_ |
| OLD | NEW |