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* relative_node, |
| 289 OrderDirection direction) const { |
| 290 if (!node || !relative_node) |
| 291 return false; |
| 292 |
| 293 if (node->id().connection_id != id_) |
| 294 return false; |
| 295 |
| 296 const Node* parent = node->GetParent(); |
| 297 if (!parent || parent != relative_node->GetParent()) |
| 298 return false; |
| 299 |
| 300 if (known_nodes_.count(NodeIdToTransportId(parent->id())) == 0) |
| 301 return false; |
| 302 |
| 303 std::vector<const Node*> children = parent->GetChildren(); |
| 304 const size_t child_i = |
| 305 std::find(children.begin(), children.end(), node) - children.begin(); |
| 306 const size_t target_i = |
| 307 std::find(children.begin(), children.end(), relative_node) - |
| 308 children.begin(); |
| 309 if ((direction == ORDER_ABOVE && child_i == target_i + 1) || |
| 310 (direction == ORDER_BELOW && child_i + 1 == target_i)) { |
| 311 return false; |
| 312 } |
| 313 |
| 314 return true; |
| 315 } |
| 316 |
270 bool ViewManagerConnection::CanDeleteNode(const NodeId& node_id) const { | 317 bool ViewManagerConnection::CanDeleteNode(const NodeId& node_id) const { |
271 return node_id.connection_id == id_; | 318 return node_id.connection_id == id_; |
272 } | 319 } |
273 | 320 |
274 bool ViewManagerConnection::CanDeleteView(const ViewId& view_id) const { | 321 bool ViewManagerConnection::CanDeleteView(const ViewId& view_id) const { |
275 return view_id.connection_id == id_; | 322 return view_id.connection_id == id_; |
276 } | 323 } |
277 | 324 |
278 bool ViewManagerConnection::CanSetView(const Node* node, | 325 bool ViewManagerConnection::CanSetView(const Node* node, |
279 const ViewId& view_id) const { | 326 const ViewId& view_id) const { |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 success = true; | 593 success = true; |
547 RootNodeManager::ScopedChange change( | 594 RootNodeManager::ScopedChange change( |
548 this, root_node_manager_, | 595 this, root_node_manager_, |
549 RootNodeManager::CHANGE_TYPE_ADVANCE_SERVER_CHANGE_ID, false); | 596 RootNodeManager::CHANGE_TYPE_ADVANCE_SERVER_CHANGE_ID, false); |
550 node->GetParent()->Remove(node); | 597 node->GetParent()->Remove(node); |
551 } | 598 } |
552 } | 599 } |
553 callback.Run(success); | 600 callback.Run(success); |
554 } | 601 } |
555 | 602 |
| 603 void ViewManagerConnection::ReorderNode(Id node_id, |
| 604 Id relative_node_id, |
| 605 OrderDirection direction, |
| 606 Id server_change_id, |
| 607 const Callback<void(bool)>& callback) { |
| 608 bool success = false; |
| 609 if (server_change_id == root_node_manager_->next_server_change_id()) { |
| 610 Node* node = GetNode(NodeIdFromTransportId(node_id)); |
| 611 Node* relative_node = GetNode(NodeIdFromTransportId(relative_node_id)); |
| 612 if (CanReorderNode(node, relative_node, direction)) { |
| 613 success = true; |
| 614 RootNodeManager::ScopedChange change( |
| 615 this, root_node_manager_, |
| 616 RootNodeManager::CHANGE_TYPE_ADVANCE_SERVER_CHANGE_ID, false); |
| 617 node->GetParent()->Reorder(node, relative_node, direction); |
| 618 root_node_manager_->ProcessNodeReorder(node, relative_node, direction); |
| 619 } |
| 620 } |
| 621 callback.Run(success); |
| 622 } |
| 623 |
556 void ViewManagerConnection::GetNodeTree( | 624 void ViewManagerConnection::GetNodeTree( |
557 Id node_id, | 625 Id node_id, |
558 const Callback<void(Array<INodePtr>)>& callback) { | 626 const Callback<void(Array<INodePtr>)>& callback) { |
559 Node* node = GetNode(NodeIdFromTransportId(node_id)); | 627 Node* node = GetNode(NodeIdFromTransportId(node_id)); |
560 std::vector<const Node*> nodes; | 628 std::vector<const Node*> nodes; |
561 if (CanGetNodeTree(node)) { | 629 if (CanGetNodeTree(node)) { |
562 GetDescendants(node, &nodes); | 630 GetDescendants(node, &nodes); |
563 for (size_t i = 0; i < nodes.size(); ++i) | 631 for (size_t i = 0; i < nodes.size(); ++i) |
564 known_nodes_.insert(NodeIdToTransportId(nodes[i]->id())); | 632 known_nodes_.insert(NodeIdToTransportId(nodes[i]->id())); |
565 } | 633 } |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 client()->OnViewManagerConnectionEstablished( | 766 client()->OnViewManagerConnectionEstablished( |
699 id_, | 767 id_, |
700 creator_url_, | 768 creator_url_, |
701 root_node_manager_->next_server_change_id(), | 769 root_node_manager_->next_server_change_id(), |
702 NodesToINodes(to_send)); | 770 NodesToINodes(to_send)); |
703 } | 771 } |
704 | 772 |
705 } // namespace service | 773 } // namespace service |
706 } // namespace view_manager | 774 } // namespace view_manager |
707 } // namespace mojo | 775 } // namespace mojo |
OLD | NEW |