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

Side by Side Diff: components/view_manager/view_tree_impl.h

Issue 1344573002: Mandoline: Rename components/view_manager to components/mus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 5 years, 3 months 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
OLDNEW
(Empty)
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.
4
5 #ifndef COMPONENTS_VIEW_MANAGER_VIEW_TREE_IMPL_H_
6 #define COMPONENTS_VIEW_MANAGER_VIEW_TREE_IMPL_H_
7
8 #include <set>
9 #include <string>
10 #include <vector>
11
12 #include "base/basictypes.h"
13 #include "base/containers/hash_tables.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "components/view_manager/access_policy_delegate.h"
17 #include "components/view_manager/ids.h"
18 #include "components/view_manager/public/interfaces/surface_id.mojom.h"
19 #include "components/view_manager/public/interfaces/view_tree.mojom.h"
20
21 namespace gfx {
22 class Rect;
23 }
24
25 namespace view_manager {
26
27 class AccessPolicy;
28 class ConnectionManager;
29 class ServerView;
30 class ViewTreeHostImpl;
31
32 // An instance of ViewTreeImpl is created for every ViewTree request.
33 // ViewTreeImpl tracks all the state and views created by a client. ViewTreeImpl
34 // coordinates with ConnectionManager to update the client (and internal state)
35 // as necessary.
36 class ViewTreeImpl : public mojo::ViewTree, public AccessPolicyDelegate {
37 public:
38 ViewTreeImpl(ConnectionManager* connection_manager,
39 mojo::ConnectionSpecificId creator_id,
40 const ViewId& root_id);
41 ~ViewTreeImpl() override;
42
43 // |services| and |exposed_services| are the ServiceProviders to pass to the
44 // client via OnEmbed().
45 void Init(mojo::ViewTreeClient* client, mojo::ViewTreePtr tree);
46
47 mojo::ConnectionSpecificId id() const { return id_; }
48 mojo::ConnectionSpecificId creator_id() const { return creator_id_; }
49
50 mojo::ViewTreeClient* client() { return client_; }
51
52 // Returns the View with the specified id.
53 ServerView* GetView(const ViewId& id) {
54 return const_cast<ServerView*>(
55 const_cast<const ViewTreeImpl*>(this)->GetView(id));
56 }
57 const ServerView* GetView(const ViewId& id) const;
58
59 // Returns true if this connection's root is |id|.
60 bool IsRoot(const ViewId& id) const;
61
62 // Returns the id of the root node. This is null if the root has been
63 // destroyed but the connection is still valid.
64 const ViewId* root() const { return root_.get(); }
65
66 bool is_embed_root() const { return is_embed_root_; }
67
68 ViewTreeHostImpl* GetHost();
69
70 // Invoked when a connection is about to be destroyed.
71 void OnWillDestroyViewTreeImpl(ViewTreeImpl* connection);
72
73 // These functions are synchronous variants of those defined in the mojom. The
74 // ViewTree implementations all call into these. See the mojom for details.
75 mojo::ErrorCode CreateView(const ViewId& view_id);
76 bool AddView(const ViewId& parent_id, const ViewId& child_id);
77 std::vector<const ServerView*> GetViewTree(const ViewId& view_id) const;
78 bool SetViewVisibility(const ViewId& view_id, bool visible);
79 bool Embed(const ViewId& view_id,
80 mojo::ViewTreeClientPtr client,
81 mojo::ConnectionSpecificId* connection_id);
82 void Embed(const ViewId& view_id, mojo::URLRequestPtr request);
83
84 // The following methods are invoked after the corresponding change has been
85 // processed. They do the appropriate bookkeeping and update the client as
86 // necessary.
87 void ProcessViewBoundsChanged(const ServerView* view,
88 const gfx::Rect& old_bounds,
89 const gfx::Rect& new_bounds,
90 bool originated_change);
91 void ProcessViewportMetricsChanged(const mojo::ViewportMetrics& old_metrics,
92 const mojo::ViewportMetrics& new_metrics,
93 bool originated_change);
94 void ProcessWillChangeViewHierarchy(const ServerView* view,
95 const ServerView* new_parent,
96 const ServerView* old_parent,
97 bool originated_change);
98 void ProcessViewPropertyChanged(const ServerView* view,
99 const std::string& name,
100 const std::vector<uint8_t>* new_data,
101 bool originated_change);
102 void ProcessViewHierarchyChanged(const ServerView* view,
103 const ServerView* new_parent,
104 const ServerView* old_parent,
105 bool originated_change);
106 void ProcessViewReorder(const ServerView* view,
107 const ServerView* relative_view,
108 mojo::OrderDirection direction,
109 bool originated_change);
110 void ProcessViewDeleted(const ViewId& view, bool originated_change);
111 void ProcessWillChangeViewVisibility(const ServerView* view,
112 bool originated_change);
113 void ProcessFocusChanged(const ServerView* old_focused_view,
114 const ServerView* new_focused_view);
115
116 private:
117 using ViewIdSet = base::hash_set<mojo::Id>;
118 using ViewMap = std::map<mojo::ConnectionSpecificId, ServerView*>;
119
120 bool IsViewKnown(const ServerView* view) const;
121
122 // These functions return true if the corresponding mojom function is allowed
123 // for this connection.
124 bool CanReorderView(const ServerView* view,
125 const ServerView* relative_view,
126 mojo::OrderDirection direction) const;
127
128 // Deletes a view owned by this connection. Returns true on success. |source|
129 // is the connection that originated the change.
130 bool DeleteViewImpl(ViewTreeImpl* source, ServerView* view);
131
132 // If |view| is known (in |known_views_|) does nothing. Otherwise adds |view|
133 // to |views|, marks |view| as known and recurses.
134 void GetUnknownViewsFrom(const ServerView* view,
135 std::vector<const ServerView*>* views);
136
137 // Removes |view| and all its descendants from |known_views_|. This does not
138 // recurse through views that were created by this connection. All views owned
139 // by this connection are added to |local_views|.
140 void RemoveFromKnown(const ServerView* view,
141 std::vector<ServerView*>* local_views);
142
143 // Resets the root of this connection.
144 void RemoveRoot();
145
146 // Converts View(s) to ViewData(s) for transport. This assumes all the views
147 // are valid for the client. The parent of views the client is not allowed to
148 // see are set to NULL (in the returned ViewData(s)).
149 mojo::Array<mojo::ViewDataPtr> ViewsToViewDatas(
150 const std::vector<const ServerView*>& views);
151 mojo::ViewDataPtr ViewToViewData(const ServerView* view);
152
153 // Implementation of GetViewTree(). Adds |view| to |views| and recurses if
154 // CanDescendIntoViewForViewTree() returns true.
155 void GetViewTreeImpl(const ServerView* view,
156 std::vector<const ServerView*>* views) const;
157
158 // Notify the client if the drawn state of any of the roots changes.
159 // |view| is the view that is changing to the drawn state |new_drawn_value|.
160 void NotifyDrawnStateChanged(const ServerView* view, bool new_drawn_value);
161
162 // Deletes all Views we own.
163 void DestroyViews();
164
165 bool CanEmbed(const ViewId& view_id) const;
166 void PrepareForEmbed(const ViewId& view_id);
167 void RemoveChildrenAsPartOfEmbed(const ViewId& view_id);
168
169 // ViewTree:
170 void CreateView(
171 mojo::Id transport_view_id,
172 const mojo::Callback<void(mojo::ErrorCode)>& callback) override;
173 void DeleteView(mojo::Id transport_view_id,
174 const mojo::Callback<void(bool)>& callback) override;
175 void AddView(mojo::Id parent_id,
176 mojo::Id child_id,
177 const mojo::Callback<void(bool)>& callback) override;
178 void RemoveViewFromParent(
179 mojo::Id view_id,
180 const mojo::Callback<void(bool)>& callback) override;
181 void ReorderView(mojo::Id view_id,
182 mojo::Id relative_view_id,
183 mojo::OrderDirection direction,
184 const mojo::Callback<void(bool)>& callback) override;
185 void GetViewTree(mojo::Id view_id,
186 const mojo::Callback<void(mojo::Array<mojo::ViewDataPtr>)>&
187 callback) override;
188 void SetViewBounds(mojo::Id view_id,
189 mojo::RectPtr bounds,
190 const mojo::Callback<void(bool)>& callback) override;
191 void SetViewVisibility(mojo::Id view_id,
192 bool visible,
193 const mojo::Callback<void(bool)>& callback) override;
194 void SetViewProperty(mojo::Id view_id,
195 const mojo::String& name,
196 mojo::Array<uint8_t> value,
197 const mojo::Callback<void(bool)>& callback) override;
198 void RequestSurface(
199 mojo::Id view_id,
200 mojo::InterfaceRequest<mojo::Surface> surface,
201 mojo::SurfaceClientPtr client) override;
202 void Embed(mojo::Id transport_view_id,
203 mojo::ViewTreeClientPtr client,
204 const EmbedCallback& callback) override;
205 void SetFocus(uint32_t view_id) override;
206 void SetViewTextInputState(uint32_t view_id,
207 mojo::TextInputStatePtr state) override;
208 void SetImeVisibility(mojo::Id transport_view_id,
209 bool visible,
210 mojo::TextInputStatePtr state) override;
211 void SetAccessPolicy(mojo::Id transport_view_id,
212 uint32 policy_bitmask) override;
213
214 // AccessPolicyDelegate:
215 bool IsRootForAccessPolicy(const ViewId& id) const override;
216 bool IsViewKnownForAccessPolicy(const ServerView* view) const override;
217 bool IsViewRootOfAnotherConnectionForAccessPolicy(
218 const ServerView* view) const override;
219 bool IsDescendantOfEmbedRoot(const ServerView* view) override;
220
221 ConnectionManager* connection_manager_;
222
223 // Id of this connection as assigned by ConnectionManager.
224 const mojo::ConnectionSpecificId id_;
225
226 // ID of the connection that created us. If 0 it indicates either we were
227 // created by the root, or the connection that created us has been destroyed.
228 mojo::ConnectionSpecificId creator_id_;
229
230 mojo::ViewTreeClient* client_;
231
232 scoped_ptr<view_manager::AccessPolicy> access_policy_;
233
234 // The views created by this connection. This connection owns these objects.
235 ViewMap view_map_;
236
237 // The set of views that has been communicated to the client.
238 ViewIdSet known_views_;
239
240 // The root of this connection. This is a scoped_ptr to reinforce the
241 // connection may have no root. A connection has no root if either the root
242 // is destroyed or Embed() is invoked on the root.
243 scoped_ptr<ViewId> root_;
244
245 bool is_embed_root_;
246
247 DISALLOW_COPY_AND_ASSIGN(ViewTreeImpl);
248 };
249
250 } // namespace view_manager
251
252 #endif // COMPONENTS_VIEW_MANAGER_VIEW_TREE_IMPL_H_
OLDNEW
« no previous file with comments | « components/view_manager/view_tree_host_impl.cc ('k') | components/view_manager/view_tree_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698