Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_EXO_ARC_ARC_INPUT_BRIDGE_H_ | |
| 6 #define COMPONENTS_EXO_ARC_ARC_INPUT_BRIDGE_H_ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "components/arc/arc_bridge_service.h" | |
| 10 #include "ui/events/event.h" | |
| 11 #include "ui/events/event_handler.h" | |
| 12 | |
| 13 namespace arc { | |
| 14 | |
| 15 class ArcBridgeService; | |
| 16 | |
| 17 // This class allows ui::Event's to be sent through the ArcBridgeService to be | |
| 18 // received by the ARC instance. | |
| 19 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.
| |
| 20 public: | |
| 21 // Registers an observer with the ArcBridgeService. This must happen before | |
| 22 // the ArcBridgeService is started so we do not miss the InstanceBootPhase | |
| 23 // messages. | |
| 24 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.
| |
| 25 virtual ~ArcInputBridge(); | |
|
jochen (gone - plz use gerrit)
2015/12/02 13:09:02
should be override
denniskempin
2015/12/03 01:26:42
Done.
| |
| 26 | |
| 27 // Gets the global instance of the ARC Input Bridge. | |
| 28 static ArcInputBridge* Get(); | |
| 29 | |
| 30 // Translates and sends a ui::Event to the appropriate bridge device of the | |
| 31 // ARC instance. If the devices have not yet been initialized, the event | |
| 32 // will be ignored. | |
| 33 void SendInputEvent(ui::Event* event); | |
| 34 | |
| 35 private: | |
| 36 // Specialized method to translate and send events to the right file | |
| 37 // descriptor | |
| 38 void SendKeyEvent(ui::KeyEvent* event); | |
| 39 void SendTouchEvent(ui::TouchEvent* event); | |
| 40 void SendMouseEvent(ui::MouseEvent* event); | |
| 41 | |
| 42 // Helper method to send a struct input_event to the file descriptor | |
| 43 // The parameters map directly to the members of input_event as | |
| 44 // defined by the evdev protocol. | |
| 45 // |type| is the type of event to sent, such as EV_SYN, EV_KEY, EV_ABS. | |
| 46 // |code| is either interpreted as axis (ABS_X, ABS_Y, ...) or as key-code | |
| 47 // (KEY_A, KEY_B, ...). | |
| 48 // |value| is either the value of that axis or the boolean value of the key | |
| 49 // as in 0 (released), 1 (pressed) or 2 (repeated press). | |
| 50 void SendKernelEvent(const base::ScopedFD& fd, | |
| 51 base::TimeDelta timestamp, | |
| 52 unsigned short type, | |
| 53 unsigned short code, | |
| 54 int value); | |
| 55 | |
| 56 // Shorthand for sending EV_SYN/SYN_REPORT | |
| 57 void SendSynReport(const base::ScopedFD& fd, base::TimeDelta timestamp); | |
| 58 | |
| 59 // ArcBridgeService::Observer: | |
| 60 void OnInstanceBootPhase(InstanceBootPhase phase) override; | |
| 61 | |
| 62 // Setup bridge devices on the instance side. This needs to be called after | |
| 63 // the InstanceBootPhase::SYSTEM_SERVICES_READY has been reached. | |
| 64 void SetupBridgeDevices(); | |
| 65 | |
| 66 // Return existing or new slot for this event. | |
| 67 int AcquireTouchSlot(ui::TouchEvent* event); | |
| 68 | |
| 69 // Return touch slot for tracking id. | |
| 70 int FindTouchSlot(int tracking_id); | |
| 71 | |
| 72 // Creates and registers file descriptor pair with the ARC bridge service, | |
| 73 // the write end is returned while the read end is sent through the bridge | |
| 74 // to the ARC instance. | |
| 75 // TODO(denniskempin): Make this interface more typesafe. | |
| 76 // |name| should be the displayable name of the emulated device (e.g. "Chrome | |
| 77 // OS Keyboard"), |device_type| the name of the device type (e.g. "keyboard") | |
| 78 // and |fd| a file descriptor that emulates the kernel events of the device. | |
| 79 // This can only be called on the thread that this class was created on. | |
| 80 base::ScopedFD CreateBridgeInputDevice(const std::string& name, | |
| 81 const std::string& device_type); | |
| 82 | |
| 83 base::WeakPtr<ArcBridgeService> arc_bridge_service_; | |
| 84 | |
| 85 // File descriptors for the different device types. | |
| 86 base::ScopedFD keyboard_fd_; | |
| 87 base::ScopedFD mouse_fd_; | |
| 88 base::ScopedFD touchscreen_fd_; | |
| 89 | |
| 90 // Currently selected slot for multi-touch events | |
| 91 int current_slot_; | |
| 92 | |
| 93 // List of touch tracking id to slot assignments | |
| 94 std::vector<int> current_slot_tracking_ids_; | |
| 95 | |
| 96 DISALLOW_COPY_AND_ASSIGN(ArcInputBridge); | |
| 97 }; | |
| 98 | |
| 99 } // namespace arc | |
| 100 | |
| 101 #endif // COMPONENTS_EXO_ARC_ARC_INPUT_BRIDGE_H_ | |
| OLD | NEW |