| 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_STATE_H_ |
| 6 #define SERVICES_UI_VIEW_MANAGER_VIEW_STATE_H_ |
| 7 |
| 8 #include <memory> |
| 9 #include <set> |
| 10 #include <unordered_map> |
| 11 |
| 12 #include "base/callback.h" |
| 13 #include "base/macros.h" |
| 14 #include "base/memory/weak_ptr.h" |
| 15 #include "mojo/services/ui/views/interfaces/views.mojom.h" |
| 16 #include "services/ui/view_manager/view_layout_request.h" |
| 17 |
| 18 namespace view_manager { |
| 19 |
| 20 class ViewTreeState; |
| 21 |
| 22 // Describes the state of a particular view. |
| 23 // This object is owned by the ViewRegistry that created it. |
| 24 class ViewState { |
| 25 public: |
| 26 using ChildrenMap = std::unordered_map<uint32_t, ViewState*>; |
| 27 |
| 28 ViewState(mojo::ui::ViewPtr view, uint32_t view_token_value); |
| 29 ~ViewState(); |
| 30 |
| 31 base::WeakPtr<ViewState> GetWeakPtr() { return weak_factory_.GetWeakPtr(); } |
| 32 |
| 33 // Gets the view interface, never null. |
| 34 // Caller does not obtain ownership of the view. |
| 35 mojo::ui::View* view() const { return view_.get(); } |
| 36 |
| 37 // Gets the view token value used to refer to this view globally. |
| 38 uint32_t view_token_value() const { return view_token_value_; } |
| 39 |
| 40 // Sets the associated host implementation and takes ownership of it. |
| 41 void set_view_host(mojo::ui::ViewHost* host) { view_host_.reset(host); } |
| 42 |
| 43 // Sets the connection error handler for the view. |
| 44 void set_view_connection_error_handler(const base::Closure& handler) { |
| 45 view_.set_connection_error_handler(handler); |
| 46 } |
| 47 |
| 48 // Gets the view tree to which this view belongs, or null if none. |
| 49 ViewTreeState* tree() const { return tree_; } |
| 50 |
| 51 // Gets the parent view state, or null if none. |
| 52 ViewState* parent() const { return parent_; } |
| 53 |
| 54 // Gets the key that this child has in its container, or 0 if none. |
| 55 uint32_t key() const { return key_; } |
| 56 |
| 57 // Recursively sets the view tree to which this view and all of its |
| 58 // descendents belongs. Must not be null. This method must only be called |
| 59 // on root views. |
| 60 void SetTree(ViewTreeState* tree, uint32_t key); |
| 61 |
| 62 // Sets the parent view state pointer, the child's key in its parent, |
| 63 // and set its view tree to that of its parent. Must not be null. |
| 64 void SetParent(ViewState* parent, uint32_t key); |
| 65 |
| 66 // Resets the parent view state and tree pointers to null. |
| 67 void ResetContainer(); |
| 68 |
| 69 // Gets the view's service provider. |
| 70 void GetServiceProvider( |
| 71 mojo::InterfaceRequest<mojo::ServiceProvider> service_provider); |
| 72 |
| 73 // The map of children, indexed by child key. |
| 74 // Child view state may be null if the child with the given key has |
| 75 // become unavailable but not yet removed. |
| 76 ChildrenMap& children() { return children_; } |
| 77 |
| 78 // The set of children needing layout. |
| 79 // This set must never contain non-existent or unavailable children. |
| 80 std::set<uint32_t>& children_needing_layout() { |
| 81 return children_needing_layout_; |
| 82 } |
| 83 |
| 84 // The list of pending layout requests. |
| 85 std::vector<std::unique_ptr<ViewLayoutRequest>>& pending_layout_requests() { |
| 86 return pending_layout_requests_; |
| 87 } |
| 88 |
| 89 // The layout parameters most recently processed by the view, |
| 90 // or null if none. These parameters are preserved across reparenting. |
| 91 mojo::ui::ViewLayoutParamsPtr& layout_params() { return layout_params_; } |
| 92 |
| 93 // The layout information most recently provided by the view in |
| 94 // response to the value of |layout_params|, or null if none. These |
| 95 // results are preserved across reparenting. |
| 96 mojo::ui::ViewLayoutInfoPtr& layout_info() { return layout_info_; } |
| 97 |
| 98 // The id of the Surface which the view manager itself created to wrap the |
| 99 // view's own Surface, or null if none. The wrapped Surface is destroyed |
| 100 // when the view is reparented so that the old parent can no longer embed |
| 101 // the view's actual content. |
| 102 mojo::SurfaceIdPtr& wrapped_surface() { return wrapped_surface_; } |
| 103 |
| 104 private: |
| 105 void SetTreeUnchecked(ViewTreeState* tree); |
| 106 |
| 107 mojo::ui::ViewPtr view_; |
| 108 const uint32_t view_token_value_; |
| 109 |
| 110 std::unique_ptr<mojo::ui::ViewHost> view_host_; |
| 111 ViewTreeState* tree_; |
| 112 ViewState* parent_; |
| 113 uint32_t key_; |
| 114 ChildrenMap children_; |
| 115 std::set<uint32_t> children_needing_layout_; |
| 116 std::vector<std::unique_ptr<ViewLayoutRequest>> pending_layout_requests_; |
| 117 mojo::ui::ViewLayoutParamsPtr layout_params_; |
| 118 mojo::ui::ViewLayoutInfoPtr layout_info_; |
| 119 mojo::SurfaceIdPtr wrapped_surface_; |
| 120 |
| 121 base::WeakPtrFactory<ViewState> weak_factory_; // must be last |
| 122 |
| 123 DISALLOW_COPY_AND_ASSIGN(ViewState); |
| 124 }; |
| 125 |
| 126 } // namespace view_manager |
| 127 |
| 128 #endif // SERVICES_UI_VIEW_MANAGER_VIEW_STATE_H_ |
| OLD | NEW |