OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_H_ | 5 #ifndef MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_H_ |
6 #define MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_H_ | 6 #define MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
12 #include "mojo/public/cpp/bindings/array.h" | 12 #include "mojo/public/cpp/bindings/array.h" |
13 #include "mojo/public/interfaces/application/service_provider.mojom.h" | 13 #include "mojo/public/interfaces/application/service_provider.mojom.h" |
14 #include "mojo/services/public/cpp/view_manager/types.h" | 14 #include "mojo/services/public/cpp/view_manager/types.h" |
15 #include "mojo/services/public/interfaces/geometry/geometry.mojom.h" | 15 #include "mojo/services/public/interfaces/geometry/geometry.mojom.h" |
16 #include "mojo/services/public/interfaces/surfaces/surface_id.mojom.h" | 16 #include "mojo/services/public/interfaces/surfaces/surface_id.mojom.h" |
17 #include "mojo/services/public/interfaces/view_manager/view_manager_constants.mo jom.h" | 17 #include "mojo/services/public/interfaces/view_manager/view_manager_constants.mo jom.h" |
18 | 18 |
19 namespace mojo { | 19 namespace mojo { |
20 | 20 |
21 class ServiceProviderImpl; | 21 class ServiceProviderImpl; |
22 class View; | 22 class View; |
23 class ViewManager; | 23 class ViewManager; |
24 class ViewObserver; | 24 class ViewObserver; |
25 | 25 |
26 // Defined in view_property.h (which we do not include) | |
27 template<typename T> | |
28 struct ViewProperty; | |
29 | |
26 // Views are owned by the ViewManager. | 30 // Views are owned by the ViewManager. |
27 // TODO(beng): Right now, you'll have to implement a ViewObserver to track | 31 // TODO(beng): Right now, you'll have to implement a ViewObserver to track |
28 // destruction and NULL any pointers you have. | 32 // destruction and NULL any pointers you have. |
29 // Investigate some kind of smart pointer or weak pointer for these. | 33 // Investigate some kind of smart pointer or weak pointer for these. |
30 class View { | 34 class View { |
31 public: | 35 public: |
32 typedef std::vector<View*> Children; | 36 typedef std::vector<View*> Children; |
33 | 37 |
34 static View* Create(ViewManager* view_manager); | 38 static View* Create(ViewManager* view_manager); |
35 | 39 |
36 // Destroys this view and all its children. | 40 // Destroys this view and all its children. |
37 void Destroy(); | 41 void Destroy(); |
38 | 42 |
39 ViewManager* view_manager() { return manager_; } | 43 ViewManager* view_manager() { return manager_; } |
40 | 44 |
41 // Configuration. | 45 // Configuration. |
42 Id id() const { return id_; } | 46 Id id() const { return id_; } |
43 | 47 |
44 // Geometric disposition. | 48 // Geometric disposition. |
45 const Rect& bounds() const { return bounds_; } | 49 const Rect& bounds() const { return bounds_; } |
46 void SetBounds(const Rect& bounds); | 50 void SetBounds(const Rect& bounds); |
47 | 51 |
48 // Visibility (also see IsDrawn()). | 52 // Visibility (also see IsDrawn()). |
49 bool visible() const { return visible_; } | 53 bool visible() const { return visible_; } |
50 void SetVisible(bool value); | 54 void SetVisible(bool value); |
51 | 55 |
56 // Returns the set of string to bag of byte properties. These properties are | |
57 // shared with all other clients of the view manager. | |
sky
2014/11/14 23:11:27
Actually, it's only the window manager that can se
| |
52 const std::map<std::string, std::vector<uint8_t>>& properties() const { | 58 const std::map<std::string, std::vector<uint8_t>>& properties() const { |
53 return properties_; | 59 return properties_; |
54 } | 60 } |
55 // Sets a property. If |data| is null, this property is deleted. | 61 // Sets a property. If |data| is null, this property is deleted. |
56 void SetProperty(const std::string& name, const std::vector<uint8_t>* data); | 62 void SetProperty(const std::string& name, const std::vector<uint8_t>* data); |
57 | 63 |
64 // Sets the |value| of the given window |property|. Setting to the default | |
65 // value (e.g., NULL) removes the property. The caller is responsible for the | |
66 // lifetime of any object set as a property on the View. | |
67 // | |
68 // These properties are only visible in the current process and are not | |
sky
2014/11/14 23:11:27
nit: 'current process' is kind of misleading here.
| |
69 // shared with other mojo services. | |
70 template<typename T> | |
71 void SetLocalProperty(const ViewProperty<T>* property, T value); | |
72 | |
73 // Returns the value of the given window |property|. Returns the | |
74 // property-specific default value if the property was not previously set. | |
75 // | |
76 // These properties are only visible in the current process and are not | |
77 // shared with other mojo services. | |
78 template<typename T> | |
79 T GetLocalProperty(const ViewProperty<T>* property) const; | |
80 | |
81 // Sets the |property| to its default value. Useful for avoiding a cast when | |
82 // setting to NULL. | |
83 // | |
84 // These properties are only visible in the current process and are not | |
85 // shared with other mojo services. | |
86 template<typename T> | |
87 void ClearLocalProperty(const ViewProperty<T>* property); | |
88 | |
89 // Type of a function to delete a property that this view owns. | |
90 typedef void (*PropertyDeallocator)(int64 value); | |
91 | |
58 // A View is drawn if the View and all its ancestors are visible and the | 92 // A View is drawn if the View and all its ancestors are visible and the |
59 // View is attached to the root. | 93 // View is attached to the root. |
60 bool IsDrawn() const; | 94 bool IsDrawn() const; |
61 | 95 |
62 // Observation. | 96 // Observation. |
63 void AddObserver(ViewObserver* observer); | 97 void AddObserver(ViewObserver* observer); |
64 void RemoveObserver(ViewObserver* observer); | 98 void RemoveObserver(ViewObserver* observer); |
65 | 99 |
66 // Tree. | 100 // Tree. |
67 View* parent() { return parent_; } | 101 View* parent() { return parent_; } |
(...skipping 26 matching lines...) Expand all Loading... | |
94 // This class is subclassed only by test classes that provide a public ctor. | 128 // This class is subclassed only by test classes that provide a public ctor. |
95 View(); | 129 View(); |
96 ~View(); | 130 ~View(); |
97 | 131 |
98 private: | 132 private: |
99 friend class ViewPrivate; | 133 friend class ViewPrivate; |
100 friend class ViewManagerClientImpl; | 134 friend class ViewManagerClientImpl; |
101 | 135 |
102 explicit View(ViewManager* manager); | 136 explicit View(ViewManager* manager); |
103 | 137 |
138 // Called by the public {Set,Get,Clear}Property functions. | |
139 int64 SetLocalPropertyInternal(const void* key, | |
140 const char* name, | |
141 PropertyDeallocator deallocator, | |
142 int64 value, | |
143 int64 default_value); | |
144 int64 GetLocalPropertyInternal(const void* key, int64 default_value) const; | |
145 | |
104 void LocalDestroy(); | 146 void LocalDestroy(); |
105 void LocalAddChild(View* child); | 147 void LocalAddChild(View* child); |
106 void LocalRemoveChild(View* child); | 148 void LocalRemoveChild(View* child); |
107 // Returns true if the order actually changed. | 149 // Returns true if the order actually changed. |
108 bool LocalReorder(View* relative, OrderDirection direction); | 150 bool LocalReorder(View* relative, OrderDirection direction); |
109 void LocalSetBounds(const Rect& old_bounds, const Rect& new_bounds); | 151 void LocalSetBounds(const Rect& old_bounds, const Rect& new_bounds); |
110 void LocalSetDrawn(bool drawn); | 152 void LocalSetDrawn(bool drawn); |
111 | 153 |
112 ViewManager* manager_; | 154 ViewManager* manager_; |
113 Id id_; | 155 Id id_; |
114 View* parent_; | 156 View* parent_; |
115 Children children_; | 157 Children children_; |
116 | 158 |
117 ObserverList<ViewObserver> observers_; | 159 ObserverList<ViewObserver> observers_; |
118 | 160 |
119 Rect bounds_; | 161 Rect bounds_; |
120 | 162 |
121 bool visible_; | 163 bool visible_; |
122 | 164 |
123 std::map<std::string, std::vector<uint8_t>> properties_; | 165 std::map<std::string, std::vector<uint8_t>> properties_; |
124 | 166 |
125 // Drawn state is derived from the visible state and the parent's visible | 167 // Drawn state is derived from the visible state and the parent's visible |
126 // state. This field is only used if the view has no parent (eg it's a root). | 168 // state. This field is only used if the view has no parent (eg it's a root). |
127 bool drawn_; | 169 bool drawn_; |
128 | 170 |
171 // Value struct to keep the name and deallocator for this property. | |
172 // Key cannot be used for this purpose because it can be char* or | |
173 // WindowProperty<>. | |
174 struct Value { | |
175 const char* name; | |
176 int64 value; | |
177 PropertyDeallocator deallocator; | |
178 }; | |
179 | |
180 std::map<const void*, Value> prop_map_; | |
181 | |
129 DISALLOW_COPY_AND_ASSIGN(View); | 182 DISALLOW_COPY_AND_ASSIGN(View); |
130 }; | 183 }; |
131 | 184 |
132 } // namespace mojo | 185 } // namespace mojo |
133 | 186 |
134 #endif // MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_H_ | 187 #endif // MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_H_ |
OLD | NEW |