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

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

Issue 1408263006: chromeos: Add ArcInputBridge to components/arc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@arcxx
Patch Set: Moved IO to IO thread. Fixed style issues pointed out by jochen@ Created 5 years 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
OLDNEW
(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 : public ArcBridgeService::Observer {
20 public:
21 // Registers an observer with the ArcBridgeService.
22 explicit ArcInputBridge(
23 base::WeakPtr<ArcBridgeService> arc_bridge_service,
24 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner);
25 ~ArcInputBridge() override;
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 void SendInputEventIO(scoped_ptr<ui::Event> event);
37
38 // Specialized method to translate and send events to the right file
39 // descriptor
40 void SendKeyEventIO(ui::KeyEvent* event);
41 void SendTouchEventIO(ui::TouchEvent* event);
42 void SendMouseEventIO(ui::MouseEvent* event);
43
44 // Helper method to send a struct input_event to the file descriptor. This
45 // method is to be called on the ui thread and will post a request to send
46 // the event to the io thread.
47 // The parameters map directly to the members of input_event as
48 // defined by the evdev protocol.
49 // |type| is the type of event to sent, such as EV_SYN, EV_KEY, EV_ABS.
50 // |code| is either interpreted as axis (ABS_X, ABS_Y, ...) or as key-code
51 // (KEY_A, KEY_B, ...).
52 // |value| is either the value of that axis or the boolean value of the key
53 // as in 0 (released), 1 (pressed) or 2 (repeated press).
54 void SendKernelEventIO(const base::ScopedFD& fd,
55 base::TimeDelta timestamp,
56 unsigned short type,
57 unsigned short code,
58 int value);
59
60 // Shorthand for sending EV_SYN/SYN_REPORT
61 void SendSynReportIO(const base::ScopedFD& fd, base::TimeDelta timestamp);
62
63 // Return existing or new slot for this event.
64 int AcquireTouchSlotIO(ui::TouchEvent* event);
65
66 // Return touch slot for tracking id.
67 int FindTouchSlotIO(int tracking_id);
68
69 // ArcBridgeService::Observer:
70 void OnInstanceBootPhase(InstanceBootPhase phase) override;
71
72 // Setup bridge devices on the instance side. This needs to be called after
73 // the InstanceBootPhase::SYSTEM_SERVICES_READY has been reached.
74 void SetupBridgeDevices();
75
76 // Creates and registers file descriptor pair with the ARC bridge service,
77 // the write end is returned while the read end is sent through the bridge
78 // to the ARC instance.
79 // TODO(denniskempin): Make this interface more typesafe.
80 // |name| should be the displayable name of the emulated device (e.g. "Chrome
81 // OS Keyboard"), |device_type| the name of the device type (e.g. "keyboard")
82 // and |fd| a file descriptor that emulates the kernel events of the device.
83 // This can only be called on the thread that this class was created on.
84 base::ScopedFD CreateBridgeInputDevice(const std::string& name,
85 const std::string& device_type);
86
87 base::WeakPtr<ArcBridgeService> arc_bridge_service_;
88
89 // File descriptors for the different device types.
90 base::ScopedFD keyboard_fd_;
91 base::ScopedFD mouse_fd_;
92 base::ScopedFD touchscreen_fd_;
93
94 // Currently selected slot for multi-touch events
95 int current_slot_;
96
97 // List of touch tracking id to slot assignments
98 std::vector<int> current_slot_tracking_ids_;
99
100 scoped_refptr<base::SequencedTaskRunner> origin_task_runner_;
101 scoped_refptr<base::SequencedTaskRunner> io_task_runner_;
102
103 // WeakPtrFactory to use callbacks.
104 base::WeakPtrFactory<ArcInputBridge> weak_factory_;
105
106 DISALLOW_COPY_AND_ASSIGN(ArcInputBridge);
107 };
108
109 } // namespace arc
110
111 #endif // COMPONENTS_EXO_ARC_ARC_INPUT_BRIDGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698