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 #include "mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h" | 5 #include "mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "mojo/public/cpp/application/application.h" | 9 #include "mojo/public/cpp/application/application.h" |
10 #include "mojo/public/cpp/application/connect.h" | 10 #include "mojo/public/cpp/application/connect.h" |
11 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" | 11 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" |
| 12 #include "mojo/services/public/cpp/view_manager/lib/node_private.h" |
12 #include "mojo/services/public/cpp/view_manager/lib/view_private.h" | 13 #include "mojo/services/public/cpp/view_manager/lib/view_private.h" |
13 #include "mojo/services/public/cpp/view_manager/lib/view_tree_node_private.h" | 14 #include "mojo/services/public/cpp/view_manager/node_observer.h" |
14 #include "mojo/services/public/cpp/view_manager/util.h" | 15 #include "mojo/services/public/cpp/view_manager/util.h" |
15 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | 16 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
16 #include "mojo/services/public/cpp/view_manager/view_observer.h" | 17 #include "mojo/services/public/cpp/view_manager/view_observer.h" |
17 #include "mojo/services/public/cpp/view_manager/view_tree_node_observer.h" | |
18 #include "third_party/skia/include/core/SkBitmap.h" | 18 #include "third_party/skia/include/core/SkBitmap.h" |
19 #include "ui/gfx/codec/png_codec.h" | 19 #include "ui/gfx/codec/png_codec.h" |
20 | 20 |
21 namespace mojo { | 21 namespace mojo { |
22 namespace view_manager { | 22 namespace view_manager { |
23 | 23 |
24 Id MakeTransportId(ConnectionSpecificId connection_id, | 24 Id MakeTransportId(ConnectionSpecificId connection_id, |
25 ConnectionSpecificId local_id) { | 25 ConnectionSpecificId local_id) { |
26 return (connection_id << 16) | local_id; | 26 return (connection_id << 16) | local_id; |
27 } | 27 } |
28 | 28 |
29 // Helper called to construct a local node/view object from transport data. | 29 // Helper called to construct a local node/view object from transport data. |
30 ViewTreeNode* AddNodeToViewManager(ViewManagerSynchronizer* synchronizer, | 30 Node* AddNodeToViewManager(ViewManagerClientImpl* client, |
31 ViewTreeNode* parent, | 31 Node* parent, |
32 Id node_id, | 32 Id node_id, |
33 Id view_id, | 33 Id view_id, |
34 const gfx::Rect& bounds) { | 34 const gfx::Rect& bounds) { |
35 // We don't use the ctor that takes a ViewManager here, since it will call | 35 // We don't use the ctor that takes a ViewManager here, since it will call |
36 // back to the service and attempt to create a new node. | 36 // back to the service and attempt to create a new node. |
37 ViewTreeNode* node = ViewTreeNodePrivate::LocalCreate(); | 37 Node* node = NodePrivate::LocalCreate(); |
38 ViewTreeNodePrivate private_node(node); | 38 NodePrivate private_node(node); |
39 private_node.set_view_manager(synchronizer); | 39 private_node.set_view_manager(client); |
40 private_node.set_id(node_id); | 40 private_node.set_id(node_id); |
41 private_node.LocalSetBounds(gfx::Rect(), bounds); | 41 private_node.LocalSetBounds(gfx::Rect(), bounds); |
42 if (parent) | 42 if (parent) |
43 ViewTreeNodePrivate(parent).LocalAddChild(node); | 43 NodePrivate(parent).LocalAddChild(node); |
44 synchronizer->AddNode(node); | 44 client->AddNode(node); |
45 | 45 |
46 // View. | 46 // View. |
47 if (view_id != 0) { | 47 if (view_id != 0) { |
48 View* view = ViewPrivate::LocalCreate(); | 48 View* view = ViewPrivate::LocalCreate(); |
49 ViewPrivate private_view(view); | 49 ViewPrivate private_view(view); |
50 private_view.set_view_manager(synchronizer); | 50 private_view.set_view_manager(client); |
51 private_view.set_id(view_id); | 51 private_view.set_id(view_id); |
52 private_view.set_node(node); | 52 private_view.set_node(node); |
53 // TODO(beng): this broadcasts notifications locally... do we want this? I | 53 // TODO(beng): this broadcasts notifications locally... do we want this? I |
54 // don't think so. same story for LocalAddChild above! | 54 // don't think so. same story for LocalAddChild above! |
55 private_node.LocalSetActiveView(view); | 55 private_node.LocalSetActiveView(view); |
56 synchronizer->AddView(view); | 56 client->AddView(view); |
57 } | 57 } |
58 return node; | 58 return node; |
59 } | 59 } |
60 | 60 |
61 ViewTreeNode* BuildNodeTree(ViewManagerSynchronizer* synchronizer, | 61 Node* BuildNodeTree(ViewManagerClientImpl* client, |
62 const Array<NodeDataPtr>& nodes) { | 62 const Array<NodeDataPtr>& nodes) { |
63 std::vector<ViewTreeNode*> parents; | 63 std::vector<Node*> parents; |
64 ViewTreeNode* root = NULL; | 64 Node* root = NULL; |
65 ViewTreeNode* last_node = NULL; | 65 Node* last_node = NULL; |
66 for (size_t i = 0; i < nodes.size(); ++i) { | 66 for (size_t i = 0; i < nodes.size(); ++i) { |
67 if (last_node && nodes[i]->parent_id == last_node->id()) { | 67 if (last_node && nodes[i]->parent_id == last_node->id()) { |
68 parents.push_back(last_node); | 68 parents.push_back(last_node); |
69 } else if (!parents.empty()) { | 69 } else if (!parents.empty()) { |
70 while (parents.back()->id() != nodes[i]->parent_id) | 70 while (parents.back()->id() != nodes[i]->parent_id) |
71 parents.pop_back(); | 71 parents.pop_back(); |
72 } | 72 } |
73 ViewTreeNode* node = AddNodeToViewManager( | 73 Node* node = AddNodeToViewManager( |
74 synchronizer, | 74 client, |
75 !parents.empty() ? parents.back() : NULL, | 75 !parents.empty() ? parents.back() : NULL, |
76 nodes[i]->node_id, | 76 nodes[i]->node_id, |
77 nodes[i]->view_id, | 77 nodes[i]->view_id, |
78 nodes[i]->bounds.To<gfx::Rect>()); | 78 nodes[i]->bounds.To<gfx::Rect>()); |
79 if (!last_node) | 79 if (!last_node) |
80 root = node; | 80 root = node; |
81 last_node = node; | 81 last_node = node; |
82 } | 82 } |
83 return root; | 83 return root; |
84 } | 84 } |
85 | 85 |
86 // Responsible for removing a root from the ViewManager when that node is | 86 // Responsible for removing a root from the ViewManager when that node is |
87 // destroyed. | 87 // destroyed. |
88 class RootObserver : public ViewTreeNodeObserver { | 88 class RootObserver : public NodeObserver { |
89 public: | 89 public: |
90 explicit RootObserver(ViewTreeNode* root) : root_(root) {} | 90 explicit RootObserver(Node* root) : root_(root) {} |
91 virtual ~RootObserver() {} | 91 virtual ~RootObserver() {} |
92 | 92 |
93 private: | 93 private: |
94 // Overridden from ViewTreeNodeObserver: | 94 // Overridden from NodeObserver: |
95 virtual void OnNodeDestroy(ViewTreeNode* node, | 95 virtual void OnNodeDestroy(Node* node, |
96 DispositionChangePhase phase) OVERRIDE { | 96 DispositionChangePhase phase) OVERRIDE { |
97 DCHECK_EQ(node, root_); | 97 DCHECK_EQ(node, root_); |
98 if (phase != ViewTreeNodeObserver::DISPOSITION_CHANGED) | 98 if (phase != NodeObserver::DISPOSITION_CHANGED) |
99 return; | 99 return; |
100 static_cast<ViewManagerSynchronizer*>( | 100 static_cast<ViewManagerClientImpl*>( |
101 ViewTreeNodePrivate(root_).view_manager())->RemoveRoot(root_); | 101 NodePrivate(root_).view_manager())->RemoveRoot(root_); |
102 delete this; | 102 delete this; |
103 } | 103 } |
104 | 104 |
105 ViewTreeNode* root_; | 105 Node* root_; |
106 | 106 |
107 DISALLOW_COPY_AND_ASSIGN(RootObserver); | 107 DISALLOW_COPY_AND_ASSIGN(RootObserver); |
108 }; | 108 }; |
109 | 109 |
110 class ViewManagerTransaction { | 110 class ViewManagerTransaction { |
111 public: | 111 public: |
112 virtual ~ViewManagerTransaction() {} | 112 virtual ~ViewManagerTransaction() {} |
113 | 113 |
114 void Commit() { | 114 void Commit() { |
115 DCHECK(!committed_); | 115 DCHECK(!committed_); |
116 DoCommit(); | 116 DoCommit(); |
117 committed_ = true; | 117 committed_ = true; |
118 } | 118 } |
119 | 119 |
120 bool committed() const { return committed_; } | 120 bool committed() const { return committed_; } |
121 | 121 |
122 protected: | 122 protected: |
123 explicit ViewManagerTransaction(ViewManagerSynchronizer* synchronizer) | 123 explicit ViewManagerTransaction(ViewManagerClientImpl* client) |
124 : committed_(false), | 124 : committed_(false), |
125 synchronizer_(synchronizer) { | 125 client_(client) { |
126 } | 126 } |
127 | 127 |
128 // Overridden to perform transaction-specific commit actions. | 128 // Overridden to perform transaction-specific commit actions. |
129 virtual void DoCommit() = 0; | 129 virtual void DoCommit() = 0; |
130 | 130 |
131 // Overridden to perform transaction-specific cleanup on commit ack from the | 131 // Overridden to perform transaction-specific cleanup on commit ack from the |
132 // service. | 132 // service. |
133 virtual void DoActionCompleted(bool success) = 0; | 133 virtual void DoActionCompleted(bool success) = 0; |
134 | 134 |
135 ViewManagerService* service() { return synchronizer_->service_; } | 135 ViewManagerService* service() { return client_->service_; } |
136 | 136 |
137 Id GetAndAdvanceNextServerChangeId() { | 137 Id GetAndAdvanceNextServerChangeId() { |
138 return synchronizer_->next_server_change_id_++; | 138 return client_->next_server_change_id_++; |
139 } | 139 } |
140 | 140 |
141 base::Callback<void(bool)> ActionCompletedCallback() { | 141 base::Callback<void(bool)> ActionCompletedCallback() { |
142 return base::Bind(&ViewManagerTransaction::OnActionCompleted, | 142 return base::Bind(&ViewManagerTransaction::OnActionCompleted, |
143 base::Unretained(this)); | 143 base::Unretained(this)); |
144 } | 144 } |
145 | 145 |
146 private: | 146 private: |
147 // General callback to be used for commits to the service. | 147 // General callback to be used for commits to the service. |
148 void OnActionCompleted(bool success) { | 148 void OnActionCompleted(bool success) { |
149 DCHECK(success); | 149 DCHECK(success); |
150 DoActionCompleted(success); | 150 DoActionCompleted(success); |
151 synchronizer_->RemoveFromPendingQueue(this); | 151 client_->RemoveFromPendingQueue(this); |
152 } | 152 } |
153 | 153 |
154 bool committed_; | 154 bool committed_; |
155 ViewManagerSynchronizer* synchronizer_; | 155 ViewManagerClientImpl* client_; |
156 | 156 |
157 DISALLOW_COPY_AND_ASSIGN(ViewManagerTransaction); | 157 DISALLOW_COPY_AND_ASSIGN(ViewManagerTransaction); |
158 }; | 158 }; |
159 | 159 |
160 class CreateViewTransaction : public ViewManagerTransaction { | 160 class CreateViewTransaction : public ViewManagerTransaction { |
161 public: | 161 public: |
162 CreateViewTransaction(Id view_id, ViewManagerSynchronizer* synchronizer) | 162 CreateViewTransaction(Id view_id, ViewManagerClientImpl* client) |
163 : ViewManagerTransaction(synchronizer), | 163 : ViewManagerTransaction(client), |
164 view_id_(view_id) {} | 164 view_id_(view_id) {} |
165 virtual ~CreateViewTransaction() {} | 165 virtual ~CreateViewTransaction() {} |
166 | 166 |
167 private: | 167 private: |
168 // Overridden from ViewManagerTransaction: | 168 // Overridden from ViewManagerTransaction: |
169 virtual void DoCommit() OVERRIDE { | 169 virtual void DoCommit() OVERRIDE { |
170 service()->CreateView(view_id_, ActionCompletedCallback()); | 170 service()->CreateView(view_id_, ActionCompletedCallback()); |
171 } | 171 } |
172 virtual void DoActionCompleted(bool success) OVERRIDE { | 172 virtual void DoActionCompleted(bool success) OVERRIDE { |
173 // TODO(beng): failure. | 173 // TODO(beng): failure. |
174 } | 174 } |
175 | 175 |
176 const Id view_id_; | 176 const Id view_id_; |
177 | 177 |
178 DISALLOW_COPY_AND_ASSIGN(CreateViewTransaction); | 178 DISALLOW_COPY_AND_ASSIGN(CreateViewTransaction); |
179 }; | 179 }; |
180 | 180 |
181 class DestroyViewTransaction : public ViewManagerTransaction { | 181 class DestroyViewTransaction : public ViewManagerTransaction { |
182 public: | 182 public: |
183 DestroyViewTransaction(Id view_id, ViewManagerSynchronizer* synchronizer) | 183 DestroyViewTransaction(Id view_id, ViewManagerClientImpl* client) |
184 : ViewManagerTransaction(synchronizer), | 184 : ViewManagerTransaction(client), |
185 view_id_(view_id) {} | 185 view_id_(view_id) {} |
186 virtual ~DestroyViewTransaction() {} | 186 virtual ~DestroyViewTransaction() {} |
187 | 187 |
188 private: | 188 private: |
189 // Overridden from ViewManagerTransaction: | 189 // Overridden from ViewManagerTransaction: |
190 virtual void DoCommit() OVERRIDE { | 190 virtual void DoCommit() OVERRIDE { |
191 service()->DeleteView(view_id_, ActionCompletedCallback()); | 191 service()->DeleteView(view_id_, ActionCompletedCallback()); |
192 } | 192 } |
193 virtual void DoActionCompleted(bool success) OVERRIDE { | 193 virtual void DoActionCompleted(bool success) OVERRIDE { |
194 // TODO(beng): recovery? | 194 // TODO(beng): recovery? |
195 } | 195 } |
196 | 196 |
197 const Id view_id_; | 197 const Id view_id_; |
198 | 198 |
199 DISALLOW_COPY_AND_ASSIGN(DestroyViewTransaction); | 199 DISALLOW_COPY_AND_ASSIGN(DestroyViewTransaction); |
200 }; | 200 }; |
201 | 201 |
202 class CreateViewTreeNodeTransaction : public ViewManagerTransaction { | 202 class CreateNodeTransaction : public ViewManagerTransaction { |
203 public: | 203 public: |
204 CreateViewTreeNodeTransaction(Id node_id, | 204 CreateNodeTransaction(Id node_id, ViewManagerClientImpl* client) |
205 ViewManagerSynchronizer* synchronizer) | 205 : ViewManagerTransaction(client), |
206 : ViewManagerTransaction(synchronizer), | |
207 node_id_(node_id) {} | 206 node_id_(node_id) {} |
208 virtual ~CreateViewTreeNodeTransaction() {} | 207 virtual ~CreateNodeTransaction() {} |
209 | 208 |
210 private: | 209 private: |
211 // Overridden from ViewManagerTransaction: | 210 // Overridden from ViewManagerTransaction: |
212 virtual void DoCommit() OVERRIDE { | 211 virtual void DoCommit() OVERRIDE { |
213 service()->CreateNode(node_id_, ActionCompletedCallback()); | 212 service()->CreateNode(node_id_, ActionCompletedCallback()); |
214 } | 213 } |
215 virtual void DoActionCompleted(bool success) OVERRIDE { | 214 virtual void DoActionCompleted(bool success) OVERRIDE { |
216 // TODO(beng): Failure means we tried to create with an extant id for this | 215 // TODO(beng): Failure means we tried to create with an extant id for this |
217 // connection. It also could mean we tried to do something | 216 // connection. It also could mean we tried to do something |
218 // invalid, or we tried applying a change out of order. Figure | 217 // invalid, or we tried applying a change out of order. Figure |
219 // out what to do. | 218 // out what to do. |
220 } | 219 } |
221 | 220 |
222 const Id node_id_; | 221 const Id node_id_; |
223 | 222 |
224 DISALLOW_COPY_AND_ASSIGN(CreateViewTreeNodeTransaction); | 223 DISALLOW_COPY_AND_ASSIGN(CreateNodeTransaction); |
225 }; | 224 }; |
226 | 225 |
227 class DestroyViewTreeNodeTransaction : public ViewManagerTransaction { | 226 class DestroyNodeTransaction : public ViewManagerTransaction { |
228 public: | 227 public: |
229 DestroyViewTreeNodeTransaction(Id node_id, | 228 DestroyNodeTransaction(Id node_id, ViewManagerClientImpl* client) |
230 ViewManagerSynchronizer* synchronizer) | 229 : ViewManagerTransaction(client), |
231 : ViewManagerTransaction(synchronizer), | |
232 node_id_(node_id) {} | 230 node_id_(node_id) {} |
233 virtual ~DestroyViewTreeNodeTransaction() {} | 231 virtual ~DestroyNodeTransaction() {} |
234 | 232 |
235 private: | 233 private: |
236 // Overridden from ViewManagerTransaction: | 234 // Overridden from ViewManagerTransaction: |
237 virtual void DoCommit() OVERRIDE { | 235 virtual void DoCommit() OVERRIDE { |
238 GetAndAdvanceNextServerChangeId(); | 236 GetAndAdvanceNextServerChangeId(); |
239 service()->DeleteNode(node_id_, ActionCompletedCallback()); | 237 service()->DeleteNode(node_id_, ActionCompletedCallback()); |
240 } | 238 } |
241 virtual void DoActionCompleted(bool success) OVERRIDE { | 239 virtual void DoActionCompleted(bool success) OVERRIDE { |
242 // TODO(beng): recovery? | 240 // TODO(beng): recovery? |
243 } | 241 } |
244 | 242 |
245 const Id node_id_; | 243 const Id node_id_; |
246 DISALLOW_COPY_AND_ASSIGN(DestroyViewTreeNodeTransaction); | 244 DISALLOW_COPY_AND_ASSIGN(DestroyNodeTransaction); |
247 }; | 245 }; |
248 | 246 |
249 class AddChildTransaction : public ViewManagerTransaction { | 247 class AddChildTransaction : public ViewManagerTransaction { |
250 public: | 248 public: |
251 AddChildTransaction(Id child_id, | 249 AddChildTransaction(Id child_id, |
252 Id parent_id, | 250 Id parent_id, |
253 ViewManagerSynchronizer* synchronizer) | 251 ViewManagerClientImpl* client) |
254 : ViewManagerTransaction(synchronizer), | 252 : ViewManagerTransaction(client), |
255 child_id_(child_id), | 253 child_id_(child_id), |
256 parent_id_(parent_id) {} | 254 parent_id_(parent_id) {} |
257 virtual ~AddChildTransaction() {} | 255 virtual ~AddChildTransaction() {} |
258 | 256 |
259 private: | 257 private: |
260 // Overridden from ViewManagerTransaction: | 258 // Overridden from ViewManagerTransaction: |
261 virtual void DoCommit() OVERRIDE { | 259 virtual void DoCommit() OVERRIDE { |
262 service()->AddNode(parent_id_, | 260 service()->AddNode(parent_id_, |
263 child_id_, | 261 child_id_, |
264 GetAndAdvanceNextServerChangeId(), | 262 GetAndAdvanceNextServerChangeId(), |
265 ActionCompletedCallback()); | 263 ActionCompletedCallback()); |
266 } | 264 } |
267 | 265 |
268 virtual void DoActionCompleted(bool success) OVERRIDE { | 266 virtual void DoActionCompleted(bool success) OVERRIDE { |
269 // TODO(beng): recovery? | 267 // TODO(beng): recovery? |
270 } | 268 } |
271 | 269 |
272 const Id child_id_; | 270 const Id child_id_; |
273 const Id parent_id_; | 271 const Id parent_id_; |
274 | 272 |
275 DISALLOW_COPY_AND_ASSIGN(AddChildTransaction); | 273 DISALLOW_COPY_AND_ASSIGN(AddChildTransaction); |
276 }; | 274 }; |
277 | 275 |
278 class RemoveChildTransaction : public ViewManagerTransaction { | 276 class RemoveChildTransaction : public ViewManagerTransaction { |
279 public: | 277 public: |
280 RemoveChildTransaction(Id child_id, | 278 RemoveChildTransaction(Id child_id, ViewManagerClientImpl* client) |
281 ViewManagerSynchronizer* synchronizer) | 279 : ViewManagerTransaction(client), |
282 : ViewManagerTransaction(synchronizer), | |
283 child_id_(child_id) {} | 280 child_id_(child_id) {} |
284 virtual ~RemoveChildTransaction() {} | 281 virtual ~RemoveChildTransaction() {} |
285 | 282 |
286 private: | 283 private: |
287 // Overridden from ViewManagerTransaction: | 284 // Overridden from ViewManagerTransaction: |
288 virtual void DoCommit() OVERRIDE { | 285 virtual void DoCommit() OVERRIDE { |
289 service()->RemoveNodeFromParent( | 286 service()->RemoveNodeFromParent( |
290 child_id_, | 287 child_id_, |
291 GetAndAdvanceNextServerChangeId(), | 288 GetAndAdvanceNextServerChangeId(), |
292 ActionCompletedCallback()); | 289 ActionCompletedCallback()); |
293 } | 290 } |
294 | 291 |
295 virtual void DoActionCompleted(bool success) OVERRIDE { | 292 virtual void DoActionCompleted(bool success) OVERRIDE { |
296 // TODO(beng): recovery? | 293 // TODO(beng): recovery? |
297 } | 294 } |
298 | 295 |
299 const Id child_id_; | 296 const Id child_id_; |
300 | 297 |
301 DISALLOW_COPY_AND_ASSIGN(RemoveChildTransaction); | 298 DISALLOW_COPY_AND_ASSIGN(RemoveChildTransaction); |
302 }; | 299 }; |
303 | 300 |
304 class ReorderNodeTransaction : public ViewManagerTransaction { | 301 class ReorderNodeTransaction : public ViewManagerTransaction { |
305 public: | 302 public: |
306 ReorderNodeTransaction(Id node_id, | 303 ReorderNodeTransaction(Id node_id, |
307 Id relative_id, | 304 Id relative_id, |
308 OrderDirection direction, | 305 OrderDirection direction, |
309 ViewManagerSynchronizer* synchronizer) | 306 ViewManagerClientImpl* client) |
310 : ViewManagerTransaction(synchronizer), | 307 : ViewManagerTransaction(client), |
311 node_id_(node_id), | 308 node_id_(node_id), |
312 relative_id_(relative_id), | 309 relative_id_(relative_id), |
313 direction_(direction) {} | 310 direction_(direction) {} |
314 virtual ~ReorderNodeTransaction() {} | 311 virtual ~ReorderNodeTransaction() {} |
315 | 312 |
316 private: | 313 private: |
317 // Overridden from ViewManagerTransaction: | 314 // Overridden from ViewManagerTransaction: |
318 virtual void DoCommit() OVERRIDE { | 315 virtual void DoCommit() OVERRIDE { |
319 service()->ReorderNode(node_id_, | 316 service()->ReorderNode(node_id_, |
320 relative_id_, | 317 relative_id_, |
(...skipping 10 matching lines...) Expand all Loading... |
331 const Id relative_id_; | 328 const Id relative_id_; |
332 const OrderDirection direction_; | 329 const OrderDirection direction_; |
333 | 330 |
334 DISALLOW_COPY_AND_ASSIGN(ReorderNodeTransaction); | 331 DISALLOW_COPY_AND_ASSIGN(ReorderNodeTransaction); |
335 }; | 332 }; |
336 | 333 |
337 class SetActiveViewTransaction : public ViewManagerTransaction { | 334 class SetActiveViewTransaction : public ViewManagerTransaction { |
338 public: | 335 public: |
339 SetActiveViewTransaction(Id node_id, | 336 SetActiveViewTransaction(Id node_id, |
340 Id view_id, | 337 Id view_id, |
341 ViewManagerSynchronizer* synchronizer) | 338 ViewManagerClientImpl* client) |
342 : ViewManagerTransaction(synchronizer), | 339 : ViewManagerTransaction(client), |
343 node_id_(node_id), | 340 node_id_(node_id), |
344 view_id_(view_id) {} | 341 view_id_(view_id) {} |
345 virtual ~SetActiveViewTransaction() {} | 342 virtual ~SetActiveViewTransaction() {} |
346 | 343 |
347 private: | 344 private: |
348 // Overridden from ViewManagerTransaction: | 345 // Overridden from ViewManagerTransaction: |
349 virtual void DoCommit() OVERRIDE { | 346 virtual void DoCommit() OVERRIDE { |
350 service()->SetView(node_id_, view_id_, ActionCompletedCallback()); | 347 service()->SetView(node_id_, view_id_, ActionCompletedCallback()); |
351 } | 348 } |
352 virtual void DoActionCompleted(bool success) OVERRIDE { | 349 virtual void DoActionCompleted(bool success) OVERRIDE { |
353 // TODO(beng): recovery? | 350 // TODO(beng): recovery? |
354 } | 351 } |
355 | 352 |
356 const Id node_id_; | 353 const Id node_id_; |
357 const Id view_id_; | 354 const Id view_id_; |
358 | 355 |
359 DISALLOW_COPY_AND_ASSIGN(SetActiveViewTransaction); | 356 DISALLOW_COPY_AND_ASSIGN(SetActiveViewTransaction); |
360 }; | 357 }; |
361 | 358 |
362 class SetBoundsTransaction : public ViewManagerTransaction { | 359 class SetBoundsTransaction : public ViewManagerTransaction { |
363 public: | 360 public: |
364 SetBoundsTransaction(Id node_id, | 361 SetBoundsTransaction(Id node_id, |
365 const gfx::Rect& bounds, | 362 const gfx::Rect& bounds, |
366 ViewManagerSynchronizer* synchronizer) | 363 ViewManagerClientImpl* client) |
367 : ViewManagerTransaction(synchronizer), | 364 : ViewManagerTransaction(client), |
368 node_id_(node_id), | 365 node_id_(node_id), |
369 bounds_(bounds) {} | 366 bounds_(bounds) {} |
370 virtual ~SetBoundsTransaction() {} | 367 virtual ~SetBoundsTransaction() {} |
371 | 368 |
372 private: | 369 private: |
373 // Overridden from ViewManagerTransaction: | 370 // Overridden from ViewManagerTransaction: |
374 virtual void DoCommit() OVERRIDE { | 371 virtual void DoCommit() OVERRIDE { |
375 service()->SetNodeBounds( | 372 service()->SetNodeBounds( |
376 node_id_, Rect::From(bounds_), ActionCompletedCallback()); | 373 node_id_, Rect::From(bounds_), ActionCompletedCallback()); |
377 } | 374 } |
378 virtual void DoActionCompleted(bool success) OVERRIDE { | 375 virtual void DoActionCompleted(bool success) OVERRIDE { |
379 // TODO(beng): recovery? | 376 // TODO(beng): recovery? |
380 } | 377 } |
381 | 378 |
382 const Id node_id_; | 379 const Id node_id_; |
383 const gfx::Rect bounds_; | 380 const gfx::Rect bounds_; |
384 | 381 |
385 DISALLOW_COPY_AND_ASSIGN(SetBoundsTransaction); | 382 DISALLOW_COPY_AND_ASSIGN(SetBoundsTransaction); |
386 }; | 383 }; |
387 | 384 |
388 class SetViewContentsTransaction : public ViewManagerTransaction { | 385 class SetViewContentsTransaction : public ViewManagerTransaction { |
389 public: | 386 public: |
390 SetViewContentsTransaction(Id view_id, | 387 SetViewContentsTransaction(Id view_id, |
391 const SkBitmap& contents, | 388 const SkBitmap& contents, |
392 ViewManagerSynchronizer* synchronizer) | 389 ViewManagerClientImpl* client) |
393 : ViewManagerTransaction(synchronizer), | 390 : ViewManagerTransaction(client), |
394 view_id_(view_id), | 391 view_id_(view_id), |
395 contents_(contents) {} | 392 contents_(contents) {} |
396 virtual ~SetViewContentsTransaction() {} | 393 virtual ~SetViewContentsTransaction() {} |
397 | 394 |
398 private: | 395 private: |
399 // Overridden from ViewManagerTransaction: | 396 // Overridden from ViewManagerTransaction: |
400 virtual void DoCommit() OVERRIDE { | 397 virtual void DoCommit() OVERRIDE { |
401 std::vector<unsigned char> data; | 398 std::vector<unsigned char> data; |
402 gfx::PNGCodec::EncodeBGRASkBitmap(contents_, false, &data); | 399 gfx::PNGCodec::EncodeBGRASkBitmap(contents_, false, &data); |
403 | 400 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 const SkBitmap contents_; | 444 const SkBitmap contents_; |
448 ScopedSharedBufferHandle shared_state_handle_; | 445 ScopedSharedBufferHandle shared_state_handle_; |
449 | 446 |
450 DISALLOW_COPY_AND_ASSIGN(SetViewContentsTransaction); | 447 DISALLOW_COPY_AND_ASSIGN(SetViewContentsTransaction); |
451 }; | 448 }; |
452 | 449 |
453 class EmbedTransaction : public ViewManagerTransaction { | 450 class EmbedTransaction : public ViewManagerTransaction { |
454 public: | 451 public: |
455 EmbedTransaction(const String& url, | 452 EmbedTransaction(const String& url, |
456 Id node_id, | 453 Id node_id, |
457 ViewManagerSynchronizer* synchronizer) | 454 ViewManagerClientImpl* client) |
458 : ViewManagerTransaction(synchronizer), | 455 : ViewManagerTransaction(client), |
459 url_(url), | 456 url_(url), |
460 node_id_(node_id) {} | 457 node_id_(node_id) {} |
461 virtual ~EmbedTransaction() {} | 458 virtual ~EmbedTransaction() {} |
462 | 459 |
463 private: | 460 private: |
464 // Overridden from ViewManagerTransaction: | 461 // Overridden from ViewManagerTransaction: |
465 virtual void DoCommit() OVERRIDE { | 462 virtual void DoCommit() OVERRIDE { |
466 std::vector<Id> ids; | 463 std::vector<Id> ids; |
467 ids.push_back(node_id_); | 464 ids.push_back(node_id_); |
468 service()->Embed(url_, Array<Id>::From(ids), ActionCompletedCallback()); | 465 service()->Embed(url_, Array<Id>::From(ids), ActionCompletedCallback()); |
469 } | 466 } |
470 virtual void DoActionCompleted(bool success) OVERRIDE { | 467 virtual void DoActionCompleted(bool success) OVERRIDE { |
471 // TODO(beng): recovery? | 468 // TODO(beng): recovery? |
472 } | 469 } |
473 | 470 |
474 const String url_; | 471 const String url_; |
475 const Id node_id_; | 472 const Id node_id_; |
476 | 473 |
477 DISALLOW_COPY_AND_ASSIGN(EmbedTransaction); | 474 DISALLOW_COPY_AND_ASSIGN(EmbedTransaction); |
478 }; | 475 }; |
479 | 476 |
480 class SetFocusTransaction : public ViewManagerTransaction { | 477 class SetFocusTransaction : public ViewManagerTransaction { |
481 public: | 478 public: |
482 SetFocusTransaction(Id node_id, ViewManagerSynchronizer* synchronizer) | 479 SetFocusTransaction(Id node_id, ViewManagerClientImpl* client) |
483 : ViewManagerTransaction(synchronizer), | 480 : ViewManagerTransaction(client), |
484 node_id_(node_id) {} | 481 node_id_(node_id) {} |
485 virtual ~SetFocusTransaction() {} | 482 virtual ~SetFocusTransaction() {} |
486 | 483 |
487 private: | 484 private: |
488 // Overridden from ViewManagerTransaction: | 485 // Overridden from ViewManagerTransaction: |
489 virtual void DoCommit() OVERRIDE { | 486 virtual void DoCommit() OVERRIDE { |
490 service()->SetFocus(node_id_, ActionCompletedCallback()); | 487 service()->SetFocus(node_id_, ActionCompletedCallback()); |
491 } | 488 } |
492 virtual void DoActionCompleted(bool success) OVERRIDE { | 489 virtual void DoActionCompleted(bool success) OVERRIDE { |
493 // TODO(beng): recovery? | 490 // TODO(beng): recovery? |
494 } | 491 } |
495 | 492 |
496 const Id node_id_; | 493 const Id node_id_; |
497 | 494 |
498 DISALLOW_COPY_AND_ASSIGN(SetFocusTransaction); | 495 DISALLOW_COPY_AND_ASSIGN(SetFocusTransaction); |
499 }; | 496 }; |
500 | 497 |
501 ViewManagerSynchronizer::ViewManagerSynchronizer(ViewManagerDelegate* delegate) | 498 ViewManagerClientImpl::ViewManagerClientImpl(ViewManagerDelegate* delegate) |
502 : connected_(false), | 499 : connected_(false), |
503 connection_id_(0), | 500 connection_id_(0), |
504 next_id_(1), | 501 next_id_(1), |
505 next_server_change_id_(0), | 502 next_server_change_id_(0), |
506 delegate_(delegate) {} | 503 delegate_(delegate) {} |
507 | 504 |
508 ViewManagerSynchronizer::~ViewManagerSynchronizer() { | 505 ViewManagerClientImpl::~ViewManagerClientImpl() { |
509 while (!nodes_.empty()) { | 506 while (!nodes_.empty()) { |
510 IdToNodeMap::iterator it = nodes_.begin(); | 507 IdToNodeMap::iterator it = nodes_.begin(); |
511 if (OwnsNode(it->second->id())) | 508 if (OwnsNode(it->second->id())) |
512 it->second->Destroy(); | 509 it->second->Destroy(); |
513 else | 510 else |
514 nodes_.erase(it); | 511 nodes_.erase(it); |
515 } | 512 } |
516 while (!views_.empty()) { | 513 while (!views_.empty()) { |
517 IdToViewMap::iterator it = views_.begin(); | 514 IdToViewMap::iterator it = views_.begin(); |
518 if (OwnsView(it->second->id())) | 515 if (OwnsView(it->second->id())) |
519 it->second->Destroy(); | 516 it->second->Destroy(); |
520 else | 517 else |
521 views_.erase(it); | 518 views_.erase(it); |
522 } | 519 } |
523 } | 520 } |
524 | 521 |
525 Id ViewManagerSynchronizer::CreateViewTreeNode() { | 522 Id ViewManagerClientImpl::CreateNode() { |
526 DCHECK(connected_); | 523 DCHECK(connected_); |
527 const Id node_id(MakeTransportId(connection_id_, ++next_id_)); | 524 const Id node_id(MakeTransportId(connection_id_, ++next_id_)); |
528 pending_transactions_.push_back( | 525 pending_transactions_.push_back(new CreateNodeTransaction(node_id, this)); |
529 new CreateViewTreeNodeTransaction(node_id, this)); | |
530 Sync(); | 526 Sync(); |
531 return node_id; | 527 return node_id; |
532 } | 528 } |
533 | 529 |
534 void ViewManagerSynchronizer::DestroyViewTreeNode(Id node_id) { | 530 void ViewManagerClientImpl::DestroyNode(Id node_id) { |
535 DCHECK(connected_); | 531 DCHECK(connected_); |
536 pending_transactions_.push_back( | 532 pending_transactions_.push_back(new DestroyNodeTransaction(node_id, this)); |
537 new DestroyViewTreeNodeTransaction(node_id, this)); | |
538 Sync(); | 533 Sync(); |
539 } | 534 } |
540 | 535 |
541 Id ViewManagerSynchronizer::CreateView() { | 536 Id ViewManagerClientImpl::CreateView() { |
542 DCHECK(connected_); | 537 DCHECK(connected_); |
543 const Id view_id(MakeTransportId(connection_id_, ++next_id_)); | 538 const Id view_id(MakeTransportId(connection_id_, ++next_id_)); |
544 pending_transactions_.push_back(new CreateViewTransaction(view_id, this)); | 539 pending_transactions_.push_back(new CreateViewTransaction(view_id, this)); |
545 Sync(); | 540 Sync(); |
546 return view_id; | 541 return view_id; |
547 } | 542 } |
548 | 543 |
549 void ViewManagerSynchronizer::DestroyView(Id view_id) { | 544 void ViewManagerClientImpl::DestroyView(Id view_id) { |
550 DCHECK(connected_); | 545 DCHECK(connected_); |
551 pending_transactions_.push_back(new DestroyViewTransaction(view_id, this)); | 546 pending_transactions_.push_back(new DestroyViewTransaction(view_id, this)); |
552 Sync(); | 547 Sync(); |
553 } | 548 } |
554 | 549 |
555 void ViewManagerSynchronizer::AddChild(Id child_id, | 550 void ViewManagerClientImpl::AddChild(Id child_id, |
556 Id parent_id) { | 551 Id parent_id) { |
557 DCHECK(connected_); | 552 DCHECK(connected_); |
558 pending_transactions_.push_back( | 553 pending_transactions_.push_back( |
559 new AddChildTransaction(child_id, parent_id, this)); | 554 new AddChildTransaction(child_id, parent_id, this)); |
560 Sync(); | 555 Sync(); |
561 } | 556 } |
562 | 557 |
563 void ViewManagerSynchronizer::RemoveChild(Id child_id, Id parent_id) { | 558 void ViewManagerClientImpl::RemoveChild(Id child_id, Id parent_id) { |
564 DCHECK(connected_); | 559 DCHECK(connected_); |
565 pending_transactions_.push_back(new RemoveChildTransaction(child_id, this)); | 560 pending_transactions_.push_back(new RemoveChildTransaction(child_id, this)); |
566 Sync(); | 561 Sync(); |
567 } | 562 } |
568 | 563 |
569 void ViewManagerSynchronizer::Reorder( | 564 void ViewManagerClientImpl::Reorder( |
570 Id node_id, | 565 Id node_id, |
571 Id relative_node_id, | 566 Id relative_node_id, |
572 OrderDirection direction) { | 567 OrderDirection direction) { |
573 DCHECK(connected_); | 568 DCHECK(connected_); |
574 pending_transactions_.push_back( | 569 pending_transactions_.push_back( |
575 new ReorderNodeTransaction(node_id, relative_node_id, direction, this)); | 570 new ReorderNodeTransaction(node_id, relative_node_id, direction, this)); |
576 Sync(); | 571 Sync(); |
577 } | 572 } |
578 | 573 |
579 bool ViewManagerSynchronizer::OwnsNode(Id id) const { | 574 bool ViewManagerClientImpl::OwnsNode(Id id) const { |
580 return HiWord(id) == connection_id_; | 575 return HiWord(id) == connection_id_; |
581 } | 576 } |
582 | 577 |
583 bool ViewManagerSynchronizer::OwnsView(Id id) const { | 578 bool ViewManagerClientImpl::OwnsView(Id id) const { |
584 return HiWord(id) == connection_id_; | 579 return HiWord(id) == connection_id_; |
585 } | 580 } |
586 | 581 |
587 void ViewManagerSynchronizer::SetActiveView(Id node_id, Id view_id) { | 582 void ViewManagerClientImpl::SetActiveView(Id node_id, Id view_id) { |
588 DCHECK(connected_); | 583 DCHECK(connected_); |
589 pending_transactions_.push_back( | 584 pending_transactions_.push_back( |
590 new SetActiveViewTransaction(node_id, view_id, this)); | 585 new SetActiveViewTransaction(node_id, view_id, this)); |
591 Sync(); | 586 Sync(); |
592 } | 587 } |
593 | 588 |
594 void ViewManagerSynchronizer::SetBounds(Id node_id, const gfx::Rect& bounds) { | 589 void ViewManagerClientImpl::SetBounds(Id node_id, const gfx::Rect& bounds) { |
595 DCHECK(connected_); | 590 DCHECK(connected_); |
596 pending_transactions_.push_back( | 591 pending_transactions_.push_back( |
597 new SetBoundsTransaction(node_id, bounds, this)); | 592 new SetBoundsTransaction(node_id, bounds, this)); |
598 Sync(); | 593 Sync(); |
599 } | 594 } |
600 | 595 |
601 void ViewManagerSynchronizer::SetViewContents(Id view_id, | 596 void ViewManagerClientImpl::SetViewContents(Id view_id, |
602 const SkBitmap& contents) { | 597 const SkBitmap& contents) { |
603 DCHECK(connected_); | 598 DCHECK(connected_); |
604 pending_transactions_.push_back( | 599 pending_transactions_.push_back( |
605 new SetViewContentsTransaction(view_id, contents, this)); | 600 new SetViewContentsTransaction(view_id, contents, this)); |
606 Sync(); | 601 Sync(); |
607 } | 602 } |
608 | 603 |
609 void ViewManagerSynchronizer::SetFocus(Id node_id) { | 604 void ViewManagerClientImpl::SetFocus(Id node_id) { |
610 DCHECK(connected_); | 605 DCHECK(connected_); |
611 pending_transactions_.push_back(new SetFocusTransaction(node_id, this)); | 606 pending_transactions_.push_back(new SetFocusTransaction(node_id, this)); |
612 Sync(); | 607 Sync(); |
613 } | 608 } |
614 | 609 |
615 void ViewManagerSynchronizer::Embed(const String& url, Id node_id) { | 610 void ViewManagerClientImpl::Embed(const String& url, Id node_id) { |
616 DCHECK(connected_); | 611 DCHECK(connected_); |
617 pending_transactions_.push_back(new EmbedTransaction(url, node_id, this)); | 612 pending_transactions_.push_back(new EmbedTransaction(url, node_id, this)); |
618 Sync(); | 613 Sync(); |
619 } | 614 } |
620 | 615 |
621 void ViewManagerSynchronizer::AddNode(ViewTreeNode* node) { | 616 void ViewManagerClientImpl::AddNode(Node* node) { |
622 DCHECK(nodes_.find(node->id()) == nodes_.end()); | 617 DCHECK(nodes_.find(node->id()) == nodes_.end()); |
623 nodes_[node->id()] = node; | 618 nodes_[node->id()] = node; |
624 } | 619 } |
625 | 620 |
626 void ViewManagerSynchronizer::RemoveNode(Id node_id) { | 621 void ViewManagerClientImpl::RemoveNode(Id node_id) { |
627 IdToNodeMap::iterator it = nodes_.find(node_id); | 622 IdToNodeMap::iterator it = nodes_.find(node_id); |
628 if (it != nodes_.end()) | 623 if (it != nodes_.end()) |
629 nodes_.erase(it); | 624 nodes_.erase(it); |
630 } | 625 } |
631 | 626 |
632 void ViewManagerSynchronizer::AddView(View* view) { | 627 void ViewManagerClientImpl::AddView(View* view) { |
633 DCHECK(views_.find(view->id()) == views_.end()); | 628 DCHECK(views_.find(view->id()) == views_.end()); |
634 views_[view->id()] = view; | 629 views_[view->id()] = view; |
635 } | 630 } |
636 | 631 |
637 void ViewManagerSynchronizer::RemoveView(Id view_id) { | 632 void ViewManagerClientImpl::RemoveView(Id view_id) { |
638 IdToViewMap::iterator it = views_.find(view_id); | 633 IdToViewMap::iterator it = views_.find(view_id); |
639 if (it != views_.end()) | 634 if (it != views_.end()) |
640 views_.erase(it); | 635 views_.erase(it); |
641 } | 636 } |
642 | 637 |
643 //////////////////////////////////////////////////////////////////////////////// | 638 //////////////////////////////////////////////////////////////////////////////// |
644 // ViewManagerSynchronizer, ViewManager implementation: | 639 // ViewManagerClientImpl, ViewManager implementation: |
645 | 640 |
646 const std::string& ViewManagerSynchronizer::GetEmbedderURL() const { | 641 const std::string& ViewManagerClientImpl::GetEmbedderURL() const { |
647 return creator_url_; | 642 return creator_url_; |
648 } | 643 } |
649 | 644 |
650 const std::vector<ViewTreeNode*>& ViewManagerSynchronizer::GetRoots() const { | 645 const std::vector<Node*>& ViewManagerClientImpl::GetRoots() const { |
651 return roots_; | 646 return roots_; |
652 } | 647 } |
653 | 648 |
654 ViewTreeNode* ViewManagerSynchronizer::GetNodeById(Id id) { | 649 Node* ViewManagerClientImpl::GetNodeById(Id id) { |
655 IdToNodeMap::const_iterator it = nodes_.find(id); | 650 IdToNodeMap::const_iterator it = nodes_.find(id); |
656 return it != nodes_.end() ? it->second : NULL; | 651 return it != nodes_.end() ? it->second : NULL; |
657 } | 652 } |
658 | 653 |
659 View* ViewManagerSynchronizer::GetViewById(Id id) { | 654 View* ViewManagerClientImpl::GetViewById(Id id) { |
660 IdToViewMap::const_iterator it = views_.find(id); | 655 IdToViewMap::const_iterator it = views_.find(id); |
661 return it != views_.end() ? it->second : NULL; | 656 return it != views_.end() ? it->second : NULL; |
662 } | 657 } |
663 | 658 |
664 //////////////////////////////////////////////////////////////////////////////// | 659 //////////////////////////////////////////////////////////////////////////////// |
665 // ViewManagerSynchronizer, InterfaceImpl overrides: | 660 // ViewManagerClientImpl, InterfaceImpl overrides: |
666 | 661 |
667 void ViewManagerSynchronizer::OnConnectionEstablished() { | 662 void ViewManagerClientImpl::OnConnectionEstablished() { |
668 service_ = client(); | 663 service_ = client(); |
669 } | 664 } |
670 | 665 |
671 //////////////////////////////////////////////////////////////////////////////// | 666 //////////////////////////////////////////////////////////////////////////////// |
672 // ViewManagerSynchronizer, ViewManagerClient implementation: | 667 // ViewManagerClientImpl, ViewManagerClient implementation: |
673 | 668 |
674 void ViewManagerSynchronizer::OnViewManagerConnectionEstablished( | 669 void ViewManagerClientImpl::OnViewManagerConnectionEstablished( |
675 ConnectionSpecificId connection_id, | 670 ConnectionSpecificId connection_id, |
676 const String& creator_url, | 671 const String& creator_url, |
677 Id next_server_change_id, | 672 Id next_server_change_id, |
678 Array<NodeDataPtr> nodes) { | 673 Array<NodeDataPtr> nodes) { |
679 connected_ = true; | 674 connected_ = true; |
680 connection_id_ = connection_id; | 675 connection_id_ = connection_id; |
681 creator_url_ = TypeConverter<String, std::string>::ConvertFrom(creator_url); | 676 creator_url_ = TypeConverter<String, std::string>::ConvertFrom(creator_url); |
682 next_server_change_id_ = next_server_change_id; | 677 next_server_change_id_ = next_server_change_id; |
683 | 678 |
684 DCHECK(pending_transactions_.empty()); | 679 DCHECK(pending_transactions_.empty()); |
685 AddRoot(BuildNodeTree(this, nodes)); | 680 AddRoot(BuildNodeTree(this, nodes)); |
686 } | 681 } |
687 | 682 |
688 void ViewManagerSynchronizer::OnRootsAdded(Array<NodeDataPtr> nodes) { | 683 void ViewManagerClientImpl::OnRootsAdded(Array<NodeDataPtr> nodes) { |
689 AddRoot(BuildNodeTree(this, nodes)); | 684 AddRoot(BuildNodeTree(this, nodes)); |
690 } | 685 } |
691 | 686 |
692 void ViewManagerSynchronizer::OnServerChangeIdAdvanced( | 687 void ViewManagerClientImpl::OnServerChangeIdAdvanced( |
693 Id next_server_change_id) { | 688 Id next_server_change_id) { |
694 next_server_change_id_ = next_server_change_id; | 689 next_server_change_id_ = next_server_change_id; |
695 } | 690 } |
696 | 691 |
697 void ViewManagerSynchronizer::OnNodeBoundsChanged(Id node_id, | 692 void ViewManagerClientImpl::OnNodeBoundsChanged(Id node_id, |
698 RectPtr old_bounds, | 693 RectPtr old_bounds, |
699 RectPtr new_bounds) { | 694 RectPtr new_bounds) { |
700 ViewTreeNode* node = GetNodeById(node_id); | 695 Node* node = GetNodeById(node_id); |
701 ViewTreeNodePrivate(node).LocalSetBounds(old_bounds.To<gfx::Rect>(), | 696 NodePrivate(node).LocalSetBounds(old_bounds.To<gfx::Rect>(), |
702 new_bounds.To<gfx::Rect>()); | 697 new_bounds.To<gfx::Rect>()); |
703 } | 698 } |
704 | 699 |
705 void ViewManagerSynchronizer::OnNodeHierarchyChanged( | 700 void ViewManagerClientImpl::OnNodeHierarchyChanged( |
706 Id node_id, | 701 Id node_id, |
707 Id new_parent_id, | 702 Id new_parent_id, |
708 Id old_parent_id, | 703 Id old_parent_id, |
709 Id server_change_id, | 704 Id server_change_id, |
710 mojo::Array<NodeDataPtr> nodes) { | 705 mojo::Array<NodeDataPtr> nodes) { |
711 next_server_change_id_ = server_change_id + 1; | 706 next_server_change_id_ = server_change_id + 1; |
712 | 707 |
713 BuildNodeTree(this, nodes); | 708 BuildNodeTree(this, nodes); |
714 | 709 |
715 ViewTreeNode* new_parent = GetNodeById(new_parent_id); | 710 Node* new_parent = GetNodeById(new_parent_id); |
716 ViewTreeNode* old_parent = GetNodeById(old_parent_id); | 711 Node* old_parent = GetNodeById(old_parent_id); |
717 ViewTreeNode* node = GetNodeById(node_id); | 712 Node* node = GetNodeById(node_id); |
718 if (new_parent) | 713 if (new_parent) |
719 ViewTreeNodePrivate(new_parent).LocalAddChild(node); | 714 NodePrivate(new_parent).LocalAddChild(node); |
720 else | 715 else |
721 ViewTreeNodePrivate(old_parent).LocalRemoveChild(node); | 716 NodePrivate(old_parent).LocalRemoveChild(node); |
722 } | 717 } |
723 | 718 |
724 void ViewManagerSynchronizer::OnNodeReordered(Id node_id, | 719 void ViewManagerClientImpl::OnNodeReordered(Id node_id, |
725 Id relative_node_id, | 720 Id relative_node_id, |
726 OrderDirection direction, | 721 OrderDirection direction, |
727 Id server_change_id) { | 722 Id server_change_id) { |
728 next_server_change_id_ = server_change_id + 1; | 723 next_server_change_id_ = server_change_id + 1; |
729 | 724 |
730 ViewTreeNode* node = GetNodeById(node_id); | 725 Node* node = GetNodeById(node_id); |
731 ViewTreeNode* relative_node = GetNodeById(relative_node_id); | 726 Node* relative_node = GetNodeById(relative_node_id); |
732 if (node && relative_node) { | 727 if (node && relative_node) { |
733 ViewTreeNodePrivate(node).LocalReorder(relative_node, direction); | 728 NodePrivate(node).LocalReorder(relative_node, direction); |
734 } | 729 } |
735 } | 730 } |
736 | 731 |
737 void ViewManagerSynchronizer::OnNodeDeleted(Id node_id, Id server_change_id) { | 732 void ViewManagerClientImpl::OnNodeDeleted(Id node_id, Id server_change_id) { |
738 next_server_change_id_ = server_change_id + 1; | 733 next_server_change_id_ = server_change_id + 1; |
739 | 734 |
740 ViewTreeNode* node = GetNodeById(node_id); | 735 Node* node = GetNodeById(node_id); |
741 if (node) | 736 if (node) |
742 ViewTreeNodePrivate(node).LocalDestroy(); | 737 NodePrivate(node).LocalDestroy(); |
743 } | 738 } |
744 | 739 |
745 void ViewManagerSynchronizer::OnNodeViewReplaced(Id node_id, | 740 void ViewManagerClientImpl::OnNodeViewReplaced(Id node_id, |
746 Id new_view_id, | 741 Id new_view_id, |
747 Id old_view_id) { | 742 Id old_view_id) { |
748 ViewTreeNode* node = GetNodeById(node_id); | 743 Node* node = GetNodeById(node_id); |
749 View* new_view = GetViewById(new_view_id); | 744 View* new_view = GetViewById(new_view_id); |
750 if (!new_view && new_view_id != 0) { | 745 if (!new_view && new_view_id != 0) { |
751 // This client wasn't aware of this View until now. | 746 // This client wasn't aware of this View until now. |
752 new_view = ViewPrivate::LocalCreate(); | 747 new_view = ViewPrivate::LocalCreate(); |
753 ViewPrivate private_view(new_view); | 748 ViewPrivate private_view(new_view); |
754 private_view.set_view_manager(this); | 749 private_view.set_view_manager(this); |
755 private_view.set_id(new_view_id); | 750 private_view.set_id(new_view_id); |
756 private_view.set_node(node); | 751 private_view.set_node(node); |
757 AddView(new_view); | 752 AddView(new_view); |
758 } | 753 } |
759 View* old_view = GetViewById(old_view_id); | 754 View* old_view = GetViewById(old_view_id); |
760 DCHECK_EQ(old_view, node->active_view()); | 755 DCHECK_EQ(old_view, node->active_view()); |
761 ViewTreeNodePrivate(node).LocalSetActiveView(new_view); | 756 NodePrivate(node).LocalSetActiveView(new_view); |
762 } | 757 } |
763 | 758 |
764 void ViewManagerSynchronizer::OnViewDeleted(Id view_id) { | 759 void ViewManagerClientImpl::OnViewDeleted(Id view_id) { |
765 View* view = GetViewById(view_id); | 760 View* view = GetViewById(view_id); |
766 if (view) | 761 if (view) |
767 ViewPrivate(view).LocalDestroy(); | 762 ViewPrivate(view).LocalDestroy(); |
768 } | 763 } |
769 | 764 |
770 void ViewManagerSynchronizer::OnViewInputEvent( | 765 void ViewManagerClientImpl::OnViewInputEvent( |
771 Id view_id, | 766 Id view_id, |
772 EventPtr event, | 767 EventPtr event, |
773 const Callback<void()>& ack_callback) { | 768 const Callback<void()>& ack_callback) { |
774 View* view = GetViewById(view_id); | 769 View* view = GetViewById(view_id); |
775 if (view) { | 770 if (view) { |
776 FOR_EACH_OBSERVER(ViewObserver, | 771 FOR_EACH_OBSERVER(ViewObserver, |
777 *ViewPrivate(view).observers(), | 772 *ViewPrivate(view).observers(), |
778 OnViewInputEvent(view, event)); | 773 OnViewInputEvent(view, event)); |
779 } | 774 } |
780 ack_callback.Run(); | 775 ack_callback.Run(); |
781 } | 776 } |
782 | 777 |
783 //////////////////////////////////////////////////////////////////////////////// | 778 //////////////////////////////////////////////////////////////////////////////// |
784 // ViewManagerSynchronizer, private: | 779 // ViewManagerClientImpl, private: |
785 | 780 |
786 void ViewManagerSynchronizer::Sync() { | 781 void ViewManagerClientImpl::Sync() { |
787 // The service connection may not be set up yet. OnConnectionEstablished() | 782 // The service connection may not be set up yet. OnConnectionEstablished() |
788 // will schedule another sync when it is. | 783 // will schedule another sync when it is. |
789 if (!connected_) | 784 if (!connected_) |
790 return; | 785 return; |
791 | 786 |
792 Transactions::const_iterator it = pending_transactions_.begin(); | 787 Transactions::const_iterator it = pending_transactions_.begin(); |
793 for (; it != pending_transactions_.end(); ++it) { | 788 for (; it != pending_transactions_.end(); ++it) { |
794 if (!(*it)->committed()) | 789 if (!(*it)->committed()) |
795 (*it)->Commit(); | 790 (*it)->Commit(); |
796 } | 791 } |
797 } | 792 } |
798 | 793 |
799 void ViewManagerSynchronizer::RemoveFromPendingQueue( | 794 void ViewManagerClientImpl::RemoveFromPendingQueue( |
800 ViewManagerTransaction* transaction) { | 795 ViewManagerTransaction* transaction) { |
801 DCHECK_EQ(transaction, pending_transactions_.front()); | 796 DCHECK_EQ(transaction, pending_transactions_.front()); |
802 pending_transactions_.erase(pending_transactions_.begin()); | 797 pending_transactions_.erase(pending_transactions_.begin()); |
803 if (pending_transactions_.empty() && !changes_acked_callback_.is_null()) | 798 if (pending_transactions_.empty() && !changes_acked_callback_.is_null()) |
804 changes_acked_callback_.Run(); | 799 changes_acked_callback_.Run(); |
805 } | 800 } |
806 | 801 |
807 void ViewManagerSynchronizer::AddRoot(ViewTreeNode* root) { | 802 void ViewManagerClientImpl::AddRoot(Node* root) { |
808 // A new root must not already exist as a root or be contained by an existing | 803 // A new root must not already exist as a root or be contained by an existing |
809 // hierarchy visible to this view manager. | 804 // hierarchy visible to this view manager. |
810 std::vector<ViewTreeNode*>::const_iterator it = roots_.begin(); | 805 std::vector<Node*>::const_iterator it = roots_.begin(); |
811 for (; it != roots_.end(); ++it) { | 806 for (; it != roots_.end(); ++it) { |
812 if (*it == root || (*it)->Contains(root)) | 807 if (*it == root || (*it)->Contains(root)) |
813 return; | 808 return; |
814 } | 809 } |
815 roots_.push_back(root); | 810 roots_.push_back(root); |
816 root->AddObserver(new RootObserver(root)); | 811 root->AddObserver(new RootObserver(root)); |
817 delegate_->OnRootAdded(this, root); | 812 delegate_->OnRootAdded(this, root); |
818 } | 813 } |
819 | 814 |
820 void ViewManagerSynchronizer::RemoveRoot(ViewTreeNode* root) { | 815 void ViewManagerClientImpl::RemoveRoot(Node* root) { |
821 std::vector<ViewTreeNode*>::iterator it = | 816 std::vector<Node*>::iterator it = |
822 std::find(roots_.begin(), roots_.end(), root); | 817 std::find(roots_.begin(), roots_.end(), root); |
823 if (it != roots_.end()) { | 818 if (it != roots_.end()) { |
824 roots_.erase(it); | 819 roots_.erase(it); |
825 delegate_->OnRootRemoved(this, root); | 820 delegate_->OnRootRemoved(this, root); |
826 } | 821 } |
827 } | 822 } |
828 | 823 |
829 //////////////////////////////////////////////////////////////////////////////// | 824 //////////////////////////////////////////////////////////////////////////////// |
830 // ViewManager, public: | 825 // ViewManager, public: |
831 | 826 |
832 // static | 827 // static |
833 void ViewManager::Create(Application* application, | 828 void ViewManager::Create(Application* application, |
834 ViewManagerDelegate* delegate) { | 829 ViewManagerDelegate* delegate) { |
835 application->AddService<ViewManagerSynchronizer>(delegate); | 830 application->AddService<ViewManagerClientImpl>(delegate); |
836 } | 831 } |
837 | 832 |
838 } // namespace view_manager | 833 } // namespace view_manager |
839 } // namespace mojo | 834 } // namespace mojo |
OLD | NEW |