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

Side by Side Diff: services/ui/view_manager/view_state.h

Issue 1679023006: Reify view ownership as a message pipe. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « services/ui/view_manager/view_registry.cc ('k') | services/ui/view_manager/view_state.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 SERVICES_UI_VIEW_MANAGER_VIEW_STATE_H_ 5 #ifndef SERVICES_UI_VIEW_MANAGER_VIEW_STATE_H_
6 #define SERVICES_UI_VIEW_MANAGER_VIEW_STATE_H_ 6 #define SERVICES_UI_VIEW_MANAGER_VIEW_STATE_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 #include <unordered_map> 11 #include <unordered_map>
12 12
13 #include "base/callback.h"
14 #include "base/macros.h" 13 #include "base/macros.h"
15 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "mojo/public/cpp/bindings/binding.h"
16 #include "mojo/services/ui/views/cpp/formatting.h" 16 #include "mojo/services/ui/views/cpp/formatting.h"
17 #include "mojo/services/ui/views/interfaces/views.mojom.h" 17 #include "mojo/services/ui/views/interfaces/views.mojom.h"
18 #include "services/ui/view_manager/view_layout_request.h" 18 #include "services/ui/view_manager/view_layout_request.h"
19 19
20 namespace view_manager { 20 namespace view_manager {
21 21
22 class ViewTreeState; 22 class ViewRegistry;
23 class ViewHostImpl;
24 class ViewStub;
23 25
24 // Describes the state of a particular view. 26 // Describes the state of a particular view.
25 // This object is owned by the ViewRegistry that created it. 27 // This object is owned by the ViewRegistry that created it.
26 class ViewState { 28 class ViewState {
27 public: 29 public:
28 using ChildrenMap = std::unordered_map<uint32_t, ViewState*>; 30 using ChildrenMap = std::unordered_map<uint32_t, std::unique_ptr<ViewStub>>;
29 31
30 ViewState(mojo::ui::ViewPtr view, 32 ViewState(ViewRegistry* registry,
33 mojo::ui::ViewPtr view,
31 mojo::ui::ViewTokenPtr view_token, 34 mojo::ui::ViewTokenPtr view_token,
35 mojo::InterfaceRequest<mojo::ui::ViewHost> view_host_request,
32 const std::string& label); 36 const std::string& label);
33 ~ViewState(); 37 ~ViewState();
34 38
35 base::WeakPtr<ViewState> GetWeakPtr() { return weak_factory_.GetWeakPtr(); } 39 base::WeakPtr<ViewState> GetWeakPtr() { return weak_factory_.GetWeakPtr(); }
36 40
37 // Gets the view interface, never null. 41 // Gets the view interface, never null.
38 // Caller does not obtain ownership of the view. 42 // Caller does not obtain ownership of the view.
39 mojo::ui::View* view() const { return view_.get(); } 43 mojo::ui::View* view() const { return view_.get(); }
40 44
41 // Gets the token used to refer to this view globally. 45 // Gets the token used to refer to this view globally.
42 // Caller does not obtain ownership of the token. 46 // Caller does not obtain ownership of the token.
43 mojo::ui::ViewToken* view_token() const { return view_token_.get(); } 47 mojo::ui::ViewToken* view_token() const { return view_token_.get(); }
44 48
45 // Sets the associated host implementation and takes ownership of it. 49 // Gets or sets the view stub which links this view into the
46 void set_view_host(mojo::ui::ViewHost* host) { view_host_.reset(host); } 50 // view hierarchy, or null if the view isn't linked anywhere.
47 51 ViewStub* view_stub() const { return view_stub_; }
48 // Sets the connection error handler for the view. 52 void set_view_stub(ViewStub* view_stub) { view_stub_ = view_stub; }
49 void set_view_connection_error_handler(const base::Closure& handler) {
50 view_.set_connection_error_handler(handler);
51 }
52
53 // Gets the view tree to which this view belongs, or null if none.
54 ViewTreeState* tree() const { return tree_; }
55
56 // Gets the parent view state, or null if none.
57 ViewState* parent() const { return parent_; }
58
59 // Gets the key that this child has in its container, or 0 if none.
60 uint32_t key() const { return key_; }
61
62 // Recursively sets the view tree to which this view and all of its
63 // descendents belongs. Must not be null. This method must only be called
64 // on root views.
65 void SetTree(ViewTreeState* tree, uint32_t key);
66
67 // Sets the parent view state pointer, the child's key in its parent,
68 // and set its view tree to that of its parent. Must not be null.
69 void SetParent(ViewState* parent, uint32_t key);
70
71 // Resets the parent view state and tree pointers to null.
72 void ResetContainer();
73 53
74 // The map of children, indexed by child key. 54 // The map of children, indexed by child key.
75 // Child view state may be null if the child with the given key has 55 // The view stub pointers are never null but some view stubs may
76 // become unavailable but not yet removed. 56 // have been marked unavailable.
77 ChildrenMap& children() { return children_; } 57 const ChildrenMap& children() const { return children_; }
58
59 // Links a child into the view tree.
60 void LinkChild(uint32_t key, std::unique_ptr<ViewStub> child);
61
62 // Unlinks a child of the view tree.
63 std::unique_ptr<ViewStub> UnlinkChild(uint32_t key);
64
65 // Unlinks all children as a single operation.
66 std::vector<std::unique_ptr<ViewStub>> UnlinkAllChildren();
78 67
79 // The set of children needing layout. 68 // The set of children needing layout.
80 // This set must never contain non-existent or unavailable children. 69 // This set must never contain non-existent or unavailable children.
81 std::set<uint32_t>& children_needing_layout() { 70 std::set<uint32_t>& children_needing_layout() {
82 return children_needing_layout_; 71 return children_needing_layout_;
83 } 72 }
84 73
85 // The list of pending layout requests. 74 // The list of pending layout requests.
86 std::vector<std::unique_ptr<ViewLayoutRequest>>& pending_layout_requests() { 75 std::vector<std::unique_ptr<ViewLayoutRequest>>& pending_layout_requests() {
87 return pending_layout_requests_; 76 return pending_layout_requests_;
(...skipping 28 matching lines...) Expand all
116 return scene_changed_since_last_report_; 105 return scene_changed_since_last_report_;
117 } 106 }
118 void set_scene_changed_since_last_report(bool value) { 107 void set_scene_changed_since_last_report(bool value) {
119 scene_changed_since_last_report_ = value; 108 scene_changed_since_last_report_ = value;
120 } 109 }
121 110
122 // Creates layout information to return to the parent or tree. 111 // Creates layout information to return to the parent or tree.
123 // Returns null if unavailable. 112 // Returns null if unavailable.
124 mojo::ui::ViewLayoutInfoPtr CreateLayoutInfo(); 113 mojo::ui::ViewLayoutInfoPtr CreateLayoutInfo();
125 114
126 const std::string& label() { return label_; } 115 // Binds the |ViewOwner| interface to the view which has the effect of
127 const std::string& FormattedLabel(); 116 // tying the view's lifetime to that of the owner's pipe.
117 void BindOwner(
118 mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request);
119
120 // Unbinds the view from its owner.
121 void ReleaseOwner();
122
123 const std::string& label() const { return label_; }
124 const std::string& FormattedLabel() const;
128 125
129 private: 126 private:
130 void SetTreeUnchecked(ViewTreeState* tree);
131
132 mojo::ui::ViewPtr view_; 127 mojo::ui::ViewPtr view_;
133 mojo::ui::ViewTokenPtr view_token_; 128 mojo::ui::ViewTokenPtr view_token_;
129
134 const std::string label_; 130 const std::string label_;
135 std::string formatted_label_cache_; 131 mutable std::string formatted_label_cache_;
136 132
137 std::unique_ptr<mojo::ui::ViewHost> view_host_; 133 std::unique_ptr<ViewHostImpl> impl_;
138 ViewTreeState* tree_ = nullptr; 134 mojo::Binding<mojo::ui::ViewHost> host_binding_;
139 ViewState* parent_ = nullptr; 135 mojo::Binding<mojo::ui::ViewOwner> owner_binding_;
140 uint32_t key_ = 0u; 136
137 ViewStub* view_stub_ = nullptr;
138
141 ChildrenMap children_; 139 ChildrenMap children_;
142 std::set<uint32_t> children_needing_layout_; 140 std::set<uint32_t> children_needing_layout_;
143 std::vector<std::unique_ptr<ViewLayoutRequest>> pending_layout_requests_; 141 std::vector<std::unique_ptr<ViewLayoutRequest>> pending_layout_requests_;
144 mojo::ui::ViewLayoutParamsPtr layout_params_; 142 mojo::ui::ViewLayoutParamsPtr layout_params_;
145 mojo::ui::ViewLayoutResultPtr layout_result_; 143 mojo::ui::ViewLayoutResultPtr layout_result_;
146 mojo::gfx::composition::SceneTokenPtr scene_token_; 144 mojo::gfx::composition::SceneTokenPtr scene_token_;
147 bool scene_changed_since_last_report_ = false; 145 bool scene_changed_since_last_report_ = false;
148 146
149 base::WeakPtrFactory<ViewState> weak_factory_; // must be last 147 base::WeakPtrFactory<ViewState> weak_factory_; // must be last
150 148
151 DISALLOW_COPY_AND_ASSIGN(ViewState); 149 DISALLOW_COPY_AND_ASSIGN(ViewState);
152 }; 150 };
153 151
154 std::ostream& operator<<(std::ostream& os, ViewState* view_state); 152 std::ostream& operator<<(std::ostream& os, ViewState* view_state);
155 153
156 } // namespace view_manager 154 } // namespace view_manager
157 155
158 #endif // SERVICES_UI_VIEW_MANAGER_VIEW_STATE_H_ 156 #endif // SERVICES_UI_VIEW_MANAGER_VIEW_STATE_H_
OLDNEW
« no previous file with comments | « services/ui/view_manager/view_registry.cc ('k') | services/ui/view_manager/view_state.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698