Commit 4a7d4ac8 authored by sky@chromium.org's avatar sky@chromium.org

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
parent ed8eb799
...@@ -143,6 +143,10 @@ class IViewManagerClientImpl ...@@ -143,6 +143,10 @@ class IViewManagerClientImpl
} }
virtual void OnViewDeleted(uint32_t view) OVERRIDE { virtual void OnViewDeleted(uint32_t view) OVERRIDE {
} }
virtual void OnViewInputEvent(uint32_t view_id,
EventPtr event,
const Callback<void()>& callback) OVERRIDE {
}
AuraDemo* aura_demo_; AuraDemo* aura_demo_;
......
include_rules = [ include_rules = [
"+ui/events",
"+ui/gfx", "+ui/gfx",
] ]
...@@ -4,19 +4,50 @@ ...@@ -4,19 +4,50 @@
#include "base/at_exit.h" #include "base/at_exit.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/strings/stringprintf.h"
#include "mojo/public/cpp/application/application.h" #include "mojo/public/cpp/application/application.h"
#include "mojo/public/cpp/environment/environment.h" #include "mojo/public/cpp/environment/environment.h"
#include "mojo/public/cpp/system/core.h" #include "mojo/public/cpp/system/core.h"
#include "mojo/public/cpp/system/macros.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.h"
#include "mojo/services/public/cpp/view_manager/view_manager.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 "mojo/services/public/cpp/view_manager/view_tree_node.h"
#include "ui/events/event_constants.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
namespace mojo { namespace mojo {
namespace examples { 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: public:
SampleApp() {} SampleApp() {}
virtual ~SampleApp() {} virtual ~SampleApp() {}
...@@ -26,6 +57,7 @@ class SampleApp : public Application { ...@@ -26,6 +57,7 @@ class SampleApp : public Application {
view_manager_->Init(); view_manager_->Init();
view_manager::ViewTreeNode* node1 = view_manager::ViewTreeNode* node1 =
view_manager::ViewTreeNode::Create(view_manager_.get()); view_manager::ViewTreeNode::Create(view_manager_.get());
node1->SetBounds(gfx::Rect(800, 600));
view_manager::ViewTreeNode* node11 = view_manager::ViewTreeNode* node11 =
view_manager::ViewTreeNode::Create(view_manager_.get()); view_manager::ViewTreeNode::Create(view_manager_.get());
node11->SetBounds(gfx::Rect(800, 600)); node11->SetBounds(gfx::Rect(800, 600));
...@@ -37,9 +69,24 @@ class SampleApp : public Application { ...@@ -37,9 +69,24 @@ class SampleApp : public Application {
node1->AddChild(node11); node1->AddChild(node11);
view11->SetColor(SK_ColorRED); view11->SetColor(SK_ColorRED);
view11->AddObserver(this);
} }
private: 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. // SampleApp creates a ViewManager and a trivial node hierarchy.
scoped_ptr<view_manager::ViewManager> view_manager_; scoped_ptr<view_manager::ViewManager> view_manager_;
......
...@@ -14,6 +14,28 @@ ...@@ -14,6 +14,28 @@
'mojo_cpp_bindings', 'mojo_cpp_bindings',
], ],
}, },
{
'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', 'target_name': 'mojo_input_events_bindings',
'type': 'static_library', 'type': 'static_library',
...@@ -130,6 +152,7 @@ ...@@ -130,6 +152,7 @@
'mojo_geometry_bindings', 'mojo_geometry_bindings',
'mojo_geometry_lib', 'mojo_geometry_lib',
'mojo_gles2_service', 'mojo_gles2_service',
'mojo_input_events_lib',
'mojo_native_viewport_bindings', 'mojo_native_viewport_bindings',
'mojo_system_impl', 'mojo_system_impl',
], ],
...@@ -179,6 +202,7 @@ ...@@ -179,6 +202,7 @@
'dependencies': [ 'dependencies': [
'mojo_cpp_bindings', 'mojo_cpp_bindings',
'mojo_geometry_bindings', 'mojo_geometry_bindings',
'mojo_input_events_bindings',
], ],
}, },
{ {
...@@ -271,6 +295,8 @@ ...@@ -271,6 +295,8 @@
'mojo_geometry_bindings', 'mojo_geometry_bindings',
'mojo_geometry_lib', 'mojo_geometry_lib',
'mojo_gles2', 'mojo_gles2',
'mojo_input_events_bindings',
'mojo_input_events_lib',
'mojo_launcher_bindings', 'mojo_launcher_bindings',
'mojo_main_chromium', 'mojo_main_chromium',
'mojo_native_viewport_bindings', 'mojo_native_viewport_bindings',
...@@ -330,6 +356,8 @@ ...@@ -330,6 +356,8 @@
'mojo_environment_chromium', 'mojo_environment_chromium',
'mojo_geometry_bindings', 'mojo_geometry_bindings',
'mojo_geometry_lib', 'mojo_geometry_lib',
'mojo_input_events_bindings',
'mojo_input_events_lib',
'mojo_service_manager', 'mojo_service_manager',
'mojo_shell_test_support', 'mojo_shell_test_support',
'mojo_system_impl', 'mojo_system_impl',
......
include_rules = [ include_rules = [
"+mojo/services/public/cpp/geometry", "+mojo/services/public/cpp/geometry",
"+mojo/services/public/cpp/input_events",
"+mojo/services/gles2", "+mojo/services/gles2",
"+ui/events", "+ui/events",
"+ui/gfx", "+ui/gfx",
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "mojo/services/native_viewport/native_viewport_service.h" #include "mojo/services/native_viewport/native_viewport_service.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "mojo/public/interfaces/service_provider/service_provider.mojom.h" #include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
...@@ -12,6 +13,7 @@ ...@@ -12,6 +13,7 @@
#include "mojo/services/native_viewport/native_viewport.h" #include "mojo/services/native_viewport/native_viewport.h"
#include "mojo/services/native_viewport/native_viewport.mojom.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/geometry/geometry_type_converters.h"
#include "mojo/services/public/cpp/input_events/input_events_type_converters.h"
#include "ui/events/event.h" #include "ui/events/event.h"
namespace mojo { namespace mojo {
...@@ -33,7 +35,8 @@ class NativeViewportImpl ...@@ -33,7 +35,8 @@ class NativeViewportImpl
NativeViewportImpl(shell::Context* context) NativeViewportImpl(shell::Context* context)
: context_(context), : context_(context),
widget_(gfx::kNullAcceleratedWidget), widget_(gfx::kNullAcceleratedWidget),
waiting_for_event_ack_(false) {} waiting_for_event_ack_(false),
weak_factory_(this) {}
virtual ~NativeViewportImpl() { virtual ~NativeViewportImpl() {
// Destroy the NativeViewport early on as it may call us back during // Destroy the NativeViewport early on as it may call us back during
// destruction and we want to be in a known state. // destruction and we want to be in a known state.
...@@ -112,33 +115,10 @@ class NativeViewportImpl ...@@ -112,33 +115,10 @@ class NativeViewportImpl
if (waiting_for_event_ack_ && IsRateLimitedEventType(ui_event)) if (waiting_for_event_ack_ && IsRateLimitedEventType(ui_event))
return false; return false;
EventPtr event(Event::New()); client()->OnEvent(
event->action = ui_event->type(); TypeConverter<EventPtr, ui::Event>::ConvertFrom(*ui_event),
event->flags = ui_event->flags(); base::Bind(&NativeViewportImpl::AckEvent,
event->time_stamp = ui_event->time_stamp().ToInternalValue(); weak_factory_.GetWeakPtr()));
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)));
waiting_for_event_ack_ = true; waiting_for_event_ack_ = true;
return false; return false;
} }
...@@ -167,6 +147,7 @@ class NativeViewportImpl ...@@ -167,6 +147,7 @@ class NativeViewportImpl
InterfaceRequest<CommandBuffer> command_buffer_request_; InterfaceRequest<CommandBuffer> command_buffer_request_;
scoped_ptr<CommandBufferImpl> command_buffer_; scoped_ptr<CommandBufferImpl> command_buffer_;
bool waiting_for_event_ack_; bool waiting_for_event_ack_;
base::WeakPtrFactory<NativeViewportImpl> weak_factory_;
}; };
} // namespace services } // namespace services
......
include_rules = [
"+ui/events",
]
// 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_
// 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
// 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_
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "mojo/services/public/cpp/view_manager/lib/view_private.h" #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/lib/view_tree_node_private.h"
#include "mojo/services/public/cpp/view_manager/util.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 "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/codec/png_codec.h" #include "ui/gfx/codec/png_codec.h"
...@@ -636,6 +637,20 @@ void ViewManagerSynchronizer::OnViewDeleted(uint32_t view_id) { ...@@ -636,6 +637,20 @@ void ViewManagerSynchronizer::OnViewDeleted(uint32_t view_id) {
ViewPrivate(view).LocalDestroy(); 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: // ViewManagerSynchronizer, private:
......
...@@ -88,6 +88,9 @@ class ViewManagerSynchronizer : public InterfaceImpl<IViewManagerClient> { ...@@ -88,6 +88,9 @@ class ViewManagerSynchronizer : public InterfaceImpl<IViewManagerClient> {
uint32_t new_view_id, uint32_t new_view_id,
uint32_t old_view_id) OVERRIDE; uint32_t old_view_id) OVERRIDE;
virtual void OnViewDeleted(uint32_t 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 // Sync the client model with the service by enumerating the pending
// transaction queue and applying them in order. // transaction queue and applying them in order.
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include "base/basictypes.h" #include "base/basictypes.h"
#include "mojo/services/public/interfaces/input_events/input_events.mojom.h"
namespace mojo { namespace mojo {
namespace view_manager { namespace view_manager {
...@@ -23,6 +25,8 @@ class ViewObserver { ...@@ -23,6 +25,8 @@ class ViewObserver {
virtual void OnViewDestroy(View* view, DispositionChangePhase phase) {} virtual void OnViewDestroy(View* view, DispositionChangePhase phase) {}
virtual void OnViewInputEvent(View* view, EventPtr event) {}
protected: protected:
virtual ~ViewObserver() {} virtual ~ViewObserver() {}
}; };
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
import "../geometry/geometry.mojom" import "../geometry/geometry.mojom"
import "../input_events/input_events.mojom"
module mojo.view_manager { module mojo.view_manager {
...@@ -147,6 +148,9 @@ interface IViewManagerClient { ...@@ -147,6 +148,9 @@ interface IViewManagerClient {
// Invoked when a view is deleted. // Invoked when a view is deleted.
OnViewDeleted(uint32 view); OnViewDeleted(uint32 view);
// Invoked when an event is targeted at the specified view.
OnViewInputEvent(uint32 view, mojo.Event event) => ();
}; };
} }
...@@ -172,6 +172,11 @@ bool Node::HasHitTestMask() const { ...@@ -172,6 +172,11 @@ bool Node::HasHitTestMask() const {
void Node::GetHitTestMask(gfx::Path* mask) const { void Node::GetHitTestMask(gfx::Path* mask) const {
} }
void Node::OnEvent(ui::Event* event) {
if (view_)
delegate_->OnViewInputEvent(view_, event);
}
} // namespace service } // namespace service
} // namespace view_manager } // namespace view_manager
} // namespace mojo } // namespace mojo
...@@ -86,6 +86,9 @@ class MOJO_VIEW_MANAGER_EXPORT Node ...@@ -86,6 +86,9 @@ class MOJO_VIEW_MANAGER_EXPORT Node
virtual bool HasHitTestMask() const OVERRIDE; virtual bool HasHitTestMask() const OVERRIDE;
virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE; virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE;
// ui::EventHandler overrides:
virtual void OnEvent(ui::Event* event) OVERRIDE;
NodeDelegate* delegate_; NodeDelegate* delegate_;
const NodeId id_; const NodeId id_;
......
...@@ -7,6 +7,10 @@ ...@@ -7,6 +7,10 @@
#include "mojo/services/view_manager/view_manager_export.h" #include "mojo/services/view_manager/view_manager_export.h"
namespace ui {
class Event;
}
namespace mojo { namespace mojo {
namespace view_manager { namespace view_manager {
namespace service { namespace service {
...@@ -26,6 +30,10 @@ class MOJO_VIEW_MANAGER_EXPORT NodeDelegate { ...@@ -26,6 +30,10 @@ class MOJO_VIEW_MANAGER_EXPORT NodeDelegate {
const View* new_view, const View* new_view,
const View* old_view) = 0; 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: protected:
virtual ~NodeDelegate() {} virtual ~NodeDelegate() {}
}; };
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "mojo/public/interfaces/service_provider/service_provider.mojom.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 "mojo/services/view_manager/view_manager_connection.h"
#include "ui/aura/env.h" #include "ui/aura/env.h"
...@@ -197,6 +198,11 @@ void RootNodeManager::OnNodeViewReplaced(const Node* node, ...@@ -197,6 +198,11 @@ void RootNodeManager::OnNodeViewReplaced(const Node* node,
ProcessNodeViewReplaced(node, new_view, old_view); 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 service
} // namespace view_manager } // namespace view_manager
} // namespace mojo } // namespace mojo
...@@ -16,6 +16,10 @@ ...@@ -16,6 +16,10 @@
#include "mojo/services/view_manager/root_view_manager.h" #include "mojo/services/view_manager/root_view_manager.h"
#include "mojo/services/view_manager/view_manager_export.h" #include "mojo/services/view_manager/view_manager_export.h"
namespace ui {
class Event;
}
namespace mojo { namespace mojo {
class ServiceProvider; class ServiceProvider;
...@@ -169,6 +173,8 @@ class MOJO_VIEW_MANAGER_EXPORT RootNodeManager : public NodeDelegate { ...@@ -169,6 +173,8 @@ class MOJO_VIEW_MANAGER_EXPORT RootNodeManager : public NodeDelegate {
virtual void OnNodeViewReplaced(const Node* node, virtual void OnNodeViewReplaced(const Node* node,
const View* new_view, const View* new_view,
const View* old_view) OVERRIDE; const View* old_view) OVERRIDE;
virtual void OnViewInputEvent(const View* view,
const ui::Event* event) OVERRIDE;
Context context_; Context context_;
......
...@@ -66,6 +66,12 @@ std::string ChangeToDescription1(const Change& change) { ...@@ -66,6 +66,12 @@ std::string ChangeToDescription1(const Change& change) {
NodeIdToString(change.node_id).c_str(), NodeIdToString(change.node_id).c_str(),
NodeIdToString(change.view_id).c_str(), NodeIdToString(change.view_id).c_str(),
NodeIdToString(change.view_id2).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(); return std::string();
} }
...@@ -108,7 +114,8 @@ Change::Change() ...@@ -108,7 +114,8 @@ Change::Change()
node_id2(0), node_id2(0),
node_id3(0), node_id3(0),
view_id(0), view_id(0),
view_id2(0) {} view_id2(0),
event_action(0) {}
Change::~Change() { Change::~Change() {
} }
...@@ -195,6 +202,14 @@ void TestChangeTracker::OnNodeViewReplaced(TransportNodeId node_id, ...@@ -195,6 +202,14 @@ void TestChangeTracker::OnNodeViewReplaced(TransportNodeId node_id,
AddChange(change); 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) { void TestChangeTracker::AddChange(const Change& change) {
changes_.push_back(change); changes_.push_back(change);
if (delegate_) if (delegate_)
......
...@@ -25,6 +25,7 @@ enum ChangeType { ...@@ -25,6 +25,7 @@ enum ChangeType {
CHANGE_TYPE_NODE_DELETED, CHANGE_TYPE_NODE_DELETED,
CHANGE_TYPE_VIEW_DELETED, CHANGE_TYPE_VIEW_DELETED,
CHANGE_TYPE_VIEW_REPLACED, CHANGE_TYPE_VIEW_REPLACED,
CHANGE_TYPE_INPUT_EVENT,
}; };
struct TestNode { struct TestNode {
...@@ -53,6 +54,7 @@ struct Change { ...@@ -53,6 +54,7 @@ struct Change {
TransportViewId view_id2; TransportViewId view_id2;
gfx::Rect bounds; gfx::Rect bounds;
gfx::Rect bounds2; gfx::Rect bounds2;
int32 event_action;
}; };
// Converts Changes to string descriptions. // Converts Changes to string descriptions.
...@@ -109,6 +111,7 @@ class TestChangeTracker { ...@@ -109,6 +111,7 @@ class TestChangeTracker {
void OnNodeViewReplaced(TransportNodeId node_id, void OnNodeViewReplaced(TransportNodeId node_id,
TransportViewId new_view_id, TransportViewId new_view_id,
TransportViewId old_view_id); TransportViewId old_view_id);
void OnViewInputEvent(TransportViewId view_id, EventPtr event);
private: private:
void AddChange(const Change& change); void AddChange(const Change& change);
......
...@@ -4,8 +4,10 @@ ...@@ -4,8 +4,10 @@
#include "mojo/services/view_manager/view_manager_connection.h" #include "mojo/services/view_manager/view_manager_connection.h"
#include "base/bind.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "mojo/services/public/cpp/geometry/geometry_type_converters.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/node.h"
#include "mojo/services/view_manager/root_node_manager.h" #include "mojo/services/view_manager/root_node_manager.h"
#include "mojo/services/view_manager/view.h" #include "mojo/services/view_manager/view.h"
...@@ -202,6 +204,15 @@ void ViewManagerConnection::ProcessViewDeleted(const ViewId& view, ...@@ -202,6 +204,15 @@ void ViewManagerConnection::ProcessViewDeleted(const ViewId& view,
client()->OnViewDeleted(ViewIdToTransportId(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() { void ViewManagerConnection::OnConnectionError() {
if (delete_on_connection_error_) if (delete_on_connection_error_)
delete this; delete this;
...@@ -618,6 +629,14 @@ void ViewManagerConnection::OnNodeViewReplaced(const Node* node, ...@@ -618,6 +629,14 @@ void ViewManagerConnection::OnNodeViewReplaced(const Node* node,
root_node_manager_->ProcessNodeViewReplaced(node, new_view, old_view); 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() { void ViewManagerConnection::OnConnectionEstablished() {
root_node_manager_->AddConnection(this); root_node_manager_->AddConnection(this);
......
...@@ -85,6 +85,7 @@ class MOJO_VIEW_MANAGER_EXPORT ViewManagerConnection ...@@ -85,6 +85,7 @@ class MOJO_VIEW_MANAGER_EXPORT ViewManagerConnection
TransportChangeId server_change_id, TransportChangeId server_change_id,
bool originated_change); bool originated_change);
void ProcessViewDeleted(const ViewId& view, 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 // TODO(sky): move this to private section (currently can't because of
// bindings). // bindings).
...@@ -183,6 +184,8 @@ class MOJO_VIEW_MANAGER_EXPORT ViewManagerConnection ...@@ -183,6 +184,8 @@ class MOJO_VIEW_MANAGER_EXPORT ViewManagerConnection
virtual void OnNodeViewReplaced(const Node* node, virtual void OnNodeViewReplaced(const Node* node,
const View* new_view, const View* new_view,
const View* old_view) OVERRIDE; const View* old_view) OVERRIDE;
virtual void OnViewInputEvent(const View* view,
const ui::Event* event) OVERRIDE;
// InterfaceImp overrides: // InterfaceImp overrides:
virtual void OnConnectionEstablished() MOJO_OVERRIDE; virtual void OnConnectionEstablished() MOJO_OVERRIDE;
......
...@@ -317,6 +317,11 @@ class TestViewManagerClientConnection ...@@ -317,6 +317,11 @@ class TestViewManagerClientConnection
TransportViewId old_view_id) OVERRIDE { TransportViewId old_view_id) OVERRIDE {
tracker_.OnNodeViewReplaced(node, new_view_id, old_view_id); 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: private:
TestChangeTracker tracker_; TestChangeTracker tracker_;
......
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