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; |
David Padlipsky | 544ae2a0 | 2024-02-17 01:25:06 | [diff] [blame] | 73 | #if BUILDFLAG(IS_CHROMEOS) |
| 74 | // Event was generated by customizing a button on a mouse or graphics tablet. |
| 75 | constexpr KeyEventFlags EF_IS_CUSTOMIZED_FROM_BUTTON = 1 << 21; |
| 76 | constexpr KeyEventFlags EF_MAX_KEY_EVENT_FLAGS_VALUE = (1 << 22) - 1; |
| 77 | #else |
Peter Kasting | 5380f8a7 | 2022-05-10 15:41:36 | [diff] [blame] | 78 | constexpr KeyEventFlags EF_MAX_KEY_EVENT_FLAGS_VALUE = (1 << 21) - 1; |
David Padlipsky | 544ae2a0 | 2024-02-17 01:25:06 | [diff] [blame] | 79 | #endif |
[email protected] | 5698964d | 2014-04-16 18:32:49 | [diff] [blame] | 80 | |
Joe Downing | a8e74ac | 2018-02-26 17:10:24 | [diff] [blame] | 81 | // Flags specific to mouse events. |
Peter Kasting | 5380f8a7 | 2022-05-10 15:41:36 | [diff] [blame] | 82 | using MouseEventFlags = EventFlags; |
| 83 | constexpr MouseEventFlags EF_IS_DOUBLE_CLICK = 1 << 16; |
| 84 | constexpr MouseEventFlags EF_IS_TRIPLE_CLICK = 1 << 17; |
| 85 | constexpr MouseEventFlags EF_IS_NON_CLIENT = 1 << 18; |
| 86 | // Indicates this mouse event is generated from an unconsumed touch/gesture |
| 87 | // event. |
| 88 | constexpr MouseEventFlags EF_FROM_TOUCH = 1 << 19; |
| 89 | // Indicates this event was generated from touch accessibility mode. |
| 90 | constexpr MouseEventFlags EF_TOUCH_ACCESSIBILITY = 1 << 20; |
| 91 | // Indicates this mouse event is generated because the cursor was just hidden. |
| 92 | // This can be used to update hover state. |
| 93 | constexpr MouseEventFlags EF_CURSOR_HIDE = 1 << 21; |
| 94 | // Indicates this mouse event is from high precision touchpad and will come with |
| 95 | // a high precision delta. |
| 96 | constexpr MouseEventFlags EF_PRECISION_SCROLLING_DELTA = 1 << 22; |
| 97 | // Indicates this mouse event is generated when users is requesting to scroll by |
| 98 | // pages. |
| 99 | constexpr MouseEventFlags EF_SCROLL_BY_PAGE = 1 << 23; |
| 100 | // Indicates this mouse event is unadjusted mouse events that has unadjusted |
| 101 | // movement delta, i.e. is from WM_INPUT on Windows. |
| 102 | constexpr MouseEventFlags EF_UNADJUSTED_MOUSE = 1 << 24; |
| 103 | // Indicates this mouse event should not trigger mouse warping (which moves the |
| 104 | // mouse to another display when the mouse hits the window boundaries). |
| 105 | constexpr MouseEventFlags EF_NOT_SUITABLE_FOR_MOUSE_WARPING = 1 << 25; |
[email protected] | 8d577a70 | 2011-02-10 04:56:36 | [diff] [blame] | 106 | |
Mitsuru Oshima | 3bb6ca41 | 2023-06-22 07:22:02 | [diff] [blame] | 107 | // Flags specific to touch events. |
| 108 | using TouchEventFlags = EventFlags; |
| 109 | |
| 110 | // Indicates this touch event is reserved for gesture recognition and |
| 111 | // should not be handled in the event handler. |
| 112 | constexpr TouchEventFlags EF_RESERVED_FOR_GESTURE = 1 << 26; |
| 113 | |
Ilya Karapsin | 2782e0e | 2023-06-02 18:47:28 | [diff] [blame] | 114 | // These value match the Windows default. |
| 115 | constexpr int kDoubleClickTimeMs = 500; |
| 116 | |
[email protected] | 5b174e0a | 2012-09-04 01:14:43 | [diff] [blame] | 117 | // Result of dispatching an event. |
| 118 | enum EventResult { |
tdresser | 8879cfc | 2014-12-09 21:00:17 | [diff] [blame] | 119 | ER_UNHANDLED = 0, // The event hasn't been handled. The event can be |
| 120 | // propagated to other handlers. |
| 121 | ER_HANDLED = 1 << 0, // The event has already been handled, but it can |
| 122 | // still be propagated to other handlers. |
| 123 | ER_CONSUMED = 1 << 1, // The event has been handled, and it should not be |
| 124 | // propagated to other handlers. |
| 125 | ER_DISABLE_SYNC_HANDLING = |
| 126 | 1 << 2, // The event shouldn't be handled synchronously. This |
| 127 | // happens if the event is being handled |
| 128 | // asynchronously, or if the event is invalid and |
| 129 | // shouldn't be handled at all. |
Mitsuru Oshima | ab67acc8 | 2023-04-13 15:30:06 | [diff] [blame] | 130 | ER_FORCE_PROCESS_GESTURE = |
| 131 | 1 << 3, // The event should be processed by gesture recognizer even if |
| 132 | // ER_HANDLED or ER_CONSUMED is set. |
Yuta Hijikata | a2724bc | 2023-12-05 01:55:15 | [diff] [blame] | 133 | ER_SKIPPED = |
| 134 | 1 << 4, // The event has been been handled, and it should not be |
| 135 | // propagated to other handlers but the dispatchers may decide to |
| 136 | // handle the event themselves. A handler should set the result |
| 137 | // to this if it wishes to stop the event from propagating |
| 138 | // further but does not take any action other than stopping it. |
[email protected] | 5b174e0a | 2012-09-04 01:14:43 | [diff] [blame] | 139 | }; |
| 140 | |
[email protected] | 1eeb97132 | 2012-09-11 05:56:51 | [diff] [blame] | 141 | // Phase of the event dispatch. |
| 142 | enum EventPhase { |
| 143 | EP_PREDISPATCH, |
| 144 | EP_PRETARGET, |
| 145 | EP_TARGET, |
| 146 | EP_POSTTARGET, |
| 147 | EP_POSTDISPATCH |
| 148 | }; |
| 149 | |
chaopeng | e8f2c03 | 2018-04-05 03:11:59 | [diff] [blame] | 150 | // Phase information used for a ScrollEvent. ScrollEventPhase is for scroll |
| 151 | // stream from user gesture, EventMomentumPhase is for inertia scroll stream |
| 152 | // after user gesture. |
| 153 | enum class ScrollEventPhase { |
| 154 | // Event has no phase information. eg. the Event is not in a scroll stream. |
| 155 | kNone, |
| 156 | |
| 157 | // Event is the beginning of a scroll event stream. |
| 158 | kBegan, |
| 159 | |
| 160 | // Event is a scroll event with phase information. |
| 161 | kUpdate, |
| 162 | |
| 163 | // Event is the end of the current scroll event stream. |
| 164 | kEnd, |
| 165 | }; |
| 166 | |
tapted | b94b06c | 2016-09-27 02:16:15 | [diff] [blame] | 167 | // Momentum phase information used for a ScrollEvent. |
| 168 | enum class EventMomentumPhase { |
| 169 | // Event is a non-momentum update to an event stream already begun. |
| 170 | NONE, |
| 171 | |
| 172 | // Event is the beginning of an event stream that may result in momentum. |
chaopeng | e8f2c03 | 2018-04-05 03:11:59 | [diff] [blame] | 173 | // BEGAN vs MAY_BEGIN: |
| 174 | // - BEGAN means we already know the inertia scroll stream must happen after |
| 175 | // BEGAN event. On Windows touchpad, we sent this when receive the first |
| 176 | // inertia scroll event or Direct Manipulation state change to INERTIA. |
| 177 | // - MAY_BEGIN means the inertia scroll stream may happen after MAY_BEGIN |
| 178 | // event. On Mac, we send this when receive releaseTouches, but we do not |
| 179 | // know the inertia scroll stream will happen or not at that time. |
| 180 | BEGAN, |
| 181 | |
| 182 | // Event maybe the beginning of an event stream that may result in momentum. |
| 183 | // This state used on Mac. |
tapted | b94b06c | 2016-09-27 02:16:15 | [diff] [blame] | 184 | MAY_BEGIN, |
| 185 | |
| 186 | // Event is an update while in a momentum phase. A "begin" event for the |
| 187 | // momentum phase portion of an event stream uses this also, but the scroll |
| 188 | // offsets will be zero. |
| 189 | INERTIAL_UPDATE, |
| 190 | |
| 191 | // Event marks the end of the current event stream. Note that this is also set |
| 192 | // for events that are not a "stream", but indicate both the start and end of |
| 193 | // the event (e.g. a mouse wheel tick). |
| 194 | END, |
Mario Bianucci | 4da9f93b | 2019-08-26 19:54:38 | [diff] [blame] | 195 | |
| 196 | // EventMomentumPhase can only be BLOCKED when ScrollEventPhase is kEnd. Event |
| 197 | // marks the end of the current event stream, when there will be no inertia |
| 198 | // scrolling after the user gesture. ScrollEventPhase must simultaneously be |
| 199 | // kEnd because that is when it is determined if an event stream that results |
| 200 | // in momentum will begin or not. This phase is only used on Windows. |
| 201 | BLOCKED, |
tapted | b94b06c | 2016-09-27 02:16:15 | [diff] [blame] | 202 | }; |
| 203 | |
Jeroen Dhollander | 89e6a4d | 2022-03-31 02:34:08 | [diff] [blame] | 204 | enum EventDeviceId { |
| 205 | // Device ID for Touch, Mouse and Key Events. |
| 206 | ED_UNKNOWN_DEVICE = -1, |
| 207 | // Device ID for events injected through a remote connection (like CRD). |
| 208 | ED_REMOTE_INPUT_DEVICE = -2, |
| 209 | }; |
[email protected] | 595079ce | 2014-07-11 22:25:13 | [diff] [blame] | 210 | |
robert.bradford | f62ea41 | 2015-08-19 16:37:49 | [diff] [blame] | 211 | // Pointing device type. |
| 212 | enum class EventPointerType : int { |
Dave Tapuska | 1621efb | 2020-04-29 15:39:54 | [diff] [blame] | 213 | kUnknown, |
| 214 | kMouse, |
| 215 | kPen, |
| 216 | kTouch, |
| 217 | kEraser, |
| 218 | kMaxValue = kEraser, |
robert.bradford | f62ea41 | 2015-08-19 16:37:49 | [diff] [blame] | 219 | }; |
| 220 | |
mohsen | 7d45a48 | 2016-05-24 21:03:44 | [diff] [blame] | 221 | // Device type for gesture events. |
| 222 | enum class GestureDeviceType : int { |
| 223 | DEVICE_UNKNOWN = 0, |
| 224 | DEVICE_TOUCHPAD, |
| 225 | DEVICE_TOUCHSCREEN, |
| 226 | }; |
| 227 | |
[email protected] | 8d577a70 | 2011-02-10 04:56:36 | [diff] [blame] | 228 | } // namespace ui |
| 229 | |
[email protected] | 86ccbd4 | 2013-09-18 18:11:54 | [diff] [blame] | 230 | #endif // UI_EVENTS_EVENT_CONSTANTS_H_ |