Commit a1347688 authored by sky@chromium.org's avatar sky@chromium.org

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
parent 111f14f6
......@@ -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_;
......
......@@ -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:
......
......@@ -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.
......
......@@ -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);
};
}
......@@ -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)
......
......@@ -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
......
......@@ -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,
......
......@@ -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) {
......
......@@ -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() {
......
......@@ -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,
......
......@@ -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).
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment