Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / events / ozone / evdev / keyboard_evdev.h
blob8cc1916f00d8c96d94f69ce484748cb308adf758
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.
38 // |code| is a Linux key code (from <linux/input.h>). |down| represents the
39 // key state. |suppress_auto_repeat| prevents the event from triggering
40 // auto-repeat, if enabled. |device_id| uniquely identifies the source
41 // keyboard device.
42 void OnKeyChange(unsigned int code,
43 bool down,
44 bool suppress_auto_repeat,
45 base::TimeDelta timestamp,
46 int device_id);
48 // Handle Caps Lock modifier.
49 void SetCapsLockEnabled(bool enabled);
50 bool IsCapsLockEnabled();
52 // Configuration for key repeat.
53 bool IsAutoRepeatEnabled();
54 void SetAutoRepeatEnabled(bool enabled);
55 void SetAutoRepeatRate(const base::TimeDelta& delay,
56 const base::TimeDelta& interval);
57 void GetAutoRepeatRate(base::TimeDelta* delay, base::TimeDelta* interval);
59 private:
60 void UpdateModifier(int modifier_flag, bool down);
61 void UpdateCapsLockLed();
62 void UpdateKeyRepeat(unsigned int key,
63 bool down,
64 bool suppress_auto_repeat,
65 int device_id);
66 void StartKeyRepeat(unsigned int key, int device_id);
67 void StopKeyRepeat();
68 void ScheduleKeyRepeat(const base::TimeDelta& delay);
69 void OnRepeatTimeout(unsigned int sequence);
70 void OnRepeatCommit(unsigned int sequence);
71 void DispatchKey(unsigned int key,
72 bool down,
73 bool repeat,
74 base::TimeDelta timestamp,
75 int device_id);
77 // Aggregated key state. There is only one bit of state per key; we do not
78 // attempt to count presses of the same key on multiple keyboards.
80 // A key is down iff the most recent event pertaining to that key was a key
81 // down event rather than a key up event. Therefore, a particular key position
82 // can be considered released even if it is being depresssed on one or more
83 // keyboards.
84 std::bitset<KEY_CNT> key_state_;
86 // Callback for dispatching events.
87 EventDispatchCallback callback_;
89 // Shared modifier state.
90 EventModifiersEvdev* modifiers_;
92 // Shared layout engine.
93 KeyboardLayoutEngine* keyboard_layout_engine_;
95 // Key repeat state.
96 bool auto_repeat_enabled_ = true;
97 unsigned int repeat_key_ = KEY_RESERVED;
98 unsigned int repeat_sequence_ = 0;
99 int repeat_device_id_ = 0;
100 base::TimeDelta repeat_delay_;
101 base::TimeDelta repeat_interval_;
103 base::WeakPtrFactory<KeyboardEvdev> weak_ptr_factory_;
105 DISALLOW_COPY_AND_ASSIGN(KeyboardEvdev);
108 } // namespace ui
110 #endif // UI_EVENTS_OZONE_EVDEV_KEYBOARD_EVDEV_H_