blob: 9c97392692d7967ebc854feeb61e478688a11935 [file] [log] [blame]
Avi Drissman3e1a26c2022-09-15 20:26:031// Copyright 2012 The Chromium Authors
[email protected]8d577a702011-02-10 04:56:362// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]86ccbd42013-09-18 18:11:545#ifndef UI_EVENTS_EVENT_CONSTANTS_H_
6#define UI_EVENTS_EVENT_CONSTANTS_H_
[email protected]8d577a702011-02-10 04:56:367
Wei Li1ce0b942018-05-23 20:08:438#include "build/build_config.h"
9
[email protected]8d577a702011-02-10 04:56:3610namespace ui {
11
Jayson Adams75533272021-10-20 20:50:2212// Event flags currently supported. It is OK to add values to the middle of
pkastingcc7f6ac2016-01-08 23:38:4713// this list and/or reorder it, but make sure you also touch the various other
Jayson Adams75533272021-10-20 20:50:2214// enums/constants that want to stay in sync with this. For example,
15// KeyEventFlags and MouseEventFlags should not overlap EventFlags.
Peter Kasting5380f8a72022-05-10 15:41:3616using EventFlags = int;
17// Used to denote no flags explicitly
18constexpr EventFlags EF_NONE = 0;
pkastingcc7f6ac2016-01-08 23:38:4719
Peter Kasting5380f8a72022-05-10 15:41:3620// Universally applicable status bits.
21constexpr EventFlags EF_IS_SYNTHESIZED = 1 << 0;
pkastingcc7f6ac2016-01-08 23:38:4722
Peter Kasting5380f8a72022-05-10 15:41:3623// Modifier key state.
24constexpr EventFlags EF_SHIFT_DOWN = 1 << 1;
25constexpr EventFlags EF_CONTROL_DOWN = 1 << 2;
26constexpr 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)
29constexpr EventFlags EF_COMMAND_DOWN = 1 << 4;
30// Function key.
31constexpr EventFlags EF_FUNCTION_DOWN = 1 << 5;
32constexpr EventFlags EF_ALTGR_DOWN = 1 << 6;
33constexpr EventFlags EF_MOD3_DOWN = 1 << 7;
pkastingcc7f6ac2016-01-08 23:38:4734
Peter Kasting5380f8a72022-05-10 15:41:3635// Other keyboard states.
36constexpr EventFlags EF_NUM_LOCK_ON = 1 << 8;
37constexpr EventFlags EF_CAPS_LOCK_ON = 1 << 9;
38constexpr EventFlags EF_SCROLL_LOCK_ON = 1 << 10;
pkastingcc7f6ac2016-01-08 23:38:4739
Peter Kasting5380f8a72022-05-10 15:41:3640// Mouse buttons.
41constexpr EventFlags EF_LEFT_MOUSE_BUTTON = 1 << 11;
42constexpr EventFlags EF_MIDDLE_MOUSE_BUTTON = 1 << 12;
43constexpr EventFlags EF_RIGHT_MOUSE_BUTTON = 1 << 13;
44constexpr EventFlags EF_BACK_MOUSE_BUTTON = 1 << 14;
45constexpr EventFlags EF_FORWARD_MOUSE_BUTTON = 1 << 15;
46constexpr 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 Li1ce0b942018-05-23 20:08:4349
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 Wangebf889e62022-01-20 07:21:3653#if BUILDFLAG(IS_APPLE)
Peter Kasting5380f8a72022-05-10 15:41:3654constexpr EventFlags EF_PLATFORM_ACCELERATOR = EF_COMMAND_DOWN;
Wei Li1ce0b942018-05-23 20:08:4355#else
Peter Kasting5380f8a72022-05-10 15:41:3656constexpr EventFlags EF_PLATFORM_ACCELERATOR = EF_CONTROL_DOWN;
Wei Li1ce0b942018-05-23 20:08:4357#endif
[email protected]8d577a702011-02-10 04:56:3658
Joe Downinga8e74ac2018-02-26 17:10:2459// Flags specific to key events.
Scott Violet154ad7d2019-01-18 20:47:5260// WARNING: If you add or remove values make sure traits for serializing these
61// values are updated.
Peter Kasting5380f8a72022-05-10 15:41:3662using KeyEventFlags = EventFlags;
63// Key event fabricated by the underlying IME without a user action. (Linux X11
64// only)
65constexpr KeyEventFlags EF_IME_FABRICATED_KEY = 1 << 16;
66constexpr KeyEventFlags EF_IS_REPEAT = 1 << 17;
67// Do not remap; the event was created with the desired final values.
68constexpr KeyEventFlags EF_FINAL = 1 << 18;
69// Windows extended key (see WM_KEYDOWN doc)
70constexpr KeyEventFlags EF_IS_EXTENDED_KEY = 1 << 19;
71// Event was generated by a stylus button
72constexpr KeyEventFlags EF_IS_STYLUS_BUTTON = 1 << 20;
David Padlipsky544ae2a02024-02-17 01:25:0673#if BUILDFLAG(IS_CHROMEOS)
74// Event was generated by customizing a button on a mouse or graphics tablet.
75constexpr KeyEventFlags EF_IS_CUSTOMIZED_FROM_BUTTON = 1 << 21;
76constexpr KeyEventFlags EF_MAX_KEY_EVENT_FLAGS_VALUE = (1 << 22) - 1;
77#else
Peter Kasting5380f8a72022-05-10 15:41:3678constexpr KeyEventFlags EF_MAX_KEY_EVENT_FLAGS_VALUE = (1 << 21) - 1;
David Padlipsky544ae2a02024-02-17 01:25:0679#endif
[email protected]5698964d2014-04-16 18:32:4980
Joe Downinga8e74ac2018-02-26 17:10:2481// Flags specific to mouse events.
Peter Kasting5380f8a72022-05-10 15:41:3682using MouseEventFlags = EventFlags;
83constexpr MouseEventFlags EF_IS_DOUBLE_CLICK = 1 << 16;
84constexpr MouseEventFlags EF_IS_TRIPLE_CLICK = 1 << 17;
85constexpr MouseEventFlags EF_IS_NON_CLIENT = 1 << 18;
86// Indicates this mouse event is generated from an unconsumed touch/gesture
87// event.
88constexpr MouseEventFlags EF_FROM_TOUCH = 1 << 19;
89// Indicates this event was generated from touch accessibility mode.
90constexpr 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.
93constexpr 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.
96constexpr MouseEventFlags EF_PRECISION_SCROLLING_DELTA = 1 << 22;
97// Indicates this mouse event is generated when users is requesting to scroll by
98// pages.
99constexpr 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.
102constexpr 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).
105constexpr MouseEventFlags EF_NOT_SUITABLE_FOR_MOUSE_WARPING = 1 << 25;
[email protected]8d577a702011-02-10 04:56:36106
Mitsuru Oshima3bb6ca412023-06-22 07:22:02107// Flags specific to touch events.
108using TouchEventFlags = EventFlags;
109
110// Indicates this touch event is reserved for gesture recognition and
111// should not be handled in the event handler.
112constexpr TouchEventFlags EF_RESERVED_FOR_GESTURE = 1 << 26;
113
Ilya Karapsin2782e0e2023-06-02 18:47:28114// These value match the Windows default.
115constexpr int kDoubleClickTimeMs = 500;
116
[email protected]5b174e0a2012-09-04 01:14:43117// Result of dispatching an event.
118enum EventResult {
tdresser8879cfc2014-12-09 21:00:17119 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 Oshimaab67acc82023-04-13 15:30:06130 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 Hijikataa2724bc2023-12-05 01:55:15133 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]5b174e0a2012-09-04 01:14:43139};
140
[email protected]1eeb971322012-09-11 05:56:51141// Phase of the event dispatch.
142enum EventPhase {
143 EP_PREDISPATCH,
144 EP_PRETARGET,
145 EP_TARGET,
146 EP_POSTTARGET,
147 EP_POSTDISPATCH
148};
149
chaopenge8f2c032018-04-05 03:11:59150// 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.
153enum 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
taptedb94b06c2016-09-27 02:16:15167// Momentum phase information used for a ScrollEvent.
168enum 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.
chaopenge8f2c032018-04-05 03:11:59173 // 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.
taptedb94b06c2016-09-27 02:16:15184 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 Bianucci4da9f93b2019-08-26 19:54:38195
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,
taptedb94b06c2016-09-27 02:16:15202};
203
Jeroen Dhollander89e6a4d2022-03-31 02:34:08204enum 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]595079ce2014-07-11 22:25:13210
robert.bradfordf62ea412015-08-19 16:37:49211// Pointing device type.
212enum class EventPointerType : int {
Dave Tapuska1621efb2020-04-29 15:39:54213 kUnknown,
214 kMouse,
215 kPen,
216 kTouch,
217 kEraser,
218 kMaxValue = kEraser,
robert.bradfordf62ea412015-08-19 16:37:49219};
220
mohsen7d45a482016-05-24 21:03:44221// Device type for gesture events.
222enum class GestureDeviceType : int {
223 DEVICE_UNKNOWN = 0,
224 DEVICE_TOUCHPAD,
225 DEVICE_TOUCHSCREEN,
226};
227
[email protected]8d577a702011-02-10 04:56:36228} // namespace ui
229
[email protected]86ccbd42013-09-18 18:11:54230#endif // UI_EVENTS_EVENT_CONSTANTS_H_