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_IMPL_H_
6 #define UI_EVENTS_OZONE_EVDEV_EVENT_CONVERTER_EVDEV_IMPL_H_
10 #include "base/files/file_path.h"
11 #include "base/message_loop/message_pump_libevent.h"
12 #include "ui/events/devices/input_device.h"
13 #include "ui/events/event.h"
14 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h"
15 #include "ui/events/ozone/evdev/event_converter_evdev.h"
16 #include "ui/events/ozone/evdev/event_device_info.h"
17 #include "ui/events/ozone/evdev/event_modifiers_evdev.h"
18 #include "ui/events/ozone/evdev/events_ozone_evdev_export.h"
19 #include "ui/events/ozone/evdev/keyboard_evdev.h"
20 #include "ui/events/ozone/evdev/mouse_button_map_evdev.h"
26 class DeviceEventDispatcherEvdev
;
28 class EVENTS_OZONE_EVDEV_EXPORT EventConverterEvdevImpl
29 : public EventConverterEvdev
{
31 EventConverterEvdevImpl(int fd
,
34 const EventDeviceInfo
& info
,
35 CursorDelegateEvdev
* cursor
,
36 DeviceEventDispatcherEvdev
* dispatcher
);
37 ~EventConverterEvdevImpl() override
;
39 // EventConverterEvdev:
40 void OnFileCanReadWithoutBlocking(int fd
) override
;
41 bool HasKeyboard() const override
;
42 bool HasTouchpad() const override
;
43 bool HasCapsLockLed() const override
;
44 void SetKeyFilter(bool enable_filter
,
45 std::vector
<DomCode
> allowed_keys
) override
;
46 void OnDisabled() override
;
48 void ProcessEvents(const struct input_event
* inputs
, int count
);
51 void ConvertKeyEvent(const input_event
& input
);
52 void ConvertMouseMoveEvent(const input_event
& input
);
53 void OnKeyChange(unsigned int key
,
55 const base::TimeDelta
& timestamp
);
57 void ReleaseMouseButtons();
59 void DispatchMouseButton(const input_event
& input
);
60 void OnButtonChange(int code
, bool down
, const base::TimeDelta
& timestamp
);
62 // Flush events delimited by EV_SYN. This is useful for handling
63 // non-axis-aligned movement properly.
64 void FlushEvents(const input_event
& input
);
66 // Input modalities for this device.
70 // LEDs for this device.
71 bool has_caps_lock_led_
;
73 // Save x-axis events of relative devices to be flushed at EV_SYN time.
76 // Save y-axis events of relative devices to be flushed at EV_SYN time.
79 // Controller for watching the input fd.
80 base::MessagePumpLibevent::FileDescriptorWatcher controller_
;
82 // The evdev codes of the keys which should be blocked.
83 std::bitset
<KEY_CNT
> blocked_keys_
;
85 // Pressed keys bitset.
86 std::bitset
<KEY_CNT
> key_state_
;
88 // Last mouse button state.
89 static const int kMouseButtonCount
= BTN_JOYSTICK
- BTN_MOUSE
;
90 std::bitset
<kMouseButtonCount
> mouse_button_state_
;
92 // Shared cursor state.
93 CursorDelegateEvdev
* cursor_
;
95 // Callbacks for dispatching events.
96 DeviceEventDispatcherEvdev
* dispatcher_
;
98 DISALLOW_COPY_AND_ASSIGN(EventConverterEvdevImpl
);
103 #endif // UI_EVENTS_OZONE_EVDEV_EVENT_CONVERTER_EVDEV_IMPL_H_