| 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/application/connect.h" | 9 #include "mojo/public/cpp/application/connect.h" |
| 10 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" | 10 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 private_view.set_node(node); | 49 private_view.set_node(node); |
| 50 // TODO(beng): this broadcasts notifications locally... do we want this? I | 50 // TODO(beng): this broadcasts notifications locally... do we want this? I |
| 51 // don't think so. same story for LocalAddChild above! | 51 // don't think so. same story for LocalAddChild above! |
| 52 private_node.LocalSetActiveView(view); | 52 private_node.LocalSetActiveView(view); |
| 53 private_manager.AddView(view->id(), view); | 53 private_manager.AddView(view->id(), view); |
| 54 } | 54 } |
| 55 return node; | 55 return node; |
| 56 } | 56 } |
| 57 | 57 |
| 58 ViewTreeNode* BuildNodeTree(ViewManager* manager, | 58 ViewTreeNode* BuildNodeTree(ViewManager* manager, |
| 59 const Array<INode>& nodes) { | 59 const Array<INodePtr>& nodes) { |
| 60 std::vector<ViewTreeNode*> parents; | 60 std::vector<ViewTreeNode*> parents; |
| 61 ViewTreeNode* root = NULL; | 61 ViewTreeNode* root = NULL; |
| 62 ViewTreeNode* last_node = NULL; | 62 ViewTreeNode* last_node = NULL; |
| 63 for (size_t i = 0; i < nodes.size(); ++i) { | 63 for (size_t i = 0; i < nodes.size(); ++i) { |
| 64 if (last_node && nodes[i].parent_id() == last_node->id()) { | 64 if (last_node && nodes[i]->parent_id == last_node->id()) { |
| 65 parents.push_back(last_node); | 65 parents.push_back(last_node); |
| 66 } else if (!parents.empty()) { | 66 } else if (!parents.empty()) { |
| 67 while (parents.back()->id() != nodes[i].parent_id()) | 67 while (parents.back()->id() != nodes[i]->parent_id) |
| 68 parents.pop_back(); | 68 parents.pop_back(); |
| 69 } | 69 } |
| 70 ViewTreeNode* node = AddNodeToViewManager( | 70 ViewTreeNode* node = AddNodeToViewManager( |
| 71 manager, | 71 manager, |
| 72 !parents.empty() ? parents.back() : NULL, | 72 !parents.empty() ? parents.back() : NULL, |
| 73 nodes[i].node_id(), | 73 nodes[i]->node_id, |
| 74 nodes[i].view_id(), | 74 nodes[i]->view_id, |
| 75 nodes[i].bounds()); | 75 nodes[i]->bounds.To<gfx::Rect>()); |
| 76 if (!last_node) | 76 if (!last_node) |
| 77 root = node; | 77 root = node; |
| 78 last_node = node; | 78 last_node = node; |
| 79 } | 79 } |
| 80 return root; | 80 return root; |
| 81 } | 81 } |
| 82 | 82 |
| 83 class ViewManagerTransaction { | 83 class ViewManagerTransaction { |
| 84 public: | 84 public: |
| 85 virtual ~ViewManagerTransaction() {} | 85 virtual ~ViewManagerTransaction() {} |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 const gfx::Rect& bounds, | 320 const gfx::Rect& bounds, |
| 321 ViewManagerSynchronizer* synchronizer) | 321 ViewManagerSynchronizer* synchronizer) |
| 322 : ViewManagerTransaction(TYPE_SET_BOUNDS, synchronizer), | 322 : ViewManagerTransaction(TYPE_SET_BOUNDS, synchronizer), |
| 323 node_id_(node_id), | 323 node_id_(node_id), |
| 324 bounds_(bounds) {} | 324 bounds_(bounds) {} |
| 325 virtual ~SetBoundsTransaction() {} | 325 virtual ~SetBoundsTransaction() {} |
| 326 | 326 |
| 327 private: | 327 private: |
| 328 // Overridden from ViewManagerTransaction: | 328 // Overridden from ViewManagerTransaction: |
| 329 virtual void DoCommit() OVERRIDE { | 329 virtual void DoCommit() OVERRIDE { |
| 330 AllocationScope scope; | 330 service()->SetNodeBounds( |
| 331 service()->SetNodeBounds(node_id_, bounds_, ActionCompletedCallback()); | 331 node_id_, Rect::From(bounds_), ActionCompletedCallback()); |
| 332 } | 332 } |
| 333 virtual void DoActionCompleted(bool success) OVERRIDE { | 333 virtual void DoActionCompleted(bool success) OVERRIDE { |
| 334 // TODO(beng): recovery? | 334 // TODO(beng): recovery? |
| 335 } | 335 } |
| 336 | 336 |
| 337 const TransportNodeId node_id_; | 337 const TransportNodeId node_id_; |
| 338 const gfx::Rect bounds_; | 338 const gfx::Rect bounds_; |
| 339 | 339 |
| 340 DISALLOW_COPY_AND_ASSIGN(SetBoundsTransaction); | 340 DISALLOW_COPY_AND_ASSIGN(SetBoundsTransaction); |
| 341 }; | 341 }; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 360 ScopedSharedBufferHandle duped; | 360 ScopedSharedBufferHandle duped; |
| 361 bool result = CreateMapAndDupSharedBuffer(data.size(), | 361 bool result = CreateMapAndDupSharedBuffer(data.size(), |
| 362 &memory, | 362 &memory, |
| 363 &shared_state_handle_, | 363 &shared_state_handle_, |
| 364 &duped); | 364 &duped); |
| 365 if (!result) | 365 if (!result) |
| 366 return; | 366 return; |
| 367 | 367 |
| 368 memcpy(memory, &data[0], data.size()); | 368 memcpy(memory, &data[0], data.size()); |
| 369 | 369 |
| 370 AllocationScope scope; | |
| 371 service()->SetViewContents(view_id_, duped.Pass(), | 370 service()->SetViewContents(view_id_, duped.Pass(), |
| 372 static_cast<uint32_t>(data.size()), | 371 static_cast<uint32_t>(data.size()), |
| 373 ActionCompletedCallback()); | 372 ActionCompletedCallback()); |
| 374 } | 373 } |
| 375 virtual void DoActionCompleted(bool success) OVERRIDE { | 374 virtual void DoActionCompleted(bool success) OVERRIDE { |
| 376 // TODO(beng): recovery? | 375 // TODO(beng): recovery? |
| 377 } | 376 } |
| 378 | 377 |
| 379 bool CreateMapAndDupSharedBuffer(size_t size, | 378 bool CreateMapAndDupSharedBuffer(size_t size, |
| 380 void** memory, | 379 void** memory, |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 new SetViewContentsTransaction(view_id, contents, this)); | 516 new SetViewContentsTransaction(view_id, contents, this)); |
| 518 Sync(); | 517 Sync(); |
| 519 } | 518 } |
| 520 | 519 |
| 521 //////////////////////////////////////////////////////////////////////////////// | 520 //////////////////////////////////////////////////////////////////////////////// |
| 522 // ViewManagerSynchronizer, IViewManagerClient implementation: | 521 // ViewManagerSynchronizer, IViewManagerClient implementation: |
| 523 | 522 |
| 524 void ViewManagerSynchronizer::OnViewManagerConnectionEstablished( | 523 void ViewManagerSynchronizer::OnViewManagerConnectionEstablished( |
| 525 TransportConnectionId connection_id, | 524 TransportConnectionId connection_id, |
| 526 TransportChangeId next_server_change_id, | 525 TransportChangeId next_server_change_id, |
| 527 const Array<INode>& nodes) { | 526 mojo::Array<INodePtr> nodes) { |
| 528 connected_ = true; | 527 connected_ = true; |
| 529 connection_id_ = connection_id; | 528 connection_id_ = connection_id; |
| 530 next_server_change_id_ = next_server_change_id; | 529 next_server_change_id_ = next_server_change_id; |
| 531 | 530 |
| 532 ViewManagerPrivate(view_manager_).set_root( | 531 ViewManagerPrivate(view_manager_).set_root( |
| 533 BuildNodeTree(view_manager_, nodes)); | 532 BuildNodeTree(view_manager_, nodes)); |
| 534 if (init_loop_) | 533 if (init_loop_) |
| 535 init_loop_->Quit(); | 534 init_loop_->Quit(); |
| 536 | 535 |
| 537 Sync(); | 536 Sync(); |
| 538 } | 537 } |
| 539 | 538 |
| 540 void ViewManagerSynchronizer::OnServerChangeIdAdvanced( | 539 void ViewManagerSynchronizer::OnServerChangeIdAdvanced( |
| 541 uint32_t next_server_change_id) { | 540 uint32_t next_server_change_id) { |
| 542 next_server_change_id_ = next_server_change_id; | 541 next_server_change_id_ = next_server_change_id; |
| 543 } | 542 } |
| 544 | 543 |
| 545 void ViewManagerSynchronizer::OnNodeBoundsChanged(uint32 node_id, | 544 void ViewManagerSynchronizer::OnNodeBoundsChanged(uint32 node_id, |
| 546 const Rect& old_bounds, | 545 RectPtr old_bounds, |
| 547 const Rect& new_bounds) { | 546 RectPtr new_bounds) { |
| 548 ViewTreeNode* node = view_manager_->GetNodeById(node_id); | 547 ViewTreeNode* node = view_manager_->GetNodeById(node_id); |
| 549 ViewTreeNodePrivate(node).LocalSetBounds(old_bounds, new_bounds); | 548 ViewTreeNodePrivate(node).LocalSetBounds(old_bounds.To<gfx::Rect>(), |
| 549 new_bounds.To<gfx::Rect>()); |
| 550 } | 550 } |
| 551 | 551 |
| 552 void ViewManagerSynchronizer::OnNodeHierarchyChanged( | 552 void ViewManagerSynchronizer::OnNodeHierarchyChanged( |
| 553 uint32_t node_id, | 553 uint32_t node_id, |
| 554 uint32_t new_parent_id, | 554 uint32_t new_parent_id, |
| 555 uint32_t old_parent_id, | 555 uint32_t old_parent_id, |
| 556 TransportChangeId server_change_id, | 556 TransportChangeId server_change_id, |
| 557 const Array<INode>& nodes) { | 557 mojo::Array<INodePtr> nodes) { |
| 558 // TODO: deal with |nodes|. | 558 // TODO: deal with |nodes|. |
| 559 next_server_change_id_ = server_change_id + 1; | 559 next_server_change_id_ = server_change_id + 1; |
| 560 | 560 |
| 561 BuildNodeTree(view_manager_, nodes); | 561 BuildNodeTree(view_manager_, nodes); |
| 562 | 562 |
| 563 ViewTreeNode* new_parent = view_manager_->GetNodeById(new_parent_id); | 563 ViewTreeNode* new_parent = view_manager_->GetNodeById(new_parent_id); |
| 564 ViewTreeNode* old_parent = view_manager_->GetNodeById(old_parent_id); | 564 ViewTreeNode* old_parent = view_manager_->GetNodeById(old_parent_id); |
| 565 ViewTreeNode* node = view_manager_->GetNodeById(node_id); | 565 ViewTreeNode* node = view_manager_->GetNodeById(node_id); |
| 566 if (new_parent) | 566 if (new_parent) |
| 567 ViewTreeNodePrivate(new_parent).LocalAddChild(node); | 567 ViewTreeNodePrivate(new_parent).LocalAddChild(node); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 void ViewManagerSynchronizer::RemoveFromPendingQueue( | 622 void ViewManagerSynchronizer::RemoveFromPendingQueue( |
| 623 ViewManagerTransaction* transaction) { | 623 ViewManagerTransaction* transaction) { |
| 624 DCHECK_EQ(transaction, pending_transactions_.front()); | 624 DCHECK_EQ(transaction, pending_transactions_.front()); |
| 625 pending_transactions_.erase(pending_transactions_.begin()); | 625 pending_transactions_.erase(pending_transactions_.begin()); |
| 626 if (pending_transactions_.empty() && !changes_acked_callback_.is_null()) | 626 if (pending_transactions_.empty() && !changes_acked_callback_.is_null()) |
| 627 changes_acked_callback_.Run(); | 627 changes_acked_callback_.Run(); |
| 628 } | 628 } |
| 629 | 629 |
| 630 } // namespace view_manager | 630 } // namespace view_manager |
| 631 } // namespace mojo | 631 } // namespace mojo |
| OLD | NEW |