| 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/view_manager/view_manager_connection.h" | 5 #include "mojo/services/view_manager/view_manager_connection.h" |
| 6 | 6 |
| 7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
| 8 #include "mojo/geometry/geometry_type_converters.h" | 8 #include "mojo/geometry/geometry_type_converters.h" |
| 9 #include "mojo/public/cpp/bindings/allocation_scope.h" | |
| 10 #include "mojo/services/view_manager/node.h" | 9 #include "mojo/services/view_manager/node.h" |
| 11 #include "mojo/services/view_manager/root_node_manager.h" | 10 #include "mojo/services/view_manager/root_node_manager.h" |
| 12 #include "mojo/services/view_manager/view.h" | 11 #include "mojo/services/view_manager/view.h" |
| 13 #include "third_party/skia/include/core/SkBitmap.h" | 12 #include "third_party/skia/include/core/SkBitmap.h" |
| 14 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
| 15 #include "ui/gfx/codec/png_codec.h" | 14 #include "ui/gfx/codec/png_codec.h" |
| 16 | 15 |
| 17 namespace mojo { | 16 namespace mojo { |
| 18 namespace view_manager { | 17 namespace view_manager { |
| 19 namespace service { | 18 namespace service { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 88 |
| 90 void ViewManagerConnection::ProcessNodeBoundsChanged( | 89 void ViewManagerConnection::ProcessNodeBoundsChanged( |
| 91 const Node* node, | 90 const Node* node, |
| 92 const gfx::Rect& old_bounds, | 91 const gfx::Rect& old_bounds, |
| 93 const gfx::Rect& new_bounds, | 92 const gfx::Rect& new_bounds, |
| 94 bool originated_change) { | 93 bool originated_change) { |
| 95 if (originated_change) | 94 if (originated_change) |
| 96 return; | 95 return; |
| 97 TransportNodeId node_id = NodeIdToTransportId(node->id()); | 96 TransportNodeId node_id = NodeIdToTransportId(node->id()); |
| 98 if (known_nodes_.count(node_id) > 0) { | 97 if (known_nodes_.count(node_id) > 0) { |
| 99 AllocationScope scope; | 98 client()->OnNodeBoundsChanged(node_id, |
| 100 client()->OnNodeBoundsChanged(node_id, old_bounds, new_bounds); | 99 Rect::From(old_bounds), |
| 100 Rect::From(new_bounds)); |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 | 103 |
| 104 void ViewManagerConnection::ProcessNodeHierarchyChanged( | 104 void ViewManagerConnection::ProcessNodeHierarchyChanged( |
| 105 const Node* node, | 105 const Node* node, |
| 106 const Node* new_parent, | 106 const Node* new_parent, |
| 107 const Node* old_parent, | 107 const Node* old_parent, |
| 108 TransportChangeId server_change_id, | 108 TransportChangeId server_change_id, |
| 109 bool originated_change) { | 109 bool originated_change) { |
| 110 if (known_nodes_.count(NodeIdToTransportId(node->id())) > 0) { | 110 if (known_nodes_.count(NodeIdToTransportId(node->id())) > 0) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 124 return; | 124 return; |
| 125 std::vector<const Node*> to_send; | 125 std::vector<const Node*> to_send; |
| 126 if (!ShouldNotifyOnHierarchyChange(node, &new_parent, &old_parent, | 126 if (!ShouldNotifyOnHierarchyChange(node, &new_parent, &old_parent, |
| 127 &to_send)) { | 127 &to_send)) { |
| 128 if (root_node_manager_->IsProcessingChange()) { | 128 if (root_node_manager_->IsProcessingChange()) { |
| 129 client()->OnServerChangeIdAdvanced( | 129 client()->OnServerChangeIdAdvanced( |
| 130 root_node_manager_->next_server_change_id() + 1); | 130 root_node_manager_->next_server_change_id() + 1); |
| 131 } | 131 } |
| 132 return; | 132 return; |
| 133 } | 133 } |
| 134 AllocationScope allocation_scope; | |
| 135 const NodeId new_parent_id(new_parent ? new_parent->id() : NodeId()); | 134 const NodeId new_parent_id(new_parent ? new_parent->id() : NodeId()); |
| 136 const NodeId old_parent_id(old_parent ? old_parent->id() : NodeId()); | 135 const NodeId old_parent_id(old_parent ? old_parent->id() : NodeId()); |
| 137 DCHECK((node->id().connection_id == id_) || | 136 DCHECK((node->id().connection_id == id_) || |
| 138 (roots_.count(NodeIdToTransportId(node->id())) > 0) || | 137 (roots_.count(NodeIdToTransportId(node->id())) > 0) || |
| 139 (new_parent && IsNodeDescendantOfRoots(new_parent)) || | 138 (new_parent && IsNodeDescendantOfRoots(new_parent)) || |
| 140 (old_parent && IsNodeDescendantOfRoots(old_parent))); | 139 (old_parent && IsNodeDescendantOfRoots(old_parent))); |
| 141 client()->OnNodeHierarchyChanged(NodeIdToTransportId(node->id()), | 140 client()->OnNodeHierarchyChanged(NodeIdToTransportId(node->id()), |
| 142 NodeIdToTransportId(new_parent_id), | 141 NodeIdToTransportId(new_parent_id), |
| 143 NodeIdToTransportId(old_parent_id), | 142 NodeIdToTransportId(old_parent_id), |
| 144 server_change_id, | 143 server_change_id, |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 roots.insert(transport_node_ids[i]); | 402 roots.insert(transport_node_ids[i]); |
| 404 } | 403 } |
| 405 roots_.swap(roots); | 404 roots_.swap(roots); |
| 406 | 405 |
| 407 // TODO(sky): remove |known_nodes_.clear()| temporary while this is done here | 406 // TODO(sky): remove |known_nodes_.clear()| temporary while this is done here |
| 408 // instead of at creation time. | 407 // instead of at creation time. |
| 409 known_nodes_.clear(); | 408 known_nodes_.clear(); |
| 410 std::vector<const Node*> to_send; | 409 std::vector<const Node*> to_send; |
| 411 for (NodeIdSet::const_iterator i = roots_.begin(); i != roots_.end(); ++i) | 410 for (NodeIdSet::const_iterator i = roots_.begin(); i != roots_.end(); ++i) |
| 412 GetUnknownNodesFrom(GetNode(NodeIdFromTransportId(*i)), &to_send); | 411 GetUnknownNodesFrom(GetNode(NodeIdFromTransportId(*i)), &to_send); |
| 413 AllocationScope allocation_scope; | |
| 414 client()->OnViewManagerConnectionEstablished( | 412 client()->OnViewManagerConnectionEstablished( |
| 415 id_, | 413 id_, |
| 416 root_node_manager_->next_server_change_id(), | 414 root_node_manager_->next_server_change_id(), |
| 417 NodesToINodes(to_send)); | 415 NodesToINodes(to_send)); |
| 418 | 416 |
| 419 return true; | 417 return true; |
| 420 } | 418 } |
| 421 | 419 |
| 422 Array<INode> ViewManagerConnection::NodesToINodes( | 420 Array<INodePtr> ViewManagerConnection::NodesToINodes( |
| 423 const std::vector<const Node*>& nodes) { | 421 const std::vector<const Node*>& nodes) { |
| 424 Array<INode>::Builder array_builder(nodes.size()); | 422 Array<INodePtr> array(nodes.size()); |
| 425 for (size_t i = 0; i < nodes.size(); ++i) { | 423 for (size_t i = 0; i < nodes.size(); ++i) { |
| 426 INode::Builder node_builder; | |
| 427 const Node* node = nodes[i]; | 424 const Node* node = nodes[i]; |
| 428 DCHECK(known_nodes_.count(NodeIdToTransportId(node->id())) > 0); | 425 DCHECK(known_nodes_.count(NodeIdToTransportId(node->id())) > 0); |
| 429 const Node* parent = node->GetParent(); | 426 const Node* parent = node->GetParent(); |
| 430 // If the parent isn't known, it means the parent is not visible to us (not | 427 // If the parent isn't known, it means the parent is not visible to us (not |
| 431 // in roots), and should not be sent over. | 428 // in roots), and should not be sent over. |
| 432 if (parent && known_nodes_.count(NodeIdToTransportId(parent->id())) == 0) | 429 if (parent && known_nodes_.count(NodeIdToTransportId(parent->id())) == 0) |
| 433 parent = NULL; | 430 parent = NULL; |
| 434 node_builder.set_parent_id(NodeIdToTransportId( | 431 INodePtr inode(INode::New()); |
| 435 parent ? parent->id() : NodeId())); | 432 inode->parent_id = NodeIdToTransportId(parent ? parent->id() : NodeId()); |
| 436 node_builder.set_node_id(NodeIdToTransportId(node->id())); | 433 inode->node_id = NodeIdToTransportId(node->id()); |
| 437 node_builder.set_view_id(ViewIdToTransportId( | 434 inode->view_id = ViewIdToTransportId( |
| 438 node->view() ? node->view()->id() : ViewId())); | 435 node->view() ? node->view()->id() : ViewId()); |
| 439 array_builder[i] = node_builder.Finish(); | 436 array[i] = inode.Pass(); |
| 440 } | 437 } |
| 441 return array_builder.Finish(); | 438 return array.Pass(); |
| 442 } | 439 } |
| 443 | 440 |
| 444 void ViewManagerConnection::CreateNode( | 441 void ViewManagerConnection::CreateNode( |
| 445 TransportNodeId transport_node_id, | 442 TransportNodeId transport_node_id, |
| 446 const Callback<void(bool)>& callback) { | 443 const Callback<void(bool)>& callback) { |
| 447 const NodeId node_id(NodeIdFromTransportId(transport_node_id)); | 444 const NodeId node_id(NodeIdFromTransportId(transport_node_id)); |
| 448 if (node_id.connection_id != id_ || | 445 if (node_id.connection_id != id_ || |
| 449 node_map_.find(node_id.node_id) != node_map_.end()) { | 446 node_map_.find(node_id.node_id) != node_map_.end()) { |
| 450 callback.Run(false); | 447 callback.Run(false); |
| 451 return; | 448 return; |
| 452 } | 449 } |
| 453 node_map_[node_id.node_id] = new Node(this, node_id); | 450 node_map_[node_id.node_id] = new Node(this, node_id); |
| 454 known_nodes_.insert(transport_node_id); | 451 known_nodes_.insert(transport_node_id); |
| 455 callback.Run(true); | 452 callback.Run(true); |
| 456 } | 453 } |
| 457 | 454 |
| 458 void ViewManagerConnection::DeleteNode( | 455 void ViewManagerConnection::DeleteNode( |
| 459 TransportNodeId transport_node_id, | 456 TransportNodeId transport_node_id, |
| 460 const Callback<void(bool)>& callback) { | 457 const Callback<void(bool)>& callback) { |
| 461 AllocationScope allocation_scope; | |
| 462 const NodeId node_id(NodeIdFromTransportId(transport_node_id)); | 458 const NodeId node_id(NodeIdFromTransportId(transport_node_id)); |
| 463 bool did_delete = CanDeleteNode(node_id); | 459 bool did_delete = CanDeleteNode(node_id); |
| 464 if (did_delete) { | 460 if (did_delete) { |
| 465 ViewManagerConnection* connection = root_node_manager_->GetConnection( | 461 ViewManagerConnection* connection = root_node_manager_->GetConnection( |
| 466 node_id.connection_id); | 462 node_id.connection_id); |
| 467 did_delete = connection && connection->DeleteNodeImpl(this, node_id); | 463 did_delete = connection && connection->DeleteNodeImpl(this, node_id); |
| 468 } | 464 } |
| 469 callback.Run(did_delete); | 465 callback.Run(did_delete); |
| 470 } | 466 } |
| 471 | 467 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 502 this, root_node_manager_, | 498 this, root_node_manager_, |
| 503 RootNodeManager::CHANGE_TYPE_ADVANCE_SERVER_CHANGE_ID, false); | 499 RootNodeManager::CHANGE_TYPE_ADVANCE_SERVER_CHANGE_ID, false); |
| 504 node->GetParent()->Remove(node); | 500 node->GetParent()->Remove(node); |
| 505 } | 501 } |
| 506 } | 502 } |
| 507 callback.Run(success); | 503 callback.Run(success); |
| 508 } | 504 } |
| 509 | 505 |
| 510 void ViewManagerConnection::GetNodeTree( | 506 void ViewManagerConnection::GetNodeTree( |
| 511 TransportNodeId node_id, | 507 TransportNodeId node_id, |
| 512 const Callback<void(Array<INode>)>& callback) { | 508 const Callback<void(Array<INodePtr>)>& callback) { |
| 513 AllocationScope allocation_scope; | |
| 514 Node* node = GetNode(NodeIdFromTransportId(node_id)); | 509 Node* node = GetNode(NodeIdFromTransportId(node_id)); |
| 515 std::vector<const Node*> nodes; | 510 std::vector<const Node*> nodes; |
| 516 if (CanGetNodeTree(node)) { | 511 if (CanGetNodeTree(node)) { |
| 517 GetDescendants(node, &nodes); | 512 GetDescendants(node, &nodes); |
| 518 for (size_t i = 0; i < nodes.size(); ++i) | 513 for (size_t i = 0; i < nodes.size(); ++i) |
| 519 known_nodes_.insert(NodeIdToTransportId(nodes[i]->id())); | 514 known_nodes_.insert(NodeIdToTransportId(nodes[i]->id())); |
| 520 } | 515 } |
| 521 callback.Run(NodesToINodes(nodes)); | 516 callback.Run(NodesToINodes(nodes)); |
| 522 } | 517 } |
| 523 | 518 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 SkBitmap bitmap; | 569 SkBitmap bitmap; |
| 575 gfx::PNGCodec::Decode(static_cast<const unsigned char*>(handle_data), | 570 gfx::PNGCodec::Decode(static_cast<const unsigned char*>(handle_data), |
| 576 buffer_size, &bitmap); | 571 buffer_size, &bitmap); |
| 577 view->SetBitmap(bitmap); | 572 view->SetBitmap(bitmap); |
| 578 UnmapBuffer(handle_data); | 573 UnmapBuffer(handle_data); |
| 579 callback.Run(true); | 574 callback.Run(true); |
| 580 } | 575 } |
| 581 | 576 |
| 582 void ViewManagerConnection::SetRoots( | 577 void ViewManagerConnection::SetRoots( |
| 583 TransportConnectionId connection_id, | 578 TransportConnectionId connection_id, |
| 584 const Array<TransportNodeId>& transport_node_ids, | 579 Array<TransportNodeId> transport_node_ids, |
| 585 const Callback<void(bool)>& callback) { | 580 const Callback<void(bool)>& callback) { |
| 586 ViewManagerConnection* connection = | 581 ViewManagerConnection* connection = |
| 587 root_node_manager_->GetConnection(connection_id); | 582 root_node_manager_->GetConnection(connection_id); |
| 588 callback.Run(connection && | 583 callback.Run(connection && |
| 589 connection->ProcessSetRoots(id_, transport_node_ids)); | 584 connection->ProcessSetRoots(id_, transport_node_ids)); |
| 590 } | 585 } |
| 591 | 586 |
| 592 void ViewManagerConnection::SetNodeBounds( | 587 void ViewManagerConnection::SetNodeBounds( |
| 593 TransportNodeId node_id, | 588 TransportNodeId node_id, |
| 594 const Rect& bounds, | 589 RectPtr bounds, |
| 595 const Callback<void(bool)>& callback) { | 590 const Callback<void(bool)>& callback) { |
| 596 if (NodeIdFromTransportId(node_id).connection_id != id_) { | 591 if (NodeIdFromTransportId(node_id).connection_id != id_) { |
| 597 callback.Run(false); | 592 callback.Run(false); |
| 598 return; | 593 return; |
| 599 } | 594 } |
| 600 | 595 |
| 601 Node* node = GetNode(NodeIdFromTransportId(node_id)); | 596 Node* node = GetNode(NodeIdFromTransportId(node_id)); |
| 602 if (!node) { | 597 if (!node) { |
| 603 callback.Run(false); | 598 callback.Run(false); |
| 604 return; | 599 return; |
| 605 } | 600 } |
| 606 | 601 |
| 607 RootNodeManager::ScopedChange change( | 602 RootNodeManager::ScopedChange change( |
| 608 this, root_node_manager_, | 603 this, root_node_manager_, |
| 609 RootNodeManager::CHANGE_TYPE_DONT_ADVANCE_SERVER_CHANGE_ID, false); | 604 RootNodeManager::CHANGE_TYPE_DONT_ADVANCE_SERVER_CHANGE_ID, false); |
| 610 gfx::Rect old_bounds = node->window()->bounds(); | 605 gfx::Rect old_bounds = node->window()->bounds(); |
| 611 node->window()->SetBounds(bounds); | 606 node->window()->SetBounds(bounds.To<gfx::Rect>()); |
| 612 root_node_manager_->ProcessNodeBoundsChanged(node, old_bounds, bounds); | 607 root_node_manager_->ProcessNodeBoundsChanged( |
| 608 node, old_bounds, bounds.To<gfx::Rect>()); |
| 613 callback.Run(true); | 609 callback.Run(true); |
| 614 } | 610 } |
| 615 | 611 |
| 616 void ViewManagerConnection::OnNodeHierarchyChanged(const Node* node, | 612 void ViewManagerConnection::OnNodeHierarchyChanged(const Node* node, |
| 617 const Node* new_parent, | 613 const Node* new_parent, |
| 618 const Node* old_parent) { | 614 const Node* old_parent) { |
| 619 root_node_manager_->ProcessNodeHierarchyChanged(node, new_parent, old_parent); | 615 root_node_manager_->ProcessNodeHierarchyChanged(node, new_parent, old_parent); |
| 620 } | 616 } |
| 621 | 617 |
| 622 void ViewManagerConnection::OnNodeViewReplaced(const Node* node, | 618 void ViewManagerConnection::OnNodeViewReplaced(const Node* node, |
| 623 const View* new_view, | 619 const View* new_view, |
| 624 const View* old_view) { | 620 const View* old_view) { |
| 625 root_node_manager_->ProcessNodeViewReplaced(node, new_view, old_view); | 621 root_node_manager_->ProcessNodeViewReplaced(node, new_view, old_view); |
| 626 } | 622 } |
| 627 | 623 |
| 628 void ViewManagerConnection::OnConnectionEstablished() { | 624 void ViewManagerConnection::OnConnectionEstablished() { |
| 629 DCHECK_EQ(0, id_); // Should only get OnConnectionEstablished() once. | 625 DCHECK_EQ(0, id_); // Should only get OnConnectionEstablished() once. |
| 630 id_ = root_node_manager_->GetAndAdvanceNextConnectionId(); | 626 id_ = root_node_manager_->GetAndAdvanceNextConnectionId(); |
| 631 root_node_manager_->AddConnection(this); | 627 root_node_manager_->AddConnection(this); |
| 632 std::vector<const Node*> to_send; | 628 std::vector<const Node*> to_send; |
| 633 GetUnknownNodesFrom(root_node_manager_->root(), &to_send); | 629 GetUnknownNodesFrom(root_node_manager_->root(), &to_send); |
| 634 AllocationScope allocation_scope; | |
| 635 client()->OnViewManagerConnectionEstablished( | 630 client()->OnViewManagerConnectionEstablished( |
| 636 id_, | 631 id_, |
| 637 root_node_manager_->next_server_change_id(), | 632 root_node_manager_->next_server_change_id(), |
| 638 NodesToINodes(to_send)); | 633 NodesToINodes(to_send)); |
| 639 } | 634 } |
| 640 | 635 |
| 641 } // namespace service | 636 } // namespace service |
| 642 } // namespace view_manager | 637 } // namespace view_manager |
| 643 } // namespace mojo | 638 } // namespace mojo |
| OLD | NEW |