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

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

Issue 2499933003: Expand aura::PropertyConverter support. (Closed)
Patch Set: Fix the other new unit test. Created 4 years, 1 month 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 <memory> 11 #include <memory>
11 #include <string> 12 #include <string>
12 #include <vector> 13 #include <vector>
13 14
14 #include "base/macros.h" 15 #include "base/macros.h"
15 #include "ui/aura/aura_export.h" 16 #include "ui/aura/aura_export.h"
17 #include "ui/aura/window.h"
18
19 namespace gfx {
20 class Rect;
21 }
16 22
17 namespace aura { 23 namespace aura {
18 24
19 class Window;
20
21 // PropertyConverter is used to convert Window properties for transport to the 25 // PropertyConverter is used to convert Window properties for transport to the
22 // mus window server and back. Any time a property changes from one side it is 26 // mus window server and back. Any time a property changes from one side it is
23 // mapped to the other using this class. Not all Window properties need to map 27 // mapped to the other using this class. Not all Window properties need to map
24 // to server properties, and similarly not all transport properties need map to 28 // to server properties, and similarly not all transport properties need map to
25 // Window properties. 29 // Window properties.
26 class AURA_EXPORT PropertyConverter { 30 class AURA_EXPORT PropertyConverter {
27 public: 31 public:
28 PropertyConverter(); 32 PropertyConverter();
29 virtual ~PropertyConverter(); 33 ~PropertyConverter();
30 34
31 // Maps a property on the Window to a property pushed to the server. Return 35 // Maps a property on the Window to a property pushed to the server. Return
32 // true if the property should be sent to the server, false if the property 36 // true if the property should be sent to the server, false if the property
33 // is only used locally. 37 // is only used locally.
34 virtual bool ConvertPropertyForTransport( 38 bool ConvertPropertyForTransport(
35 Window* window, 39 Window* window,
36 const void* key, 40 const void* key,
37 std::string* transport_name, 41 std::string* transport_name,
38 std::unique_ptr<std::vector<uint8_t>>* transport_value); 42 std::unique_ptr<std::vector<uint8_t>>* transport_value);
39 43
40 // Returns the transport name for a Window property. 44 // Returns the transport name for a Window property.
41 virtual std::string GetTransportNameForPropertyKey(const void* key); 45 std::string GetTransportNameForPropertyKey(const void* key);
42 46
43 // Applies a value from the server to |window|. |transport_name| is the 47 // Applies a value from the server to |window|. |transport_name| is the
44 // name of the property and |transport_data| the value. |transport_data| may 48 // name of the property and |transport_data| the value. |transport_data| may
45 // be null. 49 // be null.
46 virtual void SetPropertyFromTransportValue( 50 void SetPropertyFromTransportValue(
47 Window* window, 51 Window* window,
48 const std::string& transport_name, 52 const std::string& transport_name,
49 const std::vector<uint8_t>* transport_data); 53 const std::vector<uint8_t>* transport_data);
50 54
55 // Register a property to support conversion between mus and aura.
56 template<typename T>
57 void RegisterProperty(const WindowProperty<T>* property,
58 const char* transport_name) {
59 primitive_properties_[property] =
60 PropertyNames(property->name, transport_name);
61 }
62
63 // Specializations for properties to pointer types supporting mojo conversion.
64 void RegisterProperty(const WindowProperty<gfx::Rect*>* property,
65 const char* transport_name);
66 void RegisterProperty(const WindowProperty<std::string*>* property,
67 const char* transport_name);
68
51 private: 69 private:
70 // A pair with the aura::WindowProperty::name and the mus property name.
71 using PropertyNames = std::pair<const char*, const char*>;
72 // A map of aura::WindowProperty<T> to its aura and mus property names.
73 // This supports the internal codepaths for primitive types, eg. T=bool.
74 std::map<const void*, PropertyNames> primitive_properties_;
75
76 // Maps of aura::WindowProperty<T> to their mus property names.
77 // This supports types that can be serialized for Mojo, eg. T=std::string*.
78 std::map<const WindowProperty<gfx::Rect*>*, const char*> rect_properties_;
79 std::map<const WindowProperty<std::string*>*, const char*> string_properties_;
80
52 DISALLOW_COPY_AND_ASSIGN(PropertyConverter); 81 DISALLOW_COPY_AND_ASSIGN(PropertyConverter);
53 }; 82 };
54 83
55 } // namespace aura 84 } // namespace aura
56 85
57 #endif // UI_AURA_MUS_PROPERTY_CONVERTER_H_ 86 #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