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 COMPONENTS_MUS_PUBLIC_CPP_VIEW_H_ | 5 #ifndef COMPONENTS_MUS_PUBLIC_CPP_VIEW_H_ |
6 #define COMPONENTS_MUS_PUBLIC_CPP_VIEW_H_ | 6 #define COMPONENTS_MUS_PUBLIC_CPP_VIEW_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
13 #include "components/mus/public/cpp/types.h" | 13 #include "components/mus/public/cpp/types.h" |
| 14 #include "components/mus/public/interfaces/mus_constants.mojom.h" |
14 #include "components/mus/public/interfaces/surface_id.mojom.h" | 15 #include "components/mus/public/interfaces/surface_id.mojom.h" |
15 #include "components/mus/public/interfaces/view_manager_constants.mojom.h" | |
16 #include "components/mus/public/interfaces/view_tree.mojom.h" | 16 #include "components/mus/public/interfaces/view_tree.mojom.h" |
17 #include "mojo/application/public/interfaces/service_provider.mojom.h" | 17 #include "mojo/application/public/interfaces/service_provider.mojom.h" |
18 #include "third_party/mojo/src/mojo/public/cpp/bindings/array.h" | 18 #include "third_party/mojo/src/mojo/public/cpp/bindings/array.h" |
19 #include "third_party/mojo/src/mojo/public/cpp/system/macros.h" | 19 #include "third_party/mojo/src/mojo/public/cpp/system/macros.h" |
20 #include "ui/mojo/geometry/geometry.mojom.h" | 20 #include "ui/mojo/geometry/geometry.mojom.h" |
21 | 21 |
22 namespace mojo { | 22 namespace mus { |
23 | 23 |
24 class ServiceProviderImpl; | 24 class ServiceProviderImpl; |
25 class View; | 25 class View; |
26 class ViewObserver; | 26 class ViewObserver; |
27 class ViewSurface; | 27 class ViewSurface; |
28 class ViewTreeConnection; | 28 class ViewTreeConnection; |
29 | 29 |
30 // Defined in view_property.h (which we do not include) | 30 // Defined in view_property.h (which we do not include) |
31 template <typename T> | 31 template <typename T> |
32 struct ViewProperty; | 32 struct ViewProperty; |
(...skipping 15 matching lines...) Expand all Loading... |
48 // (such as the root) Destroy() does nothing. If the destruction is allowed | 48 // (such as the root) Destroy() does nothing. If the destruction is allowed |
49 // observers are notified and the View is immediately deleted. | 49 // observers are notified and the View is immediately deleted. |
50 void Destroy(); | 50 void Destroy(); |
51 | 51 |
52 ViewTreeConnection* connection() { return connection_; } | 52 ViewTreeConnection* connection() { return connection_; } |
53 | 53 |
54 // Configuration. | 54 // Configuration. |
55 Id id() const { return id_; } | 55 Id id() const { return id_; } |
56 | 56 |
57 // Geometric disposition. | 57 // Geometric disposition. |
58 const Rect& bounds() const { return bounds_; } | 58 const mojo::Rect& bounds() const { return bounds_; } |
59 void SetBounds(const Rect& bounds); | 59 void SetBounds(const mojo::Rect& bounds); |
60 | 60 |
61 // Visibility (also see IsDrawn()). When created views are hidden. | 61 // Visibility (also see IsDrawn()). When created views are hidden. |
62 bool visible() const { return visible_; } | 62 bool visible() const { return visible_; } |
63 void SetVisible(bool value); | 63 void SetVisible(bool value); |
64 | 64 |
65 const ViewportMetrics& viewport_metrics() { return *viewport_metrics_; } | 65 const mojo::ViewportMetrics& viewport_metrics() { return *viewport_metrics_; } |
66 | 66 |
67 scoped_ptr<ViewSurface> RequestSurface(); | 67 scoped_ptr<ViewSurface> RequestSurface(); |
68 | 68 |
69 // Returns the set of string to bag of byte properties. These properties are | 69 // Returns the set of string to bag of byte properties. These properties are |
70 // shared with the view manager. | 70 // shared with the view manager. |
71 const SharedProperties& shared_properties() const { return properties_; } | 71 const SharedProperties& shared_properties() const { return properties_; } |
72 // Sets a property. If |data| is null, this property is deleted. | 72 // Sets a property. If |data| is null, this property is deleted. |
73 void SetSharedProperty(const std::string& name, | 73 void SetSharedProperty(const std::string& name, |
74 const std::vector<uint8_t>* data); | 74 const std::vector<uint8_t>* data); |
75 | 75 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 const View* parent() const { return parent_; } | 113 const View* parent() const { return parent_; } |
114 const Children& children() const { return children_; } | 114 const Children& children() const { return children_; } |
115 View* GetRoot() { | 115 View* GetRoot() { |
116 return const_cast<View*>(const_cast<const View*>(this)->GetRoot()); | 116 return const_cast<View*>(const_cast<const View*>(this)->GetRoot()); |
117 } | 117 } |
118 const View* GetRoot() const; | 118 const View* GetRoot() const; |
119 | 119 |
120 void AddChild(View* child); | 120 void AddChild(View* child); |
121 void RemoveChild(View* child); | 121 void RemoveChild(View* child); |
122 | 122 |
123 void Reorder(View* relative, OrderDirection direction); | 123 void Reorder(View* relative, mojo::OrderDirection direction); |
124 void MoveToFront(); | 124 void MoveToFront(); |
125 void MoveToBack(); | 125 void MoveToBack(); |
126 | 126 |
127 bool Contains(View* child) const; | 127 bool Contains(View* child) const; |
128 | 128 |
129 View* GetChildById(Id id); | 129 View* GetChildById(Id id); |
130 | 130 |
131 void SetTextInputState(TextInputStatePtr state); | 131 void SetTextInputState(mojo::TextInputStatePtr state); |
132 void SetImeVisibility(bool visible, TextInputStatePtr state); | 132 void SetImeVisibility(bool visible, mojo::TextInputStatePtr state); |
133 | 133 |
134 // Focus. | 134 // Focus. |
135 void SetFocus(); | 135 void SetFocus(); |
136 bool HasFocus() const; | 136 bool HasFocus() const; |
137 | 137 |
138 // Embedding. See view_tree.mojom for details. | 138 // Embedding. See view_tree.mojom for details. |
139 void Embed(ViewTreeClientPtr client); | 139 void Embed(mojo::ViewTreeClientPtr client); |
140 | 140 |
141 // NOTE: callback is run synchronously if Embed() is not allowed on this | 141 // NOTE: callback is run synchronously if Embed() is not allowed on this |
142 // View. | 142 // View. |
143 void Embed(ViewTreeClientPtr client, | 143 void Embed(mojo::ViewTreeClientPtr client, |
144 uint32_t policy_bitmask, | 144 uint32_t policy_bitmask, |
145 const EmbedCallback& callback); | 145 const EmbedCallback& callback); |
146 | 146 |
147 protected: | 147 protected: |
148 // This class is subclassed only by test classes that provide a public ctor. | 148 // This class is subclassed only by test classes that provide a public ctor. |
149 View(); | 149 View(); |
150 ~View(); | 150 ~View(); |
151 | 151 |
152 private: | 152 private: |
153 friend class ViewPrivate; | 153 friend class ViewPrivate; |
154 friend class ViewTreeClientImpl; | 154 friend class ViewTreeClientImpl; |
155 | 155 |
156 View(ViewTreeConnection* connection, Id id); | 156 View(ViewTreeConnection* connection, Id id); |
157 | 157 |
158 // Called by the public {Set,Get,Clear}Property functions. | 158 // Called by the public {Set,Get,Clear}Property functions. |
159 int64_t SetLocalPropertyInternal(const void* key, | 159 int64_t SetLocalPropertyInternal(const void* key, |
160 const char* name, | 160 const char* name, |
161 PropertyDeallocator deallocator, | 161 PropertyDeallocator deallocator, |
162 int64_t value, | 162 int64_t value, |
163 int64_t default_value); | 163 int64_t default_value); |
164 int64_t GetLocalPropertyInternal(const void* key, | 164 int64_t GetLocalPropertyInternal(const void* key, |
165 int64_t default_value) const; | 165 int64_t default_value) const; |
166 | 166 |
167 void LocalDestroy(); | 167 void LocalDestroy(); |
168 void LocalAddChild(View* child); | 168 void LocalAddChild(View* child); |
169 void LocalRemoveChild(View* child); | 169 void LocalRemoveChild(View* child); |
170 // Returns true if the order actually changed. | 170 // Returns true if the order actually changed. |
171 bool LocalReorder(View* relative, OrderDirection direction); | 171 bool LocalReorder(View* relative, mojo::OrderDirection direction); |
172 void LocalSetBounds(const Rect& old_bounds, const Rect& new_bounds); | 172 void LocalSetBounds(const mojo::Rect& old_bounds, |
173 void LocalSetViewportMetrics(const ViewportMetrics& old_metrics, | 173 const mojo::Rect& new_bounds); |
174 const ViewportMetrics& new_metrics); | 174 void LocalSetViewportMetrics(const mojo::ViewportMetrics& old_metrics, |
| 175 const mojo::ViewportMetrics& new_metrics); |
175 void LocalSetDrawn(bool drawn); | 176 void LocalSetDrawn(bool drawn); |
176 void LocalSetVisible(bool visible); | 177 void LocalSetVisible(bool visible); |
177 | 178 |
178 // Methods implementing visibility change notifications. See ViewObserver | 179 // Methods implementing visibility change notifications. See ViewObserver |
179 // for more details. | 180 // for more details. |
180 void NotifyViewVisibilityChanged(View* target); | 181 void NotifyViewVisibilityChanged(View* target); |
181 // Notifies this view's observers. Returns false if |this| was deleted during | 182 // Notifies this view's observers. Returns false if |this| was deleted during |
182 // the call (by an observer), otherwise true. | 183 // the call (by an observer), otherwise true. |
183 bool NotifyViewVisibilityChangedAtReceiver(View* target); | 184 bool NotifyViewVisibilityChangedAtReceiver(View* target); |
184 // Notifies this view and its child hierarchy. Returns false if |this| was | 185 // Notifies this view and its child hierarchy. Returns false if |this| was |
185 // deleted during the call (by an observer), otherwise true. | 186 // deleted during the call (by an observer), otherwise true. |
186 bool NotifyViewVisibilityChangedDown(View* target); | 187 bool NotifyViewVisibilityChangedDown(View* target); |
187 // Notifies this view and its parent hierarchy. | 188 // Notifies this view and its parent hierarchy. |
188 void NotifyViewVisibilityChangedUp(View* target); | 189 void NotifyViewVisibilityChangedUp(View* target); |
189 | 190 |
190 // Returns true if embed is allowed for this node. If embedding is allowed all | 191 // Returns true if embed is allowed for this node. If embedding is allowed all |
191 // the children are removed. | 192 // the children are removed. |
192 bool PrepareForEmbed(); | 193 bool PrepareForEmbed(); |
193 | 194 |
194 ViewTreeConnection* connection_; | 195 ViewTreeConnection* connection_; |
195 Id id_; | 196 Id id_; |
196 View* parent_; | 197 View* parent_; |
197 Children children_; | 198 Children children_; |
198 | 199 |
199 base::ObserverList<ViewObserver> observers_; | 200 base::ObserverList<ViewObserver> observers_; |
200 | 201 |
201 Rect bounds_; | 202 mojo::Rect bounds_; |
202 ViewportMetricsPtr viewport_metrics_; | 203 mojo::ViewportMetricsPtr viewport_metrics_; |
203 | 204 |
204 bool visible_; | 205 bool visible_; |
205 | 206 |
206 SharedProperties properties_; | 207 SharedProperties properties_; |
207 | 208 |
208 // Drawn state is derived from the visible state and the parent's visible | 209 // Drawn state is derived from the visible state and the parent's visible |
209 // state. This field is only used if the view has no parent (eg it's a root). | 210 // state. This field is only used if the view has no parent (eg it's a root). |
210 bool drawn_; | 211 bool drawn_; |
211 | 212 |
212 // Value struct to keep the name and deallocator for this property. | 213 // Value struct to keep the name and deallocator for this property. |
213 // Key cannot be used for this purpose because it can be char* or | 214 // Key cannot be used for this purpose because it can be char* or |
214 // WindowProperty<>. | 215 // WindowProperty<>. |
215 struct Value { | 216 struct Value { |
216 const char* name; | 217 const char* name; |
217 int64_t value; | 218 int64_t value; |
218 PropertyDeallocator deallocator; | 219 PropertyDeallocator deallocator; |
219 }; | 220 }; |
220 | 221 |
221 std::map<const void*, Value> prop_map_; | 222 std::map<const void*, Value> prop_map_; |
222 | 223 |
223 MOJO_DISALLOW_COPY_AND_ASSIGN(View); | 224 MOJO_DISALLOW_COPY_AND_ASSIGN(View); |
224 }; | 225 }; |
225 | 226 |
226 } // namespace mojo | 227 } // namespace mus |
227 | 228 |
228 #endif // COMPONENTS_MUS_PUBLIC_CPP_VIEW_H_ | 229 #endif // COMPONENTS_MUS_PUBLIC_CPP_VIEW_H_ |
OLD | NEW |