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

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

Powered by Google App Engine
This is Rietveld 408576698