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