diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-04 22:15:03 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-04 22:15:03 +0000 |
commit | 4a7d4ac8e5822a37e33de2afff71ade92e04700b (patch) | |
tree | f04f2e745f1a7f6051b16cdf95f9d62d3a4e28b4 | |
parent | ed8eb799932371e534595d28914bb885cca0aa9a (diff) | |
download | chromium_src-4a7d4ac8e5822a37e33de2afff71ade92e04700b.zip chromium_src-4a7d4ac8e5822a37e33de2afff71ade92e04700b.tar.gz chromium_src-4a7d4ac8e5822a37e33de2afff71ade92e04700b.tar.bz2 |
Wire input events through the ViewManagerClient interface.
This is the patch at https://codereview.chromium.org/300863003/
updated for trunk with some gyp tweaks.
BUG=365012
TEST=none
R=ben@chromium.org
Review URL: https://codereview.chromium.org/316713002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274929 0039d316-1c4b-4281-b951-d872f2087c98
24 files changed, 292 insertions, 30 deletions
diff --git a/mojo/examples/aura_demo/aura_demo.cc b/mojo/examples/aura_demo/aura_demo.cc index 4ef2903..d11463e 100644 --- a/mojo/examples/aura_demo/aura_demo.cc +++ b/mojo/examples/aura_demo/aura_demo.cc @@ -143,6 +143,10 @@ class IViewManagerClientImpl } virtual void OnViewDeleted(uint32_t view) OVERRIDE { } + virtual void OnViewInputEvent(uint32_t view_id, + EventPtr event, + const Callback<void()>& callback) OVERRIDE { + } AuraDemo* aura_demo_; diff --git a/mojo/examples/sample_view_manager_app/DEPS b/mojo/examples/sample_view_manager_app/DEPS index b273ae3..8cb61f5 100644 --- a/mojo/examples/sample_view_manager_app/DEPS +++ b/mojo/examples/sample_view_manager_app/DEPS @@ -1,3 +1,4 @@ include_rules = [ + "+ui/events", "+ui/gfx", ] diff --git a/mojo/examples/sample_view_manager_app/sample_view_manager_app.cc b/mojo/examples/sample_view_manager_app/sample_view_manager_app.cc index 15113bb..686c193 100644 --- a/mojo/examples/sample_view_manager_app/sample_view_manager_app.cc +++ b/mojo/examples/sample_view_manager_app/sample_view_manager_app.cc @@ -4,19 +4,50 @@ #include "base/at_exit.h" #include "base/bind.h" +#include "base/strings/stringprintf.h" #include "mojo/public/cpp/application/application.h" #include "mojo/public/cpp/environment/environment.h" #include "mojo/public/cpp/system/core.h" #include "mojo/public/cpp/system/macros.h" #include "mojo/services/public/cpp/view_manager/view.h" #include "mojo/services/public/cpp/view_manager/view_manager.h" +#include "mojo/services/public/cpp/view_manager/view_observer.h" #include "mojo/services/public/cpp/view_manager/view_tree_node.h" +#include "ui/events/event_constants.h" #include "ui/gfx/canvas.h" namespace mojo { namespace examples { -class SampleApp : public Application { +namespace { + +std::string EventNameForAction(int32_t action) { + switch (action) { + case ui::ET_MOUSE_MOVED: + return "MouseMoved"; + case ui::ET_MOUSE_PRESSED: + return "MousePressed"; + case ui::ET_MOUSE_RELEASED: + return "MouseReleased"; + case ui::ET_MOUSE_DRAGGED: + return "MouseDragged"; + case ui::ET_KEY_PRESSED: + return "KeyPressed"; + case ui::ET_KEY_RELEASED: + return "KeyReleased"; + case ui::ET_TOUCH_PRESSED: + return "TouchPressed"; + case ui::ET_TOUCH_RELEASED: + return "TouchReleased"; + case ui::ET_TOUCH_MOVED: + return "TouchMoved"; + } + return "Other"; +} + +} // namespace + +class SampleApp : public Application, public mojo::view_manager::ViewObserver { public: SampleApp() {} virtual ~SampleApp() {} @@ -26,6 +57,7 @@ class SampleApp : public Application { view_manager_->Init(); view_manager::ViewTreeNode* node1 = view_manager::ViewTreeNode::Create(view_manager_.get()); + node1->SetBounds(gfx::Rect(800, 600)); view_manager::ViewTreeNode* node11 = view_manager::ViewTreeNode::Create(view_manager_.get()); node11->SetBounds(gfx::Rect(800, 600)); @@ -37,9 +69,24 @@ class SampleApp : public Application { node1->AddChild(node11); view11->SetColor(SK_ColorRED); + + view11->AddObserver(this); } private: + virtual void OnViewInputEvent(mojo::view_manager::View* view, + EventPtr event) OVERRIDE { + std::string event_name = EventNameForAction(event->action); + if (!event->location.is_null()) { + LOG(WARNING) << base::StringPrintf("Got %s @ %d,%d", + event_name.c_str(), + event->location->x, + event->location->y); + } else { + LOG(WARNING) << base::StringPrintf("Got %s", event_name.c_str()); + } + } + // SampleApp creates a ViewManager and a trivial node hierarchy. scoped_ptr<view_manager::ViewManager> view_manager_; diff --git a/mojo/mojo_services.gypi b/mojo/mojo_services.gypi index f94982c..2661724 100644 --- a/mojo/mojo_services.gypi +++ b/mojo/mojo_services.gypi @@ -15,6 +15,28 @@ ], }, { + 'target_name': 'mojo_input_events_lib', + 'type': '<(component)', + 'defines': [ + 'MOJO_INPUT_EVENTS_IMPLEMENTATION', + ], + 'dependencies': [ + '../base/base.gyp:base', + '../ui/events/events.gyp:events', + '../ui/gfx/gfx.gyp:gfx_geometry', + 'mojo_environment_chromium', + 'mojo_input_events_bindings', + 'mojo_geometry_bindings', + 'mojo_geometry_lib', + 'mojo_system_impl', + ], + 'sources': [ + 'services/public/cpp/input_events/lib/input_events_type_converters.cc', + 'services/public/cpp/input_events/input_events_type_converters.h', + 'services/public/cpp/input_events/mojo_input_events_export.h', + ], + }, + { 'target_name': 'mojo_input_events_bindings', 'type': 'static_library', 'sources': [ @@ -130,6 +152,7 @@ 'mojo_geometry_bindings', 'mojo_geometry_lib', 'mojo_gles2_service', + 'mojo_input_events_lib', 'mojo_native_viewport_bindings', 'mojo_system_impl', ], @@ -179,6 +202,7 @@ 'dependencies': [ 'mojo_cpp_bindings', 'mojo_geometry_bindings', + 'mojo_input_events_bindings', ], }, { @@ -271,6 +295,8 @@ 'mojo_geometry_bindings', 'mojo_geometry_lib', 'mojo_gles2', + 'mojo_input_events_bindings', + 'mojo_input_events_lib', 'mojo_launcher_bindings', 'mojo_main_chromium', 'mojo_native_viewport_bindings', @@ -330,6 +356,8 @@ 'mojo_environment_chromium', 'mojo_geometry_bindings', 'mojo_geometry_lib', + 'mojo_input_events_bindings', + 'mojo_input_events_lib', 'mojo_service_manager', 'mojo_shell_test_support', 'mojo_system_impl', diff --git a/mojo/services/native_viewport/DEPS b/mojo/services/native_viewport/DEPS index 739d17f..9afa382 100644 --- a/mojo/services/native_viewport/DEPS +++ b/mojo/services/native_viewport/DEPS @@ -1,5 +1,6 @@ include_rules = [ "+mojo/services/public/cpp/geometry", + "+mojo/services/public/cpp/input_events", "+mojo/services/gles2", "+ui/events", "+ui/gfx", diff --git a/mojo/services/native_viewport/native_viewport_service.cc b/mojo/services/native_viewport/native_viewport_service.cc index 336f497..e0465bc 100644 --- a/mojo/services/native_viewport/native_viewport_service.cc +++ b/mojo/services/native_viewport/native_viewport_service.cc @@ -5,6 +5,7 @@ #include "mojo/services/native_viewport/native_viewport_service.h" #include "base/macros.h" +#include "base/memory/weak_ptr.h" #include "base/message_loop/message_loop.h" #include "base/time/time.h" #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" @@ -12,6 +13,7 @@ #include "mojo/services/native_viewport/native_viewport.h" #include "mojo/services/native_viewport/native_viewport.mojom.h" #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" +#include "mojo/services/public/cpp/input_events/input_events_type_converters.h" #include "ui/events/event.h" namespace mojo { @@ -33,7 +35,8 @@ class NativeViewportImpl NativeViewportImpl(shell::Context* context) : context_(context), widget_(gfx::kNullAcceleratedWidget), - waiting_for_event_ack_(false) {} + waiting_for_event_ack_(false), + weak_factory_(this) {} virtual ~NativeViewportImpl() { // Destroy the NativeViewport early on as it may call us back during // destruction and we want to be in a known state. @@ -112,33 +115,10 @@ class NativeViewportImpl if (waiting_for_event_ack_ && IsRateLimitedEventType(ui_event)) return false; - EventPtr event(Event::New()); - event->action = ui_event->type(); - event->flags = ui_event->flags(); - event->time_stamp = ui_event->time_stamp().ToInternalValue(); - - if (ui_event->IsMouseEvent() || ui_event->IsTouchEvent()) { - ui::LocatedEvent* located_event = - static_cast<ui::LocatedEvent*>(ui_event); - event->location = Point::New(); - event->location->x = located_event->location().x(); - event->location->y = located_event->location().y(); - } - - if (ui_event->IsTouchEvent()) { - ui::TouchEvent* touch_event = static_cast<ui::TouchEvent*>(ui_event); - event->touch_data = TouchData::New(); - event->touch_data->pointer_id = touch_event->touch_id(); - } else if (ui_event->IsKeyEvent()) { - ui::KeyEvent* key_event = static_cast<ui::KeyEvent*>(ui_event); - event->key_data = KeyData::New(); - event->key_data->key_code = key_event->key_code(); - event->key_data->is_char = key_event->is_char(); - } - - client()->OnEvent(event.Pass(), - base::Bind(&NativeViewportImpl::AckEvent, - base::Unretained(this))); + client()->OnEvent( + TypeConverter<EventPtr, ui::Event>::ConvertFrom(*ui_event), + base::Bind(&NativeViewportImpl::AckEvent, + weak_factory_.GetWeakPtr())); waiting_for_event_ack_ = true; return false; } @@ -167,6 +147,7 @@ class NativeViewportImpl InterfaceRequest<CommandBuffer> command_buffer_request_; scoped_ptr<CommandBufferImpl> command_buffer_; bool waiting_for_event_ack_; + base::WeakPtrFactory<NativeViewportImpl> weak_factory_; }; } // namespace services diff --git a/mojo/services/public/cpp/input_events/DEPS b/mojo/services/public/cpp/input_events/DEPS new file mode 100644 index 0000000..fe1d98e --- /dev/null +++ b/mojo/services/public/cpp/input_events/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + "+ui/events", +] diff --git a/mojo/services/public/cpp/input_events/input_events_type_converters.h b/mojo/services/public/cpp/input_events/input_events_type_converters.h new file mode 100644 index 0000000..8829879 --- /dev/null +++ b/mojo/services/public/cpp/input_events/input_events_type_converters.h @@ -0,0 +1,22 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef MOJO_SERVICES_PUBLIC_CPP_INPUT_EVENTS_INPUT_EVENTS_TYPE_CONVERTERS_H_ +#define MOJO_SERVICES_PUBLIC_CPP_INPUT_EVENTS_INPUT_EVENTS_TYPE_CONVERTERS_H_ + +#include "mojo/services/public/cpp/input_events/mojo_input_events_export.h" +#include "mojo/services/public/interfaces/input_events/input_events.mojom.h" +#include "ui/events/event.h" + +namespace mojo { + +template<> +class MOJO_INPUT_EVENTS_EXPORT TypeConverter<EventPtr, ui::Event> { + public: + static EventPtr ConvertFrom(const ui::Event& input); +}; + +} // namespace mojo + +#endif // MOJO_SERVICES_PUBLIC_CPP_INPUT_EVENTS_INPUT_EVENTS_TYPE_CONVERTERS_H_ diff --git a/mojo/services/public/cpp/input_events/lib/input_events_type_converters.cc b/mojo/services/public/cpp/input_events/lib/input_events_type_converters.cc new file mode 100644 index 0000000..bc3a9c9 --- /dev/null +++ b/mojo/services/public/cpp/input_events/lib/input_events_type_converters.cc @@ -0,0 +1,44 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "mojo/services/public/cpp/input_events/input_events_type_converters.h" + +#include "mojo/services/public/cpp/geometry/geometry_type_converters.h" +#include "ui/events/keycodes/keyboard_codes.h" + +namespace mojo { + +// static +EventPtr TypeConverter<EventPtr, ui::Event>::ConvertFrom( + const ui::Event& input) { + EventPtr event(Event::New()); + event->action = input.type(); + event->flags = input.flags(); + event->time_stamp = input.time_stamp().ToInternalValue(); + + if (input.IsMouseEvent() || input.IsTouchEvent()) { + const ui::LocatedEvent* located_event = + static_cast<const ui::LocatedEvent*>(&input); + event->location = + TypeConverter<PointPtr, gfx::Point>::ConvertFrom( + located_event->location()); + } + + if (input.IsTouchEvent()) { + const ui::TouchEvent* touch_event = + static_cast<const ui::TouchEvent*>(&input); + TouchDataPtr touch_data(TouchData::New()); + touch_data->pointer_id = touch_event->touch_id(); + event->touch_data = touch_data.Pass(); + } else if (input.IsKeyEvent()) { + const ui::KeyEvent* key_event = static_cast<const ui::KeyEvent*>(&input); + KeyDataPtr key_data(KeyData::New()); + key_data->key_code = key_event->key_code(); + key_data->is_char = key_event->is_char(); + event->key_data = key_data.Pass(); + } + return event.Pass(); +} + +} // namespace mojo diff --git a/mojo/services/public/cpp/input_events/mojo_input_events_export.h b/mojo/services/public/cpp/input_events/mojo_input_events_export.h new file mode 100644 index 0000000..d7b193e --- /dev/null +++ b/mojo/services/public/cpp/input_events/mojo_input_events_export.h @@ -0,0 +1,32 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef MOJO_SERVICES_PUBLIC_CPP_INPUT_EVENTS_MOJO_INPUT_EVENTS_EXPORT_H_ +#define MOJO_SERVICES_PUBLIC_CPP_INPUT_EVENTS_MOJO_INPUT_EVENTS_EXPORT_H_ + +#if defined(COMPONENT_BUILD) + +#if defined(WIN32) + +#if defined(MOJO_INPUT_EVENTS_IMPLEMENTATION) +#define MOJO_INPUT_EVENTS_EXPORT __declspec(dllexport) +#else +#define MOJO_INPUT_EVENTS_EXPORT __declspec(dllimport) +#endif + +#else // !defined(WIN32) + +#if defined(MOJO_INPUT_EVENTS_IMPLEMENTATION) +#define MOJO_INPUT_EVENTS_EXPORT __attribute__((visibility("default"))) +#else +#define MOJO_INPUT_EVENTS_EXPORT +#endif + +#endif // defined(WIN32) + +#else // !defined(COMPONENT_BUILD) +#define MOJO_INPUT_EVENTS_EXPORT +#endif + +#endif // MOJO_SERVICES_PUBLIC_CPP_INPUT_EVENTS_MOJO_INPUT_EVENTS_EXPORT_H_ diff --git a/mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.cc b/mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.cc index 62cab23..fb9ea0e 100644 --- a/mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.cc +++ b/mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.cc @@ -12,6 +12,7 @@ #include "mojo/services/public/cpp/view_manager/lib/view_private.h" #include "mojo/services/public/cpp/view_manager/lib/view_tree_node_private.h" #include "mojo/services/public/cpp/view_manager/util.h" +#include "mojo/services/public/cpp/view_manager/view_observer.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/gfx/codec/png_codec.h" @@ -636,6 +637,20 @@ void ViewManagerSynchronizer::OnViewDeleted(uint32_t view_id) { ViewPrivate(view).LocalDestroy(); } +void ViewManagerSynchronizer::OnViewInputEvent( + uint32_t view_id, + EventPtr event, + const Callback<void()>& ack_callback) { + View* view = view_manager_->GetViewById(view_id); + if (view) { + FOR_EACH_OBSERVER(ViewObserver, + *ViewPrivate(view).observers(), + OnViewInputEvent(view, event.Pass())); + } + ack_callback.Run(); +} + + //////////////////////////////////////////////////////////////////////////////// // ViewManagerSynchronizer, private: diff --git a/mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h b/mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h index 887fef4..4f10836 100644 --- a/mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h +++ b/mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h @@ -88,6 +88,9 @@ class ViewManagerSynchronizer : public InterfaceImpl<IViewManagerClient> { uint32_t new_view_id, uint32_t old_view_id) OVERRIDE; virtual void OnViewDeleted(uint32_t view_id) OVERRIDE; + virtual void OnViewInputEvent(uint32_t view, + EventPtr event, + const Callback<void()>& callback) 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/cpp/view_manager/view_observer.h b/mojo/services/public/cpp/view_manager/view_observer.h index a2a6343..2e3571d 100644 --- a/mojo/services/public/cpp/view_manager/view_observer.h +++ b/mojo/services/public/cpp/view_manager/view_observer.h @@ -9,6 +9,8 @@ #include "base/basictypes.h" +#include "mojo/services/public/interfaces/input_events/input_events.mojom.h" + namespace mojo { namespace view_manager { @@ -23,6 +25,8 @@ class ViewObserver { virtual void OnViewDestroy(View* view, DispositionChangePhase phase) {} + virtual void OnViewInputEvent(View* view, EventPtr event) {} + protected: virtual ~ViewObserver() {} }; diff --git a/mojo/services/public/interfaces/view_manager/view_manager.mojom b/mojo/services/public/interfaces/view_manager/view_manager.mojom index d37b262..817a861 100644 --- a/mojo/services/public/interfaces/view_manager/view_manager.mojom +++ b/mojo/services/public/interfaces/view_manager/view_manager.mojom @@ -3,6 +3,7 @@ // found in the LICENSE file. import "../geometry/geometry.mojom" +import "../input_events/input_events.mojom" module mojo.view_manager { @@ -147,6 +148,9 @@ interface IViewManagerClient { // Invoked when a view is deleted. OnViewDeleted(uint32 view); + + // Invoked when an event is targeted at the specified view. + OnViewInputEvent(uint32 view, mojo.Event event) => (); }; } diff --git a/mojo/services/view_manager/node.cc b/mojo/services/view_manager/node.cc index 670012a..208c9c7 100644 --- a/mojo/services/view_manager/node.cc +++ b/mojo/services/view_manager/node.cc @@ -172,6 +172,11 @@ bool Node::HasHitTestMask() const { void Node::GetHitTestMask(gfx::Path* mask) const { } +void Node::OnEvent(ui::Event* event) { + if (view_) + delegate_->OnViewInputEvent(view_, event); +} + } // namespace service } // namespace view_manager } // namespace mojo diff --git a/mojo/services/view_manager/node.h b/mojo/services/view_manager/node.h index f5896fd..533bc3b 100644 --- a/mojo/services/view_manager/node.h +++ b/mojo/services/view_manager/node.h @@ -86,6 +86,9 @@ class MOJO_VIEW_MANAGER_EXPORT Node virtual bool HasHitTestMask() const OVERRIDE; virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE; + // ui::EventHandler overrides: + virtual void OnEvent(ui::Event* event) OVERRIDE; + NodeDelegate* delegate_; const NodeId id_; diff --git a/mojo/services/view_manager/node_delegate.h b/mojo/services/view_manager/node_delegate.h index 1079dd8..d63acc9 100644 --- a/mojo/services/view_manager/node_delegate.h +++ b/mojo/services/view_manager/node_delegate.h @@ -7,6 +7,10 @@ #include "mojo/services/view_manager/view_manager_export.h" +namespace ui { +class Event; +} + namespace mojo { namespace view_manager { namespace service { @@ -26,6 +30,10 @@ class MOJO_VIEW_MANAGER_EXPORT NodeDelegate { const View* new_view, const View* old_view) = 0; + // Invoked when an input event is received by the View at this node. + virtual void OnViewInputEvent(const View* view, + const ui::Event* event) = 0; + protected: virtual ~NodeDelegate() {} }; diff --git a/mojo/services/view_manager/root_node_manager.cc b/mojo/services/view_manager/root_node_manager.cc index 5fa9168..b5fb8c5 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/view_manager/view.h" #include "mojo/services/view_manager/view_manager_connection.h" #include "ui/aura/env.h" @@ -197,6 +198,11 @@ void RootNodeManager::OnNodeViewReplaced(const Node* node, ProcessNodeViewReplaced(node, new_view, old_view); } +void RootNodeManager::OnViewInputEvent(const View* view, + const ui::Event* event) { + GetConnection(view->id().connection_id)->ProcessViewInputEvent(view, event); +} + } // namespace service } // namespace view_manager } // namespace mojo diff --git a/mojo/services/view_manager/root_node_manager.h b/mojo/services/view_manager/root_node_manager.h index 1598e0d..6581fed 100644 --- a/mojo/services/view_manager/root_node_manager.h +++ b/mojo/services/view_manager/root_node_manager.h @@ -16,6 +16,10 @@ #include "mojo/services/view_manager/root_view_manager.h" #include "mojo/services/view_manager/view_manager_export.h" +namespace ui { +class Event; +} + namespace mojo { class ServiceProvider; @@ -169,6 +173,8 @@ class MOJO_VIEW_MANAGER_EXPORT RootNodeManager : public NodeDelegate { virtual void OnNodeViewReplaced(const Node* node, const View* new_view, const View* old_view) OVERRIDE; + virtual void OnViewInputEvent(const View* view, + const ui::Event* event) OVERRIDE; Context context_; diff --git a/mojo/services/view_manager/test_change_tracker.cc b/mojo/services/view_manager/test_change_tracker.cc index 0b6b839..1fb2e7e 100644 --- a/mojo/services/view_manager/test_change_tracker.cc +++ b/mojo/services/view_manager/test_change_tracker.cc @@ -66,6 +66,12 @@ std::string ChangeToDescription1(const Change& change) { NodeIdToString(change.node_id).c_str(), NodeIdToString(change.view_id).c_str(), NodeIdToString(change.view_id2).c_str()); + + case CHANGE_TYPE_INPUT_EVENT: + return base::StringPrintf( + "InputEvent view=%s event_action=%d", + NodeIdToString(change.view_id).c_str(), + change.event_action); } return std::string(); } @@ -108,7 +114,8 @@ Change::Change() node_id2(0), node_id3(0), view_id(0), - view_id2(0) {} + view_id2(0), + event_action(0) {} Change::~Change() { } @@ -195,6 +202,14 @@ void TestChangeTracker::OnNodeViewReplaced(TransportNodeId node_id, AddChange(change); } +void TestChangeTracker::OnViewInputEvent(TransportViewId view_id, + EventPtr event) { + Change change; + change.type = CHANGE_TYPE_INPUT_EVENT; + change.view_id = view_id; + change.event_action = event->action; +} + void TestChangeTracker::AddChange(const Change& change) { changes_.push_back(change); if (delegate_) diff --git a/mojo/services/view_manager/test_change_tracker.h b/mojo/services/view_manager/test_change_tracker.h index 52a38a4..02189de 100644 --- a/mojo/services/view_manager/test_change_tracker.h +++ b/mojo/services/view_manager/test_change_tracker.h @@ -25,6 +25,7 @@ enum ChangeType { CHANGE_TYPE_NODE_DELETED, CHANGE_TYPE_VIEW_DELETED, CHANGE_TYPE_VIEW_REPLACED, + CHANGE_TYPE_INPUT_EVENT, }; struct TestNode { @@ -53,6 +54,7 @@ struct Change { TransportViewId view_id2; gfx::Rect bounds; gfx::Rect bounds2; + int32 event_action; }; // Converts Changes to string descriptions. @@ -109,6 +111,7 @@ class TestChangeTracker { void OnNodeViewReplaced(TransportNodeId node_id, TransportViewId new_view_id, TransportViewId old_view_id); + void OnViewInputEvent(TransportViewId view_id, EventPtr event); private: void AddChange(const Change& change); diff --git a/mojo/services/view_manager/view_manager_connection.cc b/mojo/services/view_manager/view_manager_connection.cc index 08831ba..52a3904 100644 --- a/mojo/services/view_manager/view_manager_connection.cc +++ b/mojo/services/view_manager/view_manager_connection.cc @@ -4,8 +4,10 @@ #include "mojo/services/view_manager/view_manager_connection.h" +#include "base/bind.h" #include "base/stl_util.h" #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" +#include "mojo/services/public/cpp/input_events/input_events_type_converters.h" #include "mojo/services/view_manager/node.h" #include "mojo/services/view_manager/root_node_manager.h" #include "mojo/services/view_manager/view.h" @@ -202,6 +204,15 @@ void ViewManagerConnection::ProcessViewDeleted(const ViewId& view, client()->OnViewDeleted(ViewIdToTransportId(view)); } +void ViewManagerConnection::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 ViewManagerConnection::OnConnectionError() { if (delete_on_connection_error_) delete this; @@ -618,6 +629,14 @@ void ViewManagerConnection::OnNodeViewReplaced(const Node* node, root_node_manager_->ProcessNodeViewReplaced(node, new_view, old_view); } +void ViewManagerConnection::OnViewInputEvent(const View* view, + const ui::Event* event) { + ViewManagerConnection* connection = root_node_manager_->GetConnection( + view->id().connection_id); + DCHECK(connection); + connection->ProcessViewInputEvent(view, event); +} + void ViewManagerConnection::OnConnectionEstablished() { root_node_manager_->AddConnection(this); diff --git a/mojo/services/view_manager/view_manager_connection.h b/mojo/services/view_manager/view_manager_connection.h index 5b3d985..617fedc 100644 --- a/mojo/services/view_manager/view_manager_connection.h +++ b/mojo/services/view_manager/view_manager_connection.h @@ -85,6 +85,7 @@ class MOJO_VIEW_MANAGER_EXPORT ViewManagerConnection TransportChangeId 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). @@ -183,6 +184,8 @@ class MOJO_VIEW_MANAGER_EXPORT ViewManagerConnection virtual void OnNodeViewReplaced(const Node* node, const View* new_view, const View* old_view) OVERRIDE; + virtual void OnViewInputEvent(const View* view, + const ui::Event* event) OVERRIDE; // InterfaceImp overrides: virtual void OnConnectionEstablished() MOJO_OVERRIDE; diff --git a/mojo/services/view_manager/view_manager_connection_unittest.cc b/mojo/services/view_manager/view_manager_connection_unittest.cc index 61a203a..05308ac 100644 --- a/mojo/services/view_manager/view_manager_connection_unittest.cc +++ b/mojo/services/view_manager/view_manager_connection_unittest.cc @@ -317,6 +317,11 @@ class TestViewManagerClientConnection TransportViewId old_view_id) OVERRIDE { tracker_.OnNodeViewReplaced(node, new_view_id, old_view_id); } + virtual void OnViewInputEvent(TransportViewId view_id, + EventPtr event, + const Callback<void()>& callback) OVERRIDE { + tracker_.OnViewInputEvent(view_id, event.Pass()); + } private: TestChangeTracker tracker_; |