| 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_service_impl.h" | 5 #include "mojo/services/view_manager/view_manager_service_impl.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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 } | 226 } |
| 227 } | 227 } |
| 228 | 228 |
| 229 void ViewManagerServiceImpl::ProcessViewDeleted(const ViewId& view, | 229 void ViewManagerServiceImpl::ProcessViewDeleted(const ViewId& view, |
| 230 bool originated_change) { | 230 bool originated_change) { |
| 231 if (originated_change) | 231 if (originated_change) |
| 232 return; | 232 return; |
| 233 client()->OnViewDeleted(ViewIdToTransportId(view)); | 233 client()->OnViewDeleted(ViewIdToTransportId(view)); |
| 234 } | 234 } |
| 235 | 235 |
| 236 void ViewManagerServiceImpl::ProcessViewInputEvent(const View* view, | |
| 237 const ui::Event* event) { | |
| 238 DCHECK_EQ(id_, view->id().connection_id); | |
| 239 client()->OnViewInputEvent( | |
| 240 ViewIdToTransportId(view->id()), | |
| 241 TypeConverter<EventPtr, ui::Event>::ConvertFrom(*event), | |
| 242 base::Bind(&base::DoNothing)); | |
| 243 } | |
| 244 | |
| 245 void ViewManagerServiceImpl::OnConnectionError() { | 236 void ViewManagerServiceImpl::OnConnectionError() { |
| 246 if (delete_on_connection_error_) | 237 if (delete_on_connection_error_) |
| 247 delete this; | 238 delete this; |
| 248 } | 239 } |
| 249 | 240 |
| 250 bool ViewManagerServiceImpl::CanRemoveNodeFromParent(const Node* node) const { | 241 bool ViewManagerServiceImpl::CanRemoveNodeFromParent(const Node* node) const { |
| 251 if (!node) | 242 if (!node) |
| 252 return false; | 243 return false; |
| 253 | 244 |
| 254 const Node* parent = node->GetParent(); | 245 const Node* parent = node->GetParent(); |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 ViewManagerServiceImpl* existing_connection = | 737 ViewManagerServiceImpl* existing_connection = |
| 747 root_node_manager_->GetConnectionByCreator(id_, url.To<std::string>()); | 738 root_node_manager_->GetConnectionByCreator(id_, url.To<std::string>()); |
| 748 if (existing_connection) | 739 if (existing_connection) |
| 749 success = existing_connection->AddRoots(node_ids.storage()); | 740 success = existing_connection->AddRoots(node_ids.storage()); |
| 750 else | 741 else |
| 751 root_node_manager_->Embed(id_, url, node_ids); | 742 root_node_manager_->Embed(id_, url, node_ids); |
| 752 } | 743 } |
| 753 callback.Run(success); | 744 callback.Run(success); |
| 754 } | 745 } |
| 755 | 746 |
| 747 void ViewManagerServiceImpl::DispatchOnViewInputEvent(Id transport_view_id, |
| 748 EventPtr event) { |
| 749 // We only allow the WM to dispatch events. At some point this function will |
| 750 // move to a separate interface and the check can go away. |
| 751 if (id_ != kWindowManagerConnection) |
| 752 return; |
| 753 |
| 754 const ViewId view_id(ViewIdFromTransportId(transport_view_id)); |
| 755 ViewManagerServiceImpl* connection = root_node_manager_->GetConnection( |
| 756 view_id.connection_id); |
| 757 if (connection) |
| 758 connection->client()->OnViewInputEvent( |
| 759 transport_view_id, |
| 760 event.Pass(), |
| 761 base::Bind(&base::DoNothing)); |
| 762 } |
| 763 |
| 756 void ViewManagerServiceImpl::OnNodeHierarchyChanged(const Node* node, | 764 void ViewManagerServiceImpl::OnNodeHierarchyChanged(const Node* node, |
| 757 const Node* new_parent, | 765 const Node* new_parent, |
| 758 const Node* old_parent) { | 766 const Node* old_parent) { |
| 759 root_node_manager_->ProcessNodeHierarchyChanged(node, new_parent, old_parent); | 767 root_node_manager_->ProcessNodeHierarchyChanged(node, new_parent, old_parent); |
| 760 } | 768 } |
| 761 | 769 |
| 762 void ViewManagerServiceImpl::OnNodeViewReplaced(const Node* node, | 770 void ViewManagerServiceImpl::OnNodeViewReplaced(const Node* node, |
| 763 const View* new_view, | 771 const View* new_view, |
| 764 const View* old_view) { | 772 const View* old_view) { |
| 765 root_node_manager_->ProcessNodeViewReplaced(node, new_view, old_view); | 773 root_node_manager_->ProcessNodeViewReplaced(node, new_view, old_view); |
| 766 } | 774 } |
| 767 | 775 |
| 768 void ViewManagerServiceImpl::OnViewInputEvent(const View* view, | 776 void ViewManagerServiceImpl::OnViewInputEvent(const View* view, |
| 769 const ui::Event* event) { | 777 const ui::Event* event) { |
| 770 ViewManagerServiceImpl* connection = root_node_manager_->GetConnection( | 778 root_node_manager_->DispatchViewInputEventToWindowManager(view, event); |
| 771 view->id().connection_id); | |
| 772 DCHECK(connection); | |
| 773 connection->ProcessViewInputEvent(view, event); | |
| 774 } | 779 } |
| 775 | 780 |
| 776 void ViewManagerServiceImpl::OnConnectionEstablished() { | 781 void ViewManagerServiceImpl::OnConnectionEstablished() { |
| 777 root_node_manager_->AddConnection(this); | 782 root_node_manager_->AddConnection(this); |
| 778 | 783 |
| 779 std::vector<const Node*> to_send; | 784 std::vector<const Node*> to_send; |
| 780 if (roots_.empty()) { | 785 if (roots_.empty()) { |
| 781 GetUnknownNodesFrom(root_node_manager_->root(), &to_send); | 786 GetUnknownNodesFrom(root_node_manager_->root(), &to_send); |
| 782 } else { | 787 } else { |
| 783 for (NodeIdSet::const_iterator i = roots_.begin(); i != roots_.end(); ++i) | 788 for (NodeIdSet::const_iterator i = roots_.begin(); i != roots_.end(); ++i) |
| 784 GetUnknownNodesFrom(GetNode(NodeIdFromTransportId(*i)), &to_send); | 789 GetUnknownNodesFrom(GetNode(NodeIdFromTransportId(*i)), &to_send); |
| 785 } | 790 } |
| 786 | 791 |
| 787 client()->OnViewManagerConnectionEstablished( | 792 client()->OnViewManagerConnectionEstablished( |
| 788 id_, | 793 id_, |
| 789 creator_url_, | 794 creator_url_, |
| 790 root_node_manager_->next_server_change_id(), | 795 root_node_manager_->next_server_change_id(), |
| 791 NodesToNodeDatas(to_send)); | 796 NodesToNodeDatas(to_send)); |
| 792 } | 797 } |
| 793 | 798 |
| 794 } // namespace service | 799 } // namespace service |
| 795 } // namespace view_manager | 800 } // namespace view_manager |
| 796 } // namespace mojo | 801 } // namespace mojo |
| OLD | NEW |