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
,
29 InputDeviceType type
);
30 ~EventConverterEvdev() override
;
32 int id() const { return id_
; }
34 const base::FilePath
& path() const { return path_
; }
36 InputDeviceType
type() const { return type_
; }
38 void set_ignore_events(bool ignore_events
) { ignore_events_
= ignore_events
; }
40 // Start reading events.
43 // Stop reading events.
46 // Cleanup after we stop reading events (release buttons, etc).
47 virtual void OnStopped();
49 // Returns true if the converter is used for a keyboard device.
50 virtual bool HasKeyboard() const;
52 // Returns true if the converter is used for a mouse device;
53 virtual bool HasMouse() const;
55 // Returns true if the converter is used for a touchpad device.
56 virtual bool HasTouchpad() const;
58 // Returns true if the converter is used for a touchscreen device.
59 virtual bool HasTouchscreen() const;
61 // Returns true if the converter is used for a device with a caps lock LED.
62 virtual bool HasCapsLockLed() const;
64 // Returns the size of the touchscreen device if the converter is used for a
65 // touchscreen device.
66 virtual gfx::Size
GetTouchscreenSize() const;
68 // Returns the number of touch points this device supports. Should not be
69 // called unless HasTouchscreen() returns true
70 virtual int GetTouchPoints() const;
72 // Sets which keyboard keys should be processed.
73 virtual void SetAllowedKeys(scoped_ptr
<std::set
<DomCode
>> allowed_keys
);
75 // Allows all keys to be processed.
76 virtual void AllowAllKeys();
78 // Update caps lock LED state.
79 virtual void SetCapsLockLed(bool enabled
);
81 // Helper to generate a base::TimeDelta from an input_event's time
82 static base::TimeDelta
TimeDeltaFromInputEvent(const input_event
& event
);
85 // base::MessagePumpLibevent::Watcher:
86 void OnFileCanWriteWithoutBlocking(int fd
) override
;
88 // File descriptor to read.
91 // Path to input device.
94 // Uniquely identifies an event converter.
97 // Type (internal or external).
98 InputDeviceType type_
;
100 // Whether events from the device should be ignored.
103 // Controller for watching the input fd.
104 base::MessagePumpLibevent::FileDescriptorWatcher controller_
;
107 DISALLOW_COPY_AND_ASSIGN(EventConverterEvdev
);
112 #endif // UI_EVENTS_OZONE_EVDEV_EVENT_CONVERTER_EVDEV_H_