Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(641)

Unified Diff: components/arc/input/arc_input_bridge.h

Issue 1408263006: chromeos: Add ArcInputBridge to components/arc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@arcxx
Patch Set: Moved code back to components/arc Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/arc/input/arc_input_bridge.h
diff --git a/components/arc/input/arc_input_bridge.h b/components/arc/input/arc_input_bridge.h
new file mode 100644
index 0000000000000000000000000000000000000000..bc1b07a904deaa42c38fb2b6f6b1f5e71a668cf8
--- /dev/null
+++ b/components/arc/input/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 {
jochen (gone - plz use gerrit) 2015/12/02 13:09:02 no private inheritance: https://google.github.io/s
denniskempin 2015/12/03 01:26:42 Done.
+ 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);
jochen (gone - plz use gerrit) 2015/12/02 13:09:02 explicit
denniskempin 2015/12/03 01:26:42 Done.
+ virtual ~ArcInputBridge();
jochen (gone - plz use gerrit) 2015/12/02 13:09:02 should be override
denniskempin 2015/12/03 01:26:42 Done.
+
+ // 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_

Powered by Google App Engine
This is Rietveld 408576698