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/root_node_manager.h" | 5 #include "mojo/services/view_manager/root_node_manager.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "mojo/services/view_manager/view_manager_connection.h" | 8 #include "mojo/services/view_manager/view_manager_connection.h" |
9 | 9 |
10 namespace mojo { | 10 namespace mojo { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 | 44 |
45 void RootNodeManager::AddConnection(ViewManagerConnection* connection) { | 45 void RootNodeManager::AddConnection(ViewManagerConnection* connection) { |
46 DCHECK_EQ(0u, connection_map_.count(connection->id())); | 46 DCHECK_EQ(0u, connection_map_.count(connection->id())); |
47 connection_map_[connection->id()] = connection; | 47 connection_map_[connection->id()] = connection; |
48 } | 48 } |
49 | 49 |
50 void RootNodeManager::RemoveConnection(ViewManagerConnection* connection) { | 50 void RootNodeManager::RemoveConnection(ViewManagerConnection* connection) { |
51 connection_map_.erase(connection->id()); | 51 connection_map_.erase(connection->id()); |
52 } | 52 } |
53 | 53 |
| 54 ViewManagerConnection* RootNodeManager::GetConnection(uint16_t connection_id) { |
| 55 ConnectionMap::iterator i = connection_map_.find(connection_id); |
| 56 return i == connection_map_.end() ? NULL : i->second; |
| 57 } |
| 58 |
54 Node* RootNodeManager::GetNode(const NodeId& id) { | 59 Node* RootNodeManager::GetNode(const NodeId& id) { |
55 if (id == root_.id()) | 60 if (id == root_.id()) |
56 return &root_; | 61 return &root_; |
57 ConnectionMap::iterator i = connection_map_.find(id.connection_id); | 62 ConnectionMap::iterator i = connection_map_.find(id.connection_id); |
58 return i == connection_map_.end() ? NULL : i->second->GetNode(id); | 63 return i == connection_map_.end() ? NULL : i->second->GetNode(id); |
59 } | 64 } |
60 | 65 |
| 66 View* RootNodeManager::GetView(const ViewId& id) { |
| 67 ConnectionMap::iterator i = connection_map_.find(id.connection_id); |
| 68 return i == connection_map_.end() ? NULL : i->second->GetView(id); |
| 69 } |
| 70 |
61 void RootNodeManager::NotifyNodeHierarchyChanged(const NodeId& node, | 71 void RootNodeManager::NotifyNodeHierarchyChanged(const NodeId& node, |
62 const NodeId& new_parent, | 72 const NodeId& new_parent, |
63 const NodeId& old_parent) { | 73 const NodeId& old_parent) { |
64 for (ConnectionMap::iterator i = connection_map_.begin(); | 74 for (ConnectionMap::iterator i = connection_map_.begin(); |
65 i != connection_map_.end(); ++i) { | 75 i != connection_map_.end(); ++i) { |
66 const int32_t change_id = (change_ && i->first == change_->connection_id) ? | 76 const int32_t change_id = (change_ && i->first == change_->connection_id) ? |
67 change_->change_id : 0; | 77 change_->change_id : 0; |
68 i->second->NotifyNodeHierarchyChanged( | 78 i->second->NotifyNodeHierarchyChanged( |
69 node, new_parent, old_parent, change_id); | 79 node, new_parent, old_parent, change_id); |
70 } | 80 } |
71 } | 81 } |
72 | 82 |
| 83 void RootNodeManager::NotifyNodeViewReplaced(const NodeId& node, |
| 84 const ViewId& new_view_id, |
| 85 const ViewId& old_view_id) { |
| 86 // TODO(sky): make a macro for this. |
| 87 for (ConnectionMap::iterator i = connection_map_.begin(); |
| 88 i != connection_map_.end(); ++i) { |
| 89 const int32_t change_id = (change_ && i->first == change_->connection_id) ? |
| 90 change_->change_id : 0; |
| 91 i->second->NotifyNodeViewReplaced(node, new_view_id, old_view_id, |
| 92 change_id); |
| 93 } |
| 94 } |
| 95 |
73 void RootNodeManager::PrepareForChange(ViewManagerConnection* connection, | 96 void RootNodeManager::PrepareForChange(ViewManagerConnection* connection, |
74 int32_t change_id) { | 97 int32_t change_id) { |
75 DCHECK(!change_.get()); // Should only ever have one change in flight. | 98 DCHECK(!change_.get()); // Should only ever have one change in flight. |
76 change_.reset(new Change(connection->id(), change_id)); | 99 change_.reset(new Change(connection->id(), change_id)); |
77 } | 100 } |
78 | 101 |
79 void RootNodeManager::FinishChange() { | 102 void RootNodeManager::FinishChange() { |
80 DCHECK(change_.get()); // PrepareForChange/FinishChange should be balanced. | 103 DCHECK(change_.get()); // PrepareForChange/FinishChange should be balanced. |
81 change_.reset(); | 104 change_.reset(); |
82 } | 105 } |
(...skipping 11 matching lines...) Expand all Loading... |
94 const mojo::Callback<void()>& callback) { | 117 const mojo::Callback<void()>& callback) { |
95 callback.Run(); | 118 callback.Run(); |
96 } | 119 } |
97 | 120 |
98 void RootNodeManager::OnNodeHierarchyChanged(const NodeId& node, | 121 void RootNodeManager::OnNodeHierarchyChanged(const NodeId& node, |
99 const NodeId& new_parent, | 122 const NodeId& new_parent, |
100 const NodeId& old_parent) { | 123 const NodeId& old_parent) { |
101 NotifyNodeHierarchyChanged(node, new_parent, old_parent); | 124 NotifyNodeHierarchyChanged(node, new_parent, old_parent); |
102 } | 125 } |
103 | 126 |
| 127 void RootNodeManager::OnNodeViewReplaced(const NodeId& node, |
| 128 const ViewId& new_view_id, |
| 129 const ViewId& old_view_id) { |
| 130 NotifyNodeViewReplaced(node, new_view_id, old_view_id); |
| 131 } |
| 132 |
104 } // namespace view_manager | 133 } // namespace view_manager |
105 } // namespace services | 134 } // namespace services |
106 } // namespace mojo | 135 } // namespace mojo |
OLD | NEW |