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_ | |
reveman
2015/12/04 03:21:24
should be COMPONENTS_ARC_INPUT_ARC_INPUT_BRIDGE_H_
denniskempin
2015/12/04 22:35:30
Done.
| |
7 | |
8 #include "base/macros.h" | |
9 #include "components/arc/arc_bridge_service.h" | |
10 #include "ui/aura/window_observer.h" | |
11 #include "ui/aura/env.h" | |
12 #include "ui/aura/env_observer.h" | |
13 #include "ui/events/event.h" | |
14 #include "ui/events/event_handler.h" | |
15 | |
16 namespace aura { | |
17 | |
18 class Window; | |
19 | |
20 } // namespace aura | |
reveman
2015/12/04 03:21:24
fyi, typically just
namespace aura {
class Window
denniskempin
2015/12/04 22:35:30
Done.
| |
21 | |
22 namespace arc { | |
23 | |
24 class ArcBridgeService; | |
25 | |
26 // The ArcInputBridge is responsible for sending input events from ARC windows | |
27 // to the ARC instance. | |
28 // It hooks into aura::Env to watch for ExoSurface windows that are running ARC | |
29 // applications. On those windows the input bridge will attach an EventPreTarget | |
30 // to capture all input events. | |
31 // To send those events to the ARC instance it will create bridge input devices | |
32 // through the ArcBridgeService, which will provide a file descriptor to which | |
33 // we can send linux input_event's. | |
34 // ui::Events to the ARC windows are translated to linux input_event's, which | |
35 // are then sent through the respective file descriptor. | |
36 class ArcInputBridge : public ArcBridgeService::Observer, | |
37 public aura::EnvObserver, | |
38 public ui::EventHandler { | |
39 public: | |
40 // The constructor will register an Observer with aura::Env and the | |
41 // ArcBridgeService. From then on, no further interaction with this class | |
42 // is needed. | |
43 ArcInputBridge( | |
44 ArcBridgeService* arc_bridge_service, | |
45 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); | |
46 ~ArcInputBridge() override; | |
47 | |
48 protected: | |
49 // Translates and sends a ui::Event to the appropriate bridge device of the | |
50 // ARC instance. If the devices have not yet been initialized, the event | |
51 // will be ignored. | |
52 void OnEvent(ui::Event* event) override; | |
reveman
2015/12/04 03:21:24
nit: I don't recommend inheriting a public functio
denniskempin
2015/12/04 22:35:30
Done.
| |
53 | |
54 // Attaches the input bridge to the window if it is marked as an ARC window. | |
55 void OnWindowInitialized(aura::Window* new_window) override; | |
reveman
2015/12/04 03:21:24
ditto
denniskempin
2015/12/04 22:35:30
Done.
| |
56 | |
57 private: | |
58 // Initialized the aura::EnvObserver on the ui message loop. | |
59 void InitializeAuraObserver(); | |
60 | |
61 void SendInputEventIO(scoped_ptr<ui::Event> event); | |
reveman
2015/12/04 03:21:24
nit: s/IO/OnIO/
denniskempin
2015/12/04 22:35:30
Done.
| |
62 | |
63 // Specialized method to translate and send events to the right file | |
64 // descriptor | |
reveman
2015/12/04 03:21:24
nit: missing punctuation. also, does this comment
denniskempin
2015/12/04 22:35:30
close. 82. Added dot.
| |
65 void SendKeyEventIO(ui::KeyEvent* event); | |
reveman
2015/12/04 03:21:24
nit: s/IO/OnIO/
denniskempin
2015/12/04 22:35:30
Done.
| |
66 void SendTouchEventIO(ui::TouchEvent* event); | |
reveman
2015/12/04 03:21:24
nit: s/IO/OnIO/
denniskempin
2015/12/04 22:35:30
Done.
| |
67 void SendMouseEventIO(ui::MouseEvent* event); | |
reveman
2015/12/04 03:21:24
nit: s/IO/OnIO/
denniskempin
2015/12/04 22:35:30
Done.
| |
68 | |
69 // Helper method to send a struct input_event to the file descriptor. This | |
70 // method is to be called on the ui thread and will post a request to send | |
71 // the event to the io thread. | |
72 // The parameters map directly to the members of input_event as | |
73 // defined by the evdev protocol. | |
74 // |type| is the type of event to sent, such as EV_SYN, EV_KEY, EV_ABS. | |
75 // |code| is either interpreted as axis (ABS_X, ABS_Y, ...) or as key-code | |
76 // (KEY_A, KEY_B, ...). | |
77 // |value| is either the value of that axis or the boolean value of the key | |
78 // as in 0 (released), 1 (pressed) or 2 (repeated press). | |
79 void SendKernelEventIO(const base::ScopedFD& fd, | |
reveman
2015/12/04 03:21:24
nit: s/IO/OnIO/
denniskempin
2015/12/04 22:35:30
Done.
| |
80 base::TimeDelta timestamp, | |
81 unsigned short type, | |
82 unsigned short code, | |
83 int value); | |
84 | |
85 // Shorthand for sending EV_SYN/SYN_REPORT | |
86 void SendSynReportIO(const base::ScopedFD& fd, base::TimeDelta timestamp); | |
reveman
2015/12/04 03:21:24
nit: s/IO/OnIO/
denniskempin
2015/12/04 22:35:30
Done.
| |
87 | |
88 // Return existing or new slot for this event. | |
89 int AcquireTouchSlotIO(ui::TouchEvent* event); | |
reveman
2015/12/04 03:21:24
nit: s/IO/OnIO/
denniskempin
2015/12/04 22:35:30
Done.
| |
90 | |
91 // Return touch slot for tracking id. | |
92 int FindTouchSlotIO(int tracking_id); | |
reveman
2015/12/04 03:21:24
nit: s/IO/OnIO/
denniskempin
2015/12/04 22:35:30
Done.
| |
93 | |
94 // ArcBridgeService::Observer: | |
95 void OnInstanceBootPhase(InstanceBootPhase phase) override; | |
reveman
2015/12/04 03:21:24
nit: avoid inheriting a public function as private
denniskempin
2015/12/04 22:35:30
Done.
| |
96 | |
97 // Setup bridge devices on the instance side. This needs to be called after | |
98 // the InstanceBootPhase::SYSTEM_SERVICES_READY has been reached. | |
99 void SetupBridgeDevices(); | |
100 | |
101 // Creates and registers file descriptor pair with the ARC bridge service, | |
102 // the write end is returned while the read end is sent through the bridge | |
103 // to the ARC instance. | |
104 // TODO(denniskempin): Make this interface more typesafe. | |
105 // |name| should be the displayable name of the emulated device (e.g. "Chrome | |
106 // OS Keyboard"), |device_type| the name of the device type (e.g. "keyboard") | |
107 // and |fd| a file descriptor that emulates the kernel events of the device. | |
108 // This can only be called on the thread that this class was created on. | |
109 base::ScopedFD CreateBridgeInputDevice(const std::string& name, | |
110 const std::string& device_type); | |
111 | |
112 ArcBridgeService* arc_bridge_service_; | |
reveman
2015/12/04 03:21:24
it's not clear what members below are used on what
denniskempin
2015/12/04 22:35:30
Done.
| |
113 | |
114 // File descriptors for the different device types. | |
115 base::ScopedFD keyboard_fd_; | |
116 base::ScopedFD mouse_fd_; | |
117 base::ScopedFD touchscreen_fd_; | |
118 | |
119 // Scroll accumlator. | |
120 float offset_x_acc; | |
jochen (gone - plz use gerrit)
2015/12/04 14:18:12
should end in _
denniskempin
2015/12/04 22:35:30
Done.
| |
121 float offset_y_acc; | |
122 | |
123 // Currently selected slot for multi-touch events | |
124 int current_slot_; | |
125 | |
126 // List of touch tracking id to slot assignments | |
127 std::vector<int> current_slot_tracking_ids_; | |
128 | |
129 scoped_refptr<base::SequencedTaskRunner> origin_task_runner_; | |
130 scoped_refptr<base::SequencedTaskRunner> io_task_runner_; | |
131 | |
132 // WeakPtrFactory to use callbacks. | |
133 base::WeakPtrFactory<ArcInputBridge> weak_factory_; | |
134 | |
135 DISALLOW_COPY_AND_ASSIGN(ArcInputBridge); | |
136 }; | |
137 | |
138 } // namespace arc | |
139 | |
140 #endif // COMPONENTS_EXO_ARC_ARC_INPUT_BRIDGE_H_ | |
reveman
2015/12/04 03:21:24
COMPONENTS_ARC_INPUT_ARC_INPUT_BRIDGE_H_
denniskempin
2015/12/04 22:35:30
Done.
| |
OLD | NEW |