1 // Copyright 2014 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.
5 #ifndef UI_EVENTS_OZONE_EVDEV_EVENT_CONVERTER_EVDEV_H_
6 #define UI_EVENTS_OZONE_EVDEV_EVENT_CONVERTER_EVDEV_H_
10 #include "base/callback.h"
11 #include "base/files/file_path.h"
12 #include "base/message_loop/message_loop.h"
13 #include "ui/events/devices/input_device.h"
14 #include "ui/events/ozone/evdev/event_dispatch_callback.h"
15 #include "ui/events/ozone/evdev/events_ozone_evdev_export.h"
16 #include "ui/gfx/geometry/size.h"
23 class EVENTS_OZONE_EVDEV_EXPORT EventConverterEvdev
24 : public base::MessagePumpLibevent::Watcher
{
26 EventConverterEvdev(int fd
,
27 const base::FilePath
& path
,
30 const std::string
& name
,
33 ~EventConverterEvdev() override
;
35 int id() const { return input_device_
.id
; }
37 const base::FilePath
& path() const { return path_
; }
39 InputDeviceType
type() const { return input_device_
.type
; }
41 const InputDevice
& input_device() const { return input_device_
; }
43 // Start reading events.
46 // Stop reading events.
49 // Enable or disable this device. A disabled device still polls for
50 // input and can update state but must not dispatch any events to UI.
51 void SetEnabled(bool enabled
);
53 // Cleanup after we stop reading events (release buttons, etc).
54 virtual void OnStopped();
56 // Prepare for disable (e.g. should release keys/buttons/touches).
57 virtual void OnDisabled();
59 // Start or restart (e.g. should reapply keys/buttons/touches).
60 virtual void OnEnabled();
62 // Dump recent events into a file.
63 virtual void DumpTouchEventLog(const char* filename
);
65 // Returns true if the converter is used for a keyboard device.
66 virtual bool HasKeyboard() const;
68 // Returns true if the converter is used for a mouse device;
69 virtual bool HasMouse() const;
71 // Returns true if the converter is used for a touchpad device.
72 virtual bool HasTouchpad() const;
74 // Returns true if the converter is used for a touchscreen device.
75 virtual bool HasTouchscreen() const;
77 // Returns true if the converter is used for a device with a caps lock LED.
78 virtual bool HasCapsLockLed() const;
80 // Returns the size of the touchscreen device if the converter is used for a
81 // touchscreen device.
82 virtual gfx::Size
GetTouchscreenSize() const;
84 // Returns the number of touch points this device supports. Should not be
85 // called unless HasTouchscreen() returns true
86 virtual int GetTouchPoints() const;
88 // Sets which keyboard keys should be processed. If |enable_filter| is
89 // false, all keys are allowed and |allowed_keys| is ignored.
90 virtual void SetKeyFilter(bool enable_filter
,
91 std::vector
<DomCode
> allowed_keys
);
93 // Update caps lock LED state.
94 virtual void SetCapsLockLed(bool enabled
);
96 // Update touch event logging state.
97 virtual void SetTouchEventLoggingEnabled(bool enabled
);
99 // Helper to generate a base::TimeDelta from an input_event's time
100 static base::TimeDelta
TimeDeltaFromInputEvent(const input_event
& event
);
103 // base::MessagePumpLibevent::Watcher:
104 void OnFileCanWriteWithoutBlocking(int fd
) override
;
106 // File descriptor to read.
109 // Path to input device.
110 base::FilePath path_
;
112 // Input device information, including id (which uniquely identifies an
113 // event converter) and type.
114 InputDevice input_device_
;
116 // Whether we're polling for input on the device.
117 bool watching_
= false;
119 // Whether events should be dispatched to UI.
120 bool enabled_
= false;
122 // Controller for watching the input fd.
123 base::MessagePumpLibevent::FileDescriptorWatcher controller_
;
126 DISALLOW_COPY_AND_ASSIGN(EventConverterEvdev
);
131 #endif // UI_EVENTS_OZONE_EVDEV_EVENT_CONVERTER_EVDEV_H_