Index: components/exo/arc/arc_input_bridge.h |
diff --git a/components/exo/arc/arc_input_bridge.h b/components/exo/arc/arc_input_bridge.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..bc1b07a904deaa42c38fb2b6f6b1f5e71a668cf8 |
--- /dev/null |
+++ b/components/exo/arc/arc_input_bridge.h |
@@ -0,0 +1,101 @@ |
+// 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_ARC_INPUT_BRIDGE_H_ |
+#define COMPONENTS_EXO_ARC_ARC_INPUT_BRIDGE_H_ |
+ |
+#include "base/macros.h" |
+#include "components/arc/arc_bridge_service.h" |
+#include "ui/events/event.h" |
+#include "ui/events/event_handler.h" |
+ |
+namespace arc { |
+ |
+class ArcBridgeService; |
+ |
+// This class allows ui::Event's to be sent through the ArcBridgeService to be |
+// received by the ARC instance. |
+class ArcInputBridge : private ArcBridgeService::Observer { |
+ public: |
+ // Registers an observer with the ArcBridgeService. This must happen before |
+ // the ArcBridgeService is started so we do not miss the InstanceBootPhase |
+ // messages. |
+ ArcInputBridge(base::WeakPtr<ArcBridgeService> arc_bridge_service); |
+ virtual ~ArcInputBridge(); |
+ |
+ // Gets the global instance of the ARC Input Bridge. |
+ static ArcInputBridge* Get(); |
+ |
+ // 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 SendInputEvent(ui::Event* event); |
+ |
+ 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 |
+ // 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); |
+ |
+ // ArcBridgeService::Observer: |
+ void OnInstanceBootPhase(InstanceBootPhase phase) override; |
+ |
+ // Setup bridge devices on the instance side. This needs to be called after |
+ // the InstanceBootPhase::SYSTEM_SERVICES_READY has been reached. |
+ void SetupBridgeDevices(); |
+ |
+ // Return existing or new slot for this event. |
+ int AcquireTouchSlot(ui::TouchEvent* event); |
+ |
+ // Return touch slot for tracking id. |
+ int FindTouchSlot(int tracking_id); |
+ |
+ // 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); |
+ |
+ base::WeakPtr<ArcBridgeService> arc_bridge_service_; |
+ |
+ // File descriptors for the different device types. |
+ base::ScopedFD keyboard_fd_; |
+ base::ScopedFD mouse_fd_; |
+ base::ScopedFD touchscreen_fd_; |
+ |
+ // 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_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ArcInputBridge); |
+}; |
+ |
+} // namespace arc |
+ |
+#endif // COMPONENTS_EXO_ARC_ARC_INPUT_BRIDGE_H_ |