Backed out 8 changesets (bug 1901851, bug 1728331) for causing bc failures in browser...
[gecko.git] / widget / EventForwards.h
blob8c59463dd95a859d1f17ba94130b0d9a098e66ec
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
83 * if and only if the message should be dispatched with WidgetPointerEvent
84 * (depending on `dispatch_click_as_pointer_event` pref).
86 [[nodiscard]] bool IsPointerEventMessageOriginallyMouseEventMessage(
87 EventMessage aMessage);
89 /**
90 * Event class IDs
93 typedef uint8_t EventClassIDType;
95 enum EventClassID : EventClassIDType {
96 // The event class name will be:
97 // eBasicEventClass for WidgetEvent
98 // eFooEventClass for WidgetFooEvent or InternalFooEvent
99 #define NS_ROOT_EVENT_CLASS(aPrefix, aName) eBasic##aName##Class
100 #define NS_EVENT_CLASS(aPrefix, aName) , e##aName##Class
102 #include "mozilla/EventClassList.h"
104 #undef NS_EVENT_CLASS
105 #undef NS_ROOT_EVENT_CLASS
108 const char* ToChar(EventClassID aEventClassID);
110 typedef uint16_t Modifiers;
112 #define NS_DEFINE_KEYNAME(aCPPName, aDOMKeyName) KEY_NAME_INDEX_##aCPPName,
114 typedef uint16_t KeyNameIndexType;
115 enum KeyNameIndex : KeyNameIndexType {
116 #include "mozilla/KeyNameList.h"
117 // If a DOM keyboard event is synthesized by script, this is used. Then,
118 // specified key name should be stored and use it as .key value.
119 KEY_NAME_INDEX_USE_STRING
122 #undef NS_DEFINE_KEYNAME
124 const nsCString ToString(KeyNameIndex aKeyNameIndex);
126 #define NS_DEFINE_PHYSICAL_KEY_CODE_NAME(aCPPName, aDOMCodeName) \
127 CODE_NAME_INDEX_##aCPPName,
129 typedef uint8_t CodeNameIndexType;
130 enum CodeNameIndex : CodeNameIndexType {
131 #include "mozilla/PhysicalKeyCodeNameList.h"
132 // If a DOM keyboard event is synthesized by script, this is used. Then,
133 // specified code name should be stored and use it as .code value.
134 CODE_NAME_INDEX_USE_STRING
137 #undef NS_DEFINE_PHYSICAL_KEY_CODE_NAME
139 const nsCString ToString(CodeNameIndex aCodeNameIndex);
141 #define NS_DEFINE_INPUTTYPE(aCPPName, aDOMName) e##aCPPName,
143 typedef uint8_t EditorInputTypeType;
144 enum class EditorInputType : EditorInputTypeType {
145 #include "mozilla/InputTypeList.h"
146 // If a DOM input event is synthesized by script, this is used. Then,
147 // specified input type should be stored as string and use it as .inputType
148 // value.
149 eUnknown,
152 #undef NS_DEFINE_INPUTTYPE
154 inline bool ExposesClipboardDataOrDataTransfer(EditorInputType aInputType) {
155 switch (aInputType) {
156 case EditorInputType::eInsertFromPaste:
157 case EditorInputType::eInsertFromPasteAsQuotation:
158 return true;
159 default:
160 return false;
165 * IsDataAvailableOnTextEditor() returns true if aInputType on TextEditor
166 * should have non-null InputEvent.data value.
168 inline bool IsDataAvailableOnTextEditor(EditorInputType aInputType) {
169 switch (aInputType) {
170 case EditorInputType::eInsertText:
171 case EditorInputType::eInsertCompositionText:
172 case EditorInputType::eInsertFromComposition: // Only level 2
173 case EditorInputType::eInsertFromPaste:
174 case EditorInputType::eInsertFromPasteAsQuotation:
175 case EditorInputType::eInsertTranspose:
176 case EditorInputType::eInsertFromDrop:
177 case EditorInputType::eInsertReplacementText:
178 case EditorInputType::eInsertFromYank:
179 case EditorInputType::eFormatSetBlockTextDirection:
180 case EditorInputType::eFormatSetInlineTextDirection:
181 return true;
182 default:
183 return false;
188 * IsDataAvailableOnHTMLEditor() returns true if aInputType on HTMLEditor
189 * should have non-null InputEvent.data value.
191 inline bool IsDataAvailableOnHTMLEditor(EditorInputType aInputType) {
192 switch (aInputType) {
193 case EditorInputType::eInsertText:
194 case EditorInputType::eInsertCompositionText:
195 case EditorInputType::eInsertFromComposition: // Only level 2
196 case EditorInputType::eFormatSetBlockTextDirection:
197 case EditorInputType::eFormatSetInlineTextDirection:
198 case EditorInputType::eInsertLink:
199 case EditorInputType::eFormatBackColor:
200 case EditorInputType::eFormatFontColor:
201 case EditorInputType::eFormatFontName:
202 return true;
203 default:
204 return false;
209 * IsDataTransferAvailableOnHTMLEditor() returns true if aInputType on
210 * HTMLEditor should have non-null InputEvent.dataTransfer value.
212 inline bool IsDataTransferAvailableOnHTMLEditor(EditorInputType aInputType) {
213 switch (aInputType) {
214 case EditorInputType::eInsertFromPaste:
215 case EditorInputType::eInsertFromPasteAsQuotation:
216 case EditorInputType::eInsertFromDrop:
217 case EditorInputType::eInsertTranspose:
218 case EditorInputType::eInsertReplacementText:
219 case EditorInputType::eInsertFromYank:
220 return true;
221 default:
222 return false;
227 * MayHaveTargetRangesOnHTMLEditor() returns true if "beforeinput" event whose
228 * whose inputType is aInputType on HTMLEditor may return non-empty static
229 * range array from getTargetRanges().
230 * Note that TextEditor always sets empty array. Therefore, there is no
231 * method for TextEditor.
233 inline bool MayHaveTargetRangesOnHTMLEditor(EditorInputType aInputType) {
234 switch (aInputType) {
235 // Explicitly documented by the specs.
236 case EditorInputType::eHistoryRedo:
237 case EditorInputType::eHistoryUndo:
238 // Not documented, but other browsers use empty array.
239 case EditorInputType::eFormatSetBlockTextDirection:
240 return false;
241 default:
242 return true;
247 * IsCancelableBeforeInputEvent() returns true if `beforeinput` event for
248 * aInputType should be cancelable.
250 * Input Events Level 1:
251 * https://rawgit.com/w3c/input-events/v1/index.html#x5-1-2-attributes
252 * Input Events Level 2:
253 * https://w3c.github.io/input-events/#interface-InputEvent-Attributes
255 inline bool IsCancelableBeforeInputEvent(EditorInputType aInputType) {
256 switch (aInputType) {
257 case EditorInputType::eInsertText:
258 return true; // In Level 1, undefined.
259 case EditorInputType::eInsertReplacementText:
260 return true; // In Level 1, undefined.
261 case EditorInputType::eInsertLineBreak:
262 return true; // In Level 1, undefined.
263 case EditorInputType::eInsertParagraph:
264 return true; // In Level 1, undefined.
265 case EditorInputType::eInsertOrderedList:
266 return true;
267 case EditorInputType::eInsertUnorderedList:
268 return true;
269 case EditorInputType::eInsertHorizontalRule:
270 return true;
271 case EditorInputType::eInsertFromYank:
272 return true;
273 case EditorInputType::eInsertFromDrop:
274 return true;
275 case EditorInputType::eInsertFromPaste:
276 return true;
277 case EditorInputType::eInsertFromPasteAsQuotation:
278 return true;
279 case EditorInputType::eInsertTranspose:
280 return true;
281 case EditorInputType::eInsertCompositionText:
282 return false;
283 case EditorInputType::eInsertFromComposition:
284 MOZ_ASSERT(!StaticPrefs::dom_input_events_conform_to_level_1());
285 return true;
286 case EditorInputType::eInsertLink:
287 return true;
288 case EditorInputType::eDeleteCompositionText:
289 MOZ_ASSERT(!StaticPrefs::dom_input_events_conform_to_level_1());
290 return false;
291 case EditorInputType::eDeleteWordBackward:
292 return true; // In Level 1, undefined.
293 case EditorInputType::eDeleteWordForward:
294 return true; // In Level 1, undefined.
295 case EditorInputType::eDeleteSoftLineBackward:
296 return true; // In Level 1, undefined.
297 case EditorInputType::eDeleteSoftLineForward:
298 return true; // In Level 1, undefined.
299 case EditorInputType::eDeleteEntireSoftLine:
300 return true; // In Level 1, undefined.
301 case EditorInputType::eDeleteHardLineBackward:
302 return true; // In Level 1, undefined.
303 case EditorInputType::eDeleteHardLineForward:
304 return true; // In Level 1, undefined.
305 case EditorInputType::eDeleteByDrag:
306 return true;
307 case EditorInputType::eDeleteByCut:
308 return true;
309 case EditorInputType::eDeleteContent:
310 return true; // In Level 1, undefined.
311 case EditorInputType::eDeleteContentBackward:
312 return true; // In Level 1, undefined.
313 case EditorInputType::eDeleteContentForward:
314 return true; // In Level 1, undefined.
315 case EditorInputType::eHistoryUndo:
316 return true;
317 case EditorInputType::eHistoryRedo:
318 return true;
319 case EditorInputType::eFormatBold:
320 return true;
321 case EditorInputType::eFormatItalic:
322 return true;
323 case EditorInputType::eFormatUnderline:
324 return true;
325 case EditorInputType::eFormatStrikeThrough:
326 return true;
327 case EditorInputType::eFormatSuperscript:
328 return true;
329 case EditorInputType::eFormatSubscript:
330 return true;
331 case EditorInputType::eFormatJustifyFull:
332 return true;
333 case EditorInputType::eFormatJustifyCenter:
334 return true;
335 case EditorInputType::eFormatJustifyRight:
336 return true;
337 case EditorInputType::eFormatJustifyLeft:
338 return true;
339 case EditorInputType::eFormatIndent:
340 return true;
341 case EditorInputType::eFormatOutdent:
342 return true;
343 case EditorInputType::eFormatRemove:
344 return true;
345 case EditorInputType::eFormatSetBlockTextDirection:
346 return true;
347 case EditorInputType::eFormatSetInlineTextDirection:
348 return true;
349 case EditorInputType::eFormatBackColor:
350 return true;
351 case EditorInputType::eFormatFontColor:
352 return true;
353 case EditorInputType::eFormatFontName:
354 return true;
355 case EditorInputType::eUnknown:
356 // This is not declared by Input Events, but it does not make sense to
357 // allow web apps to cancel default action without inputType value check.
358 // If some our specific edit actions should be cancelable, new inputType
359 // value for them should be declared by the spec.
360 return false;
361 default:
362 MOZ_ASSERT_UNREACHABLE("The new input type is not handled");
363 return false;
367 #define NS_DEFINE_COMMAND(aName, aCommandStr) , aName
368 #define NS_DEFINE_COMMAND_WITH_PARAM(aName, aCommandStr, aParam) , aName
369 #define NS_DEFINE_COMMAND_NO_EXEC_COMMAND(aName) , aName
371 typedef uint8_t CommandInt;
372 enum class Command : CommandInt {
373 DoNothing
375 #include "mozilla/CommandList.h"
377 #undef NS_DEFINE_COMMAND
378 #undef NS_DEFINE_COMMAND_WITH_PARAM
379 #undef NS_DEFINE_COMMAND_NO_EXEC_COMMAND
381 const char* ToChar(Command aCommand);
384 * Return a command value for aCommandName.
385 * XXX: Is there a better place to put `Command` related methods instead of
386 * global scope in `mozilla` namespace?
388 * @param aCommandName Should be a XUL command name like "cmd_bold"
389 * (case sensitive).
390 * @param aCommandparams Additional parameter value of aCommandName.
391 * Can be nullptr, but if aCommandName requires
392 * additional parameter and sets this to nullptr,
393 * will return Command::DoNothing with warning.
395 Command GetInternalCommand(const char* aCommandName,
396 const nsCommandParams* aCommandParams = nullptr);
398 } // namespace mozilla
401 * All header files should include this header instead of *Events.h.
404 namespace mozilla {
406 template <class T>
407 class OwningNonNull;
409 namespace dom {
410 class StaticRange;
413 #define NS_EVENT_CLASS(aPrefix, aName) class aPrefix##aName;
414 #define NS_ROOT_EVENT_CLASS(aPrefix, aName) NS_EVENT_CLASS(aPrefix, aName)
416 #include "mozilla/EventClassList.h"
418 #undef NS_EVENT_CLASS
419 #undef NS_ROOT_EVENT_CLASS
421 // BasicEvents.h
422 struct BaseEventFlags;
423 struct EventFlags;
425 class WidgetEventTime;
427 // TextEvents.h
428 enum class AccessKeyType;
430 struct AlternativeCharCode;
431 struct ShortcutKeyCandidate;
433 typedef nsTArray<ShortcutKeyCandidate> ShortcutKeyCandidateArray;
434 typedef AutoTArray<ShortcutKeyCandidate, 10> AutoShortcutKeyCandidateArray;
436 // TextRange.h
437 typedef uint8_t RawTextRangeType;
438 enum class TextRangeType : RawTextRangeType;
440 struct TextRangeStyle;
441 struct TextRange;
443 class EditCommands;
444 class TextRangeArray;
446 typedef nsTArray<OwningNonNull<dom::StaticRange>> OwningNonNullStaticRangeArray;
448 // FontRange.h
449 struct FontRange;
451 enum MouseButton : int16_t {
452 eNotPressed = -1,
453 ePrimary = 0,
454 eMiddle = 1,
455 eSecondary = 2,
456 eX1 = 3, // Typically, "back" button
457 eX2 = 4, // Typically, "forward" button
458 eEraser = 5
461 enum MouseButtonsFlag {
462 eNoButtons = 0x00,
463 ePrimaryFlag = 0x01,
464 eSecondaryFlag = 0x02,
465 eMiddleFlag = 0x04,
466 // typicall, "back" button being left side of 5-button
467 // mice, see "buttons" attribute document of DOM3 Events.
468 e4thFlag = 0x08,
469 // typicall, "forward" button being right side of 5-button
470 // mice, see "buttons" attribute document of DOM3 Events.
471 e5thFlag = 0x10,
472 eEraserFlag = 0x20
476 * Returns a MouseButtonsFlag value which is changed by a button state change
477 * event whose mButton is aMouseButton.
479 inline MouseButtonsFlag MouseButtonsFlagToChange(MouseButton aMouseButton) {
480 switch (aMouseButton) {
481 case MouseButton::ePrimary:
482 return MouseButtonsFlag::ePrimaryFlag;
483 case MouseButton::eMiddle:
484 return MouseButtonsFlag::eMiddleFlag;
485 case MouseButton::eSecondary:
486 return MouseButtonsFlag::eSecondaryFlag;
487 case MouseButton::eX1:
488 return MouseButtonsFlag::e4thFlag;
489 case MouseButton::eX2:
490 return MouseButtonsFlag::e5thFlag;
491 case MouseButton::eEraser:
492 return MouseButtonsFlag::eEraserFlag;
493 default:
494 return MouseButtonsFlag::eNoButtons;
498 enum class TextRangeType : RawTextRangeType;
500 // IMEData.h
502 template <typename IntType>
503 class StartAndEndOffsets;
504 template <typename IntType>
505 class OffsetAndData;
507 } // namespace mozilla
509 #endif // mozilla_EventForwards_h__