Avi Drissman | 3e1a26c | 2022-09-15 20:26:03 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
[email protected] | 8d577a70 | 2011-02-10 04:56:36 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 86ccbd4 | 2013-09-18 18:11:54 | [diff] [blame] | 5 | #ifndef UI_EVENTS_EVENT_CONSTANTS_H_ |
| 6 | #define UI_EVENTS_EVENT_CONSTANTS_H_ |
[email protected] | 8d577a70 | 2011-02-10 04:56:36 | [diff] [blame] | 7 | |
Wei Li | 1ce0b94 | 2018-05-23 20:08:43 | [diff] [blame] | 8 | #include "build/build_config.h" |
| 9 | |
[email protected] | 8d577a70 | 2011-02-10 04:56:36 | [diff] [blame] | 10 | namespace ui { |
| 11 | |
Jayson Adams | 7553327 | 2021-10-20 20:50:22 | [diff] [blame] | 12 | // Event flags currently supported. It is OK to add values to the middle of |
pkasting | cc7f6ac | 2016-01-08 23:38:47 | [diff] [blame] | 13 | // this list and/or reorder it, but make sure you also touch the various other |
Jayson Adams | 7553327 | 2021-10-20 20:50:22 | [diff] [blame] | 14 | // enums/constants that want to stay in sync with this. For example, |
| 15 | // KeyEventFlags and MouseEventFlags should not overlap EventFlags. |
Peter Kasting | 5380f8a7 | 2022-05-10 15:41:36 | [diff] [blame] | 16 | using EventFlags = int; |
| 17 | // Used to denote no flags explicitly |
| 18 | constexpr EventFlags EF_NONE = 0; |
pkasting | cc7f6ac | 2016-01-08 23:38:47 | [diff] [blame] | 19 | |
Peter Kasting | 5380f8a7 | 2022-05-10 15:41:36 | [diff] [blame] | 20 | // Universally applicable status bits. |
| 21 | constexpr EventFlags EF_IS_SYNTHESIZED = 1 << 0; |
pkasting | cc7f6ac | 2016-01-08 23:38:47 | [diff] [blame] | 22 | |
Peter Kasting | 5380f8a7 | 2022-05-10 15:41:36 | [diff] [blame] | 23 | // Modifier key state. |
| 24 | constexpr EventFlags EF_SHIFT_DOWN = 1 << 1; |
| 25 | constexpr EventFlags EF_CONTROL_DOWN = 1 << 2; |
| 26 | constexpr EventFlags EF_ALT_DOWN = 1 << 3; |
| 27 | // GUI Key (e.g. Command on OS X keyboards, Search on Chromebook keyboards, |
| 28 | // Windows on MS-oriented keyboards) |
| 29 | constexpr EventFlags EF_COMMAND_DOWN = 1 << 4; |
| 30 | // Function key. |
| 31 | constexpr EventFlags EF_FUNCTION_DOWN = 1 << 5; |
| 32 | constexpr EventFlags EF_ALTGR_DOWN = 1 << 6; |
| 33 | constexpr EventFlags EF_MOD3_DOWN = 1 << 7; |
pkasting | cc7f6ac | 2016-01-08 23:38:47 | [diff] [blame] | 34 | |
Peter Kasting | 5380f8a7 | 2022-05-10 15:41:36 | [diff] [blame] | 35 | // Other keyboard states. |
| 36 | constexpr EventFlags EF_NUM_LOCK_ON = 1 << 8; |
| 37 | constexpr EventFlags EF_CAPS_LOCK_ON = 1 << 9; |
| 38 | constexpr EventFlags EF_SCROLL_LOCK_ON = 1 << 10; |
pkasting | cc7f6ac | 2016-01-08 23:38:47 | [diff] [blame] | 39 | |
Peter Kasting | 5380f8a7 | 2022-05-10 15:41:36 | [diff] [blame] | 40 | // Mouse buttons. |
| 41 | constexpr EventFlags EF_LEFT_MOUSE_BUTTON = 1 << 11; |
| 42 | constexpr EventFlags EF_MIDDLE_MOUSE_BUTTON = 1 << 12; |
| 43 | constexpr EventFlags EF_RIGHT_MOUSE_BUTTON = 1 << 13; |
| 44 | constexpr EventFlags EF_BACK_MOUSE_BUTTON = 1 << 14; |
| 45 | constexpr EventFlags EF_FORWARD_MOUSE_BUTTON = 1 << 15; |
| 46 | constexpr EventFlags EF_MOUSE_BUTTON = |
| 47 | EF_LEFT_MOUSE_BUTTON | EF_MIDDLE_MOUSE_BUTTON | EF_RIGHT_MOUSE_BUTTON | |
| 48 | EF_BACK_MOUSE_BUTTON | EF_FORWARD_MOUSE_BUTTON; |
Wei Li | 1ce0b94 | 2018-05-23 20:08:43 | [diff] [blame] | 49 | |
| 50 | // An artificial value used to bridge platform differences. |
| 51 | // Many commands on Mac as Cmd+Key are the counterparts of |
| 52 | // Ctrl+Key on other platforms. |
Xiaohan Wang | ebf889e6 | 2022-01-20 07:21:36 | [diff] [blame] | 53 | #if BUILDFLAG(IS_APPLE) |
Peter Kasting | 5380f8a7 | 2022-05-10 15:41:36 | [diff] [blame] | 54 | constexpr EventFlags EF_PLATFORM_ACCELERATOR = EF_COMMAND_DOWN; |
Wei Li | 1ce0b94 | 2018-05-23 20:08:43 | [diff] [blame] | 55 | #else |
Peter Kasting | 5380f8a7 | 2022-05-10 15:41:36 | [diff] [blame] | 56 | constexpr EventFlags EF_PLATFORM_ACCELERATOR = EF_CONTROL_DOWN; |
Wei Li | 1ce0b94 | 2018-05-23 20:08:43 | [diff] [blame] | 57 | #endif |
[email protected] | 8d577a70 | 2011-02-10 04:56:36 | [diff] [blame] | 58 | |
Joe Downing | a8e74ac | 2018-02-26 17:10:24 | [diff] [blame] | 59 | // Flags specific to key events. |
Scott Violet | 154ad7d | 2019-01-18 20:47:52 | [diff] [blame] | 60 | // WARNING: If you add or remove values make sure traits for serializing these |
| 61 | // values are updated. |
Peter Kasting | 5380f8a7 | 2022-05-10 15:41:36 | [diff] [blame] | 62 | using KeyEventFlags = EventFlags; |
| 63 | // Key event fabricated by the underlying IME without a user action. (Linux X11 |
| 64 | // only) |
| 65 | constexpr KeyEventFlags EF_IME_FABRICATED_KEY = 1 << 16; |
| 66 | constexpr KeyEventFlags EF_IS_REPEAT = 1 << 17; |
| 67 | // Do not remap; the event was created with the desired final values. |
| 68 | constexpr KeyEventFlags EF_FINAL = 1 << 18; |
| 69 | // Windows extended key (see WM_KEYDOWN doc) |
| 70 | constexpr KeyEventFlags EF_IS_EXTENDED_KEY = 1 << 19; |
| 71 | // Event was generated by a stylus button |
| 72 | constexpr KeyEventFlags EF_IS_STYLUS_BUTTON = 1 << 20; |
| 73 | constexpr KeyEventFlags EF_MAX_KEY_EVENT_FLAGS_VALUE = (1 << 21) - 1; |
[email protected] | 5698964d | 2014-04-16 18:32:49 | [diff] [blame] | 74 | |
Joe Downing | a8e74ac | 2018-02-26 17:10:24 | [diff] [blame] | 75 | // Flags specific to mouse events. |
Peter Kasting | 5380f8a7 | 2022-05-10 15:41:36 | [diff] [blame] | 76 | using MouseEventFlags = EventFlags; |
| 77 | constexpr MouseEventFlags EF_IS_DOUBLE_CLICK = 1 << 16; |
| 78 | constexpr MouseEventFlags EF_IS_TRIPLE_CLICK = 1 << 17; |
| 79 | constexpr MouseEventFlags EF_IS_NON_CLIENT = 1 << 18; |
| 80 | // Indicates this mouse event is generated from an unconsumed touch/gesture |
| 81 | // event. |
| 82 | constexpr MouseEventFlags EF_FROM_TOUCH = 1 << 19; |
| 83 | // Indicates this event was generated from touch accessibility mode. |
| 84 | constexpr MouseEventFlags EF_TOUCH_ACCESSIBILITY = 1 << 20; |
| 85 | // Indicates this mouse event is generated because the cursor was just hidden. |
| 86 | // This can be used to update hover state. |
| 87 | constexpr MouseEventFlags EF_CURSOR_HIDE = 1 << 21; |
| 88 | // Indicates this mouse event is from high precision touchpad and will come with |
| 89 | // a high precision delta. |
| 90 | constexpr MouseEventFlags EF_PRECISION_SCROLLING_DELTA = 1 << 22; |
| 91 | // Indicates this mouse event is generated when users is requesting to scroll by |
| 92 | // pages. |
| 93 | constexpr MouseEventFlags EF_SCROLL_BY_PAGE = 1 << 23; |
| 94 | // Indicates this mouse event is unadjusted mouse events that has unadjusted |
| 95 | // movement delta, i.e. is from WM_INPUT on Windows. |
| 96 | constexpr MouseEventFlags EF_UNADJUSTED_MOUSE = 1 << 24; |
| 97 | // Indicates this mouse event should not trigger mouse warping (which moves the |
| 98 | // mouse to another display when the mouse hits the window boundaries). |
| 99 | constexpr MouseEventFlags EF_NOT_SUITABLE_FOR_MOUSE_WARPING = 1 << 25; |
[email protected] | 8d577a70 | 2011-02-10 04:56:36 | [diff] [blame] | 100 | |
[email protected] | 5b174e0a | 2012-09-04 01:14:43 | [diff] [blame] | 101 | // Result of dispatching an event. |
| 102 | enum EventResult { |
tdresser | 8879cfc | 2014-12-09 21:00:17 | [diff] [blame] | 103 | ER_UNHANDLED = 0, // The event hasn't been handled. The event can be |
| 104 | // propagated to other handlers. |
| 105 | ER_HANDLED = 1 << 0, // The event has already been handled, but it can |
| 106 | // still be propagated to other handlers. |
| 107 | ER_CONSUMED = 1 << 1, // The event has been handled, and it should not be |
| 108 | // propagated to other handlers. |
| 109 | ER_DISABLE_SYNC_HANDLING = |
| 110 | 1 << 2, // The event shouldn't be handled synchronously. This |
| 111 | // happens if the event is being handled |
| 112 | // asynchronously, or if the event is invalid and |
| 113 | // shouldn't be handled at all. |
Mitsuru Oshima | ab67acc8 | 2023-04-13 15:30:06 | [diff] [blame^] | 114 | ER_FORCE_PROCESS_GESTURE = |
| 115 | 1 << 3, // The event should be processed by gesture recognizer even if |
| 116 | // ER_HANDLED or ER_CONSUMED is set. |
[email protected] | 5b174e0a | 2012-09-04 01:14:43 | [diff] [blame] | 117 | }; |
| 118 | |
[email protected] | 1eeb97132 | 2012-09-11 05:56:51 | [diff] [blame] | 119 | // Phase of the event dispatch. |
| 120 | enum EventPhase { |
| 121 | EP_PREDISPATCH, |
| 122 | EP_PRETARGET, |
| 123 | EP_TARGET, |
| 124 | EP_POSTTARGET, |
| 125 | EP_POSTDISPATCH |
| 126 | }; |
| 127 | |
chaopeng | e8f2c03 | 2018-04-05 03:11:59 | [diff] [blame] | 128 | // Phase information used for a ScrollEvent. ScrollEventPhase is for scroll |
| 129 | // stream from user gesture, EventMomentumPhase is for inertia scroll stream |
| 130 | // after user gesture. |
| 131 | enum class ScrollEventPhase { |
| 132 | // Event has no phase information. eg. the Event is not in a scroll stream. |
| 133 | kNone, |
| 134 | |
| 135 | // Event is the beginning of a scroll event stream. |
| 136 | kBegan, |
| 137 | |
| 138 | // Event is a scroll event with phase information. |
| 139 | kUpdate, |
| 140 | |
| 141 | // Event is the end of the current scroll event stream. |
| 142 | kEnd, |
| 143 | }; |
| 144 | |
tapted | b94b06c | 2016-09-27 02:16:15 | [diff] [blame] | 145 | // Momentum phase information used for a ScrollEvent. |
| 146 | enum class EventMomentumPhase { |
| 147 | // Event is a non-momentum update to an event stream already begun. |
| 148 | NONE, |
| 149 | |
| 150 | // Event is the beginning of an event stream that may result in momentum. |
chaopeng | e8f2c03 | 2018-04-05 03:11:59 | [diff] [blame] | 151 | // BEGAN vs MAY_BEGIN: |
| 152 | // - BEGAN means we already know the inertia scroll stream must happen after |
| 153 | // BEGAN event. On Windows touchpad, we sent this when receive the first |
| 154 | // inertia scroll event or Direct Manipulation state change to INERTIA. |
| 155 | // - MAY_BEGIN means the inertia scroll stream may happen after MAY_BEGIN |
| 156 | // event. On Mac, we send this when receive releaseTouches, but we do not |
| 157 | // know the inertia scroll stream will happen or not at that time. |
| 158 | BEGAN, |
| 159 | |
| 160 | // Event maybe the beginning of an event stream that may result in momentum. |
| 161 | // This state used on Mac. |
tapted | b94b06c | 2016-09-27 02:16:15 | [diff] [blame] | 162 | MAY_BEGIN, |
| 163 | |
| 164 | // Event is an update while in a momentum phase. A "begin" event for the |
| 165 | // momentum phase portion of an event stream uses this also, but the scroll |
| 166 | // offsets will be zero. |
| 167 | INERTIAL_UPDATE, |
| 168 | |
| 169 | // Event marks the end of the current event stream. Note that this is also set |
| 170 | // for events that are not a "stream", but indicate both the start and end of |
| 171 | // the event (e.g. a mouse wheel tick). |
| 172 | END, |
Mario Bianucci | 4da9f93b | 2019-08-26 19:54:38 | [diff] [blame] | 173 | |
| 174 | // EventMomentumPhase can only be BLOCKED when ScrollEventPhase is kEnd. Event |
| 175 | // marks the end of the current event stream, when there will be no inertia |
| 176 | // scrolling after the user gesture. ScrollEventPhase must simultaneously be |
| 177 | // kEnd because that is when it is determined if an event stream that results |
| 178 | // in momentum will begin or not. This phase is only used on Windows. |
| 179 | BLOCKED, |
tapted | b94b06c | 2016-09-27 02:16:15 | [diff] [blame] | 180 | }; |
| 181 | |
Jeroen Dhollander | 89e6a4d | 2022-03-31 02:34:08 | [diff] [blame] | 182 | enum EventDeviceId { |
| 183 | // Device ID for Touch, Mouse and Key Events. |
| 184 | ED_UNKNOWN_DEVICE = -1, |
| 185 | // Device ID for events injected through a remote connection (like CRD). |
| 186 | ED_REMOTE_INPUT_DEVICE = -2, |
| 187 | }; |
[email protected] | 595079ce | 2014-07-11 22:25:13 | [diff] [blame] | 188 | |
robert.bradford | f62ea41 | 2015-08-19 16:37:49 | [diff] [blame] | 189 | // Pointing device type. |
| 190 | enum class EventPointerType : int { |
Dave Tapuska | 1621efb | 2020-04-29 15:39:54 | [diff] [blame] | 191 | kUnknown, |
| 192 | kMouse, |
| 193 | kPen, |
| 194 | kTouch, |
| 195 | kEraser, |
| 196 | kMaxValue = kEraser, |
robert.bradford | f62ea41 | 2015-08-19 16:37:49 | [diff] [blame] | 197 | }; |
| 198 | |
mohsen | 7d45a48 | 2016-05-24 21:03:44 | [diff] [blame] | 199 | // Device type for gesture events. |
| 200 | enum class GestureDeviceType : int { |
| 201 | DEVICE_UNKNOWN = 0, |
| 202 | DEVICE_TOUCHPAD, |
| 203 | DEVICE_TOUCHSCREEN, |
| 204 | }; |
| 205 | |
[email protected] | 8d577a70 | 2011-02-10 04:56:36 | [diff] [blame] | 206 | } // namespace ui |
| 207 | |
[email protected] | 86ccbd4 | 2013-09-18 18:11:54 | [diff] [blame] | 208 | #endif // UI_EVENTS_EVENT_CONSTANTS_H_ |