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

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: nit fix 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_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 explicit ArcInputBridgeImpl(ArcBridgeService* arc_bridge_service);
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 // Specialized method to translate and send events to the right file
48 // descriptor.
49 void SendKeyEvent(ui::KeyEvent* event);
50 void SendTouchEvent(ui::TouchEvent* event);
51 void SendMouseEvent(ui::MouseEvent* event);
52
53 // Helper method to send a struct input_event to the file descriptor. This
54 // method is to be called on the ui thread and will post a request to send
55 // the event to the io thread.
56 // The parameters map directly to the members of input_event as
57 // defined by the evdev protocol.
58 // |type| is the type of event to sent, such as EV_SYN, EV_KEY, EV_ABS.
59 // |code| is either interpreted as axis (ABS_X, ABS_Y, ...) or as key-code
60 // (KEY_A, KEY_B, ...).
61 // |value| is either the value of that axis or the boolean value of the key
62 // as in 0 (released), 1 (pressed) or 2 (repeated press).
63 void SendKernelEvent(const base::ScopedFD& fd,
64 base::TimeDelta timestamp,
65 unsigned short type,
66 unsigned short code,
67 int value);
68
69 // Shorthand for sending EV_SYN/SYN_REPORT
70 void SendSynReport(const base::ScopedFD& fd, base::TimeDelta timestamp);
71
72 // Return existing or new slot for this event.
73 int AcquireTouchSlot(ui::TouchEvent* event);
74
75 // Return touch slot for tracking id.
76 int FindTouchSlot(int tracking_id);
77
78 // Setup bridge devices on the instance side. This needs to be called after
79 // the InstanceBootPhase::SYSTEM_SERVICES_READY has been reached.
80 void SetupBridgeDevices();
81
82 // Creates and registers file descriptor pair with the ARC bridge service,
83 // the write end is returned while the read end is sent through the bridge
84 // to the ARC instance.
85 // TODO(denniskempin): Make this interface more typesafe.
86 // |name| should be the displayable name of the emulated device (e.g. "Chrome
87 // OS Keyboard"), |device_type| the name of the device type (e.g. "keyboard")
88 // and |fd| a file descriptor that emulates the kernel events of the device.
89 // This can only be called on the thread that this class was created on.
90 base::ScopedFD CreateBridgeInputDevice(const std::string& name,
91 const std::string& device_type);
92
93 // Owned by ArcServiceManager which makes sure ArcBridgeService is destroyed
94 // after ArcInputBridge.
95 ArcBridgeService* arc_bridge_service_;
96
97 // File descriptors for the different device types.
98 base::ScopedFD keyboard_fd_;
99 base::ScopedFD mouse_fd_;
100 base::ScopedFD touchscreen_fd_;
101
102 // Scroll accumlator.
103 float offset_x_acc_;
104 float offset_y_acc_;
105
106 // Currently selected slot for multi-touch events.
107 int current_slot_;
108
109 // List of touch tracking id to slot assignments.
110 std::vector<int> current_slot_tracking_ids_;
111
112 scoped_refptr<base::SequencedTaskRunner> origin_task_runner_;
113
114 // WeakPtrFactory to use for callbacks.
115 base::WeakPtrFactory<ArcInputBridgeImpl> weak_factory_;
116
117 DISALLOW_COPY_AND_ASSIGN(ArcInputBridgeImpl);
118 };
119
120 } // namespace arc
121
122 #endif // COMPONENTS_EXO_ARC_INPUT_ARC_INPUT_BRIDGE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698