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"
22 class ApplicationConnection;
24 class ViewManagerDelegate;
25 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,
33 ApplicationConnection* app_connection);
34 virtual ~ViewManagerClientImpl();
36 bool connected() const { return connected_; }
37 ConnectionSpecificId connection_id() const { return connection_id_; }
39 // API exposed to the view implementations that pushes local changes to the
42 void DestroyView(Id view_id);
44 // These methods take TransportIds. For views owned by the current connection,
45 // the connection id high word can be zero. In all cases, the TransportId 0x1
46 // refers to the root view.
47 void AddChild(Id child_id, Id parent_id);
48 void RemoveChild(Id child_id, Id parent_id);
50 void Reorder(Id view_id, Id relative_view_id, OrderDirection direction);
52 // Returns true if the specified view was created by this connection.
53 bool OwnsView(Id id) const;
55 void SetBounds(Id view_id, const gfx::Rect& bounds);
56 void SetViewContents(Id view_id, const SkBitmap& contents);
57 void SetFocus(Id view_id);
58 void SetVisible(Id view_id, bool visible);
60 void Embed(const String& url, Id view_id);
61 void Embed(const String& url,
63 ServiceProviderPtr service_provider);
65 void set_change_acked_callback(const base::Callback<void(void)>& callback) {
66 change_acked_callback_ = callback;
68 void ClearChangeAckedCallback() {
69 change_acked_callback_ = base::Callback<void(void)>();
72 // Start/stop tracking views. While tracked, they can be retrieved via
73 // ViewManager::GetViewById.
74 void AddView(View* view);
75 void RemoveView(Id view_id);
78 friend class RootObserver;
80 typedef std::map<Id, View*> IdToViewMap;
82 // Overridden from ViewManager:
83 virtual void SetWindowManagerDelegate(
84 WindowManagerDelegate* delegate) OVERRIDE;
85 virtual void DispatchEvent(View* target, EventPtr event) OVERRIDE;
86 virtual const std::string& GetEmbedderURL() const OVERRIDE;
87 virtual const std::vector<View*>& GetRoots() const OVERRIDE;
88 virtual View* GetViewById(Id id) OVERRIDE;
90 // Overridden from InterfaceImpl:
91 virtual void OnConnectionEstablished() OVERRIDE;
93 // Overridden from ViewManagerClient:
94 virtual void OnEmbed(ConnectionSpecificId connection_id,
95 const String& creator_url,
97 InterfaceRequest<ServiceProvider> services) OVERRIDE;
98 virtual void OnViewBoundsChanged(Id view_id,
100 RectPtr new_bounds) OVERRIDE;
101 virtual void OnViewHierarchyChanged(Id view_id,
104 Array<ViewDataPtr> views) OVERRIDE;
105 virtual void OnViewReordered(Id view_id,
107 OrderDirection direction) OVERRIDE;
108 virtual void OnViewDeleted(Id view_id) OVERRIDE;
109 virtual void OnViewInputEvent(Id view,
111 const Callback<void()>& callback) OVERRIDE;
114 InterfaceRequest<ServiceProvider> service_provider) OVERRIDE;
115 virtual void DispatchOnViewInputEvent(EventPtr event) OVERRIDE;
117 // Overridden from WindowManagerClient:
118 virtual void OnWindowManagerReady() OVERRIDE;
119 virtual void OnCaptureChanged(Id old_capture_view_id,
120 Id new_capture_view_id) OVERRIDE;
121 virtual void OnFocusChanged(Id old_focused_view_id,
122 Id new_focused_view_id) OVERRIDE;
123 virtual void OnActiveWindowChanged(Id old_focused_window,
124 Id new_focused_window) OVERRIDE;
126 void RemoveRoot(View* root);
128 void OnActionCompleted(bool success);
129 void OnActionCompletedWithErrorCode(ErrorCode code);
131 base::Callback<void(bool)> ActionCompletedCallback();
132 base::Callback<void(ErrorCode)> ActionCompletedCallbackWithErrorCode();
135 ConnectionSpecificId connection_id_;
136 ConnectionSpecificId next_id_;
138 std::string creator_url_;
140 base::Callback<void(void)> change_acked_callback_;
142 ViewManagerDelegate* delegate_;
143 WindowManagerDelegate* window_manager_delegate_;
145 std::vector<View*> roots_;
149 ViewManagerService* service_;
151 WindowManagerServicePtr window_manager_;
153 DISALLOW_COPY_AND_ASSIGN(ViewManagerClientImpl);
158 #endif // MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_LIB_VIEW_MANAGER_CLIENT_IMPL_H_