ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / ui / events / ozone / evdev / event_converter_evdev.h
blob3ca5f0bcd7dbdde687e416c549380f0f9f0255ed
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_
8 #include <set>
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"
18 struct input_event;
20 namespace ui {
21 enum class DomCode;
23 class EVENTS_OZONE_EVDEV_EXPORT EventConverterEvdev
24 : public base::MessagePumpLibevent::Watcher {
25 public:
26 EventConverterEvdev(int fd,
27 const base::FilePath& path,
28 int id,
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.
41 void Start();
43 // Stop reading events.
44 void Stop();
46 // Returns true if the converter is used for a keyboard device.
47 virtual bool HasKeyboard() const;
49 // Returns true if the converter is used for a mouse device;
50 virtual bool HasMouse() const;
52 // Returns true if the converter is used for a touchpad device.
53 virtual bool HasTouchpad() const;
55 // Returns true if the converter is used for a touchscreen device.
56 virtual bool HasTouchscreen() const;
58 // Returns true if the converter is used for a device with a caps lock LED.
59 virtual bool HasCapsLockLed() const;
61 // Returns the size of the touchscreen device if the converter is used for a
62 // touchscreen device.
63 virtual gfx::Size GetTouchscreenSize() const;
65 // Returns the number of touch points this device supports. Should not be
66 // called unless HasTouchscreen() returns true
67 virtual int GetTouchPoints() const;
69 // Sets which keyboard keys should be processed.
70 virtual void SetAllowedKeys(scoped_ptr<std::set<DomCode>> allowed_keys);
72 // Allows all keys to be processed.
73 virtual void AllowAllKeys();
75 // Update caps lock LED state.
76 virtual void SetCapsLockLed(bool enabled);
78 // Helper to generate a base::TimeDelta from an input_event's time
79 static base::TimeDelta TimeDeltaFromInputEvent(const input_event& event);
81 protected:
82 // base::MessagePumpLibevent::Watcher:
83 void OnFileCanWriteWithoutBlocking(int fd) override;
85 // File descriptor to read.
86 int fd_;
88 // Path to input device.
89 base::FilePath path_;
91 // Uniquely identifies an event converter.
92 int id_;
94 // Type (internal or external).
95 InputDeviceType type_;
97 // Whether events from the device should be ignored.
98 bool ignore_events_;
100 // Controller for watching the input fd.
101 base::MessagePumpLibevent::FileDescriptorWatcher controller_;
103 private:
104 DISALLOW_COPY_AND_ASSIGN(EventConverterEvdev);
107 } // namespace ui
109 #endif // UI_EVENTS_OZONE_EVDEV_EVENT_CONVERTER_EVDEV_H_