event_constants.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. // Copyright (c) 2012 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_CONSTANTS_H_
  5. #define UI_EVENTS_EVENT_CONSTANTS_H_
  6. #include "build/build_config.h"
  7. namespace ui {
  8. // Event flags currently supported. It is OK to add values to the middle of
  9. // this list and/or reorder it, but make sure you also touch the various other
  10. // enums/constants that want to stay in sync with this. For example,
  11. // KeyEventFlags and MouseEventFlags should not overlap EventFlags.
  12. using EventFlags = int;
  13. // Used to denote no flags explicitly
  14. constexpr EventFlags EF_NONE = 0;
  15. // Universally applicable status bits.
  16. constexpr EventFlags EF_IS_SYNTHESIZED = 1 << 0;
  17. // Modifier key state.
  18. constexpr EventFlags EF_SHIFT_DOWN = 1 << 1;
  19. constexpr EventFlags EF_CONTROL_DOWN = 1 << 2;
  20. constexpr EventFlags EF_ALT_DOWN = 1 << 3;
  21. // GUI Key (e.g. Command on OS X keyboards, Search on Chromebook keyboards,
  22. // Windows on MS-oriented keyboards)
  23. constexpr EventFlags EF_COMMAND_DOWN = 1 << 4;
  24. // Function key.
  25. constexpr EventFlags EF_FUNCTION_DOWN = 1 << 5;
  26. constexpr EventFlags EF_ALTGR_DOWN = 1 << 6;
  27. constexpr EventFlags EF_MOD3_DOWN = 1 << 7;
  28. // Other keyboard states.
  29. constexpr EventFlags EF_NUM_LOCK_ON = 1 << 8;
  30. constexpr EventFlags EF_CAPS_LOCK_ON = 1 << 9;
  31. constexpr EventFlags EF_SCROLL_LOCK_ON = 1 << 10;
  32. // Mouse buttons.
  33. constexpr EventFlags EF_LEFT_MOUSE_BUTTON = 1 << 11;
  34. constexpr EventFlags EF_MIDDLE_MOUSE_BUTTON = 1 << 12;
  35. constexpr EventFlags EF_RIGHT_MOUSE_BUTTON = 1 << 13;
  36. constexpr EventFlags EF_BACK_MOUSE_BUTTON = 1 << 14;
  37. constexpr EventFlags EF_FORWARD_MOUSE_BUTTON = 1 << 15;
  38. constexpr EventFlags EF_MOUSE_BUTTON =
  39. EF_LEFT_MOUSE_BUTTON | EF_MIDDLE_MOUSE_BUTTON | EF_RIGHT_MOUSE_BUTTON |
  40. EF_BACK_MOUSE_BUTTON | EF_FORWARD_MOUSE_BUTTON;
  41. // An artificial value used to bridge platform differences.
  42. // Many commands on Mac as Cmd+Key are the counterparts of
  43. // Ctrl+Key on other platforms.
  44. #if BUILDFLAG(IS_APPLE)
  45. constexpr EventFlags EF_PLATFORM_ACCELERATOR = EF_COMMAND_DOWN;
  46. #else
  47. constexpr EventFlags EF_PLATFORM_ACCELERATOR = EF_CONTROL_DOWN;
  48. #endif
  49. // Flags specific to key events.
  50. // WARNING: If you add or remove values make sure traits for serializing these
  51. // values are updated.
  52. using KeyEventFlags = EventFlags;
  53. // Key event fabricated by the underlying IME without a user action. (Linux X11
  54. // only)
  55. constexpr KeyEventFlags EF_IME_FABRICATED_KEY = 1 << 16;
  56. constexpr KeyEventFlags EF_IS_REPEAT = 1 << 17;
  57. // Do not remap; the event was created with the desired final values.
  58. constexpr KeyEventFlags EF_FINAL = 1 << 18;
  59. // Windows extended key (see WM_KEYDOWN doc)
  60. constexpr KeyEventFlags EF_IS_EXTENDED_KEY = 1 << 19;
  61. // Event was generated by a stylus button
  62. constexpr KeyEventFlags EF_IS_STYLUS_BUTTON = 1 << 20;
  63. constexpr KeyEventFlags EF_MAX_KEY_EVENT_FLAGS_VALUE = (1 << 21) - 1;
  64. // Flags specific to mouse events.
  65. using MouseEventFlags = EventFlags;
  66. constexpr MouseEventFlags EF_IS_DOUBLE_CLICK = 1 << 16;
  67. constexpr MouseEventFlags EF_IS_TRIPLE_CLICK = 1 << 17;
  68. constexpr MouseEventFlags EF_IS_NON_CLIENT = 1 << 18;
  69. // Indicates this mouse event is generated from an unconsumed touch/gesture
  70. // event.
  71. constexpr MouseEventFlags EF_FROM_TOUCH = 1 << 19;
  72. // Indicates this event was generated from touch accessibility mode.
  73. constexpr MouseEventFlags EF_TOUCH_ACCESSIBILITY = 1 << 20;
  74. // Indicates this mouse event is generated because the cursor was just hidden.
  75. // This can be used to update hover state.
  76. constexpr MouseEventFlags EF_CURSOR_HIDE = 1 << 21;
  77. // Indicates this mouse event is from high precision touchpad and will come with
  78. // a high precision delta.
  79. constexpr MouseEventFlags EF_PRECISION_SCROLLING_DELTA = 1 << 22;
  80. // Indicates this mouse event is generated when users is requesting to scroll by
  81. // pages.
  82. constexpr MouseEventFlags EF_SCROLL_BY_PAGE = 1 << 23;
  83. // Indicates this mouse event is unadjusted mouse events that has unadjusted
  84. // movement delta, i.e. is from WM_INPUT on Windows.
  85. constexpr MouseEventFlags EF_UNADJUSTED_MOUSE = 1 << 24;
  86. // Indicates this mouse event should not trigger mouse warping (which moves the
  87. // mouse to another display when the mouse hits the window boundaries).
  88. constexpr MouseEventFlags EF_NOT_SUITABLE_FOR_MOUSE_WARPING = 1 << 25;
  89. // Result of dispatching an event.
  90. enum EventResult {
  91. ER_UNHANDLED = 0, // The event hasn't been handled. The event can be
  92. // propagated to other handlers.
  93. ER_HANDLED = 1 << 0, // The event has already been handled, but it can
  94. // still be propagated to other handlers.
  95. ER_CONSUMED = 1 << 1, // The event has been handled, and it should not be
  96. // propagated to other handlers.
  97. ER_DISABLE_SYNC_HANDLING =
  98. 1 << 2, // The event shouldn't be handled synchronously. This
  99. // happens if the event is being handled
  100. // asynchronously, or if the event is invalid and
  101. // shouldn't be handled at all.
  102. };
  103. // Phase of the event dispatch.
  104. enum EventPhase {
  105. EP_PREDISPATCH,
  106. EP_PRETARGET,
  107. EP_TARGET,
  108. EP_POSTTARGET,
  109. EP_POSTDISPATCH
  110. };
  111. // Phase information used for a ScrollEvent. ScrollEventPhase is for scroll
  112. // stream from user gesture, EventMomentumPhase is for inertia scroll stream
  113. // after user gesture.
  114. enum class ScrollEventPhase {
  115. // Event has no phase information. eg. the Event is not in a scroll stream.
  116. kNone,
  117. // Event is the beginning of a scroll event stream.
  118. kBegan,
  119. // Event is a scroll event with phase information.
  120. kUpdate,
  121. // Event is the end of the current scroll event stream.
  122. kEnd,
  123. };
  124. // Momentum phase information used for a ScrollEvent.
  125. enum class EventMomentumPhase {
  126. // Event is a non-momentum update to an event stream already begun.
  127. NONE,
  128. // Event is the beginning of an event stream that may result in momentum.
  129. // BEGAN vs MAY_BEGIN:
  130. // - BEGAN means we already know the inertia scroll stream must happen after
  131. // BEGAN event. On Windows touchpad, we sent this when receive the first
  132. // inertia scroll event or Direct Manipulation state change to INERTIA.
  133. // - MAY_BEGIN means the inertia scroll stream may happen after MAY_BEGIN
  134. // event. On Mac, we send this when receive releaseTouches, but we do not
  135. // know the inertia scroll stream will happen or not at that time.
  136. BEGAN,
  137. // Event maybe the beginning of an event stream that may result in momentum.
  138. // This state used on Mac.
  139. MAY_BEGIN,
  140. // Event is an update while in a momentum phase. A "begin" event for the
  141. // momentum phase portion of an event stream uses this also, but the scroll
  142. // offsets will be zero.
  143. INERTIAL_UPDATE,
  144. // Event marks the end of the current event stream. Note that this is also set
  145. // for events that are not a "stream", but indicate both the start and end of
  146. // the event (e.g. a mouse wheel tick).
  147. END,
  148. // EventMomentumPhase can only be BLOCKED when ScrollEventPhase is kEnd. Event
  149. // marks the end of the current event stream, when there will be no inertia
  150. // scrolling after the user gesture. ScrollEventPhase must simultaneously be
  151. // kEnd because that is when it is determined if an event stream that results
  152. // in momentum will begin or not. This phase is only used on Windows.
  153. BLOCKED,
  154. };
  155. enum EventDeviceId {
  156. // Device ID for Touch, Mouse and Key Events.
  157. ED_UNKNOWN_DEVICE = -1,
  158. // Device ID for events injected through a remote connection (like CRD).
  159. ED_REMOTE_INPUT_DEVICE = -2,
  160. };
  161. // Pointing device type.
  162. enum class EventPointerType : int {
  163. kUnknown,
  164. kMouse,
  165. kPen,
  166. kTouch,
  167. kEraser,
  168. kMaxValue = kEraser,
  169. };
  170. // Device type for gesture events.
  171. enum class GestureDeviceType : int {
  172. DEVICE_UNKNOWN = 0,
  173. DEVICE_TOUCHPAD,
  174. DEVICE_TOUCHSCREEN,
  175. };
  176. } // namespace ui
  177. #endif // UI_EVENTS_EVENT_CONSTANTS_H_