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__
11 #include "nsStringFwd.h"
15 # include "mozilla/StaticPrefs_dom.h"
16 #endif // #ifdef DEBUG
18 class nsCommandParams
;
21 * XXX Following enums should be in BasicEvents.h. However, currently, it's
22 * impossible to use foward delearation for enum.
26 * Return status for event processors.
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
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
};
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
);
75 * Return true if aMessage should be dispatched as a WidgetPointerEvent.
77 [[nodiscard
]] bool IsPointerEventMessage(EventMessage aMessage
);
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
);
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
152 #undef NS_DEFINE_INPUTTYPE
154 inline bool ExposesClipboardDataOrDataTransfer(EditorInputType aInputType
) {
155 switch (aInputType
) {
156 case EditorInputType::eInsertFromPaste
:
157 case EditorInputType::eInsertFromPasteAsQuotation
:
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
:
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
:
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
:
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
:
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
:
267 case EditorInputType::eInsertUnorderedList
:
269 case EditorInputType::eInsertHorizontalRule
:
271 case EditorInputType::eInsertFromYank
:
273 case EditorInputType::eInsertFromDrop
:
275 case EditorInputType::eInsertFromPaste
:
277 case EditorInputType::eInsertFromPasteAsQuotation
:
279 case EditorInputType::eInsertTranspose
:
281 case EditorInputType::eInsertCompositionText
:
283 case EditorInputType::eInsertFromComposition
:
284 MOZ_ASSERT(!StaticPrefs::dom_input_events_conform_to_level_1());
286 case EditorInputType::eInsertLink
:
288 case EditorInputType::eDeleteCompositionText
:
289 MOZ_ASSERT(!StaticPrefs::dom_input_events_conform_to_level_1());
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
:
307 case EditorInputType::eDeleteByCut
:
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
:
317 case EditorInputType::eHistoryRedo
:
319 case EditorInputType::eFormatBold
:
321 case EditorInputType::eFormatItalic
:
323 case EditorInputType::eFormatUnderline
:
325 case EditorInputType::eFormatStrikeThrough
:
327 case EditorInputType::eFormatSuperscript
:
329 case EditorInputType::eFormatSubscript
:
331 case EditorInputType::eFormatJustifyFull
:
333 case EditorInputType::eFormatJustifyCenter
:
335 case EditorInputType::eFormatJustifyRight
:
337 case EditorInputType::eFormatJustifyLeft
:
339 case EditorInputType::eFormatIndent
:
341 case EditorInputType::eFormatOutdent
:
343 case EditorInputType::eFormatRemove
:
345 case EditorInputType::eFormatSetBlockTextDirection
:
347 case EditorInputType::eFormatSetInlineTextDirection
:
349 case EditorInputType::eFormatBackColor
:
351 case EditorInputType::eFormatFontColor
:
353 case EditorInputType::eFormatFontName
:
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.
362 MOZ_ASSERT_UNREACHABLE("The new input type is not handled");
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
{
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"
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.
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
422 struct BaseEventFlags
;
425 class WidgetEventTime
;
428 enum class AccessKeyType
;
430 struct AlternativeCharCode
;
431 struct ShortcutKeyCandidate
;
433 typedef nsTArray
<ShortcutKeyCandidate
> ShortcutKeyCandidateArray
;
434 typedef AutoTArray
<ShortcutKeyCandidate
, 10> AutoShortcutKeyCandidateArray
;
437 typedef uint8_t RawTextRangeType
;
438 enum class TextRangeType
: RawTextRangeType
;
440 struct TextRangeStyle
;
444 class TextRangeArray
;
446 typedef nsTArray
<OwningNonNull
<dom::StaticRange
>> OwningNonNullStaticRangeArray
;
451 enum MouseButton
: int16_t {
456 eX1
= 3, // Typically, "back" button
457 eX2
= 4, // Typically, "forward" button
461 enum MouseButtonsFlag
{
464 eSecondaryFlag
= 0x02,
466 // typicall, "back" button being left side of 5-button
467 // mice, see "buttons" attribute document of DOM3 Events.
469 // typicall, "forward" button being right side of 5-button
470 // mice, see "buttons" attribute document of DOM3 Events.
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
;
494 return MouseButtonsFlag::eNoButtons
;
498 enum class TextRangeType
: RawTextRangeType
;
502 template <typename IntType
>
503 class StartAndEndOffsets
;
504 template <typename IntType
>
507 } // namespace mozilla
509 #endif // mozilla_EventForwards_h__