Chromium Code Reviews| 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" | 9 #include "mojo/services/public/cpp/geometry/geometry_type_converters.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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 (roots_.count(NodeIdToTransportId(node->id())) > 0) || | 163 (roots_.count(NodeIdToTransportId(node->id())) > 0) || |
| 164 (new_parent && IsNodeDescendantOfRoots(new_parent)) || | 164 (new_parent && IsNodeDescendantOfRoots(new_parent)) || |
| 165 (old_parent && IsNodeDescendantOfRoots(old_parent))); | 165 (old_parent && IsNodeDescendantOfRoots(old_parent))); |
| 166 client()->OnNodeHierarchyChanged(NodeIdToTransportId(node->id()), | 166 client()->OnNodeHierarchyChanged(NodeIdToTransportId(node->id()), |
| 167 NodeIdToTransportId(new_parent_id), | 167 NodeIdToTransportId(new_parent_id), |
| 168 NodeIdToTransportId(old_parent_id), | 168 NodeIdToTransportId(old_parent_id), |
| 169 server_change_id, | 169 server_change_id, |
| 170 NodesToINodes(to_send)); | 170 NodesToINodes(to_send)); |
| 171 } | 171 } |
| 172 | 172 |
| 173 void ViewManagerConnection::ProcessNodeReorder(const Node* node, | |
| 174 const Node* relative_node, | |
| 175 OrderDirection direction, | |
| 176 Id server_change_id, | |
| 177 bool originated_change) { | |
| 178 if (originated_change || | |
| 179 !known_nodes_.count(NodeIdToTransportId(node->id())) || | |
| 180 !known_nodes_.count(NodeIdToTransportId(relative_node->id()))) { | |
| 181 return; | |
| 182 } | |
| 183 | |
| 184 client()->OnNodeReordered(NodeIdToTransportId(node->id()), | |
| 185 NodeIdToTransportId(relative_node->id()), | |
| 186 direction, | |
| 187 server_change_id); | |
| 188 } | |
| 189 | |
| 173 void ViewManagerConnection::ProcessNodeViewReplaced( | 190 void ViewManagerConnection::ProcessNodeViewReplaced( |
| 174 const Node* node, | 191 const Node* node, |
| 175 const View* new_view, | 192 const View* new_view, |
| 176 const View* old_view, | 193 const View* old_view, |
| 177 bool originated_change) { | 194 bool originated_change) { |
| 178 if (originated_change || !known_nodes_.count(NodeIdToTransportId(node->id()))) | 195 if (originated_change || !known_nodes_.count(NodeIdToTransportId(node->id()))) |
| 179 return; | 196 return; |
| 180 const Id new_view_id = new_view ? | 197 const Id new_view_id = new_view ? |
| 181 ViewIdToTransportId(new_view->id()) : 0; | 198 ViewIdToTransportId(new_view->id()) : 0; |
| 182 const Id old_view_id = old_view ? | 199 const Id old_view_id = old_view ? |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 return true; // No restriction if there are no roots. | 277 return true; // No restriction if there are no roots. |
| 261 | 278 |
| 262 if (!IsNodeDescendantOfRoots(parent) && parent->id().connection_id != id_) | 279 if (!IsNodeDescendantOfRoots(parent) && parent->id().connection_id != id_) |
| 263 return false; // |parent| is not visible to this connection. | 280 return false; // |parent| is not visible to this connection. |
| 264 | 281 |
| 265 // Allow the add if the child is already a descendant of the roots or was | 282 // Allow the add if the child is already a descendant of the roots or was |
| 266 // created by this connection. | 283 // created by this connection. |
| 267 return (IsNodeDescendantOfRoots(child) || child->id().connection_id == id_); | 284 return (IsNodeDescendantOfRoots(child) || child->id().connection_id == id_); |
| 268 } | 285 } |
| 269 | 286 |
| 287 bool ViewManagerConnection::CanReorderNode(const Node* node, | |
| 288 const Node* relatve_node) const { | |
|
sky
2014/06/11 19:36:44
relative_node.
| |
| 289 return node->id().connection_id == id_ && | |
|
sky
2014/06/11 19:36:44
You should also check: both nodes are non-null, an
| |
| 290 node->GetParent() == relatve_node->GetParent(); | |
| 291 } | |
| 292 | |
| 270 bool ViewManagerConnection::CanDeleteNode(const NodeId& node_id) const { | 293 bool ViewManagerConnection::CanDeleteNode(const NodeId& node_id) const { |
| 271 return node_id.connection_id == id_; | 294 return node_id.connection_id == id_; |
| 272 } | 295 } |
| 273 | 296 |
| 274 bool ViewManagerConnection::CanDeleteView(const ViewId& view_id) const { | 297 bool ViewManagerConnection::CanDeleteView(const ViewId& view_id) const { |
| 275 return view_id.connection_id == id_; | 298 return view_id.connection_id == id_; |
| 276 } | 299 } |
| 277 | 300 |
| 278 bool ViewManagerConnection::CanSetView(const Node* node, | 301 bool ViewManagerConnection::CanSetView(const Node* node, |
| 279 const ViewId& view_id) const { | 302 const ViewId& view_id) const { |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 546 success = true; | 569 success = true; |
| 547 RootNodeManager::ScopedChange change( | 570 RootNodeManager::ScopedChange change( |
| 548 this, root_node_manager_, | 571 this, root_node_manager_, |
| 549 RootNodeManager::CHANGE_TYPE_ADVANCE_SERVER_CHANGE_ID, false); | 572 RootNodeManager::CHANGE_TYPE_ADVANCE_SERVER_CHANGE_ID, false); |
| 550 node->GetParent()->Remove(node); | 573 node->GetParent()->Remove(node); |
| 551 } | 574 } |
| 552 } | 575 } |
| 553 callback.Run(success); | 576 callback.Run(success); |
| 554 } | 577 } |
| 555 | 578 |
| 579 void ViewManagerConnection::ReorderNode(Id node_id, | |
| 580 Id relative_node_id, | |
| 581 OrderDirection direction, | |
| 582 Id server_change_id, | |
| 583 const Callback<void(bool)>& callback) { | |
| 584 bool success = false; | |
| 585 if (server_change_id == root_node_manager_->next_server_change_id()) { | |
| 586 Node* node = GetNode(NodeIdFromTransportId(node_id)); | |
| 587 Node* relative_node = GetNode(NodeIdFromTransportId(relative_node_id)); | |
| 588 if (CanReorderNode(node, relative_node)) { | |
| 589 success = true; | |
| 590 RootNodeManager::ScopedChange change( | |
| 591 this, root_node_manager_, | |
| 592 RootNodeManager::CHANGE_TYPE_ADVANCE_SERVER_CHANGE_ID, false); | |
| 593 node->GetParent()->Reorder(node, relative_node, direction); | |
| 594 root_node_manager_->ProcessNodeReorder(node, relative_node, direction); | |
| 595 } | |
| 596 } | |
| 597 callback.Run(success); | |
| 598 } | |
| 599 | |
| 556 void ViewManagerConnection::GetNodeTree( | 600 void ViewManagerConnection::GetNodeTree( |
| 557 Id node_id, | 601 Id node_id, |
| 558 const Callback<void(Array<INodePtr>)>& callback) { | 602 const Callback<void(Array<INodePtr>)>& callback) { |
| 559 Node* node = GetNode(NodeIdFromTransportId(node_id)); | 603 Node* node = GetNode(NodeIdFromTransportId(node_id)); |
| 560 std::vector<const Node*> nodes; | 604 std::vector<const Node*> nodes; |
| 561 if (CanGetNodeTree(node)) { | 605 if (CanGetNodeTree(node)) { |
| 562 GetDescendants(node, &nodes); | 606 GetDescendants(node, &nodes); |
| 563 for (size_t i = 0; i < nodes.size(); ++i) | 607 for (size_t i = 0; i < nodes.size(); ++i) |
| 564 known_nodes_.insert(NodeIdToTransportId(nodes[i]->id())); | 608 known_nodes_.insert(NodeIdToTransportId(nodes[i]->id())); |
| 565 } | 609 } |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 698 client()->OnViewManagerConnectionEstablished( | 742 client()->OnViewManagerConnectionEstablished( |
| 699 id_, | 743 id_, |
| 700 creator_url_, | 744 creator_url_, |
| 701 root_node_manager_->next_server_change_id(), | 745 root_node_manager_->next_server_change_id(), |
| 702 NodesToINodes(to_send)); | 746 NodesToINodes(to_send)); |
| 703 } | 747 } |
| 704 | 748 |
| 705 } // namespace service | 749 } // namespace service |
| 706 } // namespace view_manager | 750 } // namespace view_manager |
| 707 } // namespace mojo | 751 } // namespace mojo |
| OLD | NEW |