| 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 explicit 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 // Destroys |parent_state| if an error occurs. |
| 59 void LayoutChild(ViewState* parent_state, |
| 60 uint32_t child_key, |
| 61 mojo::ui::ViewLayoutParamsPtr child_layout_params, |
| 62 const ViewLayoutCallback& callback); |
| 63 |
| 64 // VIEW TREE HOST REQUESTS |
| 65 |
| 66 // Requests layout. |
| 67 // Destroys |tree_state| if an error occurs. |
| 68 void RequestLayout(ViewTreeState* tree_state); |
| 69 |
| 70 // Sets the root of the view tree. |
| 71 // Destroys |tree_state| if an error occurs. |
| 72 void SetRoot(ViewTreeState* tree_state, |
| 73 uint32_t root_key, |
| 74 mojo::ui::ViewTokenPtr root_view_token); |
| 75 |
| 76 // Resets the root of the view tree. |
| 77 // Destroys |tree_state| if an error occurs. |
| 78 void ResetRoot(ViewTreeState* tree_state); |
| 79 |
| 80 // Lays out a view tree's root and optionally provides its size. |
| 81 // Destroys |tree_state| if an error occurs. |
| 82 void LayoutRoot(ViewTreeState* tree_state, |
| 83 mojo::ui::ViewLayoutParamsPtr root_layout_params, |
| 84 const ViewLayoutCallback& callback); |
| 85 |
| 86 private: |
| 87 // LIFETIME |
| 88 |
| 89 void OnViewConnectionError(ViewState* view_state); |
| 90 void UnregisterView(ViewState* view_state); |
| 91 void OnViewTreeConnectionError(ViewTreeState* tree_state); |
| 92 void UnregisterViewTree(ViewTreeState* tree_state); |
| 93 |
| 94 // TREE MANIPULATION |
| 95 |
| 96 ViewState* FindView(uint32_t view_token); |
| 97 void LinkChild(ViewState* parent_state, |
| 98 uint32_t child_key, |
| 99 ViewState* child_state); |
| 100 void LinkChildAsUnavailable(ViewState* parent_state, uint32_t child_key); |
| 101 void MarkChildAsUnavailable(ViewState* parent_state, uint32_t child_key); |
| 102 void UnlinkChild(ViewState* parent_state, |
| 103 ViewState::ChildrenMap::iterator child_it); |
| 104 void LinkRoot(ViewTreeState* tree_state, |
| 105 ViewState* root_state, |
| 106 uint32_t root_key); |
| 107 void UnlinkRoot(ViewTreeState* tree_state); |
| 108 void HijackView(ViewState* view_state); |
| 109 |
| 110 // Must be called before the view is actually unlinked from the tree. |
| 111 // Caller is still responsible for actually unlinking the view. |
| 112 void ResetStateWhenUnlinking(ViewState* view_state); |
| 113 |
| 114 // LAYOUT |
| 115 |
| 116 void InvalidateLayout(ViewState* view_state); |
| 117 void InvalidateLayoutForChild(ViewState* parent_state, uint32_t child_key); |
| 118 void InvalidateLayoutForRoot(ViewTreeState* tree_state); |
| 119 void SetLayout(ViewState* view_state, |
| 120 mojo::ui::ViewLayoutParamsPtr layout_params, |
| 121 const ViewLayoutCallback& callback); |
| 122 void EnqueueLayoutRequest(ViewState* view_state, |
| 123 mojo::ui::ViewLayoutParamsPtr layout_params); |
| 124 void IssueNextViewLayoutRequest(ViewState* view_state); |
| 125 void IssueNextViewTreeLayoutRequest(ViewTreeState* tree_state); |
| 126 |
| 127 // SIGNALLING |
| 128 |
| 129 void SendChildUnavailable(ViewState* parent_state, uint32_t child_key); |
| 130 void SendRootUnavailable(ViewTreeState* tree_state, uint32_t root_key); |
| 131 void SendViewLayoutRequest(ViewState* view_state); |
| 132 void SendViewTreeLayoutRequest(ViewTreeState* tree_state); |
| 133 void OnViewLayoutResult(base::WeakPtr<ViewState> view_state_weak, |
| 134 mojo::ui::ViewLayoutInfoPtr info); |
| 135 void OnViewTreeLayoutResult(base::WeakPtr<ViewTreeState> tree_state_weak); |
| 136 |
| 137 #if DCHECK_IS_ON() |
| 138 bool IsViewStateRegisteredDebug(ViewState* view_state) { |
| 139 return view_state && FindView(view_state->view_token_value()); |
| 140 } |
| 141 |
| 142 bool IsViewTreeStateRegisteredDebug(ViewTreeState* tree_state) { |
| 143 return tree_state && std::any_of(view_trees_.begin(), view_trees_.end(), |
| 144 [tree_state](ViewTreeState* other) { |
| 145 return tree_state == other; |
| 146 }); |
| 147 } |
| 148 #endif |
| 149 |
| 150 SurfaceManager* surface_manager_; |
| 151 |
| 152 uint32_t next_view_token_value_; |
| 153 std::unordered_map<uint32_t, ViewState*> views_by_token_; |
| 154 std::vector<ViewTreeState*> view_trees_; |
| 155 |
| 156 DISALLOW_COPY_AND_ASSIGN(ViewRegistry); |
| 157 }; |
| 158 |
| 159 } // namespace view_manager |
| 160 |
| 161 #endif // SERVICES_UI_VIEW_MANAGER_VIEW_REGISTRY_H_ |
| OLD | NEW |