| 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_TREE_STATE_H_ |
| 6 #define SERVICES_UI_VIEW_MANAGER_VIEW_TREE_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/public/cpp/bindings/binding.h" |
| 16 #include "mojo/services/ui/views/interfaces/view_trees.mojom.h" |
| 17 #include "services/ui/view_manager/view_state.h" |
| 18 |
| 19 namespace view_manager { |
| 20 |
| 21 // Describes the state of a particular view tree. |
| 22 // This object is owned by the ViewRegistry that created it. |
| 23 class ViewTreeState { |
| 24 public: |
| 25 explicit ViewTreeState(mojo::ui::ViewTreePtr view_tree); |
| 26 ~ViewTreeState(); |
| 27 |
| 28 base::WeakPtr<ViewTreeState> GetWeakPtr() { |
| 29 return weak_factory_.GetWeakPtr(); |
| 30 } |
| 31 |
| 32 // Gets the view tree interface, never null. |
| 33 // Caller does not obtain ownership of the view. |
| 34 mojo::ui::ViewTree* view_tree() const { return view_tree_.get(); } |
| 35 |
| 36 // Sets the associated host implementation and takes ownership of it. |
| 37 void set_view_tree_host(mojo::ui::ViewTreeHost* host) { |
| 38 view_tree_host_.reset(host); |
| 39 } |
| 40 |
| 41 // Sets the connection error handler for the view. |
| 42 void set_view_tree_connection_error_handler(const base::Closure& handler) { |
| 43 view_tree_.set_connection_error_handler(handler); |
| 44 } |
| 45 |
| 46 // Gets the root of the view tree, or null if it is unavailable. |
| 47 ViewState* root() const { return root_; } |
| 48 |
| 49 // Sets the root of the view tree. Must not be null. |
| 50 // The view specified as the new root must not have any parents. |
| 51 void SetRoot(ViewState* root, uint32_t key); |
| 52 |
| 53 // Resets the root view to null. |
| 54 void ResetRoot(); |
| 55 |
| 56 // True if the client previously set but has not yet explicitly unset |
| 57 // the root, independent of whether it is currently available. |
| 58 bool explicit_root() const { return explicit_root_; } |
| 59 void set_explicit_root(bool value) { explicit_root_ = value; } |
| 60 |
| 61 // True if there is a pending layout request. |
| 62 bool layout_request_pending() const { return layout_request_pending_; } |
| 63 void set_layout_request_pending(bool value) { |
| 64 layout_request_pending_ = value; |
| 65 } |
| 66 |
| 67 // True if a layout request has been issued. |
| 68 bool layout_request_issued() const { return layout_request_issued_; } |
| 69 void set_layout_request_issued(bool value) { layout_request_issued_ = value; } |
| 70 |
| 71 private: |
| 72 mojo::ui::ViewTreePtr view_tree_; |
| 73 |
| 74 std::unique_ptr<mojo::ui::ViewTreeHost> view_tree_host_; |
| 75 ViewState* root_; |
| 76 bool explicit_root_; |
| 77 bool layout_request_pending_; |
| 78 bool layout_request_issued_; |
| 79 |
| 80 base::WeakPtrFactory<ViewTreeState> weak_factory_; // must be last |
| 81 |
| 82 DISALLOW_COPY_AND_ASSIGN(ViewTreeState); |
| 83 }; |
| 84 |
| 85 } // namespace view_manager |
| 86 |
| 87 #endif // SERVICES_UI_VIEW_MANAGER_VIEW_TREE_STATE_H_ |
| OLD | NEW |