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.
84 [[nodiscard
]] bool IsPointerEventMessageOriginallyMouseEventMessage(
85 EventMessage aMessage
);
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
);
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
162 #undef NS_DEFINE_INPUTTYPE
164 inline bool ExposesClipboardDataOrDataTransfer(EditorInputType aInputType
) {
165 switch (aInputType
) {
166 case EditorInputType::eInsertFromPaste
:
167 case EditorInputType::eInsertFromPasteAsQuotation
:
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
:
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
:
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
:
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
:
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
:
277 case EditorInputType::eInsertUnorderedList
:
279 case EditorInputType::eInsertHorizontalRule
:
281 case EditorInputType::eInsertFromYank
:
283 case EditorInputType::eInsertFromDrop
:
285 case EditorInputType::eInsertFromPaste
:
287 case EditorInputType::eInsertFromPasteAsQuotation
:
289 case EditorInputType::eInsertTranspose
:
291 case EditorInputType::eInsertCompositionText
:
293 case EditorInputType::eInsertFromComposition
:
294 MOZ_ASSERT(!StaticPrefs::dom_input_events_conform_to_level_1());
296 case EditorInputType::eInsertLink
:
298 case EditorInputType::eDeleteCompositionText
:
299 MOZ_ASSERT(!StaticPrefs::dom_input_events_conform_to_level_1());
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
:
317 case EditorInputType::eDeleteByCut
:
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
:
327 case EditorInputType::eHistoryRedo
:
329 case EditorInputType::eFormatBold
:
331 case EditorInputType::eFormatItalic
:
333 case EditorInputType::eFormatUnderline
:
335 case EditorInputType::eFormatStrikeThrough
:
337 case EditorInputType::eFormatSuperscript
:
339 case EditorInputType::eFormatSubscript
:
341 case EditorInputType::eFormatJustifyFull
:
343 case EditorInputType::eFormatJustifyCenter
:
345 case EditorInputType::eFormatJustifyRight
:
347 case EditorInputType::eFormatJustifyLeft
:
349 case EditorInputType::eFormatIndent
:
351 case EditorInputType::eFormatOutdent
:
353 case EditorInputType::eFormatRemove
:
355 case EditorInputType::eFormatSetBlockTextDirection
:
357 case EditorInputType::eFormatSetInlineTextDirection
:
359 case EditorInputType::eFormatBackColor
:
361 case EditorInputType::eFormatFontColor
:
363 case EditorInputType::eFormatFontName
:
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.
372 MOZ_ASSERT_UNREACHABLE("The new input type is not handled");
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
{
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"
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.
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
432 struct BaseEventFlags
;
435 class WidgetEventTime
;
438 enum class AccessKeyType
;
440 struct AlternativeCharCode
;
441 struct ShortcutKeyCandidate
;
443 typedef nsTArray
<ShortcutKeyCandidate
> ShortcutKeyCandidateArray
;
444 typedef AutoTArray
<ShortcutKeyCandidate
, 10> AutoShortcutKeyCandidateArray
;
447 typedef uint8_t RawTextRangeType
;
448 enum class TextRangeType
: RawTextRangeType
;
450 struct TextRangeStyle
;
454 class TextRangeArray
;
456 typedef nsTArray
<OwningNonNull
<dom::StaticRange
>> OwningNonNullStaticRangeArray
;
461 enum MouseButton
: int16_t {
466 eX1
= 3, // Typically, "back" button
467 eX2
= 4, // Typically, "forward" button
471 enum MouseButtonsFlag
{
474 eSecondaryFlag
= 0x02,
476 // typicall, "back" button being left side of 5-button
477 // mice, see "buttons" attribute document of DOM3 Events.
479 // typicall, "forward" button being right side of 5-button
480 // mice, see "buttons" attribute document of DOM3 Events.
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
;
504 return MouseButtonsFlag::eNoButtons
;
508 enum class TextRangeType
: RawTextRangeType
;
512 template <typename IntType
>
513 class StartAndEndOffsets
;
514 template <typename IntType
>
517 } // namespace mozilla
519 #endif // mozilla_EventForwards_h__