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/public/cpp/application/application_connection.h" | 8 #include "mojo/public/cpp/application/application_connection.h" |
9 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" | 9 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" |
10 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" | 10 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 RootNodeManager::Context::~Context() { | 41 RootNodeManager::Context::~Context() { |
42 aura::Env::DeleteInstance(); | 42 aura::Env::DeleteInstance(); |
43 } | 43 } |
44 | 44 |
45 RootNodeManager::RootNodeManager(ApplicationConnection* app_connection, | 45 RootNodeManager::RootNodeManager(ApplicationConnection* app_connection, |
46 RootViewManagerDelegate* view_manager_delegate) | 46 RootViewManagerDelegate* view_manager_delegate) |
47 : app_connection_(app_connection), | 47 : app_connection_(app_connection), |
48 next_connection_id_(1), | 48 next_connection_id_(1), |
49 next_server_change_id_(1), | 49 next_server_change_id_(1), |
50 root_view_manager_(app_connection, this, view_manager_delegate), | 50 root_view_manager_(app_connection, this, view_manager_delegate), |
51 root_(this, RootNodeId()), | 51 root_(new Node(this, RootNodeId())), |
52 current_change_(NULL) { | 52 current_change_(NULL) { |
53 } | 53 } |
54 | 54 |
55 RootNodeManager::~RootNodeManager() { | 55 RootNodeManager::~RootNodeManager() { |
56 aura::client::FocusClient* focus_client = | 56 aura::client::FocusClient* focus_client = |
57 aura::client::GetFocusClient(root_.window()); | 57 aura::client::GetFocusClient(root_->window()); |
58 focus_client->RemoveObserver(this); | 58 focus_client->RemoveObserver(this); |
59 while (!connections_created_by_connect_.empty()) | 59 while (!connections_created_by_connect_.empty()) |
60 delete *(connections_created_by_connect_.begin()); | 60 delete *(connections_created_by_connect_.begin()); |
61 // All the connections should have been destroyed. | 61 // All the connections should have been destroyed. |
62 DCHECK(connection_map_.empty()); | 62 DCHECK(connection_map_.empty()); |
| 63 root_.reset(); |
63 } | 64 } |
64 | 65 |
65 ConnectionSpecificId RootNodeManager::GetAndAdvanceNextConnectionId() { | 66 ConnectionSpecificId RootNodeManager::GetAndAdvanceNextConnectionId() { |
66 const ConnectionSpecificId id = next_connection_id_++; | 67 const ConnectionSpecificId id = next_connection_id_++; |
67 DCHECK_LT(id, next_connection_id_); | 68 DCHECK_LT(id, next_connection_id_); |
68 return id; | 69 return id; |
69 } | 70 } |
70 | 71 |
71 void RootNodeManager::AddConnection(ViewManagerServiceImpl* connection) { | 72 void RootNodeManager::AddConnection(ViewManagerServiceImpl* connection) { |
72 DCHECK_EQ(0u, connection_map_.count(connection->id())); | 73 DCHECK_EQ(0u, connection_map_.count(connection->id())); |
(...skipping 24 matching lines...) Expand all Loading... |
97 EmbedImpl(creator_id, url, node_ids)->set_delete_on_connection_error(); | 98 EmbedImpl(creator_id, url, node_ids)->set_delete_on_connection_error(); |
98 } | 99 } |
99 | 100 |
100 ViewManagerServiceImpl* RootNodeManager::GetConnection( | 101 ViewManagerServiceImpl* RootNodeManager::GetConnection( |
101 ConnectionSpecificId connection_id) { | 102 ConnectionSpecificId connection_id) { |
102 ConnectionMap::iterator i = connection_map_.find(connection_id); | 103 ConnectionMap::iterator i = connection_map_.find(connection_id); |
103 return i == connection_map_.end() ? NULL : i->second; | 104 return i == connection_map_.end() ? NULL : i->second; |
104 } | 105 } |
105 | 106 |
106 Node* RootNodeManager::GetNode(const NodeId& id) { | 107 Node* RootNodeManager::GetNode(const NodeId& id) { |
107 if (id == root_.id()) | 108 if (id == root_->id()) |
108 return &root_; | 109 return root_.get(); |
109 ConnectionMap::iterator i = connection_map_.find(id.connection_id); | 110 ConnectionMap::iterator i = connection_map_.find(id.connection_id); |
110 return i == connection_map_.end() ? NULL : i->second->GetNode(id); | 111 return i == connection_map_.end() ? NULL : i->second->GetNode(id); |
111 } | 112 } |
112 | 113 |
113 View* RootNodeManager::GetView(const ViewId& id) { | 114 View* RootNodeManager::GetView(const ViewId& id) { |
114 ConnectionMap::iterator i = connection_map_.find(id.connection_id); | 115 ConnectionMap::iterator i = connection_map_.find(id.connection_id); |
115 return i == connection_map_.end() ? NULL : i->second->GetView(id); | 116 return i == connection_map_.end() ? NULL : i->second->GetView(id); |
116 } | 117 } |
117 | 118 |
118 void RootNodeManager::OnConnectionMessagedClient(ConnectionSpecificId id) { | 119 void RootNodeManager::OnConnectionMessagedClient(ConnectionSpecificId id) { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 i != connection_map_.end(); ++i) { | 189 i != connection_map_.end(); ++i) { |
189 i->second->ProcessNodeViewReplaced(node, new_view, old_view, | 190 i->second->ProcessNodeViewReplaced(node, new_view, old_view, |
190 IsChangeSource(i->first)); | 191 IsChangeSource(i->first)); |
191 } | 192 } |
192 } | 193 } |
193 | 194 |
194 void RootNodeManager::ProcessNodeDeleted(const NodeId& node) { | 195 void RootNodeManager::ProcessNodeDeleted(const NodeId& node) { |
195 for (ConnectionMap::iterator i = connection_map_.begin(); | 196 for (ConnectionMap::iterator i = connection_map_.begin(); |
196 i != connection_map_.end(); ++i) { | 197 i != connection_map_.end(); ++i) { |
197 i->second->ProcessNodeDeleted(node, next_server_change_id_, | 198 i->second->ProcessNodeDeleted(node, next_server_change_id_, |
198 IsChangeSource(i->first)); | 199 IsChangeSource(i->first)); |
199 } | 200 } |
200 } | 201 } |
201 | 202 |
202 void RootNodeManager::ProcessViewDeleted(const ViewId& view) { | 203 void RootNodeManager::ProcessViewDeleted(const ViewId& view) { |
203 for (ConnectionMap::iterator i = connection_map_.begin(); | 204 for (ConnectionMap::iterator i = connection_map_.begin(); |
204 i != connection_map_.end(); ++i) { | 205 i != connection_map_.end(); ++i) { |
205 i->second->ProcessViewDeleted(view, IsChangeSource(i->first)); | 206 i->second->ProcessViewDeleted(view, IsChangeSource(i->first)); |
206 } | 207 } |
207 } | 208 } |
208 | 209 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 ViewManagerServiceImpl::Client::Name_, | 244 ViewManagerServiceImpl::Client::Name_, |
244 pipe.handle1.Pass()); | 245 pipe.handle1.Pass()); |
245 | 246 |
246 std::string creator_url; | 247 std::string creator_url; |
247 ConnectionMap::const_iterator it = connection_map_.find(creator_id); | 248 ConnectionMap::const_iterator it = connection_map_.find(creator_id); |
248 if (it != connection_map_.end()) | 249 if (it != connection_map_.end()) |
249 creator_url = it->second->url(); | 250 creator_url = it->second->url(); |
250 | 251 |
251 ViewManagerServiceImpl* connection = | 252 ViewManagerServiceImpl* connection = |
252 new ViewManagerServiceImpl(this, | 253 new ViewManagerServiceImpl(this, |
253 creator_id, | 254 creator_id, |
254 creator_url, | 255 creator_url, |
255 url.To<std::string>()); | 256 url.To<std::string>()); |
256 connection->SetRoots(node_ids); | 257 connection->SetRoots(node_ids); |
257 BindToPipe(connection, pipe.handle0.Pass()); | 258 BindToPipe(connection, pipe.handle0.Pass()); |
258 connections_created_by_connect_.insert(connection); | 259 connections_created_by_connect_.insert(connection); |
259 return connection; | 260 return connection; |
260 } | 261 } |
261 | 262 |
| 263 void RootNodeManager::OnNodeDestroyed(const Node* node) { |
| 264 ProcessNodeDeleted(node->id()); |
| 265 } |
| 266 |
262 void RootNodeManager::OnNodeHierarchyChanged(const Node* node, | 267 void RootNodeManager::OnNodeHierarchyChanged(const Node* node, |
263 const Node* new_parent, | 268 const Node* new_parent, |
264 const Node* old_parent) { | 269 const Node* old_parent) { |
265 if (!root_view_manager_.in_setup()) | 270 if (!root_view_manager_.in_setup()) |
266 ProcessNodeHierarchyChanged(node, new_parent, old_parent); | 271 ProcessNodeHierarchyChanged(node, new_parent, old_parent); |
267 } | 272 } |
268 | 273 |
269 void RootNodeManager::OnNodeBoundsChanged(const Node* node, | 274 void RootNodeManager::OnNodeBoundsChanged(const Node* node, |
270 const gfx::Rect& old_bounds, | 275 const gfx::Rect& old_bounds, |
271 const gfx::Rect& new_bounds) { | 276 const gfx::Rect& new_bounds) { |
272 ProcessNodeBoundsChanged(node, old_bounds, new_bounds); | 277 ProcessNodeBoundsChanged(node, old_bounds, new_bounds); |
273 } | 278 } |
274 | 279 |
275 void RootNodeManager::OnNodeViewReplaced(const Node* node, | 280 void RootNodeManager::OnNodeViewReplaced(const Node* node, |
276 const View* new_view, | 281 const View* new_view, |
277 const View* old_view) { | 282 const View* old_view) { |
278 ProcessNodeViewReplaced(node, new_view, old_view); | 283 ProcessNodeViewReplaced(node, new_view, old_view); |
279 } | 284 } |
280 | 285 |
281 void RootNodeManager::OnViewInputEvent(const View* view, | 286 void RootNodeManager::OnViewInputEvent(const View* view, |
282 const ui::Event* event) { | 287 const ui::Event* event) { |
283 DispatchViewInputEventToWindowManager(view, event); | 288 DispatchViewInputEventToWindowManager(view, event); |
284 } | 289 } |
285 | 290 |
286 } // namespace service | 291 } // namespace service |
287 } // namespace view_manager | 292 } // namespace view_manager |
288 } // namespace mojo | 293 } // namespace mojo |
OLD | NEW |