OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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_STUB_H_ |
| 6 #define SERVICES_UI_VIEW_MANAGER_VIEW_STUB_H_ |
| 7 |
| 8 #include <memory> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/macros.h" |
| 12 #include "mojo/services/ui/views/interfaces/views.mojom.h" |
| 13 #include "services/ui/view_manager/view_layout_request.h" |
| 14 |
| 15 namespace view_manager { |
| 16 |
| 17 class ViewRegistry; |
| 18 class ViewState; |
| 19 class ViewTreeState; |
| 20 |
| 21 // Describes a link in the view hierarchy either from a parent view to one |
| 22 // of its children or from the view tree to its root view. |
| 23 // |
| 24 // When this object is created, it is not yet known whether the linked |
| 25 // view actually exists. We must wait for a response from the view owner |
| 26 // to resolve the view's token and associate the stub with its child. |
| 27 // |
| 28 // Instances of this object are held by a unique pointer owned by the |
| 29 // parent view or view tree at the point where the view is being linked. |
| 30 // Note that the lifetime of the views themselves is managed by the view |
| 31 // registry. |
| 32 class ViewStub { |
| 33 public: |
| 34 // Begins the process of resolving a view. |
| 35 // Invokes |ViewRegistry.OnViewResolved| when the token is obtained |
| 36 // from the owner or passes nullptr if an error occurs. |
| 37 ViewStub(ViewRegistry* registry, mojo::ui::ViewOwnerPtr owner); |
| 38 ~ViewStub(); |
| 39 |
| 40 // Gets the view state referenced by the stub, or null if the view |
| 41 // has not yet been resolved or is unavailable. |
| 42 ViewState* state() const { return state_; } |
| 43 |
| 44 // Returns true if the view which was intended to be referenced by the |
| 45 // stub has become unavailable. |
| 46 bool is_unavailable() const { return unavailable_; } |
| 47 |
| 48 // Returns true if awaiting resolution of the view. |
| 49 bool is_pending() const { return !state_ && !unavailable_; } |
| 50 |
| 51 // Returns true if the view is linked into a tree or parent. |
| 52 bool is_linked() const { return tree_ && parent_; } |
| 53 |
| 54 // Gets the view tree to which this view belongs, or null if none. |
| 55 ViewTreeState* tree() const { return tree_; } |
| 56 |
| 57 // Gets the parent view state, or null if none. |
| 58 ViewState* parent() const { return parent_; } |
| 59 |
| 60 // Gets the key that this child has in its container, or 0 if none. |
| 61 uint32_t key() const { return key_; } |
| 62 |
| 63 // A pending layout request, held until such time as the view is attached. |
| 64 std::unique_ptr<ViewLayoutRequest>& pending_layout_request() { |
| 65 return pending_layout_request_; |
| 66 } |
| 67 |
| 68 // Binds the stub to the specified actual view, which must not be null. |
| 69 // Must be called at most once to apply the effects of resolving the |
| 70 // view owner. |
| 71 void AttachView(ViewState* state); |
| 72 |
| 73 // Marks the stub as unavailable. |
| 74 // Returns the previous view state, or null if none. |
| 75 ViewState* ReleaseView(); |
| 76 |
| 77 // THESE METHODS SHOULD ONLY BE CALLED BY VIEW STATE OR VIEW TREE STATE |
| 78 |
| 79 // Recursively sets the view tree to which this view and all of its |
| 80 // descendents belong. Must not be null. This method must only be called |
| 81 // on root views. |
| 82 void SetTree(ViewTreeState* tree, uint32_t key); |
| 83 |
| 84 // Sets the parent view state pointer, the child's key in its parent, |
| 85 // and set its view tree to that of its parent. Must not be null. |
| 86 void SetParent(ViewState* parent, uint32_t key); |
| 87 |
| 88 // Resets the parent view state and tree pointers to null. |
| 89 void Unlink(); |
| 90 |
| 91 private: |
| 92 void SetTreeRecursively(ViewTreeState* tree); |
| 93 void OnViewResolved(mojo::ui::ViewTokenPtr view_token); |
| 94 |
| 95 ViewRegistry* registry_; |
| 96 mojo::ui::ViewOwnerPtr owner_; |
| 97 ViewState* state_ = nullptr; |
| 98 bool unavailable_ = false; |
| 99 std::unique_ptr<ViewLayoutRequest> pending_layout_request_; |
| 100 |
| 101 ViewTreeState* tree_ = nullptr; |
| 102 ViewState* parent_ = nullptr; |
| 103 uint32_t key_ = 0u; |
| 104 |
| 105 DISALLOW_COPY_AND_ASSIGN(ViewStub); |
| 106 }; |
| 107 |
| 108 } // namespace view_manager |
| 109 |
| 110 #endif // SERVICES_UI_VIEW_MANAGER_VIEW_STUB_H_ |
OLD | NEW |