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/public/cpp/bindings/allocation_scope.h" | 9 #include "mojo/public/cpp/bindings/allocation_scope.h" |
9 #include "mojo/services/view_manager/node.h" | 10 #include "mojo/services/view_manager/node.h" |
10 #include "mojo/services/view_manager/root_node_manager.h" | 11 #include "mojo/services/view_manager/root_node_manager.h" |
11 #include "mojo/services/view_manager/view.h" | 12 #include "mojo/services/view_manager/view.h" |
12 #include "third_party/skia/include/core/SkBitmap.h" | 13 #include "third_party/skia/include/core/SkBitmap.h" |
13 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
14 #include "ui/gfx/codec/png_codec.h" | 15 #include "ui/gfx/codec/png_codec.h" |
15 | 16 |
16 namespace mojo { | 17 namespace mojo { |
17 namespace view_manager { | 18 namespace view_manager { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 } | 93 } |
93 | 94 |
94 const View* ViewManagerConnection::GetView(const ViewId& id) const { | 95 const View* ViewManagerConnection::GetView(const ViewId& id) const { |
95 if (id_ == id.connection_id) { | 96 if (id_ == id.connection_id) { |
96 ViewMap::const_iterator i = view_map_.find(id.view_id); | 97 ViewMap::const_iterator i = view_map_.find(id.view_id); |
97 return i == view_map_.end() ? NULL : i->second; | 98 return i == view_map_.end() ? NULL : i->second; |
98 } | 99 } |
99 return root_node_manager_->GetView(id); | 100 return root_node_manager_->GetView(id); |
100 } | 101 } |
101 | 102 |
| 103 void ViewManagerConnection::ProcessNodeBoundsChanged( |
| 104 const Node* node, |
| 105 const gfx::Rect& old_bounds, |
| 106 const gfx::Rect& new_bounds, |
| 107 bool originated_change) { |
| 108 if (originated_change) |
| 109 return; |
| 110 TransportNodeId node_id = NodeIdToTransportId(node->id()); |
| 111 if (known_nodes_.count(node_id) > 0) { |
| 112 AllocationScope scope; |
| 113 client()->OnNodeBoundsChanged(node_id, old_bounds, new_bounds); |
| 114 } |
| 115 } |
| 116 |
102 void ViewManagerConnection::ProcessNodeHierarchyChanged( | 117 void ViewManagerConnection::ProcessNodeHierarchyChanged( |
103 const Node* node, | 118 const Node* node, |
104 const Node* new_parent, | 119 const Node* new_parent, |
105 const Node* old_parent, | 120 const Node* old_parent, |
106 TransportChangeId server_change_id, | 121 TransportChangeId server_change_id, |
107 bool originated_change) { | 122 bool originated_change) { |
108 if (known_nodes_.count(NodeIdToTransportId(node->id())) > 0) { | 123 if (known_nodes_.count(NodeIdToTransportId(node->id())) > 0) { |
109 if (originated_change) | 124 if (originated_change) |
110 return; | 125 return; |
111 if (node->id().connection_id != id_ && !IsNodeDescendantOfRoots(node)) { | 126 if (node->id().connection_id != id_ && !IsNodeDescendantOfRoots(node)) { |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 void ViewManagerConnection::SetRoots( | 590 void ViewManagerConnection::SetRoots( |
576 TransportConnectionId connection_id, | 591 TransportConnectionId connection_id, |
577 const Array<TransportNodeId>& transport_node_ids, | 592 const Array<TransportNodeId>& transport_node_ids, |
578 const Callback<void(bool)>& callback) { | 593 const Callback<void(bool)>& callback) { |
579 ViewManagerConnection* connection = | 594 ViewManagerConnection* connection = |
580 root_node_manager_->GetConnection(connection_id); | 595 root_node_manager_->GetConnection(connection_id); |
581 callback.Run(connection && | 596 callback.Run(connection && |
582 connection->ProcessSetRoots(id_, transport_node_ids)); | 597 connection->ProcessSetRoots(id_, transport_node_ids)); |
583 } | 598 } |
584 | 599 |
| 600 void ViewManagerConnection::SetNodeBounds( |
| 601 TransportNodeId node_id, |
| 602 const Rect& bounds, |
| 603 const Callback<void(bool)>& callback) { |
| 604 if (NodeIdFromTransportId(node_id).connection_id != id_) { |
| 605 callback.Run(false); |
| 606 return; |
| 607 } |
| 608 |
| 609 Node* node = GetNode(NodeIdFromTransportId(node_id)); |
| 610 if (!node) { |
| 611 callback.Run(false); |
| 612 return; |
| 613 } |
| 614 |
| 615 RootNodeManager::ScopedChange change( |
| 616 this, root_node_manager_, |
| 617 RootNodeManager::CHANGE_TYPE_DONT_ADVANCE_SERVER_CHANGE_ID, false); |
| 618 gfx::Rect old_bounds = node->window()->bounds(); |
| 619 node->window()->SetBounds(bounds); |
| 620 root_node_manager_->ProcessNodeBoundsChanged(node, old_bounds, bounds); |
| 621 callback.Run(true); |
| 622 } |
| 623 |
585 void ViewManagerConnection::OnNodeHierarchyChanged(const Node* node, | 624 void ViewManagerConnection::OnNodeHierarchyChanged(const Node* node, |
586 const Node* new_parent, | 625 const Node* new_parent, |
587 const Node* old_parent) { | 626 const Node* old_parent) { |
588 root_node_manager_->ProcessNodeHierarchyChanged(node, new_parent, old_parent); | 627 root_node_manager_->ProcessNodeHierarchyChanged(node, new_parent, old_parent); |
589 } | 628 } |
590 | 629 |
591 void ViewManagerConnection::OnNodeViewReplaced(const Node* node, | 630 void ViewManagerConnection::OnNodeViewReplaced(const Node* node, |
592 const View* new_view, | 631 const View* new_view, |
593 const View* old_view) { | 632 const View* old_view) { |
594 root_node_manager_->ProcessNodeViewReplaced(node, new_view, old_view); | 633 root_node_manager_->ProcessNodeViewReplaced(node, new_view, old_view); |
595 } | 634 } |
596 | 635 |
597 } // namespace service | 636 } // namespace service |
598 } // namespace view_manager | 637 } // namespace view_manager |
599 } // namespace mojo | 638 } // namespace mojo |
OLD | NEW |