Bug 1927529 - Update dav1d to ef4aff75b0b56a8e1af996458ae653c0728a1596 r=chunmin
[gecko.git] / widget / EventForwards.h
blobadb98038498ef048abe8ad3ebe2a0bac63121361
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_EventForwards_h__
7 #define mozilla_EventForwards_h__
9 #include <stdint.h>
11 #include "nsStringFwd.h"
12 #include "nsTArray.h"
14 #ifdef DEBUG
15 # include "mozilla/StaticPrefs_dom.h"
16 #endif // #ifdef DEBUG
18 class nsCommandParams;
20 /**
21 * XXX Following enums should be in BasicEvents.h. However, currently, it's
22 * impossible to use foward delearation for enum.
25 /**
26 * Return status for event processors.
28 enum nsEventStatus {
29 // The event is ignored, do default processing
30 nsEventStatus_eIgnore,
31 // The event is consumed, don't do default processing
32 nsEventStatus_eConsumeNoDefault,
33 // The event is consumed, but do default processing
34 nsEventStatus_eConsumeDoDefault,
35 // Value is not for use, only for serialization
36 nsEventStatus_eSentinel
39 namespace mozilla {
41 enum class CanBubble { eYes, eNo };
43 enum class Cancelable { eYes, eNo };
45 enum class ChromeOnlyDispatch { eYes, eNo };
47 enum class Trusted { eYes, eNo };
49 enum class Composed { eYes, eNo, eDefault };
51 /**
52 * Event messages
55 typedef uint16_t EventMessageType;
57 enum EventMessage : EventMessageType {
59 #define NS_EVENT_MESSAGE(aMessage) aMessage,
60 #define NS_EVENT_MESSAGE_FIRST_LAST(aMessage, aFirst, aLast) \
61 aMessage##First = aFirst, aMessage##Last = aLast,
63 #include "mozilla/EventMessageList.h"
65 #undef NS_EVENT_MESSAGE
66 #undef NS_EVENT_MESSAGE_FIRST_LAST
68 // For preventing bustage due to "," after the last item.
69 eEventMessage_MaxValue
72 const char* ToChar(EventMessage aEventMessage);
74 /**
75 * Return true if aMessage should be dispatched as a WidgetPointerEvent.
77 [[nodiscard]] bool IsPointerEventMessage(EventMessage aMessage);
79 /**
80 * Return true if aMessage should be dispatched as a WidgetPointerEvent and
81 * the message was dispatched as a WidgetMouseEvent. So, this returns true
82 * if the event message is ePointerClick, ePointerAuxClick or eContextMenu.
84 [[nodiscard]] bool IsPointerEventMessageOriginallyMouseEventMessage(
85 EventMessage aMessage);
87 /**
88 * Return true if aMessage is not allowed to dispatch to a content node except
89 * Element node when we dispatch the event as a trusted event which .
91 * NOTE: This is currently designed for PresShell to consider whether a content
92 * node is proper event target for aMessage. So, this may not work the expected
93 * way in other cases. Therefore, when you use this method in a new place, you
94 * should check whether this returns the expected result for you.
96 [[nodiscard]] bool IsForbiddenDispatchingToNonElementContent(
97 EventMessage aMessage);
99 /**
100 * Event class IDs
103 typedef uint8_t EventClassIDType;
105 enum EventClassID : EventClassIDType {
106 // The event class name will be:
107 // eBasicEventClass for WidgetEvent
108 // eFooEventClass for WidgetFooEvent or InternalFooEvent
109 #define NS_ROOT_EVENT_CLASS(aPrefix, aName) eBasic##aName##Class
110 #define NS_EVENT_CLASS(aPrefix, aName) , e##aName##Class
112 #include "mozilla/EventClassList.h"
114 #undef NS_EVENT_CLASS
115 #undef NS_ROOT_EVENT_CLASS
118 const char* ToChar(EventClassID aEventClassID);
120 typedef uint16_t Modifiers;
122 #define NS_DEFINE_KEYNAME(aCPPName, aDOMKeyName) KEY_NAME_INDEX_##aCPPName,
124 typedef uint16_t KeyNameIndexType;
125 enum KeyNameIndex : KeyNameIndexType {
126 #include "mozilla/KeyNameList.h"
127 // If a DOM keyboard event is synthesized by script, this is used. Then,
128 // specified key name should be stored and use it as .key value.
129 KEY_NAME_INDEX_USE_STRING
132 #undef NS_DEFINE_KEYNAME
134 const nsCString ToString(KeyNameIndex aKeyNameIndex);
136 #define NS_DEFINE_PHYSICAL_KEY_CODE_NAME(aCPPName, aDOMCodeName) \
137 CODE_NAME_INDEX_##aCPPName,
139 typedef uint8_t CodeNameIndexType;
140 enum CodeNameIndex : CodeNameIndexType {
141 #include "mozilla/PhysicalKeyCodeNameList.h"
142 // If a DOM keyboard event is synthesized by script, this is used. Then,
143 // specified code name should be stored and use it as .code value.
144 CODE_NAME_INDEX_USE_STRING
147 #undef NS_DEFINE_PHYSICAL_KEY_CODE_NAME
149 const nsCString ToString(CodeNameIndex aCodeNameIndex);
151 #define NS_DEFINE_INPUTTYPE(aCPPName, aDOMName) e##aCPPName,
153 typedef uint8_t EditorInputTypeType;
154 enum class EditorInputType : EditorInputTypeType {
155 #include "mozilla/InputTypeList.h"
156 // If a DOM input event is synthesized by script, this is used. Then,
157 // specified input type should be stored as string and use it as .inputType
158 // value.
159 eUnknown,
162 #undef NS_DEFINE_INPUTTYPE
164 inline bool ExposesClipboardDataOrDataTransfer(EditorInputType aInputType) {
165 switch (aInputType) {
166 case EditorInputType::eInsertFromPaste:
167 case EditorInputType::eInsertFromPasteAsQuotation:
168 return true;
169 default:
170 return false;
175 * IsDataAvailableOnTextEditor() returns true if aInputType on TextEditor
176 * should have non-null InputEvent.data value.
178 inline bool IsDataAvailableOnTextEditor(EditorInputType aInputType) {
179 switch (aInputType) {
180 case EditorInputType::eInsertText:
181 case EditorInputType::eInsertCompositionText:
182 case EditorInputType::eInsertFromComposition: // Only level 2
183 case EditorInputType::eInsertFromPaste:
184 case EditorInputType::eInsertFromPasteAsQuotation:
185 case EditorInputType::eInsertTranspose:
186 case EditorInputType::eInsertFromDrop:
187 case EditorInputType::eInsertReplacementText:
188 case EditorInputType::eInsertFromYank:
189 case EditorInputType::eFormatSetBlockTextDirection:
190 case EditorInputType::eFormatSetInlineTextDirection:
191 return true;
192 default:
193 return false;
198 * IsDataAvailableOnHTMLEditor() returns true if aInputType on HTMLEditor
199 * should have non-null InputEvent.data value.
201 inline bool IsDataAvailableOnHTMLEditor(EditorInputType aInputType) {
202 switch (aInputType) {
203 case EditorInputType::eInsertText:
204 case EditorInputType::eInsertCompositionText:
205 case EditorInputType::eInsertFromComposition: // Only level 2
206 case EditorInputType::eFormatSetBlockTextDirection:
207 case EditorInputType::eFormatSetInlineTextDirection:
208 case EditorInputType::eInsertLink:
209 case EditorInputType::eFormatBackColor:
210 case EditorInputType::eFormatFontColor:
211 case EditorInputType::eFormatFontName:
212 return true;
213 default:
214 return false;
219 * IsDataTransferAvailableOnHTMLEditor() returns true if aInputType on
220 * HTMLEditor should have non-null InputEvent.dataTransfer value.
222 inline bool IsDataTransferAvailableOnHTMLEditor(EditorInputType aInputType) {
223 switch (aInputType) {
224 case EditorInputType::eInsertFromPaste:
225 case EditorInputType::eInsertFromPasteAsQuotation:
226 case EditorInputType::eInsertFromDrop:
227 case EditorInputType::eInsertTranspose:
228 case EditorInputType::eInsertReplacementText:
229 case EditorInputType::eInsertFromYank:
230 return true;
231 default:
232 return false;
237 * MayHaveTargetRangesOnHTMLEditor() returns true if "beforeinput" event whose
238 * whose inputType is aInputType on HTMLEditor may return non-empty static
239 * range array from getTargetRanges().
240 * Note that TextEditor always sets empty array. Therefore, there is no
241 * method for TextEditor.
243 inline bool MayHaveTargetRangesOnHTMLEditor(EditorInputType aInputType) {
244 switch (aInputType) {
245 // Explicitly documented by the specs.
246 case EditorInputType::eHistoryRedo:
247 case EditorInputType::eHistoryUndo:
248 // Not documented, but other browsers use empty array.
249 case EditorInputType::eFormatSetBlockTextDirection:
250 return false;
251 default:
252 return true;
257 * IsCancelableBeforeInputEvent() returns true if `beforeinput` event for
258 * aInputType should be cancelable.
260 * Input Events Level 1:
261 * https://rawgit.com/w3c/input-events/v1/index.html#x5-1-2-attributes
262 * Input Events Level 2:
263 * https://w3c.github.io/input-events/#interface-InputEvent-Attributes
265 inline bool IsCancelableBeforeInputEvent(EditorInputType aInputType) {
266 switch (aInputType) {
267 case EditorInputType::eInsertText:
268 return true; // In Level 1, undefined.
269 case EditorInputType::eInsertReplacementText:
270 return true; // In Level 1, undefined.
271 case EditorInputType::eInsertLineBreak:
272 return true; // In Level 1, undefined.
273 case EditorInputType::eInsertParagraph:
274 return true; // In Level 1, undefined.
275 case EditorInputType::eInsertOrderedList:
276 return true;
277 case EditorInputType::eInsertUnorderedList:
278 return true;
279 case EditorInputType::eInsertHorizontalRule:
280 return true;
281 case EditorInputType::eInsertFromYank:
282 return true;
283 case EditorInputType::eInsertFromDrop:
284 return true;
285 case EditorInputType::eInsertFromPaste:
286 return true;
287 case EditorInputType::eInsertFromPasteAsQuotation:
288 return true;
289 case EditorInputType::eInsertTranspose:
290 return true;
291 case EditorInputType::eInsertCompositionText:
292 return false;
293 case EditorInputType::eInsertFromComposition:
294 MOZ_ASSERT(!StaticPrefs::dom_input_events_conform_to_level_1());
295 return true;
296 case EditorInputType::eInsertLink:
297 return true;
298 case EditorInputType::eDeleteCompositionText:
299 MOZ_ASSERT(!StaticPrefs::dom_input_events_conform_to_level_1());
300 return false;
301 case EditorInputType::eDeleteWordBackward:
302 return true; // In Level 1, undefined.
303 case EditorInputType::eDeleteWordForward:
304 return true; // In Level 1, undefined.
305 case EditorInputType::eDeleteSoftLineBackward:
306 return true; // In Level 1, undefined.
307 case EditorInputType::eDeleteSoftLineForward:
308 return true; // In Level 1, undefined.
309 case EditorInputType::eDeleteEntireSoftLine:
310 return true; // In Level 1, undefined.
311 case EditorInputType::eDeleteHardLineBackward:
312 return true; // In Level 1, undefined.
313 case EditorInputType::eDeleteHardLineForward:
314 return true; // In Level 1, undefined.
315 case EditorInputType::eDeleteByDrag:
316 return true;
317 case EditorInputType::eDeleteByCut:
318 return true;
319 case EditorInputType::eDeleteContent:
320 return true; // In Level 1, undefined.
321 case EditorInputType::eDeleteContentBackward:
322 return true; // In Level 1, undefined.
323 case EditorInputType::eDeleteContentForward:
324 return true; // In Level 1, undefined.
325 case EditorInputType::eHistoryUndo:
326 return true;
327 case EditorInputType::eHistoryRedo:
328 return true;
329 case EditorInputType::eFormatBold:
330 return true;
331 case EditorInputType::eFormatItalic:
332 return true;
333 case EditorInputType::eFormatUnderline:
334 return true;
335 case EditorInputType::eFormatStrikeThrough:
336 return true;
337 case EditorInputType::eFormatSuperscript:
338 return true;
339 case EditorInputType::eFormatSubscript:
340 return true;
341 case EditorInputType::eFormatJustifyFull:
342 return true;
343 case EditorInputType::eFormatJustifyCenter:
344 return true;
345 case EditorInputType::eFormatJustifyRight:
346 return true;
347 case EditorInputType::eFormatJustifyLeft:
348 return true;
349 case EditorInputType::eFormatIndent:
350 return true;
351 case EditorInputType::eFormatOutdent:
352 return true;
353 case EditorInputType::eFormatRemove:
354 return true;
355 case EditorInputType::eFormatSetBlockTextDirection:
356 return true;
357 case EditorInputType::eFormatSetInlineTextDirection:
358 return true;
359 case EditorInputType::eFormatBackColor:
360 return true;
361 case EditorInputType::eFormatFontColor:
362 return true;
363 case EditorInputType::eFormatFontName:
364 return true;
365 case EditorInputType::eUnknown:
366 // This is not declared by Input Events, but it does not make sense to
367 // allow web apps to cancel default action without inputType value check.
368 // If some our specific edit actions should be cancelable, new inputType
369 // value for them should be declared by the spec.
370 return false;
371 default:
372 MOZ_ASSERT_UNREACHABLE("The new input type is not handled");
373 return false;
377 #define NS_DEFINE_COMMAND(aName, aCommandStr) , aName
378 #define NS_DEFINE_COMMAND_WITH_PARAM(aName, aCommandStr, aParam) , aName
379 #define NS_DEFINE_COMMAND_NO_EXEC_COMMAND(aName) , aName
381 typedef uint8_t CommandInt;
382 enum class Command : CommandInt {
383 DoNothing
385 #include "mozilla/CommandList.h"
387 #undef NS_DEFINE_COMMAND
388 #undef NS_DEFINE_COMMAND_WITH_PARAM
389 #undef NS_DEFINE_COMMAND_NO_EXEC_COMMAND
391 const char* ToChar(Command aCommand);
394 * Return a command value for aCommandName.
395 * XXX: Is there a better place to put `Command` related methods instead of
396 * global scope in `mozilla` namespace?
398 * @param aCommandName Should be a XUL command name like "cmd_bold"
399 * (case sensitive).
400 * @param aCommandparams Additional parameter value of aCommandName.
401 * Can be nullptr, but if aCommandName requires
402 * additional parameter and sets this to nullptr,
403 * will return Command::DoNothing with warning.
405 Command GetInternalCommand(const char* aCommandName,
406 const nsCommandParams* aCommandParams = nullptr);
408 } // namespace mozilla
411 * All header files should include this header instead of *Events.h.
414 namespace mozilla {
416 template <class T>
417 class OwningNonNull;
419 namespace dom {
420 class StaticRange;
423 #define NS_EVENT_CLASS(aPrefix, aName) class aPrefix##aName;
424 #define NS_ROOT_EVENT_CLASS(aPrefix, aName) NS_EVENT_CLASS(aPrefix, aName)
426 #include "mozilla/EventClassList.h"
428 #undef NS_EVENT_CLASS
429 #undef NS_ROOT_EVENT_CLASS
431 // BasicEvents.h
432 struct BaseEventFlags;
433 struct EventFlags;
435 class WidgetEventTime;
437 // TextEvents.h
438 enum class AccessKeyType;
440 struct AlternativeCharCode;
441 struct ShortcutKeyCandidate;
443 typedef nsTArray<ShortcutKeyCandidate> ShortcutKeyCandidateArray;
444 typedef AutoTArray<ShortcutKeyCandidate, 10> AutoShortcutKeyCandidateArray;
446 // TextRange.h
447 typedef uint8_t RawTextRangeType;
448 enum class TextRangeType : RawTextRangeType;
450 struct TextRangeStyle;
451 struct TextRange;
453 class EditCommands;
454 class TextRangeArray;
456 typedef nsTArray<OwningNonNull<dom::StaticRange>> OwningNonNullStaticRangeArray;
458 // FontRange.h
459 struct FontRange;
461 enum MouseButton : int16_t {
462 eNotPressed = -1,
463 ePrimary = 0,
464 eMiddle = 1,
465 eSecondary = 2,
466 eX1 = 3, // Typically, "back" button
467 eX2 = 4, // Typically, "forward" button
468 eEraser = 5
471 enum MouseButtonsFlag {
472 eNoButtons = 0x00,
473 ePrimaryFlag = 0x01,
474 eSecondaryFlag = 0x02,
475 eMiddleFlag = 0x04,
476 // typicall, "back" button being left side of 5-button
477 // mice, see "buttons" attribute document of DOM3 Events.
478 e4thFlag = 0x08,
479 // typicall, "forward" button being right side of 5-button
480 // mice, see "buttons" attribute document of DOM3 Events.
481 e5thFlag = 0x10,
482 eEraserFlag = 0x20
486 * Returns a MouseButtonsFlag value which is changed by a button state change
487 * event whose mButton is aMouseButton.
489 inline MouseButtonsFlag MouseButtonsFlagToChange(MouseButton aMouseButton) {
490 switch (aMouseButton) {
491 case MouseButton::ePrimary:
492 return MouseButtonsFlag::ePrimaryFlag;
493 case MouseButton::eMiddle:
494 return MouseButtonsFlag::eMiddleFlag;
495 case MouseButton::eSecondary:
496 return MouseButtonsFlag::eSecondaryFlag;
497 case MouseButton::eX1:
498 return MouseButtonsFlag::e4thFlag;
499 case MouseButton::eX2:
500 return MouseButtonsFlag::e5thFlag;
501 case MouseButton::eEraser:
502 return MouseButtonsFlag::eEraserFlag;
503 default:
504 return MouseButtonsFlag::eNoButtons;
508 enum class TextRangeType : RawTextRangeType;
510 // IMEData.h
512 template <typename IntType>
513 class StartAndEndOffsets;
514 template <typename IntType>
515 class OffsetAndData;
517 } // namespace mozilla
519 #endif // mozilla_EventForwards_h__