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. 4 5 #ifndef UI_EVENTS_OZONE_EVDEV_KEY_EVENT_CONVERTER_EVDEV_H_ 6 #define UI_EVENTS_OZONE_EVDEV_KEY_EVENT_CONVERTER_EVDEV_H_ 7 8 #include "base/files/file_path.h" 9 #include "base/message_loop/message_pump_libevent.h" 10 #include "ui/events/event.h" 11 #include "ui/events/ozone/evdev/event_converter_evdev.h" 12 #include "ui/events/ozone/evdev/event_modifiers_evdev.h" 13 #include "ui/events/ozone/evdev/events_ozone_evdev_export.h" 14 15 struct input_event; 16 17 namespace ui { 18 19 class EVENTS_OZONE_EVDEV_EXPORT KeyEventConverterEvdev 20 : public EventConverterEvdev, 21 public base::MessagePumpLibevent::Watcher { 22 public: 23 KeyEventConverterEvdev(int fd, 24 base::FilePath path, 25 EventModifiersEvdev* modifiers, 26 const EventDispatchCallback& dispatch); 27 virtual ~KeyEventConverterEvdev(); 28 29 // Start & stop watching for events. 30 virtual void Start() OVERRIDE; 31 virtual void Stop() OVERRIDE; 32 33 // Overidden from base::MessagePumpLibevent::Watcher. 34 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; 35 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; 36 37 void ProcessEvents(const struct input_event* inputs, int count); 38 39 private: 40 // File descriptor for the /dev/input/event* instance. 41 int fd_; 42 43 // Path to input device. 44 base::FilePath path_; 45 46 // Shared modifier state. 47 EventModifiersEvdev* modifiers_; 48 49 // Controller for watching the input fd. 50 base::MessagePumpLibevent::FileDescriptorWatcher controller_; 51 52 void ConvertKeyEvent(int key, int value); 53 54 DISALLOW_COPY_AND_ASSIGN(KeyEventConverterEvdev); 55 }; 56 57 } // namspace ui 58 59 #endif // UI_EVENTS_OZONE_EVDEV_KEY_EVENT_CONVERTER_EVDEV_H_ 60 61