summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordenniskempin <denniskempin@google.com>2015-12-08 18:42:27 -0800
committerCommit bot <commit-bot@chromium.org>2015-12-09 02:43:06 +0000
commit3b12f96225546fdcae48735e15db9124ce2add95 (patch)
tree9a8214e8b5cc535c12b4c40f7bae4607975a4516
parent8f69333a8335449148da20ea438768913a40abf2 (diff)
downloadchromium_src-3b12f96225546fdcae48735e15db9124ce2add95.zip
chromium_src-3b12f96225546fdcae48735e15db9124ce2add95.tar.gz
chromium_src-3b12f96225546fdcae48735e15db9124ce2add95.tar.bz2
This CL adds the ArcInputBridge which hooks into
aura::Windows that are running ARC applications to translate and transmit their ui::Events to the ARC instance. BUG=chromium:558499 TEST=Mouse, Touch and Keyboard events should be properly working on an ARC application window. Review URL: https://codereview.chromium.org/1408263006 Cr-Commit-Position: refs/heads/master@{#363941}
-rw-r--r--components/arc.gypi5
-rw-r--r--components/arc/BUILD.gn9
-rw-r--r--components/arc/arc_service_manager.cc2
-rw-r--r--components/arc/arc_service_manager.h2
-rw-r--r--components/arc/input/DEPS4
-rw-r--r--components/arc/input/arc_input_bridge.h43
-rw-r--r--components/arc/input/arc_input_bridge_impl.cc365
-rw-r--r--components/arc/input/arc_input_bridge_impl.h133
8 files changed, 563 insertions, 0 deletions
diff --git a/components/arc.gypi b/components/arc.gypi
index 8af8626..62cc463 100644
--- a/components/arc.gypi
+++ b/components/arc.gypi
@@ -16,6 +16,8 @@
'../base/base.gyp:base',
'../chromeos/chromeos.gyp:chromeos',
'../ipc/ipc.gyp:ipc',
+ '../ui/aura/aura.gyp:aura',
+ '../ui/events/events.gyp:events_base',
],
'sources': [
'arc/arc_bridge_bootstrap.cc',
@@ -26,6 +28,9 @@
'arc/arc_bridge_service_impl.h',
'arc/arc_service_manager.cc',
'arc/arc_service_manager.h',
+ 'arc/input/arc_input_bridge.h',
+ 'arc/input/arc_input_bridge_impl.cc',
+ 'arc/input/arc_input_bridge_impl.h',
],
},
{
diff --git a/components/arc/BUILD.gn b/components/arc/BUILD.gn
index 3d53493..0a518f5 100644
--- a/components/arc/BUILD.gn
+++ b/components/arc/BUILD.gn
@@ -14,6 +14,9 @@ static_library("arc") {
"arc_bridge_service_impl.h",
"arc_service_manager.cc",
"arc_service_manager.h",
+ "input/arc_input_bridge.h",
+ "input/arc_input_bridge_impl.cc",
+ "input/arc_input_bridge_impl.h",
]
deps = [
@@ -24,6 +27,9 @@ static_library("arc") {
"//ipc:ipc",
"//ipc/mojo:mojo",
"//third_party/mojo/src/mojo/edk/system",
+ "//ui/aura",
+ "//ui/events",
+ "//ui/events:dom_keycode_converter",
]
}
@@ -65,5 +71,8 @@ source_set("unit_tests") {
"//mojo/public/cpp/environment:environment",
"//mojo/public/cpp/system:system",
"//testing/gtest",
+ "//ui/aura",
+ "//ui/events",
+ "//ui/events:dom_keycode_converter",
]
}
diff --git a/components/arc/arc_service_manager.cc b/components/arc/arc_service_manager.cc
index 7927b55..2fc0e00 100644
--- a/components/arc/arc_service_manager.cc
+++ b/components/arc/arc_service_manager.cc
@@ -8,6 +8,7 @@
#include "base/thread_task_runner_handle.h"
#include "components/arc/arc_bridge_bootstrap.h"
#include "components/arc/arc_bridge_service_impl.h"
+#include "components/arc/input/arc_input_bridge.h"
namespace arc {
@@ -22,6 +23,7 @@ ArcServiceManager::ArcServiceManager()
: arc_bridge_service_(
new ArcBridgeServiceImpl(ArcBridgeBootstrap::Create())) {
DCHECK(!g_arc_service_manager);
+ arc_input_bridge_ = ArcInputBridge::Create(arc_bridge_service_.get());
g_arc_service_manager = this;
}
diff --git a/components/arc/arc_service_manager.h b/components/arc/arc_service_manager.h
index 1bffa89..ed4b434 100644
--- a/components/arc/arc_service_manager.h
+++ b/components/arc/arc_service_manager.h
@@ -12,6 +12,7 @@
namespace arc {
class ArcBridgeService;
+class ArcInputBridge;
// Manages creation and destruction of services that communicate with the ARC
// instance via the ArcBridgeService.
@@ -31,6 +32,7 @@ class ArcServiceManager {
private:
base::ThreadChecker thread_checker_;
scoped_ptr<ArcBridgeService> arc_bridge_service_;
+ scoped_ptr<ArcInputBridge> arc_input_bridge_;
DISALLOW_COPY_AND_ASSIGN(ArcServiceManager);
};
diff --git a/components/arc/input/DEPS b/components/arc/input/DEPS
new file mode 100644
index 0000000..6c46762
--- /dev/null
+++ b/components/arc/input/DEPS
@@ -0,0 +1,4 @@
+include_rules = [
+ "+ui/aura",
+ "+ui/events",
+]
diff --git a/components/arc/input/arc_input_bridge.h b/components/arc/input/arc_input_bridge.h
new file mode 100644
index 0000000..1082dc4
--- /dev/null
+++ b/components/arc/input/arc_input_bridge.h
@@ -0,0 +1,43 @@
+// Copyright 2015 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 COMPONENTS_EXO_ARC_INPUT_ARC_INPUT_BRIDGE_H_
+#define COMPONENTS_EXO_ARC_INPUT_ARC_INPUT_BRIDGE_H_
+
+#include "base/macros.h"
+#include "components/arc/arc_bridge_service.h"
+
+namespace arc {
+
+class ArcBridgeService;
+
+// The ArcInputBridge is responsible for sending input events from ARC windows
+// to the ARC instance.
+// It hooks into aura::Env to watch for ExoSurface windows that are running ARC
+// applications. On those windows the input bridge will attach an EventPreTarget
+// to capture all input events.
+// To send those events to the ARC instance it will create bridge input devices
+// through the ArcBridgeService, which will provide a file descriptor to which
+// we can send linux input_event's.
+// ui::Events to the ARC windows are translated to linux input_event's, which
+// are then sent through the respective file descriptor.
+class ArcInputBridge {
+ public:
+ virtual ~ArcInputBridge() {}
+
+ // Creates a new instance of ArcInputBridge. It will register an Observer
+ // with aura::Env and the ArcBridgeService.
+ static scoped_ptr<ArcInputBridge> Create(
+ ArcBridgeService* arc_bridge_service);
+
+ protected:
+ ArcInputBridge() {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ArcInputBridge);
+};
+
+} // namespace arc
+
+#endif // COMPONENTS_EXO_ARC_INPUT_ARC_INPUT_BRIDGE_H_
diff --git a/components/arc/input/arc_input_bridge_impl.cc b/components/arc/input/arc_input_bridge_impl.cc
new file mode 100644
index 0000000..c5a0065
--- /dev/null
+++ b/components/arc/input/arc_input_bridge_impl.cc
@@ -0,0 +1,365 @@
+// Copyright 2015 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 "components/arc/input/arc_input_bridge_impl.h"
+
+#include <linux/input.h>
+#include <fcntl.h>
+
+#include "base/logging.h"
+#include "base/posix/eintr_wrapper.h"
+#include "base/thread_task_runner_handle.h"
+#include "base/time/time.h"
+#include "components/arc/arc_bridge_service.h"
+#include "ui/aura/env.h"
+#include "ui/aura/env_observer.h"
+#include "ui/aura/window.h"
+#include "ui/aura/window_observer.h"
+#include "ui/events/event.h"
+#include "ui/events/event_handler.h"
+#include "ui/events/event_utils.h"
+#include "ui/events/keycodes/dom/keycode_converter.h"
+
+namespace {
+
+// input_event values for keyboard events.
+const int kKeyReleased = 0;
+const int kKeyPressed = 1;
+const int kKeyRepeated = 2;
+
+// maximum number of supported multi-touch slots (simultaneous fingers).
+const int kMaxSlots = 64;
+
+// tracking id of an empty slot.
+const int kEmptySlot = -1;
+
+// maximum possible pressure as defined in EventHubARC.
+// TODO(denniskempin): communicate maximum during initialization.
+const int kMaxPressure = 65536;
+
+// speed of the scroll emulation. Scroll events are reported at about 100 times
+// the speed of a scroll wheel.
+const float kScrollEmulationSpeed = 100.0f;
+
+struct MouseButtonMapping {
+ int ui_flag;
+ int evdev_code;
+} kMouseButtonMap[] = {
+ {ui::EF_LEFT_MOUSE_BUTTON, BTN_LEFT},
+ {ui::EF_RIGHT_MOUSE_BUTTON, BTN_RIGHT},
+ {ui::EF_MIDDLE_MOUSE_BUTTON, BTN_MIDDLE},
+};
+
+// Offset between evdev key codes and chrome native key codes
+const int kXkbKeycodeOffset = 8;
+
+} // namespace
+
+namespace arc {
+
+ArcInputBridgeImpl::ArcInputBridgeImpl(ArcBridgeService* arc_bridge_service)
+ : arc_bridge_service_(arc_bridge_service),
+ offset_x_acc_(0.5f),
+ offset_y_acc_(0.5f),
+ current_slot_(-1),
+ current_slot_tracking_ids_(kMaxSlots, kEmptySlot),
+ origin_task_runner_(base::ThreadTaskRunnerHandle::Get()),
+ weak_factory_(this) {
+ DCHECK(arc_bridge_service->state() == ArcBridgeService::State::STOPPED);
+ arc_bridge_service->AddObserver(this);
+
+ aura::Env* env = aura::Env::GetInstanceDontCreate();
+ if (env)
+ env->AddObserver(this);
+}
+
+ArcInputBridgeImpl::~ArcInputBridgeImpl() {
+ DCHECK(origin_task_runner_->RunsTasksOnCurrentThread());
+ arc_bridge_service_->RemoveObserver(this);
+
+ aura::Env* env = aura::Env::GetInstanceDontCreate();
+ if (env)
+ env->RemoveObserver(this);
+
+ for (aura::Window* window : arc_windows_.windows()) {
+ window->RemovePreTargetHandler(this);
+ }
+}
+
+void ArcInputBridgeImpl::OnInstanceBootPhase(InstanceBootPhase phase) {
+ DCHECK(origin_task_runner_->RunsTasksOnCurrentThread());
+ if (phase != INSTANCE_BOOT_PHASE_SYSTEM_SERVICES_READY)
+ return;
+
+ keyboard_fd_ = CreateBridgeInputDevice("ChromeOS Keyboard", "keyboard");
+ mouse_fd_ = CreateBridgeInputDevice("ChromeOS Mouse", "mouse");
+ touchscreen_fd_ =
+ CreateBridgeInputDevice("ChromeOS Touchscreen", "touchscreen");
+}
+
+// Translates and sends a ui::Event to the appropriate bridge device of the
+// ARC instance. If the devices have not yet been initialized, the event
+// will be ignored.
+void ArcInputBridgeImpl::OnEvent(ui::Event* event) {
+ DCHECK(origin_task_runner_->RunsTasksOnCurrentThread());
+ if (event->IsKeyEvent()) {
+ SendKeyEvent(static_cast<ui::KeyEvent*>(event));
+ } else if (event->IsMouseEvent() || event->IsScrollEvent()) {
+ SendMouseEvent(static_cast<ui::MouseEvent*>(event));
+ } else if (event->IsTouchEvent()) {
+ SendTouchEvent(static_cast<ui::TouchEvent*>(event));
+ }
+}
+
+// Attaches the input bridge to the window if it is marked as an ARC window.
+void ArcInputBridgeImpl::OnWindowInitialized(aura::Window* new_window) {
+ if (new_window->name() == "ExoSurface") {
+ arc_windows_.Add(new_window);
+ new_window->AddPreTargetHandler(this);
+ }
+}
+
+void ArcInputBridgeImpl::SendKeyEvent(ui::KeyEvent* event) {
+ if (keyboard_fd_.get() < 0) {
+ VLOG(2) << "No keyboard bridge device available.";
+ return;
+ }
+
+ unsigned short evdev_code = DomCodeToEvdevCode(event->code());
+ int evdev_value = 0;
+ if (event->type() == ui::ET_KEY_PRESSED) {
+ if (event->flags() & ui::EF_IS_REPEAT) {
+ evdev_value = kKeyRepeated;
+ } else {
+ evdev_value = kKeyPressed;
+ }
+ } else if (event->type() == ui::ET_KEY_RELEASED) {
+ evdev_value = kKeyReleased;
+ } else {
+ NOTREACHED() << "Key should be either PRESSED or RELEASED.";
+ }
+
+ base::TimeDelta time_stamp = event->time_stamp();
+ SendKernelEvent(keyboard_fd_, time_stamp, EV_KEY, evdev_code, evdev_value);
+ SendSynReport(keyboard_fd_, time_stamp);
+}
+
+void ArcInputBridgeImpl::SendTouchEvent(ui::TouchEvent* event) {
+ if (touchscreen_fd_.get() < 0) {
+ VLOG(2) << "No touchscreen bridge device available.";
+ return;
+ }
+
+ ui::PointerDetails details = event->pointer_details();
+ base::TimeDelta time_stamp = event->time_stamp();
+
+ // find or assing a slot for this tracking id
+ int slot_id = AcquireTouchSlot(event);
+ if (slot_id < 0) {
+ VLOG(1) << "Ran out of slot IDs.";
+ return;
+ }
+
+ // we only need to send the slot ID when it has changed.
+ if (slot_id != current_slot_) {
+ current_slot_ = slot_id;
+ SendKernelEvent(touchscreen_fd_, time_stamp, EV_ABS, ABS_MT_SLOT,
+ current_slot_);
+ }
+
+ // update tracking id
+ if (event->type() == ui::ET_TOUCH_PRESSED) {
+ SendKernelEvent(touchscreen_fd_, time_stamp, EV_ABS, ABS_MT_TRACKING_ID,
+ event->touch_id());
+ } else if (event->type() == ui::ET_TOUCH_RELEASED) {
+ SendKernelEvent(touchscreen_fd_, time_stamp, EV_ABS, ABS_MT_TRACKING_ID,
+ kEmptySlot);
+ }
+
+ // update touch information
+ if (event->type() == ui::ET_TOUCH_MOVED ||
+ event->type() == ui::ET_TOUCH_PRESSED) {
+ SendKernelEvent(touchscreen_fd_, time_stamp, EV_ABS, ABS_MT_POSITION_X,
+ event->x());
+ SendKernelEvent(touchscreen_fd_, time_stamp, EV_ABS, ABS_MT_POSITION_Y,
+ event->y());
+ SendKernelEvent(touchscreen_fd_, time_stamp, EV_ABS, ABS_MT_TOUCH_MAJOR,
+ details.radius_x());
+ SendKernelEvent(touchscreen_fd_, time_stamp, EV_ABS, ABS_MT_TOUCH_MINOR,
+ details.radius_y());
+ SendKernelEvent(touchscreen_fd_, time_stamp, EV_ABS, ABS_MT_PRESSURE,
+ details.force() * kMaxPressure);
+ }
+ SendSynReport(touchscreen_fd_, time_stamp);
+}
+
+void ArcInputBridgeImpl::SendMouseEvent(ui::MouseEvent* event) {
+ if (mouse_fd_.get() < 0) {
+ VLOG(2) << "No mouse bridge device available.";
+ return;
+ }
+
+ base::TimeDelta time_stamp = event->time_stamp();
+
+ // update location
+ if (event->type() == ui::ET_MOUSE_MOVED ||
+ event->type() == ui::ET_MOUSE_DRAGGED) {
+ SendKernelEvent(mouse_fd_, time_stamp, EV_ABS, ABS_X, event->x());
+ SendKernelEvent(mouse_fd_, time_stamp, EV_ABS, ABS_Y, event->y());
+ }
+
+ // update buttons
+ if (event->type() == ui::ET_MOUSE_PRESSED ||
+ event->type() == ui::ET_MOUSE_RELEASED) {
+ int evdev_value = static_cast<int>(event->type() == ui::ET_MOUSE_PRESSED);
+ for (MouseButtonMapping mapping : kMouseButtonMap) {
+ if (event->changed_button_flags() & mapping.ui_flag) {
+ SendKernelEvent(mouse_fd_, time_stamp, EV_KEY, mapping.evdev_code,
+ evdev_value);
+ }
+ }
+ }
+
+ // update scroll wheel
+ if (event->type() == ui::ET_SCROLL) {
+ ui::ScrollEvent* scroll_event = static_cast<ui::ScrollEvent*>(event);
+ // accumulate floating point scroll offset since we can only send full
+ // integer
+ // wheel events.
+ offset_x_acc_ += scroll_event->x_offset_ordinal() / kScrollEmulationSpeed;
+ offset_y_acc_ += scroll_event->y_offset_ordinal() / kScrollEmulationSpeed;
+
+ int wheel = floor(offset_y_acc_);
+ if (wheel != 0) {
+ SendKernelEvent(mouse_fd_, time_stamp, EV_REL, REL_WHEEL, wheel);
+ offset_y_acc_ -= static_cast<float>(wheel);
+ }
+
+ int hwheel = floor(offset_x_acc_);
+ if (hwheel != 0) {
+ SendKernelEvent(mouse_fd_, time_stamp, EV_REL, REL_HWHEEL, hwheel);
+ offset_x_acc_ -= static_cast<float>(hwheel);
+ }
+ }
+
+ SendSynReport(mouse_fd_, time_stamp);
+}
+
+void ArcInputBridgeImpl::SendKernelEvent(const base::ScopedFD& fd,
+ base::TimeDelta time_stamp,
+ unsigned short type,
+ unsigned short code,
+ int value) {
+ DCHECK(fd.is_valid());
+
+ // Chrome does not always use the monotonic system time for event times.
+ // For now always force the event time to the current system time.
+ // TODO(denniskempin): To enable performance tracing of events we will want
+ // to use the kernel-provided monotonic time stamps of events.
+ time_stamp = ui::EventTimeForNow();
+
+ struct input_event event;
+ event.time.tv_sec = time_stamp.InSeconds();
+ base::TimeDelta remainder =
+ time_stamp - base::TimeDelta::FromSeconds(event.time.tv_sec);
+ event.time.tv_usec = remainder.InMicroseconds();
+ event.type = type;
+ event.code = code;
+ event.value = value;
+
+ // Write event to file descriptor
+ size_t num_written = write(fd.get(), reinterpret_cast<void*>(&event),
+ sizeof(struct input_event));
+ DCHECK_EQ(num_written, sizeof(struct input_event));
+}
+
+void ArcInputBridgeImpl::SendSynReport(const base::ScopedFD& fd,
+ base::TimeDelta time) {
+ DCHECK(origin_task_runner_->RunsTasksOnCurrentThread());
+
+ SendKernelEvent(fd, time, EV_SYN, SYN_REPORT, 0);
+}
+
+int ArcInputBridgeImpl::AcquireTouchSlot(ui::TouchEvent* event) {
+ int slot_id;
+ if (event->type() == ui::ET_TOUCH_PRESSED) {
+ slot_id = FindTouchSlot(kEmptySlot);
+ } else {
+ slot_id = FindTouchSlot(event->touch_id());
+ }
+ if (slot_id < 0) {
+ return -1;
+ }
+
+ if (event->type() == ui::ET_TOUCH_RELEASED) {
+ current_slot_tracking_ids_[slot_id] = kEmptySlot;
+ } else if (event->type() == ui::ET_TOUCH_PRESSED) {
+ current_slot_tracking_ids_[slot_id] = event->touch_id();
+ }
+ return slot_id;
+}
+
+int ArcInputBridgeImpl::FindTouchSlot(int tracking_id) {
+ for (int i = 0; i < kMaxSlots; ++i) {
+ if (current_slot_tracking_ids_[i] == tracking_id) {
+ return i;
+ }
+ }
+ return -1;
+}
+
+unsigned short ArcInputBridgeImpl::DomCodeToEvdevCode(ui::DomCode dom_code) {
+ int native_code = ui::KeycodeConverter::DomCodeToNativeKeycode(dom_code);
+ if (native_code == ui::KeycodeConverter::InvalidNativeKeycode())
+ return KEY_RESERVED;
+
+ return native_code - kXkbKeycodeOffset;
+}
+
+base::ScopedFD ArcInputBridgeImpl::CreateBridgeInputDevice(
+ const std::string& name,
+ const std::string& device_type) {
+ if (!arc_bridge_service_) {
+ VLOG(1) << "ArcBridgeService disappeared.";
+ return base::ScopedFD();
+ }
+
+ // Create file descriptor pair for communication
+ int fd[2];
+ int res = HANDLE_EINTR(pipe(fd));
+ if (res < 0) {
+ VPLOG(1) << "Cannot create pipe";
+ return base::ScopedFD();
+ }
+ base::ScopedFD read_fd(fd[0]);
+ base::ScopedFD write_fd(fd[1]);
+
+ // The read end is sent to the instance, ownership of fd transfers.
+ if (!arc_bridge_service_->RegisterInputDevice(name, device_type,
+ std::move(read_fd))) {
+ VLOG(1) << "Cannot create bridge input device";
+ return base::ScopedFD();
+ }
+
+ // setup write end as non blocking
+ int flags = HANDLE_EINTR(fcntl(write_fd.get(), F_GETFL, 0));
+ if (res < 0) {
+ VPLOG(1) << "Cannot get file descriptor flags";
+ return base::ScopedFD();
+ }
+
+ res = HANDLE_EINTR(fcntl(write_fd.get(), F_SETFL, flags | O_NONBLOCK));
+ if (res < 0) {
+ VPLOG(1) << "Cannot set file descriptor flags";
+ return base::ScopedFD();
+ }
+ return write_fd;
+}
+
+scoped_ptr<ArcInputBridge> ArcInputBridge::Create(
+ ArcBridgeService* arc_bridge_service) {
+ return make_scoped_ptr(new ArcInputBridgeImpl(arc_bridge_service));
+}
+
+} // namespace arc
diff --git a/components/arc/input/arc_input_bridge_impl.h b/components/arc/input/arc_input_bridge_impl.h
new file mode 100644
index 0000000..d71fbde
--- /dev/null
+++ b/components/arc/input/arc_input_bridge_impl.h
@@ -0,0 +1,133 @@
+// Copyright 2015 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 COMPONENTS_EXO_ARC_INPUT_ARC_INPUT_BRIDGE_IMPL_H_
+#define COMPONENTS_EXO_ARC_INPUT_ARC_INPUT_BRIDGE_IMPL_H_
+
+#include "base/files/scoped_file.h"
+#include "base/macros.h"
+#include "components/arc/input/arc_input_bridge.h"
+#include "ui/aura/env.h"
+#include "ui/aura/env_observer.h"
+#include "ui/aura/window_tracker.h"
+#include "ui/events/event.h"
+#include "ui/events/event_handler.h"
+
+namespace aura {
+class Window;
+}
+
+namespace ui {
+enum class DomCode;
+}
+
+namespace arc {
+
+class ArcBridgeService;
+
+// Private implementation of ArcInputBridge
+class ArcInputBridgeImpl : public ArcInputBridge,
+ public ArcBridgeService::Observer,
+ public aura::EnvObserver,
+ public ui::EventHandler {
+ public:
+ // The constructor will register an Observer with aura::Env and the
+ // ArcBridgeService. From then on, no further interaction with this class
+ // is needed.
+ explicit ArcInputBridgeImpl(ArcBridgeService* arc_bridge_service);
+ ~ArcInputBridgeImpl() override;
+
+ // Overridden from ui::EventHandler:
+ void OnEvent(ui::Event* event) override;
+
+ // Overridden from aura::EnvObserver:
+ void OnWindowInitialized(aura::Window* new_window) override;
+
+ // Overridden from ArcBridgeService::Observer:
+ void OnInstanceBootPhase(InstanceBootPhase phase) override;
+
+ private:
+ // Specialized method to translate and send events to the right file
+ // descriptor.
+ void SendKeyEvent(ui::KeyEvent* event);
+ void SendTouchEvent(ui::TouchEvent* event);
+ void SendMouseEvent(ui::MouseEvent* event);
+
+ // Helper method to send a struct input_event to the file descriptor. This
+ // method is to be called on the ui thread and will post a request to send
+ // the event to the io thread.
+ // The parameters map directly to the members of input_event as
+ // defined by the evdev protocol.
+ // |type| is the type of event to sent, such as EV_SYN, EV_KEY, EV_ABS.
+ // |code| is either interpreted as axis (ABS_X, ABS_Y, ...) or as key-code
+ // (KEY_A, KEY_B, ...).
+ // |value| is either the value of that axis or the boolean value of the key
+ // as in 0 (released), 1 (pressed) or 2 (repeated press).
+ void SendKernelEvent(const base::ScopedFD& fd,
+ base::TimeDelta timestamp,
+ unsigned short type,
+ unsigned short code,
+ int value);
+
+ // Shorthand for sending EV_SYN/SYN_REPORT
+ void SendSynReport(const base::ScopedFD& fd, base::TimeDelta timestamp);
+
+ // Return existing or new slot for this event.
+ int AcquireTouchSlot(ui::TouchEvent* event);
+
+ // Return touch slot for tracking id.
+ int FindTouchSlot(int tracking_id);
+
+ // Maps DOM key codes to evdev key codes
+ unsigned short DomCodeToEvdevCode(ui::DomCode dom_code);
+
+
+ // Setup bridge devices on the instance side. This needs to be called after
+ // the InstanceBootPhase::SYSTEM_SERVICES_READY has been reached.
+ void SetupBridgeDevices();
+
+ // Creates and registers file descriptor pair with the ARC bridge service,
+ // the write end is returned while the read end is sent through the bridge
+ // to the ARC instance.
+ // TODO(denniskempin): Make this interface more typesafe.
+ // |name| should be the displayable name of the emulated device (e.g. "Chrome
+ // OS Keyboard"), |device_type| the name of the device type (e.g. "keyboard")
+ // and |fd| a file descriptor that emulates the kernel events of the device.
+ // This can only be called on the thread that this class was created on.
+ base::ScopedFD CreateBridgeInputDevice(const std::string& name,
+ const std::string& device_type);
+
+ // Owned by ArcServiceManager which makes sure ArcBridgeService is destroyed
+ // after ArcInputBridge.
+ ArcBridgeService* arc_bridge_service_;
+
+ // File descriptors for the different device types.
+ base::ScopedFD keyboard_fd_;
+ base::ScopedFD mouse_fd_;
+ base::ScopedFD touchscreen_fd_;
+
+ // Scroll accumlator.
+ float offset_x_acc_;
+ float offset_y_acc_;
+
+ // Currently selected slot for multi-touch events.
+ int current_slot_;
+
+ // List of touch tracking id to slot assignments.
+ std::vector<int> current_slot_tracking_ids_;
+
+ scoped_refptr<base::SequencedTaskRunner> origin_task_runner_;
+
+ // List of windows we are hooked into
+ aura::WindowTracker arc_windows_;
+
+ // WeakPtrFactory to use for callbacks.
+ base::WeakPtrFactory<ArcInputBridgeImpl> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(ArcInputBridgeImpl);
+};
+
+} // namespace arc
+
+#endif // COMPONENTS_EXO_ARC_INPUT_ARC_INPUT_BRIDGE_IMPL_H_