OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_EXO_ARC_INPUT_ARC_INPUT_BRIDGE_H_ | 5 #ifndef COMPONENTS_ARC_INPUT_ARC_INPUT_BRIDGE_H_ |
6 #define COMPONENTS_EXO_ARC_INPUT_ARC_INPUT_BRIDGE_H_ | 6 #define COMPONENTS_ARC_INPUT_ARC_INPUT_BRIDGE_H_ |
7 | 7 |
8 #include <stdint.h> | |
9 #include <string> | |
10 #include <vector> | |
11 | |
12 #include "base/files/scoped_file.h" | |
8 #include "base/macros.h" | 13 #include "base/macros.h" |
9 #include "components/arc/arc_bridge_service.h" | 14 #include "components/arc/arc_bridge_service.h" |
15 #include "components/arc/arc_service.h" | |
16 #include "ui/aura/env.h" | |
hidehiko
2016/01/18 01:26:45
nit: Looks unnecessary?
Luis Héctor Chávez
2016/01/19 17:43:54
Done.
| |
17 #include "ui/aura/env_observer.h" | |
18 #include "ui/aura/window_tracker.h" | |
19 #include "ui/events/event.h" | |
20 #include "ui/events/event_handler.h" | |
21 | |
22 namespace aura { | |
23 class Window; | |
hidehiko
2016/01/18 01:26:45
Can we include ui/aura/window.h directly, as we do
Luis Héctor Chávez
2016/01/19 17:43:54
To reduce compilation time, I'd prefer to remove u
| |
24 } | |
25 | |
26 namespace ui { | |
27 enum class DomCode; | |
28 } | |
10 | 29 |
11 namespace arc { | 30 namespace arc { |
12 | 31 |
13 class ArcBridgeService; | 32 class ArcBridgeService; |
14 | 33 |
15 // The ArcInputBridge is responsible for sending input events from ARC windows | 34 // The ArcInputBridge is responsible for sending input events from ARC |
16 // to the ARC instance. | 35 // windows to the ARC instance. |
17 // It hooks into aura::Env to watch for ExoSurface windows that are running ARC | 36 // It hooks into aura::Env to watch for ExoSurface windows that are running ARC |
18 // applications. On those windows the input bridge will attach an EventPreTarget | 37 // applications. On those windows the input bridge will attach an EventPreTarget |
19 // to capture all input events. | 38 // to capture all input events. |
20 // To send those events to the ARC instance it will create bridge input devices | 39 // To send those events to the ARC instance it will create bridge input devices |
21 // through the ArcBridgeService, which will provide a file descriptor to which | 40 // through the ArcBridgeService, which will provide a file descriptor to which |
22 // we can send linux input_event's. | 41 // we can send linux input_event's. |
23 // ui::Events to the ARC windows are translated to linux input_event's, which | 42 // ui::Events to the ARC windows are translated to linux input_event's, which |
24 // are then sent through the respective file descriptor. | 43 // are then sent through the respective file descriptor. |
25 class ArcInputBridge { | 44 class ArcInputBridge : public ArcService, |
45 public ArcBridgeService::Observer, | |
46 public aura::EnvObserver, | |
47 public ui::EventHandler { | |
26 public: | 48 public: |
27 virtual ~ArcInputBridge() {} | 49 // The constructor will register an Observer with aura::Env and the |
50 // ArcBridgeService. From then on, no further interaction with this class | |
51 // is needed. | |
52 explicit ArcInputBridge(ArcBridgeService* arc_bridge); | |
53 ~ArcInputBridge() override; | |
28 | 54 |
29 // Creates a new instance of ArcInputBridge. It will register an Observer | 55 // Overridden from ui::EventHandler: |
30 // with aura::Env and the ArcBridgeService. | 56 void OnEvent(ui::Event* event) override; |
31 static scoped_ptr<ArcInputBridge> Create( | |
32 ArcBridgeService* arc_bridge_service); | |
33 | 57 |
34 protected: | 58 // Overridden from aura::EnvObserver: |
35 ArcInputBridge() {} | 59 void OnWindowInitialized(aura::Window* new_window) override; |
60 | |
61 // Overridden from ArcBridgeService::Observer: | |
62 void OnInputInstanceReady() override; | |
36 | 63 |
37 private: | 64 private: |
65 // Specialized method to translate and send events to the right file | |
66 // descriptor. | |
67 void SendKeyEvent(ui::KeyEvent* event); | |
68 void SendTouchEvent(ui::TouchEvent* event); | |
69 void SendMouseEvent(ui::MouseEvent* event); | |
70 | |
71 // Helper method to send a struct input_event to the file descriptor. This | |
72 // method is to be called on the ui thread and will post a request to send | |
73 // the event to the io thread. | |
74 // The parameters map directly to the members of input_event as | |
75 // defined by the evdev protocol. | |
76 // |type| is the type of event to sent, such as EV_SYN, EV_KEY, EV_ABS. | |
77 // |code| is either interpreted as axis (ABS_X, ABS_Y, ...) or as key-code | |
78 // (KEY_A, KEY_B, ...). | |
79 // |value| is either the value of that axis or the boolean value of the key | |
80 // as in 0 (released), 1 (pressed) or 2 (repeated press). | |
81 void SendKernelEvent(const base::ScopedFD& fd, | |
82 base::TimeDelta timestamp, | |
83 uint16_t type, | |
84 uint16_t code, | |
85 int value); | |
86 | |
87 // Shorthand for sending EV_SYN/SYN_REPORT | |
88 void SendSynReport(const base::ScopedFD& fd, base::TimeDelta timestamp); | |
89 | |
90 // Return existing or new slot for this event. | |
91 int AcquireTouchSlot(ui::TouchEvent* event); | |
92 | |
93 // Return touch slot for tracking id. | |
94 int FindTouchSlot(int tracking_id); | |
95 | |
96 // Maps DOM key codes to evdev key codes | |
97 uint16_t DomCodeToEvdevCode(ui::DomCode dom_code); | |
98 | |
99 // Setup bridge devices on the instance side. This needs to be called after | |
100 // the InstanceBootPhase::SYSTEM_SERVICES_READY has been reached. | |
101 void SetupBridgeDevices(); | |
102 | |
103 // Creates and registers file descriptor pair with the ARC bridge service, | |
104 // the write end is returned while the read end is sent through the bridge | |
105 // to the ARC instance. | |
106 // TODO(denniskempin): Make this interface more typesafe. | |
107 // |name| should be the displayable name of the emulated device (e.g. "Chrome | |
108 // OS Keyboard"), |device_type| the name of the device type (e.g. "keyboard") | |
109 // and |fd| a file descriptor that emulates the kernel events of the device. | |
110 // This can only be called on the thread that this class was created on. | |
111 base::ScopedFD CreateBridgeInputDevice(const std::string& name, | |
112 const std::string& device_type); | |
113 | |
114 // Owned by ArcServiceManager which makes sure ArcBridgeService is destroyed | |
115 // after ArcInputBridge. | |
116 ArcBridgeService* const arc_bridge_service_; | |
117 | |
118 // File descriptors for the different device types. | |
119 base::ScopedFD keyboard_fd_; | |
120 base::ScopedFD mouse_fd_; | |
121 base::ScopedFD touchscreen_fd_; | |
122 | |
123 // Scroll accumlator. | |
124 float offset_x_acc_; | |
125 float offset_y_acc_; | |
126 | |
127 // Currently selected slot for multi-touch events. | |
128 int current_slot_; | |
129 | |
130 // List of touch tracking id to slot assignments. | |
131 std::vector<int> current_slot_tracking_ids_; | |
132 | |
133 scoped_refptr<base::SequencedTaskRunner> origin_task_runner_; | |
134 | |
135 // List of windows we are hooked into | |
136 aura::WindowTracker arc_windows_; | |
137 | |
138 // WeakPtrFactory to use for callbacks. | |
139 base::WeakPtrFactory<ArcInputBridge> weak_factory_; | |
140 | |
38 DISALLOW_COPY_AND_ASSIGN(ArcInputBridge); | 141 DISALLOW_COPY_AND_ASSIGN(ArcInputBridge); |
39 }; | 142 }; |
40 | 143 |
41 } // namespace arc | 144 } // namespace arc |
42 | 145 |
43 #endif // COMPONENTS_EXO_ARC_INPUT_ARC_INPUT_BRIDGE_H_ | 146 #endif // COMPONENTS_ARC_INPUT_ARC_INPUT_BRIDGE_H_ |
OLD | NEW |