| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef SERVICES_UI_VIEW_MANAGER_VIEW_REGISTRY_H_ |
| 6 #define SERVICES_UI_VIEW_MANAGER_VIEW_REGISTRY_H_ |
| 7 |
| 8 #include <unordered_map> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/macros.h" |
| 12 #include "mojo/services/ui/views/interfaces/view_trees.mojom.h" |
| 13 #include "mojo/services/ui/views/interfaces/views.mojom.h" |
| 14 #include "services/ui/view_manager/view_layout_request.h" |
| 15 #include "services/ui/view_manager/view_state.h" |
| 16 #include "services/ui/view_manager/view_tree_state.h" |
| 17 |
| 18 namespace view_manager { |
| 19 |
| 20 class SurfaceManager; |
| 21 |
| 22 // Maintains a registry of the state of all views. |
| 23 // All ViewState objects are owned by the registry. |
| 24 class ViewRegistry { |
| 25 public: |
| 26 ViewRegistry(SurfaceManager* surface_manager); |
| 27 ~ViewRegistry(); |
| 28 |
| 29 // VIEW MANAGER REQUESTS |
| 30 |
| 31 // Registers a view and returns its ViewToken. |
| 32 mojo::ui::ViewTokenPtr RegisterView( |
| 33 mojo::ui::ViewPtr view, |
| 34 mojo::InterfaceRequest<mojo::ui::ViewHost> view_host_request); |
| 35 |
| 36 // Registers a view tree. |
| 37 void RegisterViewTree( |
| 38 mojo::ui::ViewTreePtr view_tree, |
| 39 mojo::InterfaceRequest<mojo::ui::ViewTreeHost> view_tree_host_request); |
| 40 |
| 41 // VIEW HOST REQUESTS |
| 42 |
| 43 // Requests layout. |
| 44 // Destroys |view_state| if an error occurs. |
| 45 void RequestLayout(ViewState* view_state); |
| 46 |
| 47 // Adds a child, reparenting it if necessary. |
| 48 // Destroys |parent_state| if an error occurs. |
| 49 void AddChild(ViewState* parent_state, |
| 50 uint32_t child_key, |
| 51 mojo::ui::ViewTokenPtr child_view_token); |
| 52 |
| 53 // Removes a child. |
| 54 // Destroys |parent_state| if an error occurs. |
| 55 void RemoveChild(ViewState* parent_state, uint32_t child_key); |
| 56 |
| 57 // Lays out a child and optionally provides its size. |
| 58 // If |provide_size| is true, indicates that the parent of the view |
| 59 // is using the child's size to compute its layout. This will affect how |
| 60 // subsequent layout requests are optimized. |
| 61 // Destroys |parent_state| if an error occurs. |
| 62 void LayoutChild(ViewState* parent_state, |
| 63 uint32_t child_key, |
| 64 mojo::ui::ViewLayoutParamsPtr child_layout_params, |
| 65 bool provide_size, |
| 66 const ViewLayoutCallback& callback); |
| 67 |
| 68 // VIEW TREE HOST REQUESTS |
| 69 |
| 70 // Requests layout. |
| 71 // Destroys |tree_state| if an error occurs. |
| 72 void RequestLayout(ViewTreeState* tree_state); |
| 73 |
| 74 // Sets the root of the view tree. |
| 75 // Destroys |tree_state| if an error occurs. |
| 76 void SetRoot(ViewTreeState* tree_state, |
| 77 uint32_t root_key, |
| 78 mojo::ui::ViewTokenPtr root_view_token); |
| 79 |
| 80 // Resets the root of the view tree. |
| 81 // Destroys |tree_state| if an error occurs. |
| 82 void ResetRoot(ViewTreeState* tree_state); |
| 83 |
| 84 // Lays out a view tree's root and optionally provides its size. |
| 85 // If |provide_size| is true, indicates that the view tree is using the |
| 86 // root's size to compute its layout. This will affect how subsequent |
| 87 // layout requests are optimized. |
| 88 // Destroys |tree_state| if an error occurs. |
| 89 void LayoutRoot(ViewTreeState* tree_state, |
| 90 mojo::ui::ViewLayoutParamsPtr root_layout_params, |
| 91 bool provide_size, |
| 92 const ViewLayoutCallback& callback); |
| 93 |
| 94 private: |
| 95 // LIFETIME |
| 96 |
| 97 void OnViewConnectionError(ViewState* view_state); |
| 98 void UnregisterView(ViewState* view_state); |
| 99 void OnViewTreeConnectionError(ViewTreeState* tree_state); |
| 100 void UnregisterViewTree(ViewTreeState* tree_state); |
| 101 |
| 102 // TREE MANIPULATION |
| 103 |
| 104 ViewState* FindView(uint32_t view_token); |
| 105 void LinkChild(ViewState* parent_state, |
| 106 uint32_t child_key, |
| 107 ViewState* child_state); |
| 108 void LinkChildAsUnavailable(ViewState* parent_state, uint32_t child_key); |
| 109 void MarkChildAsUnavailable(ViewState* parent_state, uint32_t child_key); |
| 110 void UnlinkChild(ViewState* parent_state, |
| 111 decltype(ViewState::children)::iterator child_it); |
| 112 void LinkRoot(ViewTreeState* tree_state, |
| 113 ViewState* root_state, |
| 114 uint32_t root_key); |
| 115 void UnlinkRoot(ViewTreeState* tree_state); |
| 116 void HijackView(ViewState* view_state); |
| 117 |
| 118 // Must be called before the view is actually unlinked from the tree. |
| 119 // Caller is still responsible for actually unlinking the view. |
| 120 void ResetStateWhenUnlinking(ViewState* view_state); |
| 121 |
| 122 // LAYOUT |
| 123 |
| 124 void InvalidateLayout(ViewState* view_state); |
| 125 void InvalidateLayoutForChild(ViewState* parent_state, uint32_t child_key); |
| 126 void InvalidateLayoutForRoot(ViewTreeState* tree_state); |
| 127 void SetLayout(ViewState* view_state, |
| 128 mojo::ui::ViewLayoutParamsPtr layout_params, |
| 129 bool provide_size, |
| 130 const ViewLayoutCallback& callback); |
| 131 void EnqueueLayoutRequest(ViewState* view_state, |
| 132 mojo::ui::ViewLayoutParamsPtr layout_params); |
| 133 void IssueNextViewLayoutRequest(ViewState* view_state); |
| 134 void IssueNextViewTreeLayoutRequest(ViewTreeState* tree_state); |
| 135 |
| 136 // SIGNALLING |
| 137 |
| 138 void SendChildUnavailable(ViewState* parent_state, uint32_t child_key); |
| 139 void SendRootUnavailable(ViewTreeState* tree_state, uint32_t root_key); |
| 140 void SendViewLayoutRequest(ViewState* view_state); |
| 141 void SendViewTreeLayoutRequest(ViewTreeState* tree_state); |
| 142 void OnViewLayoutResult(base::WeakPtr<ViewState> view_state_weak, |
| 143 mojo::ui::ViewLayoutInfoPtr info); |
| 144 void OnViewTreeLayoutResult(base::WeakPtr<ViewTreeState> tree_state_weak); |
| 145 |
| 146 #if DCHECK_IS_ON() |
| 147 bool IsViewStateRegisteredDebug(ViewState* view_state) { |
| 148 return view_state && FindView(view_state->view_token_value()); |
| 149 } |
| 150 |
| 151 bool IsViewTreeStateRegisteredDebug(ViewTreeState* tree_state) { |
| 152 return tree_state && std::any_of(view_trees_.begin(), view_trees_.end(), |
| 153 [tree_state](ViewTreeState* other) { |
| 154 return tree_state == other; |
| 155 }); |
| 156 } |
| 157 #endif |
| 158 |
| 159 SurfaceManager* surface_manager_; |
| 160 |
| 161 uint32_t next_view_token_value_; |
| 162 std::unordered_map<uint32_t, ViewState*> views_by_token_; |
| 163 std::vector<ViewTreeState*> view_trees_; |
| 164 |
| 165 DISALLOW_COPY_AND_ASSIGN(ViewRegistry); |
| 166 }; |
| 167 |
| 168 } // namespace view_manager |
| 169 |
| 170 #endif // SERVICES_UI_VIEW_MANAGER_VIEW_REGISTRY_H_ |
| OLD | NEW |