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

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

Issue 2538633002: Adds a couple more properties to the property converter (Closed)
Patch Set: merge again Created 4 years 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 | « ui/aura/client/aura_constants.cc ('k') | ui/aura/mus/property_converter.cc » ('j') | no next file with comments »
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>
11 #include <memory> 11 #include <memory>
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "ui/aura/aura_export.h" 16 #include "ui/aura/aura_export.h"
17 #include "ui/aura/window.h" 17 #include "ui/aura/window.h"
18 18
19 namespace gfx { 19 namespace gfx {
20 class Rect; 20 class Rect;
21 class Size;
21 } 22 }
22 23
23 namespace aura { 24 namespace aura {
24 25
25 // PropertyConverter is used to convert Window properties for transport to the 26 // PropertyConverter is used to convert Window properties for transport to the
26 // mus window server and back. Any time a property changes from one side it is 27 // mus window server and back. Any time a property changes from one side it is
27 // mapped to the other using this class. Not all Window properties need to map 28 // mapped to the other using this class. Not all Window properties need to map
28 // to server properties, and similarly not all transport properties need map to 29 // to server properties, and similarly not all transport properties need map to
29 // Window properties. 30 // Window properties.
30 class AURA_EXPORT PropertyConverter { 31 class AURA_EXPORT PropertyConverter {
31 public: 32 public:
33 // All primitive values are stored using this type.
34 using PrimitiveType = int64_t;
35
32 PropertyConverter(); 36 PropertyConverter();
33 ~PropertyConverter(); 37 ~PropertyConverter();
34 38
35 // Maps a property on the Window to a property pushed to the server. Return 39 // Maps a property on the Window to a property pushed to the server. Return
36 // true if the property should be sent to the server, false if the property 40 // true if the property should be sent to the server, false if the property
37 // is only used locally. 41 // is only used locally.
38 bool ConvertPropertyForTransport( 42 bool ConvertPropertyForTransport(
39 Window* window, 43 Window* window,
40 const void* key, 44 const void* key,
41 std::string* transport_name, 45 std::string* transport_name,
42 std::unique_ptr<std::vector<uint8_t>>* transport_value); 46 std::unique_ptr<std::vector<uint8_t>>* transport_value);
43 47
44 // Returns the transport name for a Window property. 48 // Returns the transport name for a Window property.
45 std::string GetTransportNameForPropertyKey(const void* key); 49 std::string GetTransportNameForPropertyKey(const void* key);
46 50
47 // Applies a value from the server to |window|. |transport_name| is the 51 // Applies a value from the server to |window|. |transport_name| is the
48 // name of the property and |transport_data| the value. |transport_data| may 52 // name of the property and |transport_data| the value. |transport_data| may
49 // be null. 53 // be null.
50 void SetPropertyFromTransportValue( 54 void SetPropertyFromTransportValue(
51 Window* window, 55 Window* window,
52 const std::string& transport_name, 56 const std::string& transport_name,
53 const std::vector<uint8_t>* transport_data); 57 const std::vector<uint8_t>* transport_data);
54 58
59 // Returns the value for a particular transport value. All primitives are
60 // serialized as a PrimitiveType, so this function may be used for any
61 // primitive. Returns true on success and sets |value| accordingly. A return
62 // value of false indicates the value isn't known or the property type isn't
63 // primitive.
64 bool GetPropertyValueFromTransportValue(
65 const std::string& transport_name,
66 const std::vector<uint8_t>& transport_data,
67 PrimitiveType* value);
68
55 // Register a property to support conversion between mus and aura. 69 // Register a property to support conversion between mus and aura.
56 template<typename T> 70 template<typename T>
57 void RegisterProperty(const WindowProperty<T>* property, 71 void RegisterProperty(const WindowProperty<T>* property,
58 const char* transport_name) { 72 const char* transport_name) {
59 primitive_properties_[property] = 73 primitive_properties_[property] =
60 PropertyNames(property->name, transport_name); 74 PropertyNames(property->name, transport_name);
61 } 75 }
62 76
63 // Specializations for properties to pointer types supporting mojo conversion. 77 // Specializations for properties to pointer types supporting mojo conversion.
64 void RegisterProperty(const WindowProperty<gfx::ImageSkia*>* property, 78 void RegisterProperty(const WindowProperty<gfx::ImageSkia*>* property,
65 const char* transport_name); 79 const char* transport_name);
66 void RegisterProperty(const WindowProperty<gfx::Rect*>* property, 80 void RegisterProperty(const WindowProperty<gfx::Rect*>* property,
67 const char* transport_name); 81 const char* transport_name);
82 void RegisterProperty(const WindowProperty<gfx::Size*>* property,
83 const char* transport_name);
68 void RegisterProperty(const WindowProperty<std::string*>* property, 84 void RegisterProperty(const WindowProperty<std::string*>* property,
69 const char* transport_name); 85 const char* transport_name);
70 void RegisterProperty(const WindowProperty<base::string16*>* property, 86 void RegisterProperty(const WindowProperty<base::string16*>* property,
71 const char* transport_name); 87 const char* transport_name);
72 88
73 private: 89 private:
74 // A pair with the aura::WindowProperty::name and the mus property name. 90 // A pair with the aura::WindowProperty::name and the mus property name.
75 using PropertyNames = std::pair<const char*, const char*>; 91 using PropertyNames = std::pair<const char*, const char*>;
76 // A map of aura::WindowProperty<T> to its aura and mus property names. 92 // A map of aura::WindowProperty<T> to its aura and mus property names.
77 // This supports the internal codepaths for primitive types, eg. T=bool. 93 // This supports the internal codepaths for primitive types, eg. T=bool.
78 std::map<const void*, PropertyNames> primitive_properties_; 94 std::map<const void*, PropertyNames> primitive_properties_;
79 95
80 // Maps of aura::WindowProperty<T> to their mus property names. 96 // Maps of aura::WindowProperty<T> to their mus property names.
81 // This supports types that can be serialized for Mojo, eg. T=std::string*. 97 // This supports types that can be serialized for Mojo, eg. T=std::string*.
82 std::map<const WindowProperty<gfx::ImageSkia*>*, const char*> 98 std::map<const WindowProperty<gfx::ImageSkia*>*, const char*>
83 image_properties_; 99 image_properties_;
84 std::map<const WindowProperty<gfx::Rect*>*, const char*> rect_properties_; 100 std::map<const WindowProperty<gfx::Rect*>*, const char*> rect_properties_;
101 std::map<const WindowProperty<gfx::Size*>*, const char*> size_properties_;
85 std::map<const WindowProperty<std::string*>*, const char*> string_properties_; 102 std::map<const WindowProperty<std::string*>*, const char*> string_properties_;
86 std::map<const WindowProperty<base::string16*>*, const char*> 103 std::map<const WindowProperty<base::string16*>*, const char*>
87 string16_properties_; 104 string16_properties_;
88 105
89 DISALLOW_COPY_AND_ASSIGN(PropertyConverter); 106 DISALLOW_COPY_AND_ASSIGN(PropertyConverter);
90 }; 107 };
91 108
92 } // namespace aura 109 } // namespace aura
93 110
94 #endif // UI_AURA_MUS_PROPERTY_CONVERTER_H_ 111 #endif // UI_AURA_MUS_PROPERTY_CONVERTER_H_
OLDNEW
« no previous file with comments | « ui/aura/client/aura_constants.cc ('k') | ui/aura/mus/property_converter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698