| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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 COMPONENTS_VIEW_MANAGER_PUBLIC_CPP_LIB_VIEW_TREE_CLIENT_IMPL_H_ | |
| 6 #define COMPONENTS_VIEW_MANAGER_PUBLIC_CPP_LIB_VIEW_TREE_CLIENT_IMPL_H_ | |
| 7 | |
| 8 #include "components/view_manager/public/cpp/types.h" | |
| 9 #include "components/view_manager/public/cpp/view.h" | |
| 10 #include "components/view_manager/public/cpp/view_tree_connection.h" | |
| 11 #include "components/view_manager/public/interfaces/view_tree.mojom.h" | |
| 12 #include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h" | |
| 13 | |
| 14 namespace mojo { | |
| 15 class ViewTreeConnection; | |
| 16 class ViewTreeDelegate; | |
| 17 | |
| 18 // Manages the connection with the View Manager service. | |
| 19 class ViewTreeClientImpl : public ViewTreeConnection, public ViewTreeClient { | |
| 20 public: | |
| 21 ViewTreeClientImpl(ViewTreeDelegate* delegate, | |
| 22 InterfaceRequest<ViewTreeClient> request); | |
| 23 ~ViewTreeClientImpl() override; | |
| 24 | |
| 25 bool connected() const { return tree_; } | |
| 26 ConnectionSpecificId connection_id() const { return connection_id_; } | |
| 27 | |
| 28 // API exposed to the view implementations that pushes local changes to the | |
| 29 // service. | |
| 30 void DestroyView(Id view_id); | |
| 31 | |
| 32 // These methods take TransportIds. For views owned by the current connection, | |
| 33 // the connection id high word can be zero. In all cases, the TransportId 0x1 | |
| 34 // refers to the root view. | |
| 35 void AddChild(Id child_id, Id parent_id); | |
| 36 void RemoveChild(Id child_id, Id parent_id); | |
| 37 | |
| 38 void Reorder(Id view_id, Id relative_view_id, OrderDirection direction); | |
| 39 | |
| 40 // Returns true if the specified view was created by this connection. | |
| 41 bool OwnsView(Id id) const; | |
| 42 | |
| 43 void SetBounds(Id view_id, const Rect& bounds); | |
| 44 void SetFocus(Id view_id); | |
| 45 void SetVisible(Id view_id, bool visible); | |
| 46 void SetProperty(Id view_id, | |
| 47 const std::string& name, | |
| 48 const std::vector<uint8_t>& data); | |
| 49 void SetViewTextInputState(Id view_id, TextInputStatePtr state); | |
| 50 void SetImeVisibility(Id view_id, bool visible, TextInputStatePtr state); | |
| 51 void SetAccessPolicy(Id view_id, uint32_t access_policy); | |
| 52 | |
| 53 void Embed(Id view_id, | |
| 54 ViewTreeClientPtr client, | |
| 55 const ViewTree::EmbedCallback& callback); | |
| 56 | |
| 57 void RequestSurface(Id view_id, | |
| 58 InterfaceRequest<Surface> surface, | |
| 59 SurfaceClientPtr client); | |
| 60 | |
| 61 void set_change_acked_callback(const Callback<void(void)>& callback) { | |
| 62 change_acked_callback_ = callback; | |
| 63 } | |
| 64 void ClearChangeAckedCallback() { change_acked_callback_.reset(); } | |
| 65 | |
| 66 // Start/stop tracking views. While tracked, they can be retrieved via | |
| 67 // ViewTreeConnection::GetViewById. | |
| 68 void AddView(View* view); | |
| 69 void RemoveView(Id view_id); | |
| 70 | |
| 71 bool is_embed_root() const { return is_embed_root_; } | |
| 72 | |
| 73 // Called after the root view's observers have been notified of destruction | |
| 74 // (as the last step of ~View). This ordering ensures that the View Manager | |
| 75 // is torn down after the root. | |
| 76 void OnRootDestroyed(View* root); | |
| 77 | |
| 78 private: | |
| 79 typedef std::map<Id, View*> IdToViewMap; | |
| 80 | |
| 81 Id CreateViewOnServer(); | |
| 82 | |
| 83 // Overridden from ViewTreeConnection: | |
| 84 View* GetRoot() override; | |
| 85 View* GetViewById(Id id) override; | |
| 86 View* GetFocusedView() override; | |
| 87 View* CreateView() override; | |
| 88 bool IsEmbedRoot() override; | |
| 89 ConnectionSpecificId GetConnectionId() override; | |
| 90 | |
| 91 // Overridden from ViewTreeClient: | |
| 92 void OnEmbed(ConnectionSpecificId connection_id, | |
| 93 ViewDataPtr root, | |
| 94 ViewTreePtr tree, | |
| 95 Id focused_view_id, | |
| 96 uint32_t access_policy) override; | |
| 97 void OnEmbeddedAppDisconnected(Id view_id) override; | |
| 98 void OnUnembed() override; | |
| 99 void OnViewBoundsChanged(Id view_id, | |
| 100 RectPtr old_bounds, | |
| 101 RectPtr new_bounds) override; | |
| 102 void OnViewViewportMetricsChanged(ViewportMetricsPtr old_metrics, | |
| 103 ViewportMetricsPtr new_metrics) override; | |
| 104 void OnViewHierarchyChanged(Id view_id, | |
| 105 Id new_parent_id, | |
| 106 Id old_parent_id, | |
| 107 Array<ViewDataPtr> views) override; | |
| 108 void OnViewReordered(Id view_id, | |
| 109 Id relative_view_id, | |
| 110 OrderDirection direction) override; | |
| 111 void OnViewDeleted(Id view_id) override; | |
| 112 void OnViewVisibilityChanged(Id view_id, bool visible) override; | |
| 113 void OnViewDrawnStateChanged(Id view_id, bool drawn) override; | |
| 114 void OnViewSharedPropertyChanged(Id view_id, | |
| 115 const String& name, | |
| 116 Array<uint8_t> new_data) override; | |
| 117 void OnViewInputEvent(Id view_id, | |
| 118 EventPtr event, | |
| 119 const Callback<void()>& callback) override; | |
| 120 void OnViewFocused(Id focused_view_id) override; | |
| 121 | |
| 122 void RootDestroyed(View* root); | |
| 123 | |
| 124 void OnActionCompleted(bool success); | |
| 125 | |
| 126 Callback<void(bool)> ActionCompletedCallback(); | |
| 127 | |
| 128 ConnectionSpecificId connection_id_; | |
| 129 ConnectionSpecificId next_id_; | |
| 130 | |
| 131 Callback<void(void)> change_acked_callback_; | |
| 132 | |
| 133 ViewTreeDelegate* delegate_; | |
| 134 | |
| 135 View* root_; | |
| 136 | |
| 137 IdToViewMap views_; | |
| 138 | |
| 139 View* capture_view_; | |
| 140 View* focused_view_; | |
| 141 View* activated_view_; | |
| 142 | |
| 143 Binding<ViewTreeClient> binding_; | |
| 144 ViewTreePtr tree_; | |
| 145 | |
| 146 bool is_embed_root_; | |
| 147 | |
| 148 bool in_destructor_; | |
| 149 | |
| 150 MOJO_DISALLOW_COPY_AND_ASSIGN(ViewTreeClientImpl); | |
| 151 }; | |
| 152 | |
| 153 } // namespace mojo | |
| 154 | |
| 155 #endif // COMPONENTS_VIEW_MANAGER_PUBLIC_CPP_LIB_VIEW_TREE_CLIENT_IMPL_H_ | |
| OLD | NEW |