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.
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_
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/services/public/cpp/geometry/geometry_type_converters.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/public/interfaces/window_manager/window_manager.mojom.h"
23 class ViewManagerDelegate;
24 class ViewManagerTransaction;
27 // Manages the connection with the View Manager service.
28 class ViewManagerClientImpl : public ViewManager,
29 public InterfaceImpl<ViewManagerClient>,
30 public WindowManagerClient {
32 ViewManagerClientImpl(ViewManagerDelegate* delegate, Shell* shell);
33 virtual ~ViewManagerClientImpl();
35 bool connected() const { return connected_; }
36 ConnectionSpecificId connection_id() const { return connection_id_; }
38 // API exposed to the view implementations that pushes local changes to the
41 void DestroyView(Id view_id);
43 // These methods take TransportIds. For views owned by the current connection,
44 // the connection id high word can be zero. In all cases, the TransportId 0x1
45 // refers to the root view.
46 void AddChild(Id child_id, Id parent_id);
47 void RemoveChild(Id child_id, Id parent_id);
49 void Reorder(Id view_id, Id relative_view_id, OrderDirection direction);
51 // Returns true if the specified view was created by this connection.
52 bool OwnsView(Id id) const;
54 void SetBounds(Id view_id, const gfx::Rect& bounds);
55 void SetSurfaceId(Id view_id, SurfaceIdPtr surface_id);
56 void SetFocus(Id view_id);
57 void SetVisible(Id view_id, bool visible);
59 void Embed(const String& url, Id view_id);
60 void Embed(const String& url,
62 ServiceProviderPtr service_provider);
64 void set_change_acked_callback(const base::Callback<void(void)>& callback) {
65 change_acked_callback_ = callback;
67 void ClearChangeAckedCallback() {
68 change_acked_callback_ = base::Callback<void(void)>();
71 // Start/stop tracking views. While tracked, they can be retrieved via
72 // ViewManager::GetViewById.
73 void AddView(View* view);
74 void RemoveView(Id view_id);
76 Shell* shell() { return shell_; }
79 friend class RootObserver;
81 typedef std::map<Id, View*> IdToViewMap;
83 // Overridden from ViewManager:
84 virtual void SetWindowManagerDelegate(
85 WindowManagerDelegate* delegate) OVERRIDE;
86 virtual void DispatchEvent(View* target, EventPtr event) OVERRIDE;
87 virtual const std::string& GetEmbedderURL() const OVERRIDE;
88 virtual const std::vector<View*>& GetRoots() const OVERRIDE;
89 virtual View* GetViewById(Id id) OVERRIDE;
91 // Overridden from InterfaceImpl:
92 virtual void OnConnectionEstablished() OVERRIDE;
94 // Overridden from ViewManagerClient:
95 virtual void OnEmbed(ConnectionSpecificId connection_id,
96 const String& creator_url,
98 InterfaceRequest<ServiceProvider> services) OVERRIDE;
99 virtual void OnViewBoundsChanged(Id view_id,
101 RectPtr new_bounds) OVERRIDE;
102 virtual void OnViewHierarchyChanged(Id view_id,
105 Array<ViewDataPtr> views) OVERRIDE;
106 virtual void OnViewReordered(Id view_id,
108 OrderDirection direction) OVERRIDE;
109 virtual void OnViewDeleted(Id view_id) OVERRIDE;
110 virtual void OnViewVisibilityChanged(Id view_id, bool visible) OVERRIDE;
111 virtual void OnViewDrawnStateChanged(Id view_id, bool drawn) OVERRIDE;
112 virtual void OnViewInputEvent(Id view_id,
114 const Callback<void()>& callback) OVERRIDE;
117 InterfaceRequest<ServiceProvider> service_provider) OVERRIDE;
118 virtual void DispatchOnViewInputEvent(EventPtr event) OVERRIDE;
120 // Overridden from WindowManagerClient:
121 virtual void OnWindowManagerReady() OVERRIDE;
122 virtual void OnCaptureChanged(Id old_capture_view_id,
123 Id new_capture_view_id) OVERRIDE;
124 virtual void OnFocusChanged(Id old_focused_view_id,
125 Id new_focused_view_id) OVERRIDE;
126 virtual void OnActiveWindowChanged(Id old_focused_window,
127 Id new_focused_window) OVERRIDE;
129 void RemoveRoot(View* root);
131 void OnActionCompleted(bool success);
132 void OnActionCompletedWithErrorCode(ErrorCode code);
134 BitmapUploader* BitmapUploaderForView(Id view_id);
136 base::Callback<void(bool)> ActionCompletedCallback();
137 base::Callback<void(ErrorCode)> ActionCompletedCallbackWithErrorCode();
140 ConnectionSpecificId connection_id_;
141 ConnectionSpecificId next_id_;
143 std::string creator_url_;
145 base::Callback<void(void)> change_acked_callback_;
147 ViewManagerDelegate* delegate_;
148 WindowManagerDelegate* window_manager_delegate_;
150 std::vector<View*> roots_;
154 ViewManagerService* service_;
156 WindowManagerServicePtr window_manager_;
158 // TODO(jamesr): Remove once all callers switch from SetContents to
162 DISALLOW_COPY_AND_ASSIGN(ViewManagerClientImpl);
167 #endif // MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_LIB_VIEW_MANAGER_CLIENT_IMPL_H_