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

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

Issue 1408263006: chromeos: Add ArcInputBridge to components/arc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@arcxx
Patch Set: removed CL dependency 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_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_tracker.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 ui {
22 enum class DomCode;
23 }
24
25 namespace arc {
26
27 class ArcBridgeService;
28
29 // Private implementation of ArcInputBridge
30 class ArcInputBridgeImpl : public ArcInputBridge,
31 public ArcBridgeService::Observer,
32 public aura::EnvObserver,
33 public ui::EventHandler {
34 public:
35 // The constructor will register an Observer with aura::Env and the
36 // ArcBridgeService. From then on, no further interaction with this class
37 // is needed.
38 explicit ArcInputBridgeImpl(ArcBridgeService* arc_bridge_service);
39 ~ArcInputBridgeImpl() override;
40
41 // Overridden from ui::EventHandler:
42 void OnEvent(ui::Event* event) override;
43
44 // Overridden from aura::EnvObserver:
45 void OnWindowInitialized(aura::Window* new_window) override;
46
47 // Overridden from ArcBridgeService::Observer:
48 void OnInstanceBootPhase(InstanceBootPhase phase) override;
49
50 private:
51 // Specialized method to translate and send events to the right file
52 // descriptor.
53 void SendKeyEvent(ui::KeyEvent* event);
54 void SendTouchEvent(ui::TouchEvent* event);
55 void SendMouseEvent(ui::MouseEvent* event);
56
57 // Helper method to send a struct input_event to the file descriptor. This
58 // method is to be called on the ui thread and will post a request to send
59 // the event to the io thread.
60 // The parameters map directly to the members of input_event as
61 // defined by the evdev protocol.
62 // |type| is the type of event to sent, such as EV_SYN, EV_KEY, EV_ABS.
63 // |code| is either interpreted as axis (ABS_X, ABS_Y, ...) or as key-code
64 // (KEY_A, KEY_B, ...).
65 // |value| is either the value of that axis or the boolean value of the key
66 // as in 0 (released), 1 (pressed) or 2 (repeated press).
67 void SendKernelEvent(const base::ScopedFD& fd,
68 base::TimeDelta timestamp,
69 unsigned short type,
70 unsigned short code,
71 int value);
72
73 // Shorthand for sending EV_SYN/SYN_REPORT
74 void SendSynReport(const base::ScopedFD& fd, base::TimeDelta timestamp);
75
76 // Return existing or new slot for this event.
77 int AcquireTouchSlot(ui::TouchEvent* event);
78
79 // Return touch slot for tracking id.
80 int FindTouchSlot(int tracking_id);
81
82 // Maps DOM key codes to evdev key codes
83 unsigned short DomCodeToEvdevCode(ui::DomCode dom_code);
84
85
86 // Setup bridge devices on the instance side. This needs to be called after
87 // the InstanceBootPhase::SYSTEM_SERVICES_READY has been reached.
88 void SetupBridgeDevices();
89
90 // Creates and registers file descriptor pair with the ARC bridge service,
91 // the write end is returned while the read end is sent through the bridge
92 // to the ARC instance.
93 // TODO(denniskempin): Make this interface more typesafe.
94 // |name| should be the displayable name of the emulated device (e.g. "Chrome
95 // OS Keyboard"), |device_type| the name of the device type (e.g. "keyboard")
96 // and |fd| a file descriptor that emulates the kernel events of the device.
97 // This can only be called on the thread that this class was created on.
98 base::ScopedFD CreateBridgeInputDevice(const std::string& name,
99 const std::string& device_type);
100
101 // Owned by ArcServiceManager which makes sure ArcBridgeService is destroyed
102 // after ArcInputBridge.
103 ArcBridgeService* arc_bridge_service_;
104
105 // File descriptors for the different device types.
106 base::ScopedFD keyboard_fd_;
107 base::ScopedFD mouse_fd_;
108 base::ScopedFD touchscreen_fd_;
109
110 // Scroll accumlator.
111 float offset_x_acc_;
112 float offset_y_acc_;
113
114 // Currently selected slot for multi-touch events.
115 int current_slot_;
116
117 // List of touch tracking id to slot assignments.
118 std::vector<int> current_slot_tracking_ids_;
119
120 scoped_refptr<base::SequencedTaskRunner> origin_task_runner_;
121
122 // WeakPtrFactory to use for callbacks.
123 base::WeakPtrFactory<ArcInputBridgeImpl> weak_factory_;
124
125 // List of windows we are hooked into
126 aura::WindowTracker arc_windows_;
127
128 DISALLOW_COPY_AND_ASSIGN(ArcInputBridgeImpl);
129 };
130
131 } // namespace arc
132
133 #endif // COMPONENTS_EXO_ARC_INPUT_ARC_INPUT_BRIDGE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698