Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(271)

Side by Side Diff: ui/aura/mus/property_converter.h

Issue 2635983005: Add PropertyConverter support for non-zero default primitive values. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ui/aura/mus/property_converter.cc » ('j') | ui/aura/mus/property_converter.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 primitive_properties_.insert(std::pair<const void*, PrimitiveProperty>(
74 PropertyNames(property->name, transport_name); 74 property, PrimitiveProperty(property->name, transport_name,
75 property->default_value)));
75 } 76 }
76 77
77 // Specializations for properties to pointer types supporting mojo conversion. 78 // Specializations for properties to pointer types supporting mojo conversion.
78 void RegisterProperty(const WindowProperty<gfx::ImageSkia*>* property, 79 void RegisterProperty(const WindowProperty<gfx::ImageSkia*>* property,
79 const char* transport_name); 80 const char* transport_name);
80 void RegisterProperty(const WindowProperty<gfx::Rect*>* property, 81 void RegisterProperty(const WindowProperty<gfx::Rect*>* property,
81 const char* transport_name); 82 const char* transport_name);
82 void RegisterProperty(const WindowProperty<gfx::Size*>* property, 83 void RegisterProperty(const WindowProperty<gfx::Size*>* property,
83 const char* transport_name); 84 const char* transport_name);
84 void RegisterProperty(const WindowProperty<std::string*>* property, 85 void RegisterProperty(const WindowProperty<std::string*>* property,
85 const char* transport_name); 86 const char* transport_name);
86 void RegisterProperty(const WindowProperty<base::string16*>* property, 87 void RegisterProperty(const WindowProperty<base::string16*>* property,
87 const char* transport_name); 88 const char* transport_name);
88 89
89 private: 90 private:
90 // A pair with the aura::WindowProperty::name and the mus property name. 91 // Contains data needed to store and convert primitive-type properties.
91 using PropertyNames = std::pair<const char*, const char*>; 92 struct PrimitiveProperty {
92 // A map of aura::WindowProperty<T> to its aura and mus property names. 93 PrimitiveProperty(const char* property_name,
94 const char* transport_name,
95 const PrimitiveType default_value);
96
97 // The aura::WindowProperty::name used for storage.
98 const char* property_name;
99 // The mus property name used for transport.
100 const char* transport_name;
101 // The aura::WindowProperty::default_value stored using PrimitiveType.
102 PrimitiveType default_value;
103 };
104
105 // A map of aura::WindowProperty<T> to PrimitiveProperty structs.
93 // This supports the internal codepaths for primitive types, eg. T=bool. 106 // This supports the internal codepaths for primitive types, eg. T=bool.
94 std::map<const void*, PropertyNames> primitive_properties_; 107 std::map<const void*, PrimitiveProperty> primitive_properties_;
95 108
96 // Maps of aura::WindowProperty<T> to their mus property names. 109 // Maps of aura::WindowProperty<T> to their mus property names.
97 // This supports types that can be serialized for Mojo, eg. T=std::string*. 110 // This supports types that can be serialized for Mojo, eg. T=std::string*.
98 std::map<const WindowProperty<gfx::ImageSkia*>*, const char*> 111 std::map<const WindowProperty<gfx::ImageSkia*>*, const char*>
99 image_properties_; 112 image_properties_;
100 std::map<const WindowProperty<gfx::Rect*>*, const char*> rect_properties_; 113 std::map<const WindowProperty<gfx::Rect*>*, const char*> rect_properties_;
101 std::map<const WindowProperty<gfx::Size*>*, const char*> size_properties_; 114 std::map<const WindowProperty<gfx::Size*>*, const char*> size_properties_;
102 std::map<const WindowProperty<std::string*>*, const char*> string_properties_; 115 std::map<const WindowProperty<std::string*>*, const char*> string_properties_;
103 std::map<const WindowProperty<base::string16*>*, const char*> 116 std::map<const WindowProperty<base::string16*>*, const char*>
104 string16_properties_; 117 string16_properties_;
105 118
106 DISALLOW_COPY_AND_ASSIGN(PropertyConverter); 119 DISALLOW_COPY_AND_ASSIGN(PropertyConverter);
107 }; 120 };
108 121
109 } // namespace aura 122 } // namespace aura
110 123
111 #endif // UI_AURA_MUS_PROPERTY_CONVERTER_H_ 124 #endif // UI_AURA_MUS_PROPERTY_CONVERTER_H_
OLDNEW
« no previous file with comments | « no previous file | ui/aura/mus/property_converter.cc » ('j') | ui/aura/mus/property_converter.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698