| 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 MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_LIB_VIEW_MANAGER_CLIENT_IMPL_H_ | |
| 6 #define MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_LIB_VIEW_MANAGER_CLIENT_IMPL_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/callback.h" | |
| 10 #include "base/memory/scoped_vector.h" | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "mojo/public/cpp/bindings/strong_binding.h" | |
| 13 #include "mojo/services/public/cpp/view_manager/types.h" | |
| 14 #include "mojo/services/public/cpp/view_manager/view.h" | |
| 15 #include "mojo/services/public/cpp/view_manager/view_manager.h" | |
| 16 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" | |
| 17 #include "mojo/services/window_manager/public/interfaces/window_manager.mojom.h" | |
| 18 | |
| 19 namespace mojo { | |
| 20 class Shell; | |
| 21 class ViewManager; | |
| 22 class ViewManagerDelegate; | |
| 23 class ViewManagerTransaction; | |
| 24 | |
| 25 // Manages the connection with the View Manager service. | |
| 26 class ViewManagerClientImpl : public ViewManager, | |
| 27 public ViewManagerClient, | |
| 28 public WindowManagerClient, | |
| 29 public ErrorHandler { | |
| 30 public: | |
| 31 ViewManagerClientImpl(ViewManagerDelegate* delegate, | |
| 32 Shell* shell, | |
| 33 ScopedMessagePipeHandle handle, | |
| 34 bool delete_on_error); | |
| 35 ~ViewManagerClientImpl() override; | |
| 36 | |
| 37 bool connected() const { return connected_; } | |
| 38 ConnectionSpecificId connection_id() const { return connection_id_; } | |
| 39 | |
| 40 // API exposed to the view implementations that pushes local changes to the | |
| 41 // service. | |
| 42 Id CreateView(); | |
| 43 void DestroyView(Id view_id); | |
| 44 | |
| 45 // These methods take TransportIds. For views owned by the current connection, | |
| 46 // the connection id high word can be zero. In all cases, the TransportId 0x1 | |
| 47 // refers to the root view. | |
| 48 void AddChild(Id child_id, Id parent_id); | |
| 49 void RemoveChild(Id child_id, Id parent_id); | |
| 50 | |
| 51 void Reorder(Id view_id, Id relative_view_id, OrderDirection direction); | |
| 52 | |
| 53 // Returns true if the specified view was created by this connection. | |
| 54 bool OwnsView(Id id) const; | |
| 55 | |
| 56 void SetBounds(Id view_id, const Rect& bounds); | |
| 57 void SetSurfaceId(Id view_id, SurfaceIdPtr surface_id); | |
| 58 void SetFocus(Id view_id); | |
| 59 void SetVisible(Id view_id, bool visible); | |
| 60 void SetProperty(Id view_id, | |
| 61 const std::string& name, | |
| 62 const std::vector<uint8_t>& data); | |
| 63 | |
| 64 void Embed(const String& url, Id view_id); | |
| 65 void Embed(const String& url, | |
| 66 Id view_id, | |
| 67 ServiceProviderPtr service_provider); | |
| 68 | |
| 69 void set_change_acked_callback(const base::Callback<void(void)>& callback) { | |
| 70 change_acked_callback_ = callback; | |
| 71 } | |
| 72 void ClearChangeAckedCallback() { | |
| 73 change_acked_callback_ = base::Callback<void(void)>(); | |
| 74 } | |
| 75 | |
| 76 // Start/stop tracking views. While tracked, they can be retrieved via | |
| 77 // ViewManager::GetViewById. | |
| 78 void AddView(View* view); | |
| 79 void RemoveView(Id view_id); | |
| 80 | |
| 81 private: | |
| 82 friend class RootObserver; | |
| 83 | |
| 84 typedef std::map<Id, View*> IdToViewMap; | |
| 85 | |
| 86 // Overridden from ViewManager: | |
| 87 const std::string& GetEmbedderURL() const override; | |
| 88 const std::vector<View*>& GetRoots() const override; | |
| 89 View* GetViewById(Id id) override; | |
| 90 | |
| 91 // Overridden from ViewManagerClient: | |
| 92 void OnEmbed(ConnectionSpecificId connection_id, | |
| 93 const String& creator_url, | |
| 94 ViewDataPtr root, | |
| 95 InterfaceRequest<ServiceProvider> parent_services, | |
| 96 ScopedMessagePipeHandle window_manager_pipe) override; | |
| 97 void OnEmbeddedAppDisconnected(Id view_id) override; | |
| 98 void OnViewBoundsChanged(Id view_id, | |
| 99 RectPtr old_bounds, | |
| 100 RectPtr new_bounds) override; | |
| 101 void OnViewHierarchyChanged(Id view_id, | |
| 102 Id new_parent_id, | |
| 103 Id old_parent_id, | |
| 104 Array<ViewDataPtr> views) override; | |
| 105 void OnViewReordered(Id view_id, | |
| 106 Id relative_view_id, | |
| 107 OrderDirection direction) override; | |
| 108 void OnViewDeleted(Id view_id) override; | |
| 109 void OnViewVisibilityChanged(Id view_id, bool visible) override; | |
| 110 void OnViewDrawnStateChanged(Id view_id, bool drawn) override; | |
| 111 void OnViewSharedPropertyChanged(Id view_id, | |
| 112 const String& name, | |
| 113 Array<uint8_t> new_data) override; | |
| 114 void OnViewInputEvent(Id view_id, | |
| 115 EventPtr event, | |
| 116 const Callback<void()>& callback) override; | |
| 117 | |
| 118 // Overridden from WindowManagerClient: | |
| 119 void OnCaptureChanged(Id old_capture_view_id, | |
| 120 Id new_capture_view_id) override; | |
| 121 void OnFocusChanged(Id old_focused_view_id, Id new_focused_view_id) override; | |
| 122 void OnActiveWindowChanged(Id old_focused_window, | |
| 123 Id new_focused_window) override; | |
| 124 | |
| 125 // ErrorHandler implementation. | |
| 126 void OnConnectionError() override; | |
| 127 | |
| 128 void RemoveRoot(View* root); | |
| 129 | |
| 130 void OnActionCompleted(bool success); | |
| 131 void OnActionCompletedWithErrorCode(ErrorCode code); | |
| 132 | |
| 133 base::Callback<void(bool)> ActionCompletedCallback(); | |
| 134 base::Callback<void(ErrorCode)> ActionCompletedCallbackWithErrorCode(); | |
| 135 | |
| 136 bool connected_; | |
| 137 ConnectionSpecificId connection_id_; | |
| 138 ConnectionSpecificId next_id_; | |
| 139 | |
| 140 std::string creator_url_; | |
| 141 | |
| 142 base::Callback<void(void)> change_acked_callback_; | |
| 143 | |
| 144 ViewManagerDelegate* delegate_; | |
| 145 | |
| 146 std::vector<View*> roots_; | |
| 147 | |
| 148 IdToViewMap views_; | |
| 149 | |
| 150 WindowManagerPtr window_manager_; | |
| 151 | |
| 152 Binding<ViewManagerClient> binding_; | |
| 153 ViewManagerService* service_; | |
| 154 const bool delete_on_error_; | |
| 155 | |
| 156 DISALLOW_COPY_AND_ASSIGN(ViewManagerClientImpl); | |
| 157 }; | |
| 158 | |
| 159 } // namespace mojo | |
| 160 | |
| 161 #endif // MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_LIB_VIEW_MANAGER_CLIENT_IMPL_H_ | |
| OLD | NEW |