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

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

Issue 2538633002: Adds a couple more properties to the property converter (Closed)
Patch Set: cleanup 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
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 represented as this
msw 2016/11/29 01:15:45 nit: trailing period; optionally "are stored using
sky 2016/11/29 04:19:36 Done.
34 using PrimitiveType = int64_t;
35
32 PropertyConverter(); 36 PropertyConverter();
33 ~PropertyConverter(); 37 ~PropertyConverter();
34 38
39 // Convenience for calling SetPropertyFromTransportValue() for all the entries
40 // in |properties|.
41 void ApplyAllTransportProperties(
42 Window* window,
43 const std::map<std::string, std::vector<uint8_t>>& properties);
44
35 // Maps a property on the Window to a property pushed to the server. Return 45 // 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 46 // true if the property should be sent to the server, false if the property
37 // is only used locally. 47 // is only used locally.
38 bool ConvertPropertyForTransport( 48 bool ConvertPropertyForTransport(
39 Window* window, 49 Window* window,
40 const void* key, 50 const void* key,
41 std::string* transport_name, 51 std::string* transport_name,
42 std::unique_ptr<std::vector<uint8_t>>* transport_value); 52 std::unique_ptr<std::vector<uint8_t>>* transport_value);
43 53
44 // Returns the transport name for a Window property. 54 // Returns the transport name for a Window property.
45 std::string GetTransportNameForPropertyKey(const void* key); 55 std::string GetTransportNameForPropertyKey(const void* key);
46 56
47 // Applies a value from the server to |window|. |transport_name| is the 57 // 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 58 // name of the property and |transport_data| the value. |transport_data| may
49 // be null. 59 // be null.
50 void SetPropertyFromTransportValue( 60 void SetPropertyFromTransportValue(
51 Window* window, 61 Window* window,
52 const std::string& transport_name, 62 const std::string& transport_name,
53 const std::vector<uint8_t>* transport_data); 63 const std::vector<uint8_t>* transport_data);
54 64
65 // Returns the value for a particular transport value. All primitives are
66 // serialized as a PrimitiveType, so this function may be used for any
67 // primitive. Returns true on success and sets |value| accordingly. A return
68 // value of false indicates the value isn't known.
msw 2016/11/29 01:15:45 "or the property type isn't primitive."
sky 2016/11/29 04:19:36 Done.
69 bool GetPropertyValueFromTransformValue(
msw 2016/11/29 01:15:45 s/Transform/Transport/?
sky 2016/11/29 04:19:36 Wow! And I just started wearing glasses. Apparentl
70 const std::string& transport_name,
71 const std::vector<uint8_t>& transport_data,
72 PrimitiveType* value);
73
55 // Register a property to support conversion between mus and aura. 74 // Register a property to support conversion between mus and aura.
56 template<typename T> 75 template<typename T>
57 void RegisterProperty(const WindowProperty<T>* property, 76 void RegisterProperty(const WindowProperty<T>* property,
58 const char* transport_name) { 77 const char* transport_name) {
59 primitive_properties_[property] = 78 primitive_properties_[property] =
60 PropertyNames(property->name, transport_name); 79 PropertyNames(property->name, transport_name);
61 } 80 }
62 81
63 // Specializations for properties to pointer types supporting mojo conversion. 82 // Specializations for properties to pointer types supporting mojo conversion.
64 void RegisterProperty(const WindowProperty<gfx::ImageSkia*>* property, 83 void RegisterProperty(const WindowProperty<gfx::ImageSkia*>* property,
65 const char* transport_name); 84 const char* transport_name);
66 void RegisterProperty(const WindowProperty<gfx::Rect*>* property, 85 void RegisterProperty(const WindowProperty<gfx::Rect*>* property,
67 const char* transport_name); 86 const char* transport_name);
87 void RegisterProperty(const WindowProperty<gfx::Size*>* property,
88 const char* transport_name);
68 void RegisterProperty(const WindowProperty<std::string*>* property, 89 void RegisterProperty(const WindowProperty<std::string*>* property,
69 const char* transport_name); 90 const char* transport_name);
70 void RegisterProperty(const WindowProperty<base::string16*>* property, 91 void RegisterProperty(const WindowProperty<base::string16*>* property,
71 const char* transport_name); 92 const char* transport_name);
72 93
73 private: 94 private:
74 // A pair with the aura::WindowProperty::name and the mus property name. 95 // A pair with the aura::WindowProperty::name and the mus property name.
75 using PropertyNames = std::pair<const char*, const char*>; 96 using PropertyNames = std::pair<const char*, const char*>;
76 // A map of aura::WindowProperty<T> to its aura and mus property names. 97 // 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. 98 // This supports the internal codepaths for primitive types, eg. T=bool.
78 std::map<const void*, PropertyNames> primitive_properties_; 99 std::map<const void*, PropertyNames> primitive_properties_;
79 100
80 // Maps of aura::WindowProperty<T> to their mus property names. 101 // Maps of aura::WindowProperty<T> to their mus property names.
81 // This supports types that can be serialized for Mojo, eg. T=std::string*. 102 // This supports types that can be serialized for Mojo, eg. T=std::string*.
82 std::map<const WindowProperty<gfx::ImageSkia*>*, const char*> 103 std::map<const WindowProperty<gfx::ImageSkia*>*, const char*>
83 image_properties_; 104 image_properties_;
84 std::map<const WindowProperty<gfx::Rect*>*, const char*> rect_properties_; 105 std::map<const WindowProperty<gfx::Rect*>*, const char*> rect_properties_;
106 std::map<const WindowProperty<gfx::Size*>*, const char*> size_properties_;
85 std::map<const WindowProperty<std::string*>*, const char*> string_properties_; 107 std::map<const WindowProperty<std::string*>*, const char*> string_properties_;
86 std::map<const WindowProperty<base::string16*>*, const char*> 108 std::map<const WindowProperty<base::string16*>*, const char*>
87 string16_properties_; 109 string16_properties_;
88 110
89 DISALLOW_COPY_AND_ASSIGN(PropertyConverter); 111 DISALLOW_COPY_AND_ASSIGN(PropertyConverter);
90 }; 112 };
91 113
92 } // namespace aura 114 } // namespace aura
93 115
94 #endif // UI_AURA_MUS_PROPERTY_CONVERTER_H_ 116 #endif // UI_AURA_MUS_PROPERTY_CONVERTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698