Bug 1608587 [wpt PR 21137] - Update wpt metadata, a=testonly
[gecko.git] / widget / TextEvents.h
blobc45a0cb646ba86c9919756e349a583ac96603cf9
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_TextEvents_h__
7 #define mozilla_TextEvents_h__
9 #include <stdint.h>
11 #include "mozilla/Assertions.h"
12 #include "mozilla/BasicEvents.h"
13 #include "mozilla/CheckedInt.h"
14 #include "mozilla/dom/DataTransfer.h"
15 #include "mozilla/EventForwards.h" // for KeyNameIndex, temporarily
16 #include "mozilla/FontRange.h"
17 #include "mozilla/Maybe.h"
18 #include "mozilla/TextRange.h"
19 #include "mozilla/WritingModes.h"
20 #include "mozilla/dom/KeyboardEventBinding.h"
21 #include "nsCOMPtr.h"
22 #include "nsISelectionListener.h"
23 #include "nsITransferable.h"
24 #include "nsRect.h"
25 #include "nsString.h"
26 #include "nsTArray.h"
28 class nsStringHashKey;
29 template <class, class>
30 class nsDataHashtable;
32 /******************************************************************************
33 * virtual keycode values
34 ******************************************************************************/
36 enum {
37 #define NS_DEFINE_VK(aDOMKeyName, aDOMKeyCode) NS_##aDOMKeyName = aDOMKeyCode,
38 #include "mozilla/VirtualKeyCodeList.h"
39 #undef NS_DEFINE_VK
40 NS_VK_UNKNOWN = 0xFF
43 namespace mozilla {
45 enum : uint32_t {
46 eKeyLocationStandard = dom::KeyboardEvent_Binding::DOM_KEY_LOCATION_STANDARD,
47 eKeyLocationLeft = dom::KeyboardEvent_Binding::DOM_KEY_LOCATION_LEFT,
48 eKeyLocationRight = dom::KeyboardEvent_Binding::DOM_KEY_LOCATION_RIGHT,
49 eKeyLocationNumpad = dom::KeyboardEvent_Binding::DOM_KEY_LOCATION_NUMPAD
52 const nsCString GetDOMKeyCodeName(uint32_t aKeyCode);
54 namespace dom {
55 class PBrowserParent;
56 class PBrowserChild;
57 } // namespace dom
58 namespace plugins {
59 class PPluginInstanceChild;
60 } // namespace plugins
62 enum class AccessKeyType {
63 // Handle access key for chrome.
64 eChrome,
65 // Handle access key for content.
66 eContent,
67 // Don't handle access key.
68 eNone
71 /******************************************************************************
72 * mozilla::AlternativeCharCode
74 * This stores alternative charCode values of a key event with some modifiers.
75 * The stored values proper for testing shortcut key or access key.
76 ******************************************************************************/
78 struct AlternativeCharCode {
79 AlternativeCharCode() : mUnshiftedCharCode(0), mShiftedCharCode(0) {}
80 AlternativeCharCode(uint32_t aUnshiftedCharCode, uint32_t aShiftedCharCode)
81 : mUnshiftedCharCode(aUnshiftedCharCode),
82 mShiftedCharCode(aShiftedCharCode) {}
83 uint32_t mUnshiftedCharCode;
84 uint32_t mShiftedCharCode;
87 /******************************************************************************
88 * mozilla::ShortcutKeyCandidate
90 * This stores a candidate of shortcut key combination.
91 ******************************************************************************/
93 struct ShortcutKeyCandidate {
94 ShortcutKeyCandidate() : mCharCode(0), mIgnoreShift(0) {}
95 ShortcutKeyCandidate(uint32_t aCharCode, bool aIgnoreShift)
96 : mCharCode(aCharCode), mIgnoreShift(aIgnoreShift) {}
97 // The mCharCode value which must match keyboard shortcut definition.
98 uint32_t mCharCode;
99 // true if Shift state can be ignored. Otherwise, Shift key state must
100 // match keyboard shortcut definition.
101 bool mIgnoreShift;
104 /******************************************************************************
105 * mozilla::IgnoreModifierState
107 * This stores flags for modifiers that should be ignored when matching
108 * XBL handlers.
109 ******************************************************************************/
111 struct IgnoreModifierState {
112 // When mShift is true, Shift key state will be ignored.
113 bool mShift;
114 // When mOS is true, OS key state will be ignored.
115 bool mOS;
117 IgnoreModifierState() : mShift(false), mOS(false) {}
120 /******************************************************************************
121 * mozilla::WidgetKeyboardEvent
122 ******************************************************************************/
124 class WidgetKeyboardEvent : public WidgetInputEvent {
125 private:
126 friend class dom::PBrowserParent;
127 friend class dom::PBrowserChild;
128 friend struct IPC::ParamTraits<WidgetKeyboardEvent>;
130 protected:
131 WidgetKeyboardEvent()
132 : mNativeKeyEvent(nullptr),
133 mKeyCode(0),
134 mCharCode(0),
135 mPseudoCharCode(0),
136 mLocation(eKeyLocationStandard),
137 mUniqueId(0)
138 #ifdef XP_MACOSX
140 mNativeModifierFlags(0),
141 mNativeKeyCode(0)
142 #endif // #ifdef XP_MACOSX
144 mKeyNameIndex(KEY_NAME_INDEX_Unidentified),
145 mCodeNameIndex(CODE_NAME_INDEX_UNKNOWN),
146 mIsRepeat(false),
147 mIsComposing(false),
148 mIsSynthesizedByTIP(false),
149 mMaybeSkippableInRemoteProcess(true),
150 mUseLegacyKeyCodeAndCharCodeValues(false),
151 mEditCommandsForSingleLineEditorInitialized(false),
152 mEditCommandsForMultiLineEditorInitialized(false),
153 mEditCommandsForRichTextEditorInitialized(false) {
156 public:
157 virtual WidgetKeyboardEvent* AsKeyboardEvent() override { return this; }
159 WidgetKeyboardEvent(bool aIsTrusted, EventMessage aMessage,
160 nsIWidget* aWidget,
161 EventClassID aEventClassID = eKeyboardEventClass)
162 : WidgetInputEvent(aIsTrusted, aMessage, aWidget, aEventClassID),
163 mNativeKeyEvent(nullptr),
164 mKeyCode(0),
165 mCharCode(0),
166 mPseudoCharCode(0),
167 mLocation(eKeyLocationStandard),
168 mUniqueId(0)
169 #ifdef XP_MACOSX
171 mNativeModifierFlags(0),
172 mNativeKeyCode(0)
173 #endif // #ifdef XP_MACOSX
175 mKeyNameIndex(KEY_NAME_INDEX_Unidentified),
176 mCodeNameIndex(CODE_NAME_INDEX_UNKNOWN),
177 mIsRepeat(false),
178 mIsComposing(false),
179 mIsSynthesizedByTIP(false),
180 mMaybeSkippableInRemoteProcess(true),
181 mUseLegacyKeyCodeAndCharCodeValues(false),
182 mEditCommandsForSingleLineEditorInitialized(false),
183 mEditCommandsForMultiLineEditorInitialized(false),
184 mEditCommandsForRichTextEditorInitialized(false) {
185 // If this is a keyboard event on a plugin, it shouldn't fired on content.
186 if (IsKeyEventOnPlugin()) {
187 mFlags.mOnlySystemGroupDispatchInContent = true;
188 StopCrossProcessForwarding();
192 static bool IsKeyDownOrKeyDownOnPlugin(EventMessage aMessage) {
193 return aMessage == eKeyDown || aMessage == eKeyDownOnPlugin;
195 bool IsKeyDownOrKeyDownOnPlugin() const {
196 return IsKeyDownOrKeyDownOnPlugin(mMessage);
198 static bool IsKeyUpOrKeyUpOnPlugin(EventMessage aMessage) {
199 return aMessage == eKeyUp || aMessage == eKeyUpOnPlugin;
201 bool IsKeyUpOrKeyUpOnPlugin() const {
202 return IsKeyUpOrKeyUpOnPlugin(mMessage);
204 static bool IsKeyEventOnPlugin(EventMessage aMessage) {
205 return aMessage == eKeyDownOnPlugin || aMessage == eKeyUpOnPlugin;
207 bool IsKeyEventOnPlugin() const { return IsKeyEventOnPlugin(mMessage); }
209 // IsInputtingText() and IsInputtingLineBreak() are used to check if
210 // it should cause eKeyPress events even on web content.
211 // UI Events defines that "keypress" event should be fired "if and only if
212 // that key normally produces a character value".
213 // <https://www.w3.org/TR/uievents/#event-type-keypress>
214 // Additionally, for backward compatiblity with all existing browsers,
215 // there is a spec issue for Enter key press.
216 // <https://github.com/w3c/uievents/issues/183>
217 bool IsInputtingText() const {
218 // NOTE: On some keyboard layout, some characters are inputted with Control
219 // key or Alt key, but at that time, widget clears the modifier flag
220 // from eKeyPress event because our TextEditor won't handle eKeyPress
221 // events as inputting text (bug 1346832).
222 // NOTE: There are some complicated issues of our traditional behavior.
223 // -- On Windows, KeyboardLayout::WillDispatchKeyboardEvent() clears
224 // MODIFIER_ALT and MODIFIER_CONTROL of eKeyPress event if it
225 // should be treated as inputting a character because AltGr is
226 // represented with both Alt key and Ctrl key are pressed, and
227 // some keyboard layouts may produces a character with Ctrl key.
228 // -- On Linux, KeymapWrapper doesn't have this hack since perhaps,
229 // we don't have any bug reports that user cannot input proper
230 // character with Alt and/or Ctrl key.
231 // -- On macOS, IMEInputHandler::WillDispatchKeyboardEvent() clears
232 // MODIFIER_ALT and MDOFIEIR_CONTROL of eKeyPress event only when
233 // TextInputHandler::InsertText() has been called for the event.
234 // I.e., they are cleared only when an editor has focus (even if IME
235 // is disabled in password field or by |ime-mode: disabled;|) because
236 // TextInputHandler::InsertText() is called while
237 // TextInputHandler::HandleKeyDownEvent() calls interpretKeyEvents:
238 // to notify text input processor of Cocoa (including IME). In other
239 // words, when we need to disable IME completey when no editor has
240 // focus, we cannot call interpretKeyEvents:. So,
241 // TextInputHandler::InsertText() won't be called when no editor has
242 // focus so that neither MODIFIER_ALT nor MODIFIER_CONTROL is
243 // cleared. So, fortunately, altKey and ctrlKey values of "keypress"
244 // events are same as the other browsers only when no editor has
245 // focus.
246 // NOTE: As mentioned above, for compatibility with the other browsers on
247 // macOS, we should keep MODIFIER_ALT and MODIFIER_CONTROL flags of
248 // eKeyPress events when no editor has focus. However, Alt key,
249 // labeled "option" on keyboard for Mac, is AltGraph key on the other
250 // platforms. So, even if MODIFIER_ALT is set, we need to dispatch
251 // eKeyPress event even on web content unless mCharCode is 0.
252 // Therefore, we need to ignore MODIFIER_ALT flag here only on macOS.
253 return mMessage == eKeyPress && mCharCode &&
254 !(mModifiers & (
255 #ifndef XP_MACOSX
256 // So, ignore MODIFIER_ALT only on macOS since
257 // option key is used as AltGraph key on macOS.
258 MODIFIER_ALT |
259 #endif // #ifndef XP_MAXOSX
260 MODIFIER_CONTROL | MODIFIER_META | MODIFIER_OS));
263 bool IsInputtingLineBreak() const {
264 return mMessage == eKeyPress && mKeyNameIndex == KEY_NAME_INDEX_Enter &&
265 !(mModifiers &
266 (MODIFIER_ALT | MODIFIER_CONTROL | MODIFIER_META | MODIFIER_OS));
270 * ShouldKeyPressEventBeFiredOnContent() should be called only when the
271 * instance is eKeyPress event. This returns true when the eKeyPress
272 * event should be fired even on content in the default event group.
274 bool ShouldKeyPressEventBeFiredOnContent() const {
275 MOZ_DIAGNOSTIC_ASSERT(mMessage == eKeyPress);
276 if (IsInputtingText() || IsInputtingLineBreak()) {
277 return true;
279 // Ctrl + Enter won't cause actual input in our editor.
280 // However, the other browsers fire keypress event in any platforms.
281 // So, for compatibility with them, we should fire keypress event for
282 // Ctrl + Enter too.
283 return mMessage == eKeyPress && mKeyNameIndex == KEY_NAME_INDEX_Enter &&
284 !(mModifiers &
285 (MODIFIER_ALT | MODIFIER_META | MODIFIER_OS | MODIFIER_SHIFT));
288 virtual WidgetEvent* Duplicate() const override {
289 MOZ_ASSERT(mClass == eKeyboardEventClass,
290 "Duplicate() must be overridden by sub class");
291 // Not copying widget, it is a weak reference.
292 WidgetKeyboardEvent* result =
293 new WidgetKeyboardEvent(false, mMessage, nullptr);
294 result->AssignKeyEventData(*this, true);
295 result->mEditCommandsForSingleLineEditor = mEditCommandsForSingleLineEditor;
296 result->mEditCommandsForMultiLineEditor = mEditCommandsForMultiLineEditor;
297 result->mEditCommandsForRichTextEditor = mEditCommandsForRichTextEditor;
298 result->mFlags = mFlags;
299 return result;
302 bool CanUserGestureActivateTarget() const {
303 // Printable keys, 'carriage return' and 'space' are supported user gestures
304 // for activating the document. However, if supported key is being pressed
305 // combining with other operation keys, such like alt, control ..etc., we
306 // won't activate the target for them because at that time user might
307 // interact with browser or window manager which doesn't necessarily
308 // demonstrate user's intent to play media.
309 const bool isCombiningWithOperationKeys = (IsControl() && !IsAltGraph()) ||
310 (IsAlt() && !IsAltGraph()) ||
311 IsMeta() || IsOS();
312 const bool isEnterOrSpaceKey =
313 mKeyNameIndex == KEY_NAME_INDEX_Enter || mKeyCode == NS_VK_SPACE;
314 return (PseudoCharCode() || isEnterOrSpaceKey) &&
315 !isCombiningWithOperationKeys;
319 * CanTreatAsUserInput() returns true if the key is pressed for perhaps
320 * doing something on the web app or our UI. This means that when this
321 * returns false, e.g., when user presses a modifier key, user is probably
322 * displeased by opening popup, entering fullscreen mode, etc. Therefore,
323 * only when this returns true, such reactions should be allowed.
325 bool CanTreatAsUserInput() const {
326 if (!IsTrusted()) {
327 return false;
329 switch (mKeyNameIndex) {
330 case KEY_NAME_INDEX_Escape:
331 // modifier keys:
332 case KEY_NAME_INDEX_Alt:
333 case KEY_NAME_INDEX_AltGraph:
334 case KEY_NAME_INDEX_CapsLock:
335 case KEY_NAME_INDEX_Control:
336 case KEY_NAME_INDEX_Fn:
337 case KEY_NAME_INDEX_FnLock:
338 case KEY_NAME_INDEX_Meta:
339 case KEY_NAME_INDEX_NumLock:
340 case KEY_NAME_INDEX_ScrollLock:
341 case KEY_NAME_INDEX_Shift:
342 case KEY_NAME_INDEX_Symbol:
343 case KEY_NAME_INDEX_SymbolLock:
344 // legacy modifier keys:
345 case KEY_NAME_INDEX_Hyper:
346 case KEY_NAME_INDEX_Super:
347 // obsolete modifier key:
348 case KEY_NAME_INDEX_OS:
349 return false;
350 default:
351 return true;
356 * ShouldInteractionTimeRecorded() returns true if the handling time of
357 * the event should be recorded with the telemetry.
359 bool ShouldInteractionTimeRecorded() const {
360 // Let's record only when we can treat the instance is a user input.
361 return CanTreatAsUserInput();
364 // OS translated Unicode chars which are used for accesskey and accelkey
365 // handling. The handlers will try from first character to last character.
366 nsTArray<AlternativeCharCode> mAlternativeCharCodes;
367 // DOM KeyboardEvent.key only when mKeyNameIndex is KEY_NAME_INDEX_USE_STRING.
368 nsString mKeyValue;
369 // DOM KeyboardEvent.code only when mCodeNameIndex is
370 // CODE_NAME_INDEX_USE_STRING.
371 nsString mCodeValue;
373 #ifdef XP_MACOSX
374 // Values given by a native NSEvent, for use with Cocoa NPAPI plugins.
375 nsString mNativeCharacters;
376 nsString mNativeCharactersIgnoringModifiers;
377 // If this is non-empty, create a text event for plugins instead of a
378 // keyboard event.
379 nsString mPluginTextEventString;
380 #endif // #ifdef XP_MACOSX
382 // OS-specific native event can optionally be preserved
383 void* mNativeKeyEvent;
384 // A DOM keyCode value or 0. If a keypress event whose mCharCode is 0, this
385 // should be 0.
386 uint32_t mKeyCode;
387 // If the instance is a keypress event of a printable key, this is a UTF-16
388 // value of the key. Otherwise, 0. This value must not be a control
389 // character when some modifiers are active. Then, this value should be an
390 // unmodified value except Shift and AltGr.
391 uint32_t mCharCode;
392 // mPseudoCharCode is valid only when mMessage is an eKeyDown event.
393 // This stores mCharCode value of keypress event which is fired with same
394 // key value and same modifier state.
395 uint32_t mPseudoCharCode;
396 // One of eKeyLocation*
397 uint32_t mLocation;
398 // Unique id associated with a keydown / keypress event. It's ok if this wraps
399 // over long periods.
400 uint32_t mUniqueId;
402 #ifdef XP_MACOSX
403 // Values given by a native NSEvent, for use with Cocoa NPAPI plugins.
404 uint32_t mNativeModifierFlags;
405 uint16_t mNativeKeyCode;
406 #endif // #ifdef XP_MACOSX
408 // DOM KeyboardEvent.key
409 KeyNameIndex mKeyNameIndex;
410 // DOM KeyboardEvent.code
411 CodeNameIndex mCodeNameIndex;
413 // Indicates whether the event is generated by auto repeat or not.
414 // if this is keyup event, always false.
415 bool mIsRepeat;
416 // Indicates whether the event is generated during IME (or deadkey)
417 // composition. This is initialized by EventStateManager. So, key event
418 // dispatchers don't need to initialize this.
419 bool mIsComposing;
420 // Indicates whether the event is synthesized from Text Input Processor
421 // or an actual event from nsAppShell.
422 bool mIsSynthesizedByTIP;
423 // Indicates whether the event is skippable in remote process.
424 // Don't refer this member directly when you need to check this.
425 // Use CanSkipInRemoteProcess() instead.
426 bool mMaybeSkippableInRemoteProcess;
427 // Indicates whether the event should return legacy keyCode value and
428 // charCode value to web apps (one of them is always 0) or not, when it's
429 // an eKeyPress event.
430 bool mUseLegacyKeyCodeAndCharCodeValues;
432 bool CanSkipInRemoteProcess() const {
433 // If this is a repeat event (i.e., generated by auto-repeat feature of
434 // the platform), remove process may skip to handle it because of
435 // performances reasons.. However, if it's caused by odd keyboard utils,
436 // we should not ignore any key events even marked as repeated since
437 // generated key sequence may be important to input proper text. E.g.,
438 // "SinhalaTamil IME" on Windows emulates dead key like input with
439 // generating WM_KEYDOWN for VK_PACKET (inputting any Unicode characters
440 // without keyboard layout information) and VK_BACK (Backspace) to remove
441 // previous character(s) and those messages may be marked as "repeat" by
442 // their bug.
443 return mIsRepeat && mMaybeSkippableInRemoteProcess;
447 * Retrieves all edit commands from mWidget. This shouldn't be called when
448 * the instance is an untrusted event, doesn't have widget or in non-chrome
449 * process.
451 void InitAllEditCommands();
454 * Retrieves edit commands from mWidget only for aType. This shouldn't be
455 * called when the instance is an untrusted event or doesn't have widget.
457 * @return false if some resource is not available to get
458 * commands unexpectedly. Otherwise, true even if
459 * retrieved command is nothing.
461 bool InitEditCommandsFor(nsIWidget::NativeKeyBindingsType aType);
464 * PreventNativeKeyBindings() makes the instance to not cause any edit
465 * actions even if it matches with a native key binding.
467 void PreventNativeKeyBindings() {
468 mEditCommandsForSingleLineEditor.Clear();
469 mEditCommandsForMultiLineEditor.Clear();
470 mEditCommandsForRichTextEditor.Clear();
471 mEditCommandsForSingleLineEditorInitialized = true;
472 mEditCommandsForMultiLineEditorInitialized = true;
473 mEditCommandsForRichTextEditorInitialized = true;
477 * EditCommandsConstRef() returns reference to edit commands for aType.
479 const nsTArray<CommandInt>& EditCommandsConstRef(
480 nsIWidget::NativeKeyBindingsType aType) const {
481 return const_cast<WidgetKeyboardEvent*>(this)->EditCommandsRef(aType);
485 * IsEditCommandsInitialized() returns true if edit commands for aType
486 * was already initialized. Otherwise, false.
488 bool IsEditCommandsInitialized(nsIWidget::NativeKeyBindingsType aType) const {
489 return const_cast<WidgetKeyboardEvent*>(this)->IsEditCommandsInitializedRef(
490 aType);
493 #ifdef DEBUG
495 * AreAllEditCommandsInitialized() returns true if edit commands for all
496 * types were already initialized. Otherwise, false.
498 bool AreAllEditCommandsInitialized() const {
499 return mEditCommandsForSingleLineEditorInitialized &&
500 mEditCommandsForMultiLineEditorInitialized &&
501 mEditCommandsForRichTextEditorInitialized;
503 #endif // #ifdef DEBUG
506 * Execute edit commands for aType.
508 * @return true if the caller should do nothing anymore.
509 * false, otherwise.
511 typedef void (*DoCommandCallback)(Command, void*);
512 bool ExecuteEditCommands(nsIWidget::NativeKeyBindingsType aType,
513 DoCommandCallback aCallback, void* aCallbackData);
515 // If the key should cause keypress events, this returns true.
516 // Otherwise, false.
517 bool ShouldCauseKeypressEvents() const;
519 // mCharCode value of non-eKeyPress events is always 0. However, if
520 // non-eKeyPress event has one or more alternative char code values,
521 // its first item should be the mCharCode value of following eKeyPress event.
522 // PseudoCharCode() returns mCharCode value for eKeyPress event,
523 // the first alternative char code value of non-eKeyPress event or 0.
524 uint32_t PseudoCharCode() const {
525 return mMessage == eKeyPress ? mCharCode : mPseudoCharCode;
527 void SetCharCode(uint32_t aCharCode) {
528 if (mMessage == eKeyPress) {
529 mCharCode = aCharCode;
530 } else {
531 mPseudoCharCode = aCharCode;
535 void GetDOMKeyName(nsAString& aKeyName) {
536 if (mKeyNameIndex == KEY_NAME_INDEX_USE_STRING) {
537 aKeyName = mKeyValue;
538 return;
540 GetDOMKeyName(mKeyNameIndex, aKeyName);
542 void GetDOMCodeName(nsAString& aCodeName) {
543 if (mCodeNameIndex == CODE_NAME_INDEX_USE_STRING) {
544 aCodeName = mCodeValue;
545 return;
547 GetDOMCodeName(mCodeNameIndex, aCodeName);
551 * GetFallbackKeyCodeOfPunctuationKey() returns a DOM keyCode value for
552 * aCodeNameIndex. This is keyCode value of the key when active keyboard
553 * layout is ANSI (US), JIS or ABNT keyboard layout (the latter 2 layouts
554 * are used only when ANSI doesn't have the key). The result is useful
555 * if the key doesn't produce ASCII character with active keyboard layout
556 * nor with alternative ASCII capable keyboard layout.
558 static uint32_t GetFallbackKeyCodeOfPunctuationKey(
559 CodeNameIndex aCodeNameIndex);
561 bool IsModifierKeyEvent() const {
562 return GetModifierForKeyName(mKeyNameIndex) != MODIFIER_NONE;
566 * Get the candidates for shortcut key.
568 * @param aCandidates [out] the candidate shortcut key combination list.
569 * the first item is most preferred.
571 void GetShortcutKeyCandidates(ShortcutKeyCandidateArray& aCandidates) const;
574 * Get the candidates for access key.
576 * @param aCandidates [out] the candidate access key list.
577 * the first item is most preferred.
579 void GetAccessKeyCandidates(nsTArray<uint32_t>& aCandidates) const;
582 * Check whether the modifiers match with chrome access key or
583 * content access key.
585 bool ModifiersMatchWithAccessKey(AccessKeyType aType) const;
588 * Return active modifiers which may match with access key.
589 * For example, even if Alt is access key modifier, then, when Control,
590 * CapseLock and NumLock are active, this returns only MODIFIER_CONTROL.
592 Modifiers ModifiersForAccessKeyMatching() const;
595 * Return access key modifiers.
597 static Modifiers AccessKeyModifiers(AccessKeyType aType);
599 static void Shutdown();
602 * ComputeLocationFromCodeValue() returns one of .mLocation value
603 * (eKeyLocation*) which is the most preferred value for the specified code
604 * value.
606 static uint32_t ComputeLocationFromCodeValue(CodeNameIndex aCodeNameIndex);
609 * ComputeKeyCodeFromKeyNameIndex() return a .mKeyCode value which can be
610 * mapped from the specified key value. Note that this returns 0 if the
611 * key name index is KEY_NAME_INDEX_Unidentified or KEY_NAME_INDEX_USE_STRING.
612 * This means that this method is useful only for non-printable keys.
614 static uint32_t ComputeKeyCodeFromKeyNameIndex(KeyNameIndex aKeyNameIndex);
617 * ComputeCodeNameIndexFromKeyNameIndex() returns a code name index which
618 * is typically mapped to given key name index on the platform.
619 * Note that this returns CODE_NAME_INDEX_UNKNOWN if the key name index is
620 * KEY_NAME_INDEX_Unidentified or KEY_NAME_INDEX_USE_STRING.
621 * This means that this method is useful only for non-printable keys.
623 * @param aKeyNameIndex A non-printable key name index.
624 * @param aLocation Should be one of location value. This is
625 * important when aKeyNameIndex may exist in
626 * both Numpad or Standard, or in both Left or
627 * Right. If this is nothing, this method
628 * returns Left or Standard position's code
629 * value.
631 static CodeNameIndex ComputeCodeNameIndexFromKeyNameIndex(
632 KeyNameIndex aKeyNameIndex, const Maybe<uint32_t>& aLocation);
635 * GetModifierForKeyName() returns a value of Modifier which is activated
636 * by the aKeyNameIndex.
638 static Modifier GetModifierForKeyName(KeyNameIndex aKeyNameIndex);
641 * IsLeftOrRightModiferKeyNameIndex() returns true if aKeyNameIndex is a
642 * modifier key which may be in Left and Right location.
644 static bool IsLeftOrRightModiferKeyNameIndex(KeyNameIndex aKeyNameIndex) {
645 switch (aKeyNameIndex) {
646 case KEY_NAME_INDEX_Alt:
647 case KEY_NAME_INDEX_Control:
648 case KEY_NAME_INDEX_Meta:
649 case KEY_NAME_INDEX_OS:
650 case KEY_NAME_INDEX_Shift:
651 return true;
652 default:
653 return false;
658 * IsLockableModifier() returns true if aKeyNameIndex is a lockable modifier
659 * key such as CapsLock and NumLock.
661 static bool IsLockableModifier(KeyNameIndex aKeyNameIndex);
663 static void GetDOMKeyName(KeyNameIndex aKeyNameIndex, nsAString& aKeyName);
664 static void GetDOMCodeName(CodeNameIndex aCodeNameIndex,
665 nsAString& aCodeName);
667 static KeyNameIndex GetKeyNameIndex(const nsAString& aKeyValue);
668 static CodeNameIndex GetCodeNameIndex(const nsAString& aCodeValue);
670 static const char* GetCommandStr(Command aCommand);
672 void AssignKeyEventData(const WidgetKeyboardEvent& aEvent,
673 bool aCopyTargets) {
674 AssignInputEventData(aEvent, aCopyTargets);
676 mKeyCode = aEvent.mKeyCode;
677 mCharCode = aEvent.mCharCode;
678 mPseudoCharCode = aEvent.mPseudoCharCode;
679 mLocation = aEvent.mLocation;
680 mAlternativeCharCodes = aEvent.mAlternativeCharCodes;
681 mIsRepeat = aEvent.mIsRepeat;
682 mIsComposing = aEvent.mIsComposing;
683 mKeyNameIndex = aEvent.mKeyNameIndex;
684 mCodeNameIndex = aEvent.mCodeNameIndex;
685 mKeyValue = aEvent.mKeyValue;
686 mCodeValue = aEvent.mCodeValue;
687 // Don't copy mNativeKeyEvent because it may be referred after its instance
688 // is destroyed.
689 mNativeKeyEvent = nullptr;
690 mUniqueId = aEvent.mUniqueId;
691 #ifdef XP_MACOSX
692 mNativeKeyCode = aEvent.mNativeKeyCode;
693 mNativeModifierFlags = aEvent.mNativeModifierFlags;
694 mNativeCharacters.Assign(aEvent.mNativeCharacters);
695 mNativeCharactersIgnoringModifiers.Assign(
696 aEvent.mNativeCharactersIgnoringModifiers);
697 mPluginTextEventString.Assign(aEvent.mPluginTextEventString);
698 #endif
699 mIsSynthesizedByTIP = aEvent.mIsSynthesizedByTIP;
700 mMaybeSkippableInRemoteProcess = aEvent.mMaybeSkippableInRemoteProcess;
701 mUseLegacyKeyCodeAndCharCodeValues =
702 aEvent.mUseLegacyKeyCodeAndCharCodeValues;
704 // Don't copy mEditCommandsFor*Editor because it may require a lot of
705 // memory space. For example, if the event is dispatched but grabbed by
706 // a JS variable, they are not necessary anymore.
708 mEditCommandsForSingleLineEditorInitialized =
709 aEvent.mEditCommandsForSingleLineEditorInitialized;
710 mEditCommandsForMultiLineEditorInitialized =
711 aEvent.mEditCommandsForMultiLineEditorInitialized;
712 mEditCommandsForRichTextEditorInitialized =
713 aEvent.mEditCommandsForRichTextEditorInitialized;
716 void AssignCommands(const WidgetKeyboardEvent& aEvent) {
717 mEditCommandsForSingleLineEditorInitialized =
718 aEvent.mEditCommandsForSingleLineEditorInitialized;
719 if (mEditCommandsForSingleLineEditorInitialized) {
720 mEditCommandsForSingleLineEditor =
721 aEvent.mEditCommandsForSingleLineEditor;
722 } else {
723 mEditCommandsForSingleLineEditor.Clear();
725 mEditCommandsForMultiLineEditorInitialized =
726 aEvent.mEditCommandsForMultiLineEditorInitialized;
727 if (mEditCommandsForMultiLineEditorInitialized) {
728 mEditCommandsForMultiLineEditor = aEvent.mEditCommandsForMultiLineEditor;
729 } else {
730 mEditCommandsForMultiLineEditor.Clear();
732 mEditCommandsForRichTextEditorInitialized =
733 aEvent.mEditCommandsForRichTextEditorInitialized;
734 if (mEditCommandsForRichTextEditorInitialized) {
735 mEditCommandsForRichTextEditor = aEvent.mEditCommandsForRichTextEditor;
736 } else {
737 mEditCommandsForRichTextEditor.Clear();
741 private:
742 static const char16_t* const kKeyNames[];
743 static const char16_t* const kCodeNames[];
744 typedef nsDataHashtable<nsStringHashKey, KeyNameIndex> KeyNameIndexHashtable;
745 typedef nsDataHashtable<nsStringHashKey, CodeNameIndex>
746 CodeNameIndexHashtable;
747 static KeyNameIndexHashtable* sKeyNameIndexHashtable;
748 static CodeNameIndexHashtable* sCodeNameIndexHashtable;
750 // mEditCommandsFor*Editor store edit commands. This should be initialized
751 // with InitEditCommandsFor().
752 // XXX Ideally, this should be array of Command rather than CommandInt.
753 // However, ParamTraits isn't aware of enum array.
754 nsTArray<CommandInt> mEditCommandsForSingleLineEditor;
755 nsTArray<CommandInt> mEditCommandsForMultiLineEditor;
756 nsTArray<CommandInt> mEditCommandsForRichTextEditor;
758 nsTArray<CommandInt>& EditCommandsRef(
759 nsIWidget::NativeKeyBindingsType aType) {
760 switch (aType) {
761 case nsIWidget::NativeKeyBindingsForSingleLineEditor:
762 return mEditCommandsForSingleLineEditor;
763 case nsIWidget::NativeKeyBindingsForMultiLineEditor:
764 return mEditCommandsForMultiLineEditor;
765 case nsIWidget::NativeKeyBindingsForRichTextEditor:
766 return mEditCommandsForRichTextEditor;
767 default:
768 MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE(
769 "Invalid native key binding type");
773 // mEditCommandsFor*EditorInitialized are set to true when
774 // InitEditCommandsFor() initializes edit commands for the type.
775 bool mEditCommandsForSingleLineEditorInitialized;
776 bool mEditCommandsForMultiLineEditorInitialized;
777 bool mEditCommandsForRichTextEditorInitialized;
779 bool& IsEditCommandsInitializedRef(nsIWidget::NativeKeyBindingsType aType) {
780 switch (aType) {
781 case nsIWidget::NativeKeyBindingsForSingleLineEditor:
782 return mEditCommandsForSingleLineEditorInitialized;
783 case nsIWidget::NativeKeyBindingsForMultiLineEditor:
784 return mEditCommandsForMultiLineEditorInitialized;
785 case nsIWidget::NativeKeyBindingsForRichTextEditor:
786 return mEditCommandsForRichTextEditorInitialized;
787 default:
788 MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE(
789 "Invalid native key binding type");
794 /******************************************************************************
795 * mozilla::WidgetCompositionEvent
796 ******************************************************************************/
798 class WidgetCompositionEvent : public WidgetGUIEvent {
799 private:
800 friend class mozilla::dom::PBrowserParent;
801 friend class mozilla::dom::PBrowserChild;
803 WidgetCompositionEvent() : mOriginalMessage(eVoidEvent) {}
805 public:
806 virtual WidgetCompositionEvent* AsCompositionEvent() override { return this; }
808 WidgetCompositionEvent(bool aIsTrusted, EventMessage aMessage,
809 nsIWidget* aWidget)
810 : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, eCompositionEventClass),
811 mNativeIMEContext(aWidget),
812 mOriginalMessage(eVoidEvent) {}
814 virtual WidgetEvent* Duplicate() const override {
815 MOZ_ASSERT(mClass == eCompositionEventClass,
816 "Duplicate() must be overridden by sub class");
817 // Not copying widget, it is a weak reference.
818 WidgetCompositionEvent* result =
819 new WidgetCompositionEvent(false, mMessage, nullptr);
820 result->AssignCompositionEventData(*this, true);
821 result->mFlags = mFlags;
822 return result;
825 // The composition string or the commit string. If the instance is a
826 // compositionstart event, this is initialized with selected text by
827 // TextComposition automatically.
828 nsString mData;
830 RefPtr<TextRangeArray> mRanges;
832 // mNativeIMEContext stores the native IME context which causes the
833 // composition event.
834 widget::NativeIMEContext mNativeIMEContext;
836 // If the instance is a clone of another event, mOriginalMessage stores
837 // the another event's mMessage.
838 EventMessage mOriginalMessage;
840 void AssignCompositionEventData(const WidgetCompositionEvent& aEvent,
841 bool aCopyTargets) {
842 AssignGUIEventData(aEvent, aCopyTargets);
844 mData = aEvent.mData;
845 mOriginalMessage = aEvent.mOriginalMessage;
846 mRanges = aEvent.mRanges;
848 // Currently, we don't need to copy the other members because they are
849 // for internal use only (not available from JS).
852 bool IsComposing() const { return mRanges && mRanges->IsComposing(); }
854 uint32_t TargetClauseOffset() const {
855 return mRanges ? mRanges->TargetClauseOffset() : 0;
858 uint32_t TargetClauseLength() const {
859 uint32_t length = UINT32_MAX;
860 if (mRanges) {
861 length = mRanges->TargetClauseLength();
863 return length == UINT32_MAX ? mData.Length() : length;
866 uint32_t RangeCount() const { return mRanges ? mRanges->Length() : 0; }
868 bool CausesDOMTextEvent() const {
869 return mMessage == eCompositionChange || mMessage == eCompositionCommit ||
870 mMessage == eCompositionCommitAsIs;
873 bool CausesDOMCompositionEndEvent() const {
874 return mMessage == eCompositionEnd || mMessage == eCompositionCommit ||
875 mMessage == eCompositionCommitAsIs;
878 bool IsFollowedByCompositionEnd() const {
879 return IsFollowedByCompositionEnd(mOriginalMessage);
882 static bool IsFollowedByCompositionEnd(EventMessage aEventMessage) {
883 return aEventMessage == eCompositionCommit ||
884 aEventMessage == eCompositionCommitAsIs;
888 /******************************************************************************
889 * mozilla::WidgetQueryContentEvent
890 ******************************************************************************/
892 class WidgetQueryContentEvent : public WidgetGUIEvent {
893 private:
894 friend class dom::PBrowserParent;
895 friend class dom::PBrowserChild;
897 WidgetQueryContentEvent()
898 : mSucceeded(false),
899 mUseNativeLineBreak(true),
900 mWithFontRanges(false),
901 mNeedsToFlushLayout(true) {
902 MOZ_CRASH("WidgetQueryContentEvent is created without proper arguments");
905 public:
906 virtual WidgetQueryContentEvent* AsQueryContentEvent() override {
907 return this;
910 WidgetQueryContentEvent(bool aIsTrusted, EventMessage aMessage,
911 nsIWidget* aWidget)
912 : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, eQueryContentEventClass),
913 mSucceeded(false),
914 mUseNativeLineBreak(true),
915 mWithFontRanges(false),
916 mNeedsToFlushLayout(true) {}
918 WidgetQueryContentEvent(EventMessage aMessage,
919 const WidgetQueryContentEvent& aOtherEvent)
920 : WidgetGUIEvent(aOtherEvent.IsTrusted(), aMessage,
921 const_cast<nsIWidget*>(aOtherEvent.mWidget.get()),
922 eQueryContentEventClass),
923 mSucceeded(false),
924 mUseNativeLineBreak(aOtherEvent.mUseNativeLineBreak),
925 mWithFontRanges(false),
926 mNeedsToFlushLayout(aOtherEvent.mNeedsToFlushLayout) {}
928 virtual WidgetEvent* Duplicate() const override {
929 // This event isn't an internal event of any DOM event.
930 NS_ASSERTION(!IsAllowedToDispatchDOMEvent(),
931 "WidgetQueryContentEvent needs to support Duplicate()");
932 MOZ_CRASH("WidgetQueryContentEvent doesn't support Duplicate()");
935 struct Options final {
936 bool mUseNativeLineBreak;
937 bool mRelativeToInsertionPoint;
939 explicit Options()
940 : mUseNativeLineBreak(true), mRelativeToInsertionPoint(false) {}
942 explicit Options(const WidgetQueryContentEvent& aEvent)
943 : mUseNativeLineBreak(aEvent.mUseNativeLineBreak),
944 mRelativeToInsertionPoint(aEvent.mInput.mRelativeToInsertionPoint) {}
947 void Init(const Options& aOptions) {
948 mUseNativeLineBreak = aOptions.mUseNativeLineBreak;
949 mInput.mRelativeToInsertionPoint = aOptions.mRelativeToInsertionPoint;
950 MOZ_ASSERT(mInput.IsValidEventMessage(mMessage));
953 void InitForQueryTextContent(int64_t aOffset, uint32_t aLength,
954 const Options& aOptions = Options()) {
955 NS_ASSERTION(mMessage == eQueryTextContent, "wrong initializer is called");
956 mInput.mOffset = aOffset;
957 mInput.mLength = aLength;
958 Init(aOptions);
959 MOZ_ASSERT(mInput.IsValidOffset());
962 void InitForQueryCaretRect(int64_t aOffset,
963 const Options& aOptions = Options()) {
964 NS_ASSERTION(mMessage == eQueryCaretRect, "wrong initializer is called");
965 mInput.mOffset = aOffset;
966 Init(aOptions);
967 MOZ_ASSERT(mInput.IsValidOffset());
970 void InitForQueryTextRect(int64_t aOffset, uint32_t aLength,
971 const Options& aOptions = Options()) {
972 NS_ASSERTION(mMessage == eQueryTextRect, "wrong initializer is called");
973 mInput.mOffset = aOffset;
974 mInput.mLength = aLength;
975 Init(aOptions);
976 MOZ_ASSERT(mInput.IsValidOffset());
979 void InitForQuerySelectedText(SelectionType aSelectionType,
980 const Options& aOptions = Options()) {
981 MOZ_ASSERT(mMessage == eQuerySelectedText);
982 MOZ_ASSERT(aSelectionType != SelectionType::eNone);
983 mInput.mSelectionType = aSelectionType;
984 Init(aOptions);
987 void InitForQueryDOMWidgetHittest(
988 const mozilla::LayoutDeviceIntPoint& aPoint) {
989 NS_ASSERTION(mMessage == eQueryDOMWidgetHittest,
990 "wrong initializer is called");
991 mRefPoint = aPoint;
994 void InitForQueryTextRectArray(uint32_t aOffset, uint32_t aLength,
995 const Options& aOptions = Options()) {
996 NS_ASSERTION(mMessage == eQueryTextRectArray,
997 "wrong initializer is called");
998 mInput.mOffset = aOffset;
999 mInput.mLength = aLength;
1000 Init(aOptions);
1003 bool NeedsToFlushLayout() const { return mNeedsToFlushLayout; }
1005 void RequestFontRanges() {
1006 NS_ASSERTION(mMessage == eQueryTextContent, "not querying text content");
1007 mWithFontRanges = true;
1010 uint32_t GetSelectionStart(void) const {
1011 NS_ASSERTION(mMessage == eQuerySelectedText, "not querying selection");
1012 return mReply.mOffset + (mReply.mReversed ? mReply.mString.Length() : 0);
1015 uint32_t GetSelectionEnd(void) const {
1016 NS_ASSERTION(mMessage == eQuerySelectedText, "not querying selection");
1017 return mReply.mOffset + (mReply.mReversed ? 0 : mReply.mString.Length());
1020 mozilla::WritingMode GetWritingMode(void) const {
1021 NS_ASSERTION(mMessage == eQuerySelectedText ||
1022 mMessage == eQueryCaretRect || mMessage == eQueryTextRect,
1023 "not querying selection or text rect");
1024 return mReply.mWritingMode;
1027 bool mSucceeded;
1028 bool mUseNativeLineBreak;
1029 bool mWithFontRanges;
1030 bool mNeedsToFlushLayout;
1031 struct Input final {
1032 uint32_t EndOffset() const {
1033 CheckedInt<uint32_t> endOffset = CheckedInt<uint32_t>(mOffset) + mLength;
1034 return NS_WARN_IF(!endOffset.isValid()) ? UINT32_MAX : endOffset.value();
1037 int64_t mOffset;
1038 uint32_t mLength;
1039 SelectionType mSelectionType;
1040 // If mOffset is true, mOffset is relative to the start offset of
1041 // composition if there is, otherwise, the start of the first selection
1042 // range.
1043 bool mRelativeToInsertionPoint;
1045 Input()
1046 : mOffset(0),
1047 mLength(0),
1048 mSelectionType(SelectionType::eNormal),
1049 mRelativeToInsertionPoint(false) {}
1051 bool IsValidOffset() const {
1052 return mRelativeToInsertionPoint || mOffset >= 0;
1054 bool IsValidEventMessage(EventMessage aEventMessage) const {
1055 if (!mRelativeToInsertionPoint) {
1056 return true;
1058 switch (aEventMessage) {
1059 case eQueryTextContent:
1060 case eQueryCaretRect:
1061 case eQueryTextRect:
1062 return true;
1063 default:
1064 return false;
1067 bool MakeOffsetAbsolute(uint32_t aInsertionPointOffset) {
1068 if (NS_WARN_IF(!mRelativeToInsertionPoint)) {
1069 return true;
1071 mRelativeToInsertionPoint = false;
1072 // If mOffset + aInsertionPointOffset becomes negative value,
1073 // we should assume the absolute offset is 0.
1074 if (mOffset < 0 && -mOffset > aInsertionPointOffset) {
1075 mOffset = 0;
1076 return true;
1078 // Otherwise, we don't allow too large offset.
1079 CheckedInt<uint32_t> absOffset =
1080 CheckedInt<uint32_t>(mOffset) + aInsertionPointOffset;
1081 if (NS_WARN_IF(!absOffset.isValid())) {
1082 mOffset = UINT32_MAX;
1083 return false;
1085 mOffset = absOffset.value();
1086 return true;
1088 } mInput;
1090 struct Reply final {
1091 void* mContentsRoot;
1092 uint32_t mOffset;
1093 // mTentativeCaretOffset is used by only eQueryCharacterAtPoint.
1094 // This is the offset where caret would be if user clicked at the mRefPoint.
1095 uint32_t mTentativeCaretOffset;
1096 nsString mString;
1097 // mRect is used by eQueryTextRect, eQueryCaretRect, eQueryCharacterAtPoint
1098 // and eQueryEditorRect. The coordinates is system coordinates relative to
1099 // the top level widget of mFocusedWidget. E.g., if a <xul:panel> which
1100 // is owned by a window has focused editor, the offset of mRect is relative
1101 // to the owner window, not the <xul:panel>.
1102 mozilla::LayoutDeviceIntRect mRect;
1103 // The return widget has the caret. This is set at all query events.
1104 nsIWidget* mFocusedWidget;
1105 // mozilla::WritingMode value at the end (focus) of the selection
1106 mozilla::WritingMode mWritingMode;
1107 // Used by eQuerySelectionAsTransferable
1108 nsCOMPtr<nsITransferable> mTransferable;
1109 // Used by eQueryTextContent with font ranges requested
1110 AutoTArray<mozilla::FontRange, 1> mFontRanges;
1111 // Used by eQueryTextRectArray
1112 nsTArray<mozilla::LayoutDeviceIntRect> mRectArray;
1113 // true if selection is reversed (end < start)
1114 bool mReversed;
1115 // true if the selection exists
1116 bool mHasSelection;
1117 // true if DOM element under mouse belongs to widget
1118 bool mWidgetIsHit;
1120 Reply()
1121 : mContentsRoot(nullptr),
1122 mOffset(NOT_FOUND),
1123 mTentativeCaretOffset(NOT_FOUND),
1124 mFocusedWidget(nullptr),
1125 mReversed(false),
1126 mHasSelection(false),
1127 mWidgetIsHit(false) {}
1128 } mReply;
1130 enum { NOT_FOUND = UINT32_MAX };
1132 // values of mComputedScrollAction
1133 enum { SCROLL_ACTION_NONE, SCROLL_ACTION_LINE, SCROLL_ACTION_PAGE };
1136 /******************************************************************************
1137 * mozilla::WidgetSelectionEvent
1138 ******************************************************************************/
1140 class WidgetSelectionEvent : public WidgetGUIEvent {
1141 private:
1142 friend class mozilla::dom::PBrowserParent;
1143 friend class mozilla::dom::PBrowserChild;
1145 WidgetSelectionEvent()
1146 : mOffset(0),
1147 mLength(0),
1148 mReversed(false),
1149 mExpandToClusterBoundary(true),
1150 mSucceeded(false),
1151 mUseNativeLineBreak(true),
1152 mReason(nsISelectionListener::NO_REASON) {}
1154 public:
1155 virtual WidgetSelectionEvent* AsSelectionEvent() override { return this; }
1157 WidgetSelectionEvent(bool aIsTrusted, EventMessage aMessage,
1158 nsIWidget* aWidget)
1159 : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, eSelectionEventClass),
1160 mOffset(0),
1161 mLength(0),
1162 mReversed(false),
1163 mExpandToClusterBoundary(true),
1164 mSucceeded(false),
1165 mUseNativeLineBreak(true),
1166 mReason(nsISelectionListener::NO_REASON) {}
1168 virtual WidgetEvent* Duplicate() const override {
1169 // This event isn't an internal event of any DOM event.
1170 NS_ASSERTION(!IsAllowedToDispatchDOMEvent(),
1171 "WidgetSelectionEvent needs to support Duplicate()");
1172 MOZ_CRASH("WidgetSelectionEvent doesn't support Duplicate()");
1173 return nullptr;
1176 // Start offset of selection
1177 uint32_t mOffset;
1178 // Length of selection
1179 uint32_t mLength;
1180 // Selection "anchor" should be in front
1181 bool mReversed;
1182 // Cluster-based or character-based
1183 bool mExpandToClusterBoundary;
1184 // true if setting selection succeeded.
1185 bool mSucceeded;
1186 // true if native line breaks are used for mOffset and mLength
1187 bool mUseNativeLineBreak;
1188 // Fennec provides eSetSelection reason codes for downstream
1189 // use in AccessibleCaret visibility logic.
1190 int16_t mReason;
1193 /******************************************************************************
1194 * mozilla::InternalEditorInputEvent
1195 ******************************************************************************/
1197 class InternalEditorInputEvent : public InternalUIEvent {
1198 private:
1199 InternalEditorInputEvent()
1200 : mData(VoidString()),
1201 mInputType(EditorInputType::eUnknown),
1202 mIsComposing(false) {}
1204 public:
1205 virtual InternalEditorInputEvent* AsEditorInputEvent() override {
1206 return this;
1209 InternalEditorInputEvent(bool aIsTrusted, EventMessage aMessage,
1210 nsIWidget* aWidget = nullptr)
1211 : InternalUIEvent(aIsTrusted, aMessage, aWidget, eEditorInputEventClass),
1212 mData(VoidString()),
1213 mInputType(EditorInputType::eUnknown) {}
1215 virtual WidgetEvent* Duplicate() const override {
1216 MOZ_ASSERT(mClass == eEditorInputEventClass,
1217 "Duplicate() must be overridden by sub class");
1218 // Not copying widget, it is a weak reference.
1219 InternalEditorInputEvent* result =
1220 new InternalEditorInputEvent(false, mMessage, nullptr);
1221 result->AssignEditorInputEventData(*this, true);
1222 result->mFlags = mFlags;
1223 return result;
1226 nsString mData;
1227 RefPtr<dom::DataTransfer> mDataTransfer;
1229 EditorInputType mInputType;
1231 bool mIsComposing;
1233 void AssignEditorInputEventData(const InternalEditorInputEvent& aEvent,
1234 bool aCopyTargets) {
1235 AssignUIEventData(aEvent, aCopyTargets);
1237 mData = aEvent.mData;
1238 mDataTransfer = aEvent.mDataTransfer;
1239 mInputType = aEvent.mInputType;
1240 mIsComposing = aEvent.mIsComposing;
1243 void GetDOMInputTypeName(nsAString& aInputTypeName) {
1244 GetDOMInputTypeName(mInputType, aInputTypeName);
1246 static void GetDOMInputTypeName(EditorInputType aInputType,
1247 nsAString& aInputTypeName);
1248 static EditorInputType GetEditorInputType(const nsAString& aInputType);
1250 static void Shutdown();
1252 private:
1253 static const char16_t* const kInputTypeNames[];
1254 typedef nsDataHashtable<nsStringHashKey, EditorInputType> InputTypeHashtable;
1255 static InputTypeHashtable* sInputTypeHashtable;
1258 } // namespace mozilla
1260 #endif // mozilla_TextEvents_h__