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

Side by Side Diff: services/ui/view_manager/view_tree_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
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_TREE_STATE_H_ 5 #ifndef SERVICES_UI_VIEW_MANAGER_VIEW_TREE_STATE_H_
6 #define SERVICES_UI_VIEW_MANAGER_VIEW_TREE_STATE_H_ 6 #define SERVICES_UI_VIEW_MANAGER_VIEW_TREE_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"
16 #include "mojo/common/binding_set.h"
17 #include "mojo/public/cpp/bindings/binding.h" 15 #include "mojo/public/cpp/bindings/binding.h"
18 #include "mojo/services/ui/views/cpp/formatting.h" 16 #include "mojo/services/ui/views/cpp/formatting.h"
19 #include "mojo/services/ui/views/interfaces/view_trees.mojom.h" 17 #include "mojo/services/ui/views/interfaces/view_trees.mojom.h"
20 #include "services/ui/view_manager/view_state.h"
21 18
22 namespace view_manager { 19 namespace view_manager {
23 20
21 class ViewRegistry;
22 class ViewState;
23 class ViewStub;
24 class ViewTreeHostImpl;
25
24 // Describes the state of a particular view tree. 26 // Describes the state of a particular view tree.
25 // This object is owned by the ViewRegistry that created it. 27 // This object is owned by the ViewRegistry that created it.
26 class ViewTreeState { 28 class ViewTreeState {
27 public: 29 public:
28 explicit ViewTreeState(mojo::ui::ViewTreePtr view_tree, 30 ViewTreeState(
29 mojo::ui::ViewTreeTokenPtr view_tree_token, 31 ViewRegistry* registry,
30 const std::string& label); 32 mojo::ui::ViewTreePtr view_tree,
33 mojo::ui::ViewTreeTokenPtr view_tree_token,
34 mojo::InterfaceRequest<mojo::ui::ViewTreeHost> view_tree_host_request,
35 const std::string& label);
31 ~ViewTreeState(); 36 ~ViewTreeState();
32 37
33 base::WeakPtr<ViewTreeState> GetWeakPtr() { 38 base::WeakPtr<ViewTreeState> GetWeakPtr() {
34 return weak_factory_.GetWeakPtr(); 39 return weak_factory_.GetWeakPtr();
35 } 40 }
36 41
37 // Gets the view tree interface, never null. 42 // Gets the view tree interface, never null.
38 // Caller does not obtain ownership of the view. 43 // Caller does not obtain ownership of the view tree.
39 mojo::ui::ViewTree* view_tree() const { return view_tree_.get(); } 44 mojo::ui::ViewTree* view_tree() const { return view_tree_.get(); }
40 45
41 // Gets the token used to refer to this view tree globally. 46 // Gets the token used to refer to this view tree globally.
42 // Caller does not obtain ownership of the token. 47 // Caller does not obtain ownership of the token.
43 mojo::ui::ViewTreeToken* view_tree_token() const { 48 mojo::ui::ViewTreeToken* view_tree_token() const {
44 return view_tree_token_.get(); 49 return view_tree_token_.get();
45 } 50 }
46 51
47 // Sets the associated host implementation and takes ownership of it. 52 // Gets the root of the view tree, or null if there is no root.
48 void set_view_tree_host(mojo::ui::ViewTreeHost* host) { 53 ViewStub* root() const { return root_.get(); }
49 view_tree_host_.reset(host);
50 }
51 54
52 // Sets the connection error handler for the view. 55 // Links the root of the view tree.
53 void set_view_tree_connection_error_handler(const base::Closure& handler) { 56 void LinkRoot(uint32_t key, std::unique_ptr<ViewStub> root);
54 view_tree_.set_connection_error_handler(handler);
55 }
56 57
57 // Gets the root of the view tree, or null if it is unavailable. 58 // Unlinks the root of the view tree and returns it.
58 ViewState* root() const { return root_; } 59 std::unique_ptr<ViewStub> UnlinkRoot();
59
60 // Sets the root of the view tree. Must not be null.
61 // The view specified as the new root must not have any parents.
62 void SetRoot(ViewState* root, uint32_t key);
63
64 // Resets the root view to null.
65 void ResetRoot();
66
67 // True if the client previously set but has not yet explicitly unset
68 // the root, independent of whether it is currently available.
69 bool explicit_root() const { return explicit_root_; }
70 void set_explicit_root(bool value) { explicit_root_ = value; }
71 60
72 // True if there is a pending layout request. 61 // True if there is a pending layout request.
73 bool layout_request_pending() const { return layout_request_pending_; } 62 bool layout_request_pending() const { return layout_request_pending_; }
74 void set_layout_request_pending(bool value) { 63 void set_layout_request_pending(bool value) {
75 layout_request_pending_ = value; 64 layout_request_pending_ = value;
76 } 65 }
77 66
78 // True if a layout request has been issued. 67 // True if a layout request has been issued.
79 bool layout_request_issued() const { return layout_request_issued_; } 68 bool layout_request_issued() const { return layout_request_issued_; }
80 void set_layout_request_issued(bool value) { layout_request_issued_ = value; } 69 void set_layout_request_issued(bool value) { layout_request_issued_ = value; }
81 70
82 const std::string& label() { return label_; } 71 const std::string& label() const { return label_; }
83 const std::string& FormattedLabel(); 72 const std::string& FormattedLabel() const;
84 73
85 private: 74 private:
86 mojo::ui::ViewTreePtr view_tree_; 75 mojo::ui::ViewTreePtr view_tree_;
87 mojo::ui::ViewTreeTokenPtr view_tree_token_; 76 mojo::ui::ViewTreeTokenPtr view_tree_token_;
77
88 const std::string label_; 78 const std::string label_;
89 std::string formatted_label_cache_; 79 mutable std::string formatted_label_cache_;
80
81 std::unique_ptr<ViewTreeHostImpl> impl_;
82 mojo::Binding<mojo::ui::ViewTreeHost> host_binding_;
90 83
91 std::unique_ptr<mojo::ui::ViewTreeHost> view_tree_host_; 84 std::unique_ptr<mojo::ui::ViewTreeHost> view_tree_host_;
92 ViewState* root_ = nullptr; 85 std::unique_ptr<ViewStub> root_;
93 bool explicit_root_ = false;
94 bool layout_request_pending_ = false; 86 bool layout_request_pending_ = false;
95 bool layout_request_issued_ = false; 87 bool layout_request_issued_ = false;
96 88
97 base::WeakPtrFactory<ViewTreeState> weak_factory_; // must be last 89 base::WeakPtrFactory<ViewTreeState> weak_factory_; // must be last
98 90
99 DISALLOW_COPY_AND_ASSIGN(ViewTreeState); 91 DISALLOW_COPY_AND_ASSIGN(ViewTreeState);
100 }; 92 };
101 93
102 std::ostream& operator<<(std::ostream& os, ViewTreeState* view_tree_state); 94 std::ostream& operator<<(std::ostream& os, ViewTreeState* view_tree_state);
103 95
104 } // namespace view_manager 96 } // namespace view_manager
105 97
106 #endif // SERVICES_UI_VIEW_MANAGER_VIEW_TREE_STATE_H_ 98 #endif // SERVICES_UI_VIEW_MANAGER_VIEW_TREE_STATE_H_
OLDNEW
« no previous file with comments | « services/ui/view_manager/view_tree_host_impl.cc ('k') | services/ui/view_manager/view_tree_state.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698