event_modifiers.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. #ifndef UI_EVENTS_EVENT_MODIFIERS_H_
  5. #define UI_EVENTS_EVENT_MODIFIERS_H_
  6. #include "ui/events/events_export.h"
  7. namespace ui {
  8. enum {
  9. MODIFIER_NONE,
  10. MODIFIER_SHIFT,
  11. MODIFIER_CONTROL,
  12. MODIFIER_ALT,
  13. MODIFIER_COMMAND,
  14. MODIFIER_ALTGR,
  15. MODIFIER_MOD3,
  16. MODIFIER_CAPS_LOCK,
  17. MODIFIER_LEFT_MOUSE_BUTTON,
  18. MODIFIER_MIDDLE_MOUSE_BUTTON,
  19. MODIFIER_RIGHT_MOUSE_BUTTON,
  20. MODIFIER_BACK_MOUSE_BUTTON,
  21. MODIFIER_FORWARD_MOUSE_BUTTON,
  22. MODIFIER_NUM_MODIFIERS
  23. };
  24. // Modifier key state for Evdev.
  25. //
  26. // Chrome relies on the underlying OS to interpret modifier keys such as Shift,
  27. // Ctrl, and Alt. The Linux input subsystem does not assign any special meaning
  28. // to these keys, so this work must happen at a higher layer (normally X11 or
  29. // the console driver). When using evdev directly, we must do it ourselves.
  30. //
  31. // The modifier state is shared between all input devices connected to the
  32. // system. This is to support actions such as Shift-Clicking that use multiple
  33. // devices.
  34. //
  35. // Normally a modifier is set if any of the keys or buttons assigned to it are
  36. // currently pressed. However some keys toggle a persistent "lock" for the
  37. // modifier instead, such as CapsLock. If a modifier is "locked" then its state
  38. // is inverted until it is unlocked.
  39. class EVENTS_EXPORT EventModifiers {
  40. public:
  41. EventModifiers();
  42. EventModifiers(const EventModifiers&) = delete;
  43. EventModifiers& operator=(const EventModifiers&) = delete;
  44. ~EventModifiers();
  45. // Record key press or release for regular modifier key (shift, alt, etc).
  46. void UpdateModifier(unsigned int modifier, bool down);
  47. // Record key press or release for locking modifier key (caps lock).
  48. void UpdateModifierLock(unsigned int modifier, bool down);
  49. // Directly set the state of a locking modifier key (caps lock).
  50. void SetModifierLock(unsigned int modifier, bool locked);
  51. // Return current flags to use for incoming events.
  52. int GetModifierFlags();
  53. // Release modifier keys.
  54. void ResetKeyboardModifiers();
  55. // Return the mask for the specified modifier.
  56. static int GetEventFlagFromModifier(unsigned int modifier);
  57. // Return the modifier for the specified mask.
  58. static int GetModifierFromEventFlag(int flag);
  59. private:
  60. // Count of keys pressed for each modifier.
  61. int modifiers_down_[MODIFIER_NUM_MODIFIERS];
  62. // Mask of modifier flags currently "locked".
  63. int modifier_flags_locked_ = 0;
  64. // Mask of modifier flags currently active (nonzero keys pressed xor locked).
  65. int modifier_flags_ = 0;
  66. // Update modifier_flags_ from modifiers_down_ and modifier_flags_locked_.
  67. void UpdateFlags(unsigned int modifier);
  68. };
  69. } // namespace ui
  70. #endif // UI_EVENTS_EVENT_MODIFIERS_H_