Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / events / ozone / evdev / libgestures_glue / event_reader_libevdev_cros.h
blob36ee1725b2118733e7a1ec1b5194a8ad269dee16
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_LIBGESTURES_GLUE_EVENT_READER_LIBEVDEV_CROS_H_
6 #define UI_EVENTS_OZONE_EVDEV_LIBGESTURES_GLUE_EVENT_READER_LIBEVDEV_CROS_H_
8 #include <libevdev/libevdev.h>
10 #include "base/files/file_path.h"
11 #include "base/message_loop/message_loop.h"
12 #include "ui/events/ozone/evdev/event_converter_evdev.h"
13 #include "ui/events/ozone/evdev/event_device_info.h"
15 namespace ui {
17 // Basic wrapper for libevdev-cros.
19 // This drives libevdev-cros from a file descriptor and calls delegate
20 // with the updated event state from libevdev-cros.
22 // The library doesn't support all devices currently. In particular there
23 // is no support for keyboard events.
24 class EventReaderLibevdevCros : public EventConverterEvdev {
25 public:
26 class Delegate {
27 public:
28 virtual ~Delegate();
30 // Notifier for open. This is called with the initial event state.
31 virtual void OnLibEvdevCrosOpen(Evdev* evdev, EventStateRec* evstate) = 0;
33 // Notifier for event. This is called with the updated event state.
34 virtual void OnLibEvdevCrosEvent(Evdev* evdev,
35 EventStateRec* state,
36 const timeval& time) = 0;
38 // Notifier for stop. This is called with the final event state.
39 virtual void OnLibEvdevCrosStopped(Evdev* evdev, EventStateRec* state) = 0;
42 EventReaderLibevdevCros(int fd,
43 const base::FilePath& path,
44 int id,
45 const EventDeviceInfo& devinfo,
46 scoped_ptr<Delegate> delegate);
47 ~EventReaderLibevdevCros() override;
49 // EventConverterEvdev:
50 void OnFileCanReadWithoutBlocking(int fd) override;
51 bool HasKeyboard() const override;
52 bool HasMouse() const override;
53 bool HasTouchpad() const override;
54 bool HasCapsLockLed() const override;
55 void OnDisabled() override;
57 private:
58 static void OnSynReport(void* data,
59 EventStateRec* evstate,
60 struct timeval* tv);
61 static void OnLogMessage(void*, int level, const char*, ...);
63 // Input modalities for this device.
64 bool has_keyboard_;
65 bool has_mouse_;
66 bool has_touchpad_;
68 // LEDs for this device.
69 bool has_caps_lock_led_;
71 // Libevdev state.
72 Evdev evdev_;
74 // Event state.
75 EventStateRec evstate_;
77 // Path to input device.
78 base::FilePath path_;
80 // Delegate for event processing.
81 scoped_ptr<Delegate> delegate_;
83 DISALLOW_COPY_AND_ASSIGN(EventReaderLibevdevCros);
86 } // namspace ui
88 #endif // UI_EVENTS_OZONE_EVDEV_LIBGESTURES_GLUE_EVENT_READER_LIBEVDEV_CROS_H_