cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / components / view_manager / public / cpp / view.h
blob4430eb1118ba917d1307625c2d7f6d0012082a32
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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_VIEW_MANAGER_PUBLIC_CPP_VIEW_H_
6 #define COMPONENTS_VIEW_MANAGER_PUBLIC_CPP_VIEW_H_
8 #include <stdint.h>
9 #include <vector>
11 #include "base/observer_list.h"
12 #include "components/view_manager/public/cpp/types.h"
13 #include "components/view_manager/public/interfaces/surface_id.mojom.h"
14 #include "components/view_manager/public/interfaces/view_manager_constants.mojom.h"
15 #include "components/view_manager/public/interfaces/view_tree.mojom.h"
16 #include "mojo/application/public/interfaces/service_provider.mojom.h"
17 #include "third_party/mojo/src/mojo/public/cpp/bindings/array.h"
18 #include "third_party/mojo/src/mojo/public/cpp/system/macros.h"
19 #include "ui/mojo/geometry/geometry.mojom.h"
21 namespace mojo {
23 class ServiceProviderImpl;
24 class View;
25 class ViewObserver;
26 class ViewSurface;
27 class ViewTreeConnection;
29 // Defined in view_property.h (which we do not include)
30 template <typename T>
31 struct ViewProperty;
33 // Views are owned by the ViewTreeConnection. See ViewTreeDelegate for details
34 // on ownership.
36 // TODO(beng): Right now, you'll have to implement a ViewObserver to track
37 // destruction and NULL any pointers you have.
38 // Investigate some kind of smart pointer or weak pointer for these.
39 class View {
40 public:
41 using Children = std::vector<View*>;
42 using SharedProperties = std::map<std::string, std::vector<uint8_t>>;
44 // Destroys this view and all its children. Destruction is allowed for views
45 // that were created by this connection. For views from other connections
46 // (such as the root) Destroy() does nothing. If the destruction is allowed
47 // observers are notified and the View is immediately deleted.
48 void Destroy();
50 ViewTreeConnection* connection() { return connection_; }
52 // Configuration.
53 Id id() const { return id_; }
55 // Geometric disposition.
56 const Rect& bounds() const { return bounds_; }
57 void SetBounds(const Rect& bounds);
59 // Visibility (also see IsDrawn()). When created views are hidden.
60 bool visible() const { return visible_; }
61 void SetVisible(bool value);
63 const ViewportMetrics& viewport_metrics() { return *viewport_metrics_; }
65 scoped_ptr<ViewSurface> RequestSurface();
67 // Returns the set of string to bag of byte properties. These properties are
68 // shared with the view manager.
69 const SharedProperties& shared_properties() const { return properties_; }
70 // Sets a property. If |data| is null, this property is deleted.
71 void SetSharedProperty(const std::string& name,
72 const std::vector<uint8_t>* data);
74 // Sets the |value| of the given window |property|. Setting to the default
75 // value (e.g., NULL) removes the property. The caller is responsible for the
76 // lifetime of any object set as a property on the View.
78 // These properties are not visible to the view manager.
79 template <typename T>
80 void SetLocalProperty(const ViewProperty<T>* property, T value);
82 // Returns the value of the given window |property|. Returns the
83 // property-specific default value if the property was not previously set.
85 // These properties are only visible in the current process and are not
86 // shared with other mojo services.
87 template <typename T>
88 T GetLocalProperty(const ViewProperty<T>* property) const;
90 // Sets the |property| to its default value. Useful for avoiding a cast when
91 // setting to NULL.
93 // These properties are only visible in the current process and are not
94 // shared with other mojo services.
95 template <typename T>
96 void ClearLocalProperty(const ViewProperty<T>* property);
98 // Type of a function to delete a property that this view owns.
99 typedef void (*PropertyDeallocator)(int64_t value);
101 // A View is drawn if the View and all its ancestors are visible and the
102 // View is attached to the root.
103 bool IsDrawn() const;
105 // See mojom for details.
106 void SetAccessPolicy(uint32_t policy_bitmask);
108 // Observation.
109 void AddObserver(ViewObserver* observer);
110 void RemoveObserver(ViewObserver* observer);
112 // Tree.
113 View* parent() { return parent_; }
114 const View* parent() const { return parent_; }
115 const Children& children() const { return children_; }
116 View* GetRoot() {
117 return const_cast<View*>(const_cast<const View*>(this)->GetRoot());
119 const View* GetRoot() const;
121 void AddChild(View* child);
122 void RemoveChild(View* child);
124 void Reorder(View* relative, OrderDirection direction);
125 void MoveToFront();
126 void MoveToBack();
128 bool Contains(View* child) const;
130 View* GetChildById(Id id);
132 void SetTextInputState(TextInputStatePtr state);
133 void SetImeVisibility(bool visible, TextInputStatePtr state);
135 // Focus.
136 void SetFocus();
137 bool HasFocus() const;
139 // Embedding. See view_tree.mojom for details.
140 void Embed(ViewTreeClientPtr client);
142 protected:
143 // This class is subclassed only by test classes that provide a public ctor.
144 View();
145 ~View();
147 private:
148 friend class ViewPrivate;
149 friend class ViewTreeClientImpl;
151 View(ViewTreeConnection* connection, Id id);
153 // Called by the public {Set,Get,Clear}Property functions.
154 int64_t SetLocalPropertyInternal(const void* key,
155 const char* name,
156 PropertyDeallocator deallocator,
157 int64_t value,
158 int64_t default_value);
159 int64_t GetLocalPropertyInternal(const void* key,
160 int64_t default_value) const;
162 void LocalDestroy();
163 void LocalAddChild(View* child);
164 void LocalRemoveChild(View* child);
165 // Returns true if the order actually changed.
166 bool LocalReorder(View* relative, OrderDirection direction);
167 void LocalSetBounds(const Rect& old_bounds, const Rect& new_bounds);
168 void LocalSetViewportMetrics(const ViewportMetrics& old_metrics,
169 const ViewportMetrics& new_metrics);
170 void LocalSetDrawn(bool drawn);
171 void LocalSetVisible(bool visible);
173 // Methods implementing visibility change notifications. See ViewObserver
174 // for more details.
175 void NotifyViewVisibilityChanged(View* target);
176 // Notifies this view's observers. Returns false if |this| was deleted during
177 // the call (by an observer), otherwise true.
178 bool NotifyViewVisibilityChangedAtReceiver(View* target);
179 // Notifies this view and its child hierarchy. Returns false if |this| was
180 // deleted during the call (by an observer), otherwise true.
181 bool NotifyViewVisibilityChangedDown(View* target);
182 // Notifies this view and its parent hierarchy.
183 void NotifyViewVisibilityChangedUp(View* target);
185 // Returns true if embed is allowed for this node. If embedding is allowed all
186 // the children are removed.
187 bool PrepareForEmbed();
189 ViewTreeConnection* connection_;
190 Id id_;
191 View* parent_;
192 Children children_;
194 base::ObserverList<ViewObserver> observers_;
196 Rect bounds_;
197 ViewportMetricsPtr viewport_metrics_;
199 bool visible_;
201 SharedProperties properties_;
203 // Drawn state is derived from the visible state and the parent's visible
204 // state. This field is only used if the view has no parent (eg it's a root).
205 bool drawn_;
207 // Value struct to keep the name and deallocator for this property.
208 // Key cannot be used for this purpose because it can be char* or
209 // WindowProperty<>.
210 struct Value {
211 const char* name;
212 int64_t value;
213 PropertyDeallocator deallocator;
216 std::map<const void*, Value> prop_map_;
218 MOJO_DISALLOW_COPY_AND_ASSIGN(View);
221 } // namespace mojo
223 #endif // COMPONENTS_VIEW_MANAGER_PUBLIC_CPP_VIEW_H_