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_MODIFIERS_EVDEV_H_
6 #define UI_EVENTS_OZONE_EVDEV_EVENT_MODIFIERS_EVDEV_H_
8 #include "base/basictypes.h"
9 #include "ui/events/ozone/evdev/events_ozone_evdev_export.h"
15 EVDEV_MODIFIER_CAPS_LOCK
,
17 EVDEV_MODIFIER_CONTROL
,
19 EVDEV_MODIFIER_LEFT_MOUSE_BUTTON
,
20 EVDEV_MODIFIER_MIDDLE_MOUSE_BUTTON
,
21 EVDEV_MODIFIER_RIGHT_MOUSE_BUTTON
,
22 EVDEV_MODIFIER_COMMAND
,
28 // Modifier key state for Evdev.
30 // Chrome relies on the underlying OS to interpret modifier keys such as Shift,
31 // Ctrl, and Alt. The Linux input subsystem does not assign any special meaning
32 // to these keys, so this work must happen at a higher layer (normally X11 or
33 // the console driver). When using evdev directly, we must do it ourselves.
35 // The modifier state is shared between all input devices connected to the
36 // system. This is to support actions such as Shift-Clicking that use multiple
39 // Normally a modifier is set if any of the keys or buttons assigned to it are
40 // currently pressed. However some keys toggle a persistent "lock" for the
41 // modifier instead, such as CapsLock. If a modifier is "locked" then its state
42 // is inverted until it is unlocked.
43 class EVENTS_OZONE_EVDEV_EXPORT EventModifiersEvdev
{
45 EventModifiersEvdev();
46 ~EventModifiersEvdev();
48 // Record key press or release for regular modifier key (shift, alt, etc).
49 void UpdateModifier(unsigned int modifier
, bool down
);
51 // Record key press or release for locking modifier key (caps lock).
52 void UpdateModifierLock(unsigned int modifier
, bool down
);
54 // Directly set the state of a locking modifier key (caps lock).
55 void SetModifierLock(unsigned int modifier
, bool locked
);
57 // Return current flags to use for incoming events.
58 int GetModifierFlags();
60 // Return the mask for the specified modifier.
61 static int GetEventFlagFromModifier(unsigned int modifier
);
64 // Count of keys pressed for each modifier.
65 int modifiers_down_
[EVDEV_NUM_MODIFIERS
];
67 // Mask of modifier flags currently "locked".
68 int modifier_flags_locked_
;
70 // Mask of modifier flags currently active (nonzero keys pressed xor locked).
73 // Update modifier_flags_ from modifiers_down_ and modifier_flags_locked_.
74 void UpdateFlags(unsigned int modifier
);
76 DISALLOW_COPY_AND_ASSIGN(EventModifiersEvdev
);
81 #endif // UI_EVENTS_OZONE_EVDEV_EVENT_MODIFIERS_EVDEV_H_