Drive: Add BatchableRequest subclass.
[chromium-blink-merge.git] / ui / events / ozone / evdev / keyboard_evdev.h
blob8b49ebb765bde7b0f6fb952944185c97219f71b6
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_KEYBOARD_EVDEV_H_
6 #define UI_EVENTS_OZONE_EVDEV_KEYBOARD_EVDEV_H_
8 #include <bitset>
9 #include <linux/input.h>
11 #include "base/time/time.h"
12 #include "base/timer/timer.h"
13 #include "ui/events/ozone/evdev/event_device_util.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/events/ozone/layout/keyboard_layout_engine.h"
18 namespace ui {
20 class EventModifiersEvdev;
21 enum class DomCode;
23 // Keyboard for evdev.
25 // This object is responsible for combining all attached keyboards into
26 // one logical keyboard, applying modifiers & implementing key repeat.
28 // It also currently also applies the layout.
29 class EVENTS_OZONE_EVDEV_EXPORT KeyboardEvdev {
30 public:
31 KeyboardEvdev(EventModifiersEvdev* modifiers,
32 KeyboardLayoutEngine* keyboard_layout_engine,
33 const EventDispatchCallback& callback);
34 ~KeyboardEvdev();
36 // Handlers for raw key presses & releases.
37 void OnKeyChange(unsigned int code, bool down, base::TimeDelta timestamp);
39 // Handle Caps Lock modifier.
40 void SetCapsLockEnabled(bool enabled);
41 bool IsCapsLockEnabled();
43 // Configuration for key repeat.
44 bool IsAutoRepeatEnabled();
45 void SetAutoRepeatEnabled(bool enabled);
46 void SetAutoRepeatRate(const base::TimeDelta& delay,
47 const base::TimeDelta& interval);
48 void GetAutoRepeatRate(base::TimeDelta* delay, base::TimeDelta* interval);
50 private:
51 void UpdateModifier(int modifier_flag, bool down);
52 void UpdateCapsLockLed();
53 void UpdateKeyRepeat(unsigned int key, bool down);
54 void StartKeyRepeat(unsigned int key);
55 void StopKeyRepeat();
56 void ScheduleKeyRepeat(const base::TimeDelta& delay);
57 void OnRepeatTimeout(unsigned int sequence);
58 void DispatchKey(unsigned int key,
59 bool down,
60 bool repeat,
61 base::TimeDelta timestamp);
63 // Aggregated key state. There is only one bit of state per key; we do not
64 // attempt to count presses of the same key on multiple keyboards.
66 // A key is down iff the most recent event pertaining to that key was a key
67 // down event rather than a key up event. Therefore, a particular key position
68 // can be considered released even if it is being depresssed on one or more
69 // keyboards.
70 std::bitset<KEY_CNT> key_state_;
72 // Callback for dispatching events.
73 EventDispatchCallback callback_;
75 // Shared modifier state.
76 EventModifiersEvdev* modifiers_;
78 // Shared layout engine.
79 KeyboardLayoutEngine* keyboard_layout_engine_;
81 // Key repeat state.
82 bool repeat_enabled_;
83 unsigned int repeat_key_;
84 unsigned int repeat_sequence_;
85 base::TimeDelta repeat_delay_;
86 base::TimeDelta repeat_interval_;
88 base::WeakPtrFactory<KeyboardEvdev> weak_ptr_factory_;
90 DISALLOW_COPY_AND_ASSIGN(KeyboardEvdev);
93 } // namespace ui
95 #endif // UI_EVENTS_OZONE_EVDEV_KEYBOARD_EVDEV_H_