diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-18 08:24:42 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-18 08:24:42 +0000 |
commit | a1347688aed6d55655ec2b193158bce884dd6b22 (patch) | |
tree | f51e97b682721c6505950fc66f2183f2ce954ce7 /mojo | |
parent | 111f14f6fd881d9e34804e5820440a2d53b804ef (diff) | |
download | chromium_src-a1347688aed6d55655ec2b193158bce884dd6b22.zip chromium_src-a1347688aed6d55655ec2b193158bce884dd6b22.tar.gz chromium_src-a1347688aed6d55655ec2b193158bce884dd6b22.tar.bz2 |
Changes routing of input events in view manager
Events are now sent to the window manager (assumed to be at connection
id 1 for now). The window manager can then do what it wants with
them. For now I made it bounce the event back to the server so
everything works as it did.
Until we get FIFO across pipes I'm putting these messages on the
ViewManager/ViewManagerClient interface. That'll change.
BUG=384433
TEST=covered by tests
R=ben@chromium.org
Review URL: https://codereview.chromium.org/338353006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@277982 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo')
11 files changed, 91 insertions, 16 deletions
diff --git a/mojo/examples/aura_demo/aura_demo.cc b/mojo/examples/aura_demo/aura_demo.cc index fe3398e..b246484 100644 --- a/mojo/examples/aura_demo/aura_demo.cc +++ b/mojo/examples/aura_demo/aura_demo.cc @@ -187,6 +187,9 @@ class ViewManagerClientImpl EventPtr event, const Callback<void()>& callback) OVERRIDE { } + virtual void DispatchOnViewInputEvent(uint32_t view_id, + EventPtr event) OVERRIDE { + } AuraDemo* aura_demo_; diff --git a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc b/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc index 59790ce..cb7b0713 100644 --- a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc +++ b/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc @@ -776,6 +776,14 @@ void ViewManagerClientImpl::OnViewInputEvent( ack_callback.Run(); } +void ViewManagerClientImpl::DispatchOnViewInputEvent(Id view_id, + EventPtr event) { + // For now blindly bounce the message back to the server. Doing this means the + // event is sent to the correct target (|view_id|). + // Note: This function is only invoked on the window manager. + service_->DispatchOnViewInputEvent(view_id, event.Pass()); +} + //////////////////////////////////////////////////////////////////////////////// // ViewManagerClientImpl, private: diff --git a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h b/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h index cccdc08..01cdc34 100644 --- a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h +++ b/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h @@ -120,6 +120,7 @@ class ViewManagerClientImpl : public ViewManager, virtual void OnViewInputEvent(Id view, EventPtr event, const Callback<void()>& callback) OVERRIDE; + virtual void DispatchOnViewInputEvent(Id view_id, EventPtr event) OVERRIDE; // Sync the client model with the service by enumerating the pending // transaction queue and applying them in order. diff --git a/mojo/services/public/interfaces/view_manager/view_manager.mojom b/mojo/services/public/interfaces/view_manager/view_manager.mojom index 2b2f257..ea1d3b5 100644 --- a/mojo/services/public/interfaces/view_manager/view_manager.mojom +++ b/mojo/services/public/interfaces/view_manager/view_manager.mojom @@ -118,6 +118,11 @@ interface ViewManagerService { // the connection is reused. When this happens the ViewManagerClient is // notified of the additional roots by way of OnRootsAdded(). Embed(string url, uint32[] nodes) => (bool success); + + // TODO(sky): move these to a separate interface when FIFO works. + + // Sends OnViewInputEvent() to the owner of the specified view. + DispatchOnViewInputEvent(uint32 view_id, mojo.Event event); }; // Changes to nodes/views are not sent to the connection that originated the @@ -179,6 +184,10 @@ interface ViewManagerClient { // Invoked when an event is targeted at the specified view. OnViewInputEvent(uint32 view, mojo.Event event) => (); + + // TODO(sky): move to separate interface when FIFO sorted out. + + DispatchOnViewInputEvent(uint32 view, mojo.Event event); }; } diff --git a/mojo/services/view_manager/ids.h b/mojo/services/view_manager/ids.h index b7cfe45..8d906be 100644 --- a/mojo/services/view_manager/ids.h +++ b/mojo/services/view_manager/ids.h @@ -16,6 +16,10 @@ namespace service { // Connection id reserved for the root. const ConnectionSpecificId kRootConnection = 0; +// TODO(sky): remove this, temporary while window manager API is in existing +// api. +const ConnectionSpecificId kWindowManagerConnection = 1; + // Adds a bit of type safety to node ids. struct MOJO_VIEW_MANAGER_EXPORT NodeId { NodeId(ConnectionSpecificId connection_id, ConnectionSpecificId node_id) diff --git a/mojo/services/view_manager/root_node_manager.cc b/mojo/services/view_manager/root_node_manager.cc index a3cb62a..f5c681f 100644 --- a/mojo/services/view_manager/root_node_manager.cc +++ b/mojo/services/view_manager/root_node_manager.cc @@ -6,6 +6,7 @@ #include "base/logging.h" #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" +#include "mojo/services/public/cpp/input_events/input_events_type_converters.h" #include "mojo/services/view_manager/view.h" #include "mojo/services/view_manager/view_manager_service_impl.h" #include "ui/aura/env.h" @@ -130,6 +131,19 @@ ViewManagerServiceImpl* RootNodeManager::GetConnectionByCreator( return NULL; } +void RootNodeManager::DispatchViewInputEventToWindowManager( + const View* view, + const ui::Event* event) { + // Input events are forwarded to the WindowManager. The WindowManager + // eventually calls back to us with DispatchOnViewInputEvent(). + ViewManagerServiceImpl* connection = GetConnection(kWindowManagerConnection); + if (!connection) + return; + connection->client()->DispatchOnViewInputEvent( + ViewIdToTransportId(view->id()), + TypeConverter<EventPtr, ui::Event>::ConvertFrom(*event)); +} + void RootNodeManager::ProcessNodeBoundsChanged(const Node* node, const gfx::Rect& old_bounds, const gfx::Rect& new_bounds) { @@ -243,7 +257,7 @@ void RootNodeManager::OnNodeViewReplaced(const Node* node, void RootNodeManager::OnViewInputEvent(const View* view, const ui::Event* event) { - GetConnection(view->id().connection_id)->ProcessViewInputEvent(view, event); + DispatchViewInputEventToWindowManager(view, event); } } // namespace service diff --git a/mojo/services/view_manager/root_node_manager.h b/mojo/services/view_manager/root_node_manager.h index 35415bb..dba45d9 100644 --- a/mojo/services/view_manager/root_node_manager.h +++ b/mojo/services/view_manager/root_node_manager.h @@ -129,6 +129,9 @@ class MOJO_VIEW_MANAGER_EXPORT RootNodeManager : public NodeDelegate { ConnectionSpecificId creator_id, const std::string& url) const; + void DispatchViewInputEventToWindowManager(const View* view, + const ui::Event* event); + // These functions trivially delegate to all ViewManagerServiceImpls, which in // term notify their clients. void ProcessNodeBoundsChanged(const Node* node, diff --git a/mojo/services/view_manager/test_change_tracker.cc b/mojo/services/view_manager/test_change_tracker.cc index 192e093..89e7fbb 100644 --- a/mojo/services/view_manager/test_change_tracker.cc +++ b/mojo/services/view_manager/test_change_tracker.cc @@ -242,6 +242,7 @@ void TestChangeTracker::OnViewInputEvent(Id view_id, EventPtr event) { change.type = CHANGE_TYPE_INPUT_EVENT; change.view_id = view_id; change.event_action = event->action; + AddChange(change); } void TestChangeTracker::AddChange(const Change& change) { diff --git a/mojo/services/view_manager/view_manager_service_impl.cc b/mojo/services/view_manager/view_manager_service_impl.cc index e25980a..0af11c3 100644 --- a/mojo/services/view_manager/view_manager_service_impl.cc +++ b/mojo/services/view_manager/view_manager_service_impl.cc @@ -233,15 +233,6 @@ void ViewManagerServiceImpl::ProcessViewDeleted(const ViewId& view, client()->OnViewDeleted(ViewIdToTransportId(view)); } -void ViewManagerServiceImpl::ProcessViewInputEvent(const View* view, - const ui::Event* event) { - DCHECK_EQ(id_, view->id().connection_id); - client()->OnViewInputEvent( - ViewIdToTransportId(view->id()), - TypeConverter<EventPtr, ui::Event>::ConvertFrom(*event), - base::Bind(&base::DoNothing)); -} - void ViewManagerServiceImpl::OnConnectionError() { if (delete_on_connection_error_) delete this; @@ -755,6 +746,23 @@ void ViewManagerServiceImpl::Embed(const String& url, callback.Run(success); } +void ViewManagerServiceImpl::DispatchOnViewInputEvent(Id transport_view_id, + EventPtr event) { + // We only allow the WM to dispatch events. At some point this function will + // move to a separate interface and the check can go away. + if (id_ != kWindowManagerConnection) + return; + + const ViewId view_id(ViewIdFromTransportId(transport_view_id)); + ViewManagerServiceImpl* connection = root_node_manager_->GetConnection( + view_id.connection_id); + if (connection) + connection->client()->OnViewInputEvent( + transport_view_id, + event.Pass(), + base::Bind(&base::DoNothing)); +} + void ViewManagerServiceImpl::OnNodeHierarchyChanged(const Node* node, const Node* new_parent, const Node* old_parent) { @@ -769,10 +777,7 @@ void ViewManagerServiceImpl::OnNodeViewReplaced(const Node* node, void ViewManagerServiceImpl::OnViewInputEvent(const View* view, const ui::Event* event) { - ViewManagerServiceImpl* connection = root_node_manager_->GetConnection( - view->id().connection_id); - DCHECK(connection); - connection->ProcessViewInputEvent(view, event); + root_node_manager_->DispatchViewInputEventToWindowManager(view, event); } void ViewManagerServiceImpl::OnConnectionEstablished() { diff --git a/mojo/services/view_manager/view_manager_service_impl.h b/mojo/services/view_manager/view_manager_service_impl.h index b193967..53950dc 100644 --- a/mojo/services/view_manager/view_manager_service_impl.h +++ b/mojo/services/view_manager/view_manager_service_impl.h @@ -99,7 +99,6 @@ class MOJO_VIEW_MANAGER_EXPORT ViewManagerServiceImpl Id server_change_id, bool originated_change); void ProcessViewDeleted(const ViewId& view, bool originated_change); - void ProcessViewInputEvent(const View* view, const ui::Event* event); // TODO(sky): move this to private section (currently can't because of // bindings). @@ -207,6 +206,8 @@ class MOJO_VIEW_MANAGER_EXPORT ViewManagerServiceImpl virtual void Embed(const mojo::String& url, mojo::Array<uint32_t> node_ids, const mojo::Callback<void(bool)>& callback) OVERRIDE; + virtual void DispatchOnViewInputEvent(Id transport_view_id, + EventPtr event) OVERRIDE; // Overridden from NodeDelegate: virtual void OnNodeHierarchyChanged(const Node* node, diff --git a/mojo/services/view_manager/view_manager_unittest.cc b/mojo/services/view_manager/view_manager_unittest.cc index 927bf58..22faff6 100644 --- a/mojo/services/view_manager/view_manager_unittest.cc +++ b/mojo/services/view_manager/view_manager_unittest.cc @@ -64,6 +64,8 @@ class ViewManagerProxy : public TestChangeTracker::Delegate { return instance; } + ViewManagerService* view_manager() { return view_manager_; } + // Runs the main loop until |count| changes have been received. std::vector<Change> DoRunLoopUntilChangesCount(size_t count) { DCHECK_EQ(0u, quit_count_); @@ -292,7 +294,7 @@ class TestViewManagerClientConnection connection_.set_view_manager(client()); } - // IViewMangerClient: + // ViewMangerClient: virtual void OnViewManagerConnectionEstablished( ConnectionSpecificId connection_id, const String& creator_url, @@ -344,6 +346,9 @@ class TestViewManagerClientConnection const Callback<void()>& callback) OVERRIDE { tracker_.OnViewInputEvent(view_id, event.Pass()); } + virtual void DispatchOnViewInputEvent(Id view_id, + mojo::EventPtr event) OVERRIDE { + } private: TestChangeTracker tracker_; @@ -1330,6 +1335,27 @@ TEST_F(ViewManagerTest, ConnectTwice) { } } +TEST_F(ViewManagerTest, OnViewInput) { + // Create node 1 and assign a view from connection 2 to it. + ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); + ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); + ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 11))); + ASSERT_TRUE(connection2_->SetView(BuildNodeId(1, 1), BuildViewId(2, 11))); + + // Dispatch an event to the view and verify its received. + { + EventPtr event(Event::New()); + event->action = 1; + connection_->view_manager()->DispatchOnViewInputEvent( + BuildViewId(2, 11), + event.Pass()); + connection2_->DoRunLoopUntilChangesCount(1); + const Changes changes(ChangesToDescription1(connection2_->changes())); + ASSERT_EQ(1u, changes.size()); + EXPECT_EQ("InputEvent view=2,11 event_action=1", changes[0]); + } +} + // TODO(sky): add coverage of test that destroys connections and ensures other // connections get deletion notification (or advanced server id). |