OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_LIB_VIEW_MANAGER_CLIENT_IMPL_H_ | 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_ | 6 #define MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_LIB_VIEW_MANAGER_CLIENT_IMPL_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" | 12 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" |
13 #include "mojo/services/public/cpp/view_manager/node.h" | |
14 #include "mojo/services/public/cpp/view_manager/types.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" | 15 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
16 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" | 16 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" |
17 | 17 |
18 class SkBitmap; | 18 class SkBitmap; |
19 | 19 |
20 namespace mojo { | 20 namespace mojo { |
21 class ApplicationConnection; | 21 class ApplicationConnection; |
22 class ViewManager; | 22 class ViewManager; |
23 class ViewManagerDelegate; | 23 class ViewManagerDelegate; |
24 class ViewManagerTransaction; | 24 class ViewManagerTransaction; |
25 | 25 |
26 // Manages the connection with the View Manager service. | 26 // Manages the connection with the View Manager service. |
27 class ViewManagerClientImpl : public ViewManager, | 27 class ViewManagerClientImpl : public ViewManager, |
28 public InterfaceImpl<ViewManagerClient> { | 28 public InterfaceImpl<ViewManagerClient> { |
29 public: | 29 public: |
30 explicit ViewManagerClientImpl(ViewManagerDelegate* delegate); | 30 explicit ViewManagerClientImpl(ViewManagerDelegate* delegate); |
31 virtual ~ViewManagerClientImpl(); | 31 virtual ~ViewManagerClientImpl(); |
32 | 32 |
33 bool connected() const { return connected_; } | 33 bool connected() const { return connected_; } |
34 ConnectionSpecificId connection_id() const { return connection_id_; } | 34 ConnectionSpecificId connection_id() const { return connection_id_; } |
35 | 35 |
36 // API exposed to the node/view implementations that pushes local changes to | 36 // API exposed to the view implementations that pushes local changes to the |
37 // the service. | 37 // service. |
38 Id CreateNode(); | 38 Id CreateView(); |
39 void DestroyNode(Id node_id); | 39 void DestroyView(Id view_id); |
40 | 40 |
41 // These methods take TransportIds. For views owned by the current connection, | 41 // These methods take TransportIds. For views owned by the current connection, |
42 // the connection id high word can be zero. In all cases, the TransportId 0x1 | 42 // the connection id high word can be zero. In all cases, the TransportId 0x1 |
43 // refers to the root node. | 43 // refers to the root view. |
44 void AddChild(Id child_id, Id parent_id); | 44 void AddChild(Id child_id, Id parent_id); |
45 void RemoveChild(Id child_id, Id parent_id); | 45 void RemoveChild(Id child_id, Id parent_id); |
46 | 46 |
47 void Reorder(Id node_id, Id relative_node_id, OrderDirection direction); | 47 void Reorder(Id view_id, Id relative_view_id, OrderDirection direction); |
48 | 48 |
49 // Returns true if the specified node was created by this connection. | 49 // Returns true if the specified view was created by this connection. |
50 bool OwnsNode(Id id) const; | 50 bool OwnsView(Id id) const; |
51 | 51 |
52 void SetBounds(Id node_id, const gfx::Rect& bounds); | 52 void SetBounds(Id view_id, const gfx::Rect& bounds); |
53 void SetNodeContents(Id node_id, const SkBitmap& contents); | 53 void SetViewContents(Id view_id, const SkBitmap& contents); |
54 void SetFocus(Id node_id); | 54 void SetFocus(Id view_id); |
55 void SetVisible(Id node_id, bool visible); | 55 void SetVisible(Id view_id, bool visible); |
56 | 56 |
57 void Embed(const String& url, Id node_id); | 57 void Embed(const String& url, Id view_id); |
58 void Embed(const String& url, | 58 void Embed(const String& url, |
59 Id node_id, | 59 Id view_id, |
60 ServiceProviderPtr service_provider); | 60 ServiceProviderPtr service_provider); |
61 | 61 |
62 void set_change_acked_callback(const base::Callback<void(void)>& callback) { | 62 void set_change_acked_callback(const base::Callback<void(void)>& callback) { |
63 change_acked_callback_ = callback; | 63 change_acked_callback_ = callback; |
64 } | 64 } |
65 void ClearChangeAckedCallback() { | 65 void ClearChangeAckedCallback() { |
66 change_acked_callback_ = base::Callback<void(void)>(); | 66 change_acked_callback_ = base::Callback<void(void)>(); |
67 } | 67 } |
68 | 68 |
69 // Start/stop tracking nodes. While tracked, they can be retrieved via | 69 // Start/stop tracking views. While tracked, they can be retrieved via |
70 // ViewManager::GetNodeById. | 70 // ViewManager::GetViewById. |
71 void AddNode(Node* node); | 71 void AddView(View* view); |
72 void RemoveNode(Id node_id); | 72 void RemoveView(Id view_id); |
73 | 73 |
74 private: | 74 private: |
75 friend class RootObserver; | 75 friend class RootObserver; |
76 | 76 |
77 typedef std::map<Id, Node*> IdToNodeMap; | 77 typedef std::map<Id, View*> IdToViewMap; |
78 typedef std::map<Id, View*> IdToViewMap; | 78 typedef std::map<Id, View*> IdToViewMap; |
79 | 79 |
80 // Overridden from ViewManager: | 80 // Overridden from ViewManager: |
81 virtual void SetWindowManagerDelegate( | 81 virtual void SetWindowManagerDelegate( |
82 WindowManagerDelegate* delegate) OVERRIDE; | 82 WindowManagerDelegate* delegate) OVERRIDE; |
83 virtual void DispatchEvent(Node* target, EventPtr event) OVERRIDE; | 83 virtual void DispatchEvent(View* target, EventPtr event) OVERRIDE; |
84 virtual const std::string& GetEmbedderURL() const OVERRIDE; | 84 virtual const std::string& GetEmbedderURL() const OVERRIDE; |
85 virtual const std::vector<Node*>& GetRoots() const OVERRIDE; | 85 virtual const std::vector<View*>& GetRoots() const OVERRIDE; |
86 virtual Node* GetNodeById(Id id) OVERRIDE; | 86 virtual View* GetViewById(Id id) OVERRIDE; |
87 | 87 |
88 // Overridden from InterfaceImpl: | 88 // Overridden from InterfaceImpl: |
89 virtual void OnConnectionEstablished() OVERRIDE; | 89 virtual void OnConnectionEstablished() OVERRIDE; |
90 | 90 |
91 // Overridden from ViewManagerClient: | 91 // Overridden from ViewManagerClient: |
92 virtual void OnEmbed(ConnectionSpecificId connection_id, | 92 virtual void OnEmbed(ConnectionSpecificId connection_id, |
93 const String& creator_url, | 93 const String& creator_url, |
94 NodeDataPtr root, | 94 ViewDataPtr root, |
95 InterfaceRequest<ServiceProvider> services) OVERRIDE; | 95 InterfaceRequest<ServiceProvider> services) OVERRIDE; |
96 virtual void OnNodeBoundsChanged(Id node_id, | 96 virtual void OnViewBoundsChanged(Id view_id, |
97 RectPtr old_bounds, | 97 RectPtr old_bounds, |
98 RectPtr new_bounds) OVERRIDE; | 98 RectPtr new_bounds) OVERRIDE; |
99 virtual void OnNodeHierarchyChanged(Id node_id, | 99 virtual void OnViewHierarchyChanged(Id view_id, |
100 Id new_parent_id, | 100 Id new_parent_id, |
101 Id old_parent_id, | 101 Id old_parent_id, |
102 Array<NodeDataPtr> nodes) OVERRIDE; | 102 Array<ViewDataPtr> views) OVERRIDE; |
103 virtual void OnNodeReordered(Id node_id, | 103 virtual void OnViewReordered(Id view_id, |
104 Id relative_node_id, | 104 Id relative_view_id, |
105 OrderDirection direction) OVERRIDE; | 105 OrderDirection direction) OVERRIDE; |
106 virtual void OnNodeDeleted(Id node_id) OVERRIDE; | 106 virtual void OnViewDeleted(Id view_id) OVERRIDE; |
107 virtual void OnNodeInputEvent(Id node, | 107 virtual void OnViewInputEvent(Id view, |
108 EventPtr event, | 108 EventPtr event, |
109 const Callback<void()>& callback) OVERRIDE; | 109 const Callback<void()>& callback) OVERRIDE; |
110 virtual void OnFocusChanged(Id gained_focus_id, Id lost_focus_id) OVERRIDE; | 110 virtual void OnFocusChanged(Id gained_focus_id, Id lost_focus_id) OVERRIDE; |
111 virtual void Embed( | 111 virtual void Embed( |
112 const String& url, | 112 const String& url, |
113 InterfaceRequest<ServiceProvider> service_provider) OVERRIDE; | 113 InterfaceRequest<ServiceProvider> service_provider) OVERRIDE; |
114 virtual void DispatchOnNodeInputEvent(Id node_id, EventPtr event) OVERRIDE; | 114 virtual void DispatchOnViewInputEvent(Id view_id, EventPtr event) OVERRIDE; |
115 | 115 |
116 void RemoveRoot(Node* root); | 116 void RemoveRoot(View* root); |
117 | 117 |
118 void OnActionCompleted(bool success); | 118 void OnActionCompleted(bool success); |
119 void OnActionCompletedWithErrorCode(ErrorCode code); | 119 void OnActionCompletedWithErrorCode(ErrorCode code); |
120 | 120 |
121 base::Callback<void(bool)> ActionCompletedCallback(); | 121 base::Callback<void(bool)> ActionCompletedCallback(); |
122 base::Callback<void(ErrorCode)> ActionCompletedCallbackWithErrorCode(); | 122 base::Callback<void(ErrorCode)> ActionCompletedCallbackWithErrorCode(); |
123 | 123 |
124 bool connected_; | 124 bool connected_; |
125 ConnectionSpecificId connection_id_; | 125 ConnectionSpecificId connection_id_; |
126 ConnectionSpecificId next_id_; | 126 ConnectionSpecificId next_id_; |
127 | 127 |
128 std::string creator_url_; | 128 std::string creator_url_; |
129 | 129 |
130 base::Callback<void(void)> change_acked_callback_; | 130 base::Callback<void(void)> change_acked_callback_; |
131 | 131 |
132 ViewManagerDelegate* delegate_; | 132 ViewManagerDelegate* delegate_; |
133 WindowManagerDelegate* window_manager_delegate_; | 133 WindowManagerDelegate* window_manager_delegate_; |
134 | 134 |
135 std::vector<Node*> roots_; | 135 std::vector<View*> roots_; |
136 | 136 |
137 IdToNodeMap nodes_; | 137 IdToViewMap views_; |
138 | 138 |
139 ViewManagerService* service_; | 139 ViewManagerService* service_; |
140 | 140 |
141 DISALLOW_COPY_AND_ASSIGN(ViewManagerClientImpl); | 141 DISALLOW_COPY_AND_ASSIGN(ViewManagerClientImpl); |
142 }; | 142 }; |
143 | 143 |
144 } // namespace mojo | 144 } // namespace mojo |
145 | 145 |
146 #endif // MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_LIB_VIEW_MANAGER_CLIENT_IMPL_H_ | 146 #endif // MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_LIB_VIEW_MANAGER_CLIENT_IMPL_H_ |
OLD | NEW |