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_INPUT_ARC_INPUT_BRIDGE_IMPL_H_ | |
6 #define COMPONENTS_EXO_ARC_INPUT_ARC_INPUT_BRIDGE_IMPL_H_ | |
7 | |
8 #include "base/files/scoped_file.h" | |
9 #include "base/macros.h" | |
10 #include "components/arc/input/arc_input_bridge.h" | |
11 #include "ui/aura/env.h" | |
12 #include "ui/aura/env_observer.h" | |
13 #include "ui/aura/window_observer.h" | |
14 #include "ui/events/event.h" | |
15 #include "ui/events/event_handler.h" | |
16 | |
17 namespace aura { | |
18 class Window; | |
19 } | |
20 | |
21 namespace arc { | |
22 | |
23 class ArcBridgeService; | |
24 | |
25 // Private implementation of ArcInputBridge | |
26 class ArcInputBridgeImpl : public ArcInputBridge, | |
27 public ArcBridgeService::Observer, | |
28 public aura::EnvObserver, | |
29 public ui::EventHandler { | |
30 public: | |
31 // The constructor will register an Observer with aura::Env and the | |
32 // ArcBridgeService. From then on, no further interaction with this class | |
33 // is needed. | |
34 ArcInputBridgeImpl(ArcBridgeService* arc_bridge_service); | |
reveman
2015/12/04 23:19:32
nit: explicit
denniskempin
2015/12/05 00:05:19
Done.
| |
35 ~ArcInputBridgeImpl() override; | |
36 | |
37 // Overridden from ui::EventHandler: | |
38 void OnEvent(ui::Event* event) override; | |
39 | |
40 // Overridden from aura::EnvObserver: | |
41 void OnWindowInitialized(aura::Window* new_window) override; | |
42 | |
43 // Overridden from ArcBridgeService::Observer: | |
44 void OnInstanceBootPhase(InstanceBootPhase phase) override; | |
45 | |
46 private: | |
47 // Initialized the aura::EnvObserver on the ui message loop. | |
48 void InitializeAuraObserver(); | |
49 | |
50 // Specialized method to translate and send events to the right file | |
51 // descriptor. | |
52 void SendKeyEvent(ui::KeyEvent* event); | |
53 void SendTouchEvent(ui::TouchEvent* event); | |
54 void SendMouseEvent(ui::MouseEvent* event); | |
55 | |
56 // Helper method to send a struct input_event to the file descriptor. This | |
57 // method is to be called on the ui thread and will post a request to send | |
58 // the event to the io thread. | |
59 // The parameters map directly to the members of input_event as | |
60 // defined by the evdev protocol. | |
61 // |type| is the type of event to sent, such as EV_SYN, EV_KEY, EV_ABS. | |
62 // |code| is either interpreted as axis (ABS_X, ABS_Y, ...) or as key-code | |
63 // (KEY_A, KEY_B, ...). | |
64 // |value| is either the value of that axis or the boolean value of the key | |
65 // as in 0 (released), 1 (pressed) or 2 (repeated press). | |
66 void SendKernelEvent(const base::ScopedFD& fd, | |
67 base::TimeDelta timestamp, | |
68 unsigned short type, | |
69 unsigned short code, | |
70 int value); | |
71 | |
72 // Shorthand for sending EV_SYN/SYN_REPORT | |
73 void SendSynReport(const base::ScopedFD& fd, base::TimeDelta timestamp); | |
74 | |
75 // Return existing or new slot for this event. | |
76 int AcquireTouchSlot(ui::TouchEvent* event); | |
77 | |
78 // Return touch slot for tracking id. | |
79 int FindTouchSlot(int tracking_id); | |
80 | |
81 // Setup bridge devices on the instance side. This needs to be called after | |
82 // the InstanceBootPhase::SYSTEM_SERVICES_READY has been reached. | |
83 void SetupBridgeDevices(); | |
84 | |
85 // Creates and registers file descriptor pair with the ARC bridge service, | |
86 // the write end is returned while the read end is sent through the bridge | |
87 // to the ARC instance. | |
88 // TODO(denniskempin): Make this interface more typesafe. | |
89 // |name| should be the displayable name of the emulated device (e.g. "Chrome | |
90 // OS Keyboard"), |device_type| the name of the device type (e.g. "keyboard") | |
91 // and |fd| a file descriptor that emulates the kernel events of the device. | |
92 // This can only be called on the thread that this class was created on. | |
93 base::ScopedFD CreateBridgeInputDevice(const std::string& name, | |
94 const std::string& device_type); | |
95 | |
96 ArcBridgeService* arc_bridge_service_; | |
Luis Héctor Chávez
2015/12/04 22:52:08
Just add a comment about lifetime and why it's saf
denniskempin
2015/12/05 00:05:19
Done.
| |
97 | |
98 // File descriptors for the different device types. | |
99 base::ScopedFD keyboard_fd_; | |
100 base::ScopedFD mouse_fd_; | |
101 base::ScopedFD touchscreen_fd_; | |
102 | |
103 // Scroll accumlator. | |
104 float offset_x_acc_; | |
105 float offset_y_acc_; | |
106 | |
107 // Currently selected slot for multi-touch events. | |
108 int current_slot_; | |
109 | |
110 // List of touch tracking id to slot assignments. | |
111 std::vector<int> current_slot_tracking_ids_; | |
112 | |
113 scoped_refptr<base::SequencedTaskRunner> origin_task_runner_; | |
114 | |
115 // WeakPtrFactory to use for callbacks. | |
116 base::WeakPtrFactory<ArcInputBridgeImpl> weak_factory_; | |
117 | |
118 DISALLOW_COPY_AND_ASSIGN(ArcInputBridgeImpl); | |
119 }; | |
120 | |
121 } // namespace arc | |
122 | |
123 #endif // COMPONENTS_EXO_ARC_INPUT_ARC_INPUT_BRIDGE_IMPL_H_ | |
OLD | NEW |