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

Side by Side Diff: components/arc/input/arc_input_bridge.h

Issue 1596663002: arc-bridge: Introduce the ArcService class (Closed) Base URL: https://chromium.googlesource.com/a/chromium/src.git@master
Patch Set: Rebased + protected ArcService direct instantiation Created 4 years, 11 months 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 unified diff | Download patch
« no previous file with comments | « components/arc/ime/arc_ime_bridge.cc ('k') | components/arc/input/arc_input_bridge.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_observer.h"
17 #include "ui/aura/window_tracker.h"
18 #include "ui/events/event_handler.h"
19
20 namespace aura {
21 class Window;
22 }
23
24 namespace ui {
25 enum class DomCode;
26 class Event;
27 }
10 28
11 namespace arc { 29 namespace arc {
12 30
13 class ArcBridgeService; 31 class ArcBridgeService;
14 32
15 // The ArcInputBridge is responsible for sending input events from ARC windows 33 // The ArcInputBridge is responsible for sending input events from ARC
16 // to the ARC instance. 34 // windows to the ARC instance.
17 // It hooks into aura::Env to watch for ExoSurface windows that are running ARC 35 // 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 36 // applications. On those windows the input bridge will attach an EventPreTarget
19 // to capture all input events. 37 // to capture all input events.
20 // To send those events to the ARC instance it will create bridge input devices 38 // 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 39 // through the ArcBridgeService, which will provide a file descriptor to which
22 // we can send linux input_event's. 40 // we can send linux input_event's.
23 // ui::Events to the ARC windows are translated to linux input_event's, which 41 // ui::Events to the ARC windows are translated to linux input_event's, which
24 // are then sent through the respective file descriptor. 42 // are then sent through the respective file descriptor.
25 class ArcInputBridge { 43 class ArcInputBridge : public ArcService,
44 public ArcBridgeService::Observer,
45 public aura::EnvObserver,
46 public ui::EventHandler {
26 public: 47 public:
27 virtual ~ArcInputBridge() {} 48 // The constructor will register an Observer with aura::Env and the
49 // ArcBridgeService. From then on, no further interaction with this class
50 // is needed.
51 explicit ArcInputBridge(ArcBridgeService* bridge_service);
52 ~ArcInputBridge() override;
28 53
29 // Creates a new instance of ArcInputBridge. It will register an Observer 54 // Overridden from ui::EventHandler:
30 // with aura::Env and the ArcBridgeService. 55 void OnEvent(ui::Event* event) override;
31 static scoped_ptr<ArcInputBridge> Create(
32 ArcBridgeService* arc_bridge_service);
33 56
34 protected: 57 // Overridden from aura::EnvObserver:
35 ArcInputBridge() {} 58 void OnWindowInitialized(aura::Window* new_window) override;
59
60 // Overridden from ArcBridgeService::Observer:
61 void OnInputInstanceReady() override;
36 62
37 private: 63 private:
64 // Specialized method to translate and send events to the right file
65 // descriptor.
66 void SendKeyEvent(ui::KeyEvent* event);
67 void SendTouchEvent(ui::TouchEvent* event);
68 void SendMouseEvent(ui::MouseEvent* event);
69
70 // Helper method to send a struct input_event to the file descriptor. This
71 // method is to be called on the ui thread and will post a request to send
72 // the event to the io thread.
73 // The parameters map directly to the members of input_event as
74 // defined by the evdev protocol.
75 // |type| is the type of event to sent, such as EV_SYN, EV_KEY, EV_ABS.
76 // |code| is either interpreted as axis (ABS_X, ABS_Y, ...) or as key-code
77 // (KEY_A, KEY_B, ...).
78 // |value| is either the value of that axis or the boolean value of the key
79 // as in 0 (released), 1 (pressed) or 2 (repeated press).
80 void SendKernelEvent(const base::ScopedFD& fd,
81 base::TimeDelta timestamp,
82 uint16_t type,
83 uint16_t code,
84 int value);
85
86 // Shorthand for sending EV_SYN/SYN_REPORT
87 void SendSynReport(const base::ScopedFD& fd, base::TimeDelta timestamp);
88
89 // Return existing or new slot for this event.
90 int AcquireTouchSlot(ui::TouchEvent* event);
91
92 // Return touch slot for tracking id.
93 int FindTouchSlot(int tracking_id);
94
95 // Maps DOM key codes to evdev key codes
96 uint16_t DomCodeToEvdevCode(ui::DomCode dom_code);
97
98 // Setup bridge devices on the instance side. This needs to be called after
99 // the InstanceBootPhase::SYSTEM_SERVICES_READY has been reached.
100 void SetupBridgeDevices();
101
102 // Creates and registers file descriptor pair with the ARC bridge service,
103 // the write end is returned while the read end is sent through the bridge
104 // to the ARC instance.
105 // TODO(denniskempin): Make this interface more typesafe.
106 // |name| should be the displayable name of the emulated device (e.g. "Chrome
107 // OS Keyboard"), |device_type| the name of the device type (e.g. "keyboard")
108 // and |fd| a file descriptor that emulates the kernel events of the device.
109 // This can only be called on the thread that this class was created on.
110 base::ScopedFD CreateBridgeInputDevice(const std::string& name,
111 const std::string& device_type);
112
113 // File descriptors for the different device types.
114 base::ScopedFD keyboard_fd_;
115 base::ScopedFD mouse_fd_;
116 base::ScopedFD touchscreen_fd_;
117
118 // Scroll accumlator.
119 float offset_x_acc_;
120 float offset_y_acc_;
121
122 // Currently selected slot for multi-touch events.
123 int current_slot_;
124
125 // List of touch tracking id to slot assignments.
126 std::vector<int> current_slot_tracking_ids_;
127
128 scoped_refptr<base::SequencedTaskRunner> origin_task_runner_;
129
130 // List of windows we are hooked into
131 aura::WindowTracker arc_windows_;
132
133 // WeakPtrFactory to use for callbacks.
134 base::WeakPtrFactory<ArcInputBridge> weak_factory_;
135
38 DISALLOW_COPY_AND_ASSIGN(ArcInputBridge); 136 DISALLOW_COPY_AND_ASSIGN(ArcInputBridge);
39 }; 137 };
40 138
41 } // namespace arc 139 } // namespace arc
42 140
43 #endif // COMPONENTS_EXO_ARC_INPUT_ARC_INPUT_BRIDGE_H_ 141 #endif // COMPONENTS_ARC_INPUT_ARC_INPUT_BRIDGE_H_
OLDNEW
« no previous file with comments | « components/arc/ime/arc_ime_bridge.cc ('k') | components/arc/input/arc_input_bridge.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698