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_VIEW_MANAGER_PUBLIC_CPP_VIEW_H_ | 5 #ifndef MOJO_SERVICES_VIEW_MANAGER_PUBLIC_CPP_VIEW_H_ |
6 #define MOJO_SERVICES_VIEW_MANAGER_PUBLIC_CPP_VIEW_H_ | 6 #define MOJO_SERVICES_VIEW_MANAGER_PUBLIC_CPP_VIEW_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 template <typename T> | 27 template <typename T> |
28 struct ViewProperty; | 28 struct ViewProperty; |
29 | 29 |
30 // Views are owned by the ViewManager. | 30 // Views are owned by the ViewManager. |
31 // 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 |
32 // destruction and NULL any pointers you have. | 32 // destruction and NULL any pointers you have. |
33 // Investigate some kind of smart pointer or weak pointer for these. | 33 // Investigate some kind of smart pointer or weak pointer for these. |
34 class View { | 34 class View { |
35 public: | 35 public: |
36 using Children = std::vector<View*>; | 36 using Children = std::vector<View*>; |
37 | 37 using SharedProperties = std::map<std::string, std::vector<uint8_t>>; |
38 // Creates and returns a new View (which is owned by the ViewManager). Views | |
39 // are initially hidden, use SetVisible(true) to show. | |
40 static View* Create(ViewManager* view_manager); | |
41 | 38 |
42 // Destroys this view and all its children. | 39 // Destroys this view and all its children. |
43 void Destroy(); | 40 void Destroy(); |
44 | 41 |
45 ViewManager* view_manager() { return manager_; } | 42 ViewManager* view_manager() { return manager_; } |
46 | 43 |
47 // Configuration. | 44 // Configuration. |
48 Id id() const { return id_; } | 45 Id id() const { return id_; } |
49 | 46 |
50 // Geometric disposition. | 47 // Geometric disposition. |
51 const Rect& bounds() const { return bounds_; } | 48 const Rect& bounds() const { return bounds_; } |
52 void SetBounds(const Rect& bounds); | 49 void SetBounds(const Rect& bounds); |
53 | 50 |
54 // Visibility (also see IsDrawn()). When created views are hidden. | 51 // Visibility (also see IsDrawn()). When created views are hidden. |
55 bool visible() const { return visible_; } | 52 bool visible() const { return visible_; } |
56 void SetVisible(bool value); | 53 void SetVisible(bool value); |
57 | 54 |
58 // Returns the set of string to bag of byte properties. These properties are | 55 // Returns the set of string to bag of byte properties. These properties are |
59 // shared with the view manager. | 56 // shared with the view manager. |
60 const std::map<std::string, std::vector<uint8_t>>& shared_properties() const { | 57 const SharedProperties& shared_properties() const { return properties_; } |
61 return properties_; | |
62 } | |
63 // Sets a property. If |data| is null, this property is deleted. | 58 // Sets a property. If |data| is null, this property is deleted. |
64 void SetSharedProperty(const std::string& name, | 59 void SetSharedProperty(const std::string& name, |
65 const std::vector<uint8_t>* data); | 60 const std::vector<uint8_t>* data); |
66 | 61 |
67 // Sets the |value| of the given window |property|. Setting to the default | 62 // Sets the |value| of the given window |property|. Setting to the default |
68 // value (e.g., NULL) removes the property. The caller is responsible for the | 63 // value (e.g., NULL) removes the property. The caller is responsible for the |
69 // lifetime of any object set as a property on the View. | 64 // lifetime of any object set as a property on the View. |
70 // | 65 // |
71 // These properties are not visible to the view manager. | 66 // These properties are not visible to the view manager. |
72 template <typename T> | 67 template <typename T> |
(...skipping 23 matching lines...) Expand all Loading... |
96 bool IsDrawn() const; | 91 bool IsDrawn() const; |
97 | 92 |
98 // Observation. | 93 // Observation. |
99 void AddObserver(ViewObserver* observer); | 94 void AddObserver(ViewObserver* observer); |
100 void RemoveObserver(ViewObserver* observer); | 95 void RemoveObserver(ViewObserver* observer); |
101 | 96 |
102 // Tree. | 97 // Tree. |
103 View* parent() { return parent_; } | 98 View* parent() { return parent_; } |
104 const View* parent() const { return parent_; } | 99 const View* parent() const { return parent_; } |
105 const Children& children() const { return children_; } | 100 const Children& children() const { return children_; } |
| 101 View* GetRoot() { |
| 102 return const_cast<View*>(const_cast<const View*>(this)->GetRoot()); |
| 103 } |
106 const View* GetRoot() const; | 104 const View* GetRoot() const; |
107 | 105 |
108 void AddChild(View* child); | 106 void AddChild(View* child); |
109 void RemoveChild(View* child); | 107 void RemoveChild(View* child); |
110 | 108 |
111 void Reorder(View* relative, OrderDirection direction); | 109 void Reorder(View* relative, OrderDirection direction); |
112 void MoveToFront(); | 110 void MoveToFront(); |
113 void MoveToBack(); | 111 void MoveToBack(); |
114 | 112 |
115 bool Contains(View* child) const; | 113 bool Contains(View* child) const; |
(...skipping 13 matching lines...) Expand all Loading... |
129 | 127 |
130 protected: | 128 protected: |
131 // This class is subclassed only by test classes that provide a public ctor. | 129 // This class is subclassed only by test classes that provide a public ctor. |
132 View(); | 130 View(); |
133 ~View(); | 131 ~View(); |
134 | 132 |
135 private: | 133 private: |
136 friend class ViewPrivate; | 134 friend class ViewPrivate; |
137 friend class ViewManagerClientImpl; | 135 friend class ViewManagerClientImpl; |
138 | 136 |
139 explicit View(ViewManager* manager); | 137 View(ViewManager* manager, Id id); |
140 | 138 |
141 // Called by the public {Set,Get,Clear}Property functions. | 139 // Called by the public {Set,Get,Clear}Property functions. |
142 int64 SetLocalPropertyInternal(const void* key, | 140 int64 SetLocalPropertyInternal(const void* key, |
143 const char* name, | 141 const char* name, |
144 PropertyDeallocator deallocator, | 142 PropertyDeallocator deallocator, |
145 int64 value, | 143 int64 value, |
146 int64 default_value); | 144 int64 default_value); |
147 int64 GetLocalPropertyInternal(const void* key, int64 default_value) const; | 145 int64 GetLocalPropertyInternal(const void* key, int64 default_value) const; |
148 | 146 |
149 void LocalDestroy(); | 147 void LocalDestroy(); |
(...skipping 20 matching lines...) Expand all Loading... |
170 Id id_; | 168 Id id_; |
171 View* parent_; | 169 View* parent_; |
172 Children children_; | 170 Children children_; |
173 | 171 |
174 ObserverList<ViewObserver> observers_; | 172 ObserverList<ViewObserver> observers_; |
175 | 173 |
176 Rect bounds_; | 174 Rect bounds_; |
177 | 175 |
178 bool visible_; | 176 bool visible_; |
179 | 177 |
180 std::map<std::string, std::vector<uint8_t>> properties_; | 178 SharedProperties properties_; |
181 | 179 |
182 // Drawn state is derived from the visible state and the parent's visible | 180 // Drawn state is derived from the visible state and the parent's visible |
183 // state. This field is only used if the view has no parent (eg it's a root). | 181 // state. This field is only used if the view has no parent (eg it's a root). |
184 bool drawn_; | 182 bool drawn_; |
185 | 183 |
186 // Value struct to keep the name and deallocator for this property. | 184 // Value struct to keep the name and deallocator for this property. |
187 // Key cannot be used for this purpose because it can be char* or | 185 // Key cannot be used for this purpose because it can be char* or |
188 // WindowProperty<>. | 186 // WindowProperty<>. |
189 struct Value { | 187 struct Value { |
190 const char* name; | 188 const char* name; |
191 int64 value; | 189 int64 value; |
192 PropertyDeallocator deallocator; | 190 PropertyDeallocator deallocator; |
193 }; | 191 }; |
194 | 192 |
195 std::map<const void*, Value> prop_map_; | 193 std::map<const void*, Value> prop_map_; |
196 | 194 |
197 DISALLOW_COPY_AND_ASSIGN(View); | 195 DISALLOW_COPY_AND_ASSIGN(View); |
198 }; | 196 }; |
199 | 197 |
200 } // namespace mojo | 198 } // namespace mojo |
201 | 199 |
202 #endif // MOJO_SERVICES_VIEW_MANAGER_PUBLIC_CPP_VIEW_H_ | 200 #endif // MOJO_SERVICES_VIEW_MANAGER_PUBLIC_CPP_VIEW_H_ |
OLD | NEW |