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_synchronizer.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "mojo/public/cpp/shell/connect.h" | 9 #include "mojo/public/cpp/shell/connect.h" |
10 #include "mojo/public/interfaces/shell/shell.mojom.h" | 10 #include "mojo/public/interfaces/shell/shell.mojom.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 // View creation and destruction. | 92 // View creation and destruction. |
93 TYPE_CREATE_VIEW, | 93 TYPE_CREATE_VIEW, |
94 TYPE_DESTROY_VIEW, | 94 TYPE_DESTROY_VIEW, |
95 // Node creation and destruction. | 95 // Node creation and destruction. |
96 TYPE_CREATE_VIEW_TREE_NODE, | 96 TYPE_CREATE_VIEW_TREE_NODE, |
97 TYPE_DESTROY_VIEW_TREE_NODE, | 97 TYPE_DESTROY_VIEW_TREE_NODE, |
98 // Modifications to the hierarchy (addition of or removal of nodes from a | 98 // Modifications to the hierarchy (addition of or removal of nodes from a |
99 // parent.) | 99 // parent.) |
100 TYPE_HIERARCHY, | 100 TYPE_HIERARCHY, |
101 // View replacement. | 101 // View replacement. |
102 TYPE_SET_ACTIVE_VIEW | 102 TYPE_SET_ACTIVE_VIEW, |
| 103 // Node bounds. |
| 104 TYPE_SET_BOUNDS |
103 }; | 105 }; |
104 | 106 |
105 ViewManagerTransaction(TransactionType transaction_type, | 107 ViewManagerTransaction(TransactionType transaction_type, |
106 ViewManagerSynchronizer* synchronizer) | 108 ViewManagerSynchronizer* synchronizer) |
107 : transaction_type_(transaction_type), | 109 : transaction_type_(transaction_type), |
108 committed_(false), | 110 committed_(false), |
109 synchronizer_(synchronizer) { | 111 synchronizer_(synchronizer) { |
110 } | 112 } |
111 | 113 |
112 // Overridden to perform transaction-specific commit actions. | 114 // Overridden to perform transaction-specific commit actions. |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 virtual void DoActionCompleted(bool success) OVERRIDE { | 300 virtual void DoActionCompleted(bool success) OVERRIDE { |
299 // TODO(beng): recovery? | 301 // TODO(beng): recovery? |
300 } | 302 } |
301 | 303 |
302 const TransportNodeId node_id_; | 304 const TransportNodeId node_id_; |
303 const TransportViewId view_id_; | 305 const TransportViewId view_id_; |
304 | 306 |
305 DISALLOW_COPY_AND_ASSIGN(SetActiveViewTransaction); | 307 DISALLOW_COPY_AND_ASSIGN(SetActiveViewTransaction); |
306 }; | 308 }; |
307 | 309 |
| 310 class SetBoundsTransaction : public ViewManagerTransaction { |
| 311 public: |
| 312 SetBoundsTransaction(TransportNodeId node_id, |
| 313 const gfx::Rect& bounds, |
| 314 ViewManagerSynchronizer* synchronizer) |
| 315 : ViewManagerTransaction(TYPE_SET_BOUNDS, synchronizer), |
| 316 node_id_(node_id), |
| 317 bounds_(bounds) {} |
| 318 virtual ~SetBoundsTransaction() {} |
| 319 |
| 320 private: |
| 321 // Overridden from ViewManagerTransaction: |
| 322 virtual void DoCommit() OVERRIDE { |
| 323 AllocationScope scope; |
| 324 service()->SetNodeBounds(node_id_, bounds_, ActionCompletedCallback()); |
| 325 } |
| 326 virtual void DoActionCompleted(bool success) OVERRIDE { |
| 327 // TODO(beng): recovery? |
| 328 } |
| 329 |
| 330 const TransportNodeId node_id_; |
| 331 const gfx::Rect bounds_; |
| 332 |
| 333 DISALLOW_COPY_AND_ASSIGN(SetBoundsTransaction); |
| 334 }; |
| 335 |
308 ViewManagerSynchronizer::ViewManagerSynchronizer(ViewManager* view_manager) | 336 ViewManagerSynchronizer::ViewManagerSynchronizer(ViewManager* view_manager) |
309 : view_manager_(view_manager), | 337 : view_manager_(view_manager), |
310 connected_(false), | 338 connected_(false), |
311 connection_id_(0), | 339 connection_id_(0), |
312 next_id_(1), | 340 next_id_(1), |
313 next_server_change_id_(0), | 341 next_server_change_id_(0), |
314 sync_factory_(this), | 342 sync_factory_(this), |
315 init_loop_(NULL) { | 343 init_loop_(NULL) { |
316 ConnectTo(ViewManagerPrivate(view_manager_).shell(), "mojo:mojo_view_manager", | 344 ConnectTo(ViewManagerPrivate(view_manager_).shell(), "mojo:mojo_view_manager", |
317 &service_); | 345 &service_); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 } | 420 } |
393 | 421 |
394 void ViewManagerSynchronizer::SetActiveView(TransportNodeId node_id, | 422 void ViewManagerSynchronizer::SetActiveView(TransportNodeId node_id, |
395 TransportViewId view_id) { | 423 TransportViewId view_id) { |
396 DCHECK(connected_); | 424 DCHECK(connected_); |
397 pending_transactions_.push_back( | 425 pending_transactions_.push_back( |
398 new SetActiveViewTransaction(node_id, view_id, this)); | 426 new SetActiveViewTransaction(node_id, view_id, this)); |
399 Sync(); | 427 Sync(); |
400 } | 428 } |
401 | 429 |
| 430 void ViewManagerSynchronizer::SetBounds(TransportNodeId node_id, |
| 431 const gfx::Rect& bounds) { |
| 432 DCHECK(connected_); |
| 433 pending_transactions_.push_back( |
| 434 new SetBoundsTransaction(node_id, bounds, this)); |
| 435 Sync(); |
| 436 } |
| 437 |
402 //////////////////////////////////////////////////////////////////////////////// | 438 //////////////////////////////////////////////////////////////////////////////// |
403 // ViewManagerSynchronizer, IViewManagerClient implementation: | 439 // ViewManagerSynchronizer, IViewManagerClient implementation: |
404 | 440 |
405 void ViewManagerSynchronizer::OnConnectionEstablished( | 441 void ViewManagerSynchronizer::OnConnectionEstablished( |
406 TransportConnectionId connection_id, | 442 TransportConnectionId connection_id, |
407 TransportChangeId next_server_change_id, | 443 TransportChangeId next_server_change_id, |
408 const Array<INode>& nodes) { | 444 const Array<INode>& nodes) { |
409 connected_ = true; | 445 connected_ = true; |
410 connection_id_ = connection_id; | 446 connection_id_ = connection_id; |
411 next_server_change_id_ = next_server_change_id; | 447 next_server_change_id_ = next_server_change_id; |
412 | 448 |
413 ViewManagerPrivate(view_manager_).set_root( | 449 ViewManagerPrivate(view_manager_).set_root( |
414 BuildNodeTree(view_manager_, nodes)); | 450 BuildNodeTree(view_manager_, nodes)); |
415 if (init_loop_) | 451 if (init_loop_) |
416 init_loop_->Quit(); | 452 init_loop_->Quit(); |
417 | 453 |
418 Sync(); | 454 Sync(); |
419 } | 455 } |
420 | 456 |
421 void ViewManagerSynchronizer::OnServerChangeIdAdvanced( | 457 void ViewManagerSynchronizer::OnServerChangeIdAdvanced( |
422 uint32_t next_server_change_id) { | 458 uint32_t next_server_change_id) { |
423 next_server_change_id_ = next_server_change_id; | 459 next_server_change_id_ = next_server_change_id; |
424 } | 460 } |
425 | 461 |
| 462 void ViewManagerSynchronizer::OnNodeBoundsChanged(uint32 node_id, |
| 463 const Rect& old_bounds, |
| 464 const Rect& new_bounds) { |
| 465 ViewTreeNode* node = view_manager_->GetNodeById(node_id); |
| 466 ViewTreeNodePrivate(node).LocalSetBounds(old_bounds, new_bounds); |
| 467 } |
| 468 |
426 void ViewManagerSynchronizer::OnNodeHierarchyChanged( | 469 void ViewManagerSynchronizer::OnNodeHierarchyChanged( |
427 uint32_t node_id, | 470 uint32_t node_id, |
428 uint32_t new_parent_id, | 471 uint32_t new_parent_id, |
429 uint32_t old_parent_id, | 472 uint32_t old_parent_id, |
430 TransportChangeId server_change_id, | 473 TransportChangeId server_change_id, |
431 const Array<INode>& nodes) { | 474 const Array<INode>& nodes) { |
432 // TODO: deal with |nodes|. | 475 // TODO: deal with |nodes|. |
433 next_server_change_id_ = server_change_id + 1; | 476 next_server_change_id_ = server_change_id + 1; |
434 | 477 |
435 BuildNodeTree(view_manager_, nodes); | 478 BuildNodeTree(view_manager_, nodes); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 void ViewManagerSynchronizer::RemoveFromPendingQueue( | 539 void ViewManagerSynchronizer::RemoveFromPendingQueue( |
497 ViewManagerTransaction* transaction) { | 540 ViewManagerTransaction* transaction) { |
498 DCHECK_EQ(transaction, pending_transactions_.front()); | 541 DCHECK_EQ(transaction, pending_transactions_.front()); |
499 pending_transactions_.erase(pending_transactions_.begin()); | 542 pending_transactions_.erase(pending_transactions_.begin()); |
500 if (pending_transactions_.empty() && !changes_acked_callback_.is_null()) | 543 if (pending_transactions_.empty() && !changes_acked_callback_.is_null()) |
501 changes_acked_callback_.Run(); | 544 changes_acked_callback_.Run(); |
502 } | 545 } |
503 | 546 |
504 } // namespace view_manager | 547 } // namespace view_manager |
505 } // namespace mojo | 548 } // namespace mojo |
OLD | NEW |