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
);
78 typedef uint8_t EventClassIDType
;
80 enum EventClassID
: EventClassIDType
{
81 // The event class name will be:
82 // eBasicEventClass for WidgetEvent
83 // eFooEventClass for WidgetFooEvent or InternalFooEvent
84 #define NS_ROOT_EVENT_CLASS(aPrefix, aName) eBasic##aName##Class
85 #define NS_EVENT_CLASS(aPrefix, aName) , e##aName##Class
87 #include "mozilla/EventClassList.h"
90 #undef NS_ROOT_EVENT_CLASS
93 const char* ToChar(EventClassID aEventClassID
);
95 typedef uint16_t Modifiers
;
97 #define NS_DEFINE_KEYNAME(aCPPName, aDOMKeyName) KEY_NAME_INDEX_##aCPPName,
99 typedef uint16_t KeyNameIndexType
;
100 enum KeyNameIndex
: KeyNameIndexType
{
101 #include "mozilla/KeyNameList.h"
102 // If a DOM keyboard event is synthesized by script, this is used. Then,
103 // specified key name should be stored and use it as .key value.
104 KEY_NAME_INDEX_USE_STRING
107 #undef NS_DEFINE_KEYNAME
109 const nsCString
ToString(KeyNameIndex aKeyNameIndex
);
111 #define NS_DEFINE_PHYSICAL_KEY_CODE_NAME(aCPPName, aDOMCodeName) \
112 CODE_NAME_INDEX_##aCPPName,
114 typedef uint8_t CodeNameIndexType
;
115 enum CodeNameIndex
: CodeNameIndexType
{
116 #include "mozilla/PhysicalKeyCodeNameList.h"
117 // If a DOM keyboard event is synthesized by script, this is used. Then,
118 // specified code name should be stored and use it as .code value.
119 CODE_NAME_INDEX_USE_STRING
122 #undef NS_DEFINE_PHYSICAL_KEY_CODE_NAME
124 const nsCString
ToString(CodeNameIndex aCodeNameIndex
);
126 #define NS_DEFINE_INPUTTYPE(aCPPName, aDOMName) e##aCPPName,
128 typedef uint8_t EditorInputTypeType
;
129 enum class EditorInputType
: EditorInputTypeType
{
130 #include "mozilla/InputTypeList.h"
131 // If a DOM input event is synthesized by script, this is used. Then,
132 // specified input type should be stored as string and use it as .inputType
137 #undef NS_DEFINE_INPUTTYPE
139 inline bool ExposesClipboardDataOrDataTransfer(EditorInputType aInputType
) {
140 switch (aInputType
) {
141 case EditorInputType::eInsertFromPaste
:
142 case EditorInputType::eInsertFromPasteAsQuotation
:
150 * IsDataAvailableOnTextEditor() returns true if aInputType on TextEditor
151 * should have non-null InputEvent.data value.
153 inline bool IsDataAvailableOnTextEditor(EditorInputType aInputType
) {
154 switch (aInputType
) {
155 case EditorInputType::eInsertText
:
156 case EditorInputType::eInsertCompositionText
:
157 case EditorInputType::eInsertFromComposition
: // Only level 2
158 case EditorInputType::eInsertFromPaste
:
159 case EditorInputType::eInsertFromPasteAsQuotation
:
160 case EditorInputType::eInsertTranspose
:
161 case EditorInputType::eInsertFromDrop
:
162 case EditorInputType::eInsertReplacementText
:
163 case EditorInputType::eInsertFromYank
:
164 case EditorInputType::eFormatSetBlockTextDirection
:
165 case EditorInputType::eFormatSetInlineTextDirection
:
173 * IsDataAvailableOnHTMLEditor() returns true if aInputType on HTMLEditor
174 * should have non-null InputEvent.data value.
176 inline bool IsDataAvailableOnHTMLEditor(EditorInputType aInputType
) {
177 switch (aInputType
) {
178 case EditorInputType::eInsertText
:
179 case EditorInputType::eInsertCompositionText
:
180 case EditorInputType::eInsertFromComposition
: // Only level 2
181 case EditorInputType::eFormatSetBlockTextDirection
:
182 case EditorInputType::eFormatSetInlineTextDirection
:
183 case EditorInputType::eInsertLink
:
184 case EditorInputType::eFormatBackColor
:
185 case EditorInputType::eFormatFontColor
:
186 case EditorInputType::eFormatFontName
:
194 * IsDataTransferAvailableOnHTMLEditor() returns true if aInputType on
195 * HTMLEditor should have non-null InputEvent.dataTransfer value.
197 inline bool IsDataTransferAvailableOnHTMLEditor(EditorInputType aInputType
) {
198 switch (aInputType
) {
199 case EditorInputType::eInsertFromPaste
:
200 case EditorInputType::eInsertFromPasteAsQuotation
:
201 case EditorInputType::eInsertFromDrop
:
202 case EditorInputType::eInsertTranspose
:
203 case EditorInputType::eInsertReplacementText
:
204 case EditorInputType::eInsertFromYank
:
212 * MayHaveTargetRangesOnHTMLEditor() returns true if "beforeinput" event whose
213 * whose inputType is aInputType on HTMLEditor may return non-empty static
214 * range array from getTargetRanges().
215 * Note that TextEditor always sets empty array. Therefore, there is no
216 * method for TextEditor.
218 inline bool MayHaveTargetRangesOnHTMLEditor(EditorInputType aInputType
) {
219 switch (aInputType
) {
220 // Explicitly documented by the specs.
221 case EditorInputType::eHistoryRedo
:
222 case EditorInputType::eHistoryUndo
:
223 // Not documented, but other browsers use empty array.
224 case EditorInputType::eFormatSetBlockTextDirection
:
232 * IsCancelableBeforeInputEvent() returns true if `beforeinput` event for
233 * aInputType should be cancelable.
235 * Input Events Level 1:
236 * https://rawgit.com/w3c/input-events/v1/index.html#x5-1-2-attributes
237 * Input Events Level 2:
238 * https://w3c.github.io/input-events/#interface-InputEvent-Attributes
240 inline bool IsCancelableBeforeInputEvent(EditorInputType aInputType
) {
241 switch (aInputType
) {
242 case EditorInputType::eInsertText
:
243 return true; // In Level 1, undefined.
244 case EditorInputType::eInsertReplacementText
:
245 return true; // In Level 1, undefined.
246 case EditorInputType::eInsertLineBreak
:
247 return true; // In Level 1, undefined.
248 case EditorInputType::eInsertParagraph
:
249 return true; // In Level 1, undefined.
250 case EditorInputType::eInsertOrderedList
:
252 case EditorInputType::eInsertUnorderedList
:
254 case EditorInputType::eInsertHorizontalRule
:
256 case EditorInputType::eInsertFromYank
:
258 case EditorInputType::eInsertFromDrop
:
260 case EditorInputType::eInsertFromPaste
:
262 case EditorInputType::eInsertFromPasteAsQuotation
:
264 case EditorInputType::eInsertTranspose
:
266 case EditorInputType::eInsertCompositionText
:
268 case EditorInputType::eInsertFromComposition
:
269 MOZ_ASSERT(!StaticPrefs::dom_input_events_conform_to_level_1());
271 case EditorInputType::eInsertLink
:
273 case EditorInputType::eDeleteCompositionText
:
274 MOZ_ASSERT(!StaticPrefs::dom_input_events_conform_to_level_1());
276 case EditorInputType::eDeleteWordBackward
:
277 return true; // In Level 1, undefined.
278 case EditorInputType::eDeleteWordForward
:
279 return true; // In Level 1, undefined.
280 case EditorInputType::eDeleteSoftLineBackward
:
281 return true; // In Level 1, undefined.
282 case EditorInputType::eDeleteSoftLineForward
:
283 return true; // In Level 1, undefined.
284 case EditorInputType::eDeleteEntireSoftLine
:
285 return true; // In Level 1, undefined.
286 case EditorInputType::eDeleteHardLineBackward
:
287 return true; // In Level 1, undefined.
288 case EditorInputType::eDeleteHardLineForward
:
289 return true; // In Level 1, undefined.
290 case EditorInputType::eDeleteByDrag
:
292 case EditorInputType::eDeleteByCut
:
294 case EditorInputType::eDeleteContent
:
295 return true; // In Level 1, undefined.
296 case EditorInputType::eDeleteContentBackward
:
297 return true; // In Level 1, undefined.
298 case EditorInputType::eDeleteContentForward
:
299 return true; // In Level 1, undefined.
300 case EditorInputType::eHistoryUndo
:
302 case EditorInputType::eHistoryRedo
:
304 case EditorInputType::eFormatBold
:
306 case EditorInputType::eFormatItalic
:
308 case EditorInputType::eFormatUnderline
:
310 case EditorInputType::eFormatStrikeThrough
:
312 case EditorInputType::eFormatSuperscript
:
314 case EditorInputType::eFormatSubscript
:
316 case EditorInputType::eFormatJustifyFull
:
318 case EditorInputType::eFormatJustifyCenter
:
320 case EditorInputType::eFormatJustifyRight
:
322 case EditorInputType::eFormatJustifyLeft
:
324 case EditorInputType::eFormatIndent
:
326 case EditorInputType::eFormatOutdent
:
328 case EditorInputType::eFormatRemove
:
330 case EditorInputType::eFormatSetBlockTextDirection
:
332 case EditorInputType::eFormatSetInlineTextDirection
:
334 case EditorInputType::eFormatBackColor
:
336 case EditorInputType::eFormatFontColor
:
338 case EditorInputType::eFormatFontName
:
340 case EditorInputType::eUnknown
:
341 // This is not declared by Input Events, but it does not make sense to
342 // allow web apps to cancel default action without inputType value check.
343 // If some our specific edit actions should be cancelable, new inputType
344 // value for them should be declared by the spec.
347 MOZ_ASSERT_UNREACHABLE("The new input type is not handled");
352 #define NS_DEFINE_COMMAND(aName, aCommandStr) , aName
353 #define NS_DEFINE_COMMAND_WITH_PARAM(aName, aCommandStr, aParam) , aName
354 #define NS_DEFINE_COMMAND_NO_EXEC_COMMAND(aName) , aName
356 typedef uint8_t CommandInt
;
357 enum class Command
: CommandInt
{
360 #include "mozilla/CommandList.h"
362 #undef NS_DEFINE_COMMAND
363 #undef NS_DEFINE_COMMAND_WITH_PARAM
364 #undef NS_DEFINE_COMMAND_NO_EXEC_COMMAND
366 const char* ToChar(Command aCommand
);
369 * Return a command value for aCommandName.
370 * XXX: Is there a better place to put `Command` related methods instead of
371 * global scope in `mozilla` namespace?
373 * @param aCommandName Should be a XUL command name like "cmd_bold"
375 * @param aCommandparams Additional parameter value of aCommandName.
376 * Can be nullptr, but if aCommandName requires
377 * additional parameter and sets this to nullptr,
378 * will return Command::DoNothing with warning.
380 Command
GetInternalCommand(const char* aCommandName
,
381 const nsCommandParams
* aCommandParams
= nullptr);
383 } // namespace mozilla
386 * All header files should include this header instead of *Events.h.
398 #define NS_EVENT_CLASS(aPrefix, aName) class aPrefix##aName;
399 #define NS_ROOT_EVENT_CLASS(aPrefix, aName) NS_EVENT_CLASS(aPrefix, aName)
401 #include "mozilla/EventClassList.h"
403 #undef NS_EVENT_CLASS
404 #undef NS_ROOT_EVENT_CLASS
407 struct BaseEventFlags
;
410 class WidgetEventTime
;
413 enum class AccessKeyType
;
415 struct AlternativeCharCode
;
416 struct ShortcutKeyCandidate
;
418 typedef nsTArray
<ShortcutKeyCandidate
> ShortcutKeyCandidateArray
;
419 typedef AutoTArray
<ShortcutKeyCandidate
, 10> AutoShortcutKeyCandidateArray
;
422 typedef uint8_t RawTextRangeType
;
423 enum class TextRangeType
: RawTextRangeType
;
425 struct TextRangeStyle
;
429 class TextRangeArray
;
431 typedef nsTArray
<OwningNonNull
<dom::StaticRange
>> OwningNonNullStaticRangeArray
;
436 enum MouseButton
: int16_t {
441 eX1
= 3, // Typically, "back" button
442 eX2
= 4, // Typically, "forward" button
446 enum MouseButtonsFlag
{
449 eSecondaryFlag
= 0x02,
451 // typicall, "back" button being left side of 5-button
452 // mice, see "buttons" attribute document of DOM3 Events.
454 // typicall, "forward" button being right side of 5-button
455 // mice, see "buttons" attribute document of DOM3 Events.
461 * Returns a MouseButtonsFlag value which is changed by a button state change
462 * event whose mButton is aMouseButton.
464 inline MouseButtonsFlag
MouseButtonsFlagToChange(MouseButton aMouseButton
) {
465 switch (aMouseButton
) {
466 case MouseButton::ePrimary
:
467 return MouseButtonsFlag::ePrimaryFlag
;
468 case MouseButton::eMiddle
:
469 return MouseButtonsFlag::eMiddleFlag
;
470 case MouseButton::eSecondary
:
471 return MouseButtonsFlag::eSecondaryFlag
;
472 case MouseButton::eX1
:
473 return MouseButtonsFlag::e4thFlag
;
474 case MouseButton::eX2
:
475 return MouseButtonsFlag::e5thFlag
;
476 case MouseButton::eEraser
:
477 return MouseButtonsFlag::eEraserFlag
;
479 return MouseButtonsFlag::eNoButtons
;
483 enum class TextRangeType
: RawTextRangeType
;
487 template <typename IntType
>
488 class StartAndEndOffsets
;
489 template <typename IntType
>
492 } // namespace mozilla
494 #endif // mozilla_EventForwards_h__