| 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_client_impl.h" | 5 #include "mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "mojo/public/cpp/application/application_connection.h" | 9 #include "mojo/public/cpp/application/application_connection.h" |
| 10 #include "mojo/public/cpp/application/connect.h" | 10 #include "mojo/public/cpp/application/connect.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 private_view.set_node(node); | 52 private_view.set_node(node); |
| 53 // TODO(beng): this broadcasts notifications locally... do we want this? I | 53 // TODO(beng): this broadcasts notifications locally... do we want this? I |
| 54 // don't think so. same story for LocalAddChild above! | 54 // don't think so. same story for LocalAddChild above! |
| 55 private_node.LocalSetActiveView(view); | 55 private_node.LocalSetActiveView(view); |
| 56 client->AddView(view); | 56 client->AddView(view); |
| 57 } | 57 } |
| 58 return node; | 58 return node; |
| 59 } | 59 } |
| 60 | 60 |
| 61 Node* BuildNodeTree(ViewManagerClientImpl* client, | 61 Node* BuildNodeTree(ViewManagerClientImpl* client, |
| 62 const Array<NodeDataPtr>& nodes) { | 62 const Array<NodeDataPtr>& nodes, |
| 63 Node* initial_parent) { |
| 63 std::vector<Node*> parents; | 64 std::vector<Node*> parents; |
| 64 Node* root = NULL; | 65 Node* root = NULL; |
| 65 Node* last_node = NULL; | 66 Node* last_node = NULL; |
| 67 if (initial_parent) |
| 68 parents.push_back(initial_parent); |
| 66 for (size_t i = 0; i < nodes.size(); ++i) { | 69 for (size_t i = 0; i < nodes.size(); ++i) { |
| 67 if (last_node && nodes[i]->parent_id == last_node->id()) { | 70 if (last_node && nodes[i]->parent_id == last_node->id()) { |
| 68 parents.push_back(last_node); | 71 parents.push_back(last_node); |
| 69 } else if (!parents.empty()) { | 72 } else if (!parents.empty()) { |
| 70 while (parents.back()->id() != nodes[i]->parent_id) | 73 while (parents.back()->id() != nodes[i]->parent_id) |
| 71 parents.pop_back(); | 74 parents.pop_back(); |
| 72 } | 75 } |
| 73 Node* node = AddNodeToViewManager( | 76 Node* node = AddNodeToViewManager( |
| 74 client, | 77 client, |
| 75 !parents.empty() ? parents.back() : NULL, | 78 !parents.empty() ? parents.back() : NULL, |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 //////////////////////////////////////////////////////////////////////////////// | 320 //////////////////////////////////////////////////////////////////////////////// |
| 318 // ViewManagerClientImpl, ViewManagerClient implementation: | 321 // ViewManagerClientImpl, ViewManagerClient implementation: |
| 319 | 322 |
| 320 void ViewManagerClientImpl::OnViewManagerConnectionEstablished( | 323 void ViewManagerClientImpl::OnViewManagerConnectionEstablished( |
| 321 ConnectionSpecificId connection_id, | 324 ConnectionSpecificId connection_id, |
| 322 const String& creator_url, | 325 const String& creator_url, |
| 323 Array<NodeDataPtr> nodes) { | 326 Array<NodeDataPtr> nodes) { |
| 324 connected_ = true; | 327 connected_ = true; |
| 325 connection_id_ = connection_id; | 328 connection_id_ = connection_id; |
| 326 creator_url_ = TypeConverter<String, std::string>::ConvertFrom(creator_url); | 329 creator_url_ = TypeConverter<String, std::string>::ConvertFrom(creator_url); |
| 327 AddRoot(BuildNodeTree(this, nodes)); | 330 AddRoot(BuildNodeTree(this, nodes, NULL)); |
| 328 } | 331 } |
| 329 | 332 |
| 330 void ViewManagerClientImpl::OnRootAdded(Array<NodeDataPtr> nodes) { | 333 void ViewManagerClientImpl::OnRootAdded(Array<NodeDataPtr> nodes) { |
| 331 AddRoot(BuildNodeTree(this, nodes)); | 334 AddRoot(BuildNodeTree(this, nodes, NULL)); |
| 332 } | 335 } |
| 333 | 336 |
| 334 void ViewManagerClientImpl::OnNodeBoundsChanged(Id node_id, | 337 void ViewManagerClientImpl::OnNodeBoundsChanged(Id node_id, |
| 335 RectPtr old_bounds, | 338 RectPtr old_bounds, |
| 336 RectPtr new_bounds) { | 339 RectPtr new_bounds) { |
| 337 Node* node = GetNodeById(node_id); | 340 Node* node = GetNodeById(node_id); |
| 338 NodePrivate(node).LocalSetBounds(old_bounds.To<gfx::Rect>(), | 341 NodePrivate(node).LocalSetBounds(old_bounds.To<gfx::Rect>(), |
| 339 new_bounds.To<gfx::Rect>()); | 342 new_bounds.To<gfx::Rect>()); |
| 340 } | 343 } |
| 341 | 344 |
| 342 void ViewManagerClientImpl::OnNodeHierarchyChanged( | 345 void ViewManagerClientImpl::OnNodeHierarchyChanged( |
| 343 Id node_id, | 346 Id node_id, |
| 344 Id new_parent_id, | 347 Id new_parent_id, |
| 345 Id old_parent_id, | 348 Id old_parent_id, |
| 346 mojo::Array<NodeDataPtr> nodes) { | 349 mojo::Array<NodeDataPtr> nodes) { |
| 347 BuildNodeTree(this, nodes); | 350 Node* initial_parent = nodes.size() ? |
| 351 GetNodeById(nodes[0]->parent_id) : NULL; |
| 352 |
| 353 BuildNodeTree(this, nodes, initial_parent); |
| 348 | 354 |
| 349 Node* new_parent = GetNodeById(new_parent_id); | 355 Node* new_parent = GetNodeById(new_parent_id); |
| 350 Node* old_parent = GetNodeById(old_parent_id); | 356 Node* old_parent = GetNodeById(old_parent_id); |
| 351 Node* node = GetNodeById(node_id); | 357 Node* node = GetNodeById(node_id); |
| 352 if (new_parent) | 358 if (new_parent) |
| 353 NodePrivate(new_parent).LocalAddChild(node); | 359 NodePrivate(new_parent).LocalAddChild(node); |
| 354 else | 360 else |
| 355 NodePrivate(old_parent).LocalRemoveChild(node); | 361 NodePrivate(old_parent).LocalRemoveChild(node); |
| 356 } | 362 } |
| 357 | 363 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 base::Unretained(this)); | 476 base::Unretained(this)); |
| 471 } | 477 } |
| 472 | 478 |
| 473 base::Callback<void(ErrorCode)> | 479 base::Callback<void(ErrorCode)> |
| 474 ViewManagerClientImpl::ActionCompletedCallbackWithErrorCode() { | 480 ViewManagerClientImpl::ActionCompletedCallbackWithErrorCode() { |
| 475 return base::Bind(&ViewManagerClientImpl::OnActionCompletedWithErrorCode, | 481 return base::Bind(&ViewManagerClientImpl::OnActionCompletedWithErrorCode, |
| 476 base::Unretained(this)); | 482 base::Unretained(this)); |
| 477 } | 483 } |
| 478 | 484 |
| 479 } // namespace mojo | 485 } // namespace mojo |
| OLD | NEW |