Bug 1540028 [wpt PR 16099] - Catch more exceptions in Document-createElement-namespac...
[gecko.git] / widget / TextEvents.h
bloba47e6dae30ff70bbdeb05f346e4c285b87436b2d
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 "nsISelectionController.h"
23 #include "nsISelectionListener.h"
24 #include "nsITransferable.h"
25 #include "nsRect.h"
26 #include "nsString.h"
27 #include "nsTArray.h"
29 class nsStringHashKey;
30 template <class, class>
31 class nsDataHashtable;
33 /******************************************************************************
34 * virtual keycode values
35 ******************************************************************************/
37 enum {
38 #define NS_DEFINE_VK(aDOMKeyName, aDOMKeyCode) NS_##aDOMKeyName = aDOMKeyCode,
39 #include "mozilla/VirtualKeyCodeList.h"
40 #undef NS_DEFINE_VK
41 NS_VK_UNKNOWN = 0xFF
44 namespace mozilla {
46 enum : uint32_t {
47 eKeyLocationStandard = dom::KeyboardEvent_Binding::DOM_KEY_LOCATION_STANDARD,
48 eKeyLocationLeft = dom::KeyboardEvent_Binding::DOM_KEY_LOCATION_LEFT,
49 eKeyLocationRight = dom::KeyboardEvent_Binding::DOM_KEY_LOCATION_RIGHT,
50 eKeyLocationNumpad = dom::KeyboardEvent_Binding::DOM_KEY_LOCATION_NUMPAD
53 const nsCString GetDOMKeyCodeName(uint32_t aKeyCode);
55 namespace dom {
56 class PBrowserParent;
57 class PBrowserChild;
58 } // namespace dom
59 namespace plugins {
60 class PPluginInstanceChild;
61 } // namespace plugins
63 enum class AccessKeyType {
64 // Handle access key for chrome.
65 eChrome,
66 // Handle access key for content.
67 eContent,
68 // Don't handle access key.
69 eNone
72 /******************************************************************************
73 * mozilla::AlternativeCharCode
75 * This stores alternative charCode values of a key event with some modifiers.
76 * The stored values proper for testing shortcut key or access key.
77 ******************************************************************************/
79 struct AlternativeCharCode {
80 AlternativeCharCode() : mUnshiftedCharCode(0), mShiftedCharCode(0) {}
81 AlternativeCharCode(uint32_t aUnshiftedCharCode, uint32_t aShiftedCharCode)
82 : mUnshiftedCharCode(aUnshiftedCharCode),
83 mShiftedCharCode(aShiftedCharCode) {}
84 uint32_t mUnshiftedCharCode;
85 uint32_t mShiftedCharCode;
88 /******************************************************************************
89 * mozilla::ShortcutKeyCandidate
91 * This stores a candidate of shortcut key combination.
92 ******************************************************************************/
94 struct ShortcutKeyCandidate {
95 ShortcutKeyCandidate() : mCharCode(0), mIgnoreShift(0) {}
96 ShortcutKeyCandidate(uint32_t aCharCode, bool aIgnoreShift)
97 : mCharCode(aCharCode), mIgnoreShift(aIgnoreShift) {}
98 // The mCharCode value which must match keyboard shortcut definition.
99 uint32_t mCharCode;
100 // true if Shift state can be ignored. Otherwise, Shift key state must
101 // match keyboard shortcut definition.
102 bool mIgnoreShift;
105 /******************************************************************************
106 * mozilla::IgnoreModifierState
108 * This stores flags for modifiers that should be ignored when matching
109 * XBL handlers.
110 ******************************************************************************/
112 struct IgnoreModifierState {
113 // When mShift is true, Shift key state will be ignored.
114 bool mShift;
115 // When mOS is true, OS key state will be ignored.
116 bool mOS;
118 IgnoreModifierState() : mShift(false), mOS(false) {}
121 /******************************************************************************
122 * mozilla::WidgetKeyboardEvent
123 ******************************************************************************/
125 class WidgetKeyboardEvent : public WidgetInputEvent {
126 private:
127 friend class dom::PBrowserParent;
128 friend class dom::PBrowserChild;
129 friend struct IPC::ParamTraits<WidgetKeyboardEvent>;
131 protected:
132 WidgetKeyboardEvent()
133 : mNativeKeyEvent(nullptr),
134 mKeyCode(0),
135 mCharCode(0),
136 mPseudoCharCode(0),
137 mLocation(eKeyLocationStandard),
138 mUniqueId(0)
139 #ifdef XP_MACOSX
141 mNativeModifierFlags(0),
142 mNativeKeyCode(0)
143 #endif // #ifdef XP_MACOSX
145 mKeyNameIndex(KEY_NAME_INDEX_Unidentified),
146 mCodeNameIndex(CODE_NAME_INDEX_UNKNOWN),
147 mIsRepeat(false),
148 mIsComposing(false),
149 mIsSynthesizedByTIP(false),
150 mMaybeSkippableInRemoteProcess(true),
151 mUseLegacyKeyCodeAndCharCodeValues(false),
152 mEditCommandsForSingleLineEditorInitialized(false),
153 mEditCommandsForMultiLineEditorInitialized(false),
154 mEditCommandsForRichTextEditorInitialized(false) {
157 public:
158 virtual WidgetKeyboardEvent* AsKeyboardEvent() override { return this; }
160 WidgetKeyboardEvent(bool aIsTrusted, EventMessage aMessage,
161 nsIWidget* aWidget,
162 EventClassID aEventClassID = eKeyboardEventClass)
163 : WidgetInputEvent(aIsTrusted, aMessage, aWidget, aEventClassID),
164 mNativeKeyEvent(nullptr),
165 mKeyCode(0),
166 mCharCode(0),
167 mPseudoCharCode(0),
168 mLocation(eKeyLocationStandard),
169 mUniqueId(0)
170 #ifdef XP_MACOSX
172 mNativeModifierFlags(0),
173 mNativeKeyCode(0)
174 #endif // #ifdef XP_MACOSX
176 mKeyNameIndex(KEY_NAME_INDEX_Unidentified),
177 mCodeNameIndex(CODE_NAME_INDEX_UNKNOWN),
178 mIsRepeat(false),
179 mIsComposing(false),
180 mIsSynthesizedByTIP(false),
181 mMaybeSkippableInRemoteProcess(true),
182 mUseLegacyKeyCodeAndCharCodeValues(false),
183 mEditCommandsForSingleLineEditorInitialized(false),
184 mEditCommandsForMultiLineEditorInitialized(false),
185 mEditCommandsForRichTextEditorInitialized(false) {
186 // If this is a keyboard event on a plugin, it shouldn't fired on content.
187 if (IsKeyEventOnPlugin()) {
188 mFlags.mOnlySystemGroupDispatchInContent = true;
189 StopCrossProcessForwarding();
193 static bool IsKeyDownOrKeyDownOnPlugin(EventMessage aMessage) {
194 return aMessage == eKeyDown || aMessage == eKeyDownOnPlugin;
196 bool IsKeyDownOrKeyDownOnPlugin() const {
197 return IsKeyDownOrKeyDownOnPlugin(mMessage);
199 static bool IsKeyUpOrKeyUpOnPlugin(EventMessage aMessage) {
200 return aMessage == eKeyUp || aMessage == eKeyUpOnPlugin;
202 bool IsKeyUpOrKeyUpOnPlugin() const {
203 return IsKeyUpOrKeyUpOnPlugin(mMessage);
205 static bool IsKeyEventOnPlugin(EventMessage aMessage) {
206 return aMessage == eKeyDownOnPlugin || aMessage == eKeyUpOnPlugin;
208 bool IsKeyEventOnPlugin() const { return IsKeyEventOnPlugin(mMessage); }
210 // IsInputtingText() and IsInputtingLineBreak() are used to check if
211 // it should cause eKeyPress events even on web content.
212 // UI Events defines that "keypress" event should be fired "if and only if
213 // that key normally produces a character value".
214 // <https://www.w3.org/TR/uievents/#event-type-keypress>
215 // Additionally, for backward compatiblity with all existing browsers,
216 // there is a spec issue for Enter key press.
217 // <https://github.com/w3c/uievents/issues/183>
218 bool IsInputtingText() const {
219 // NOTE: On some keyboard layout, some characters are inputted with Control
220 // key or Alt key, but at that time, widget clears the modifier flag
221 // from eKeyPress event because our TextEditor won't handle eKeyPress
222 // events as inputting text (bug 1346832).
223 // NOTE: There are some complicated issues of our traditional behavior.
224 // -- On Windows, KeyboardLayout::WillDispatchKeyboardEvent() clears
225 // MODIFIER_ALT and MODIFIER_CONTROL of eKeyPress event if it
226 // should be treated as inputting a character because AltGr is
227 // represented with both Alt key and Ctrl key are pressed, and
228 // some keyboard layouts may produces a character with Ctrl key.
229 // -- On Linux, KeymapWrapper doesn't have this hack since perhaps,
230 // we don't have any bug reports that user cannot input proper
231 // character with Alt and/or Ctrl key.
232 // -- On macOS, IMEInputHandler::WillDispatchKeyboardEvent() clears
233 // MODIFIER_ALT and MDOFIEIR_CONTROL of eKeyPress event only when
234 // TextInputHandler::InsertText() has been called for the event.
235 // I.e., they are cleared only when an editor has focus (even if IME
236 // is disabled in password field or by |ime-mode: disabled;|) because
237 // TextInputHandler::InsertText() is called while
238 // TextInputHandler::HandleKeyDownEvent() calls interpretKeyEvents:
239 // to notify text input processor of Cocoa (including IME). In other
240 // words, when we need to disable IME completey when no editor has
241 // focus, we cannot call interpretKeyEvents:. So,
242 // TextInputHandler::InsertText() won't be called when no editor has
243 // focus so that neither MODIFIER_ALT nor MODIFIER_CONTROL is
244 // cleared. So, fortunately, altKey and ctrlKey values of "keypress"
245 // events are same as the other browsers only when no editor has
246 // focus.
247 // NOTE: As mentioned above, for compatibility with the other browsers on
248 // macOS, we should keep MODIFIER_ALT and MODIFIER_CONTROL flags of
249 // eKeyPress events when no editor has focus. However, Alt key,
250 // labeled "option" on keyboard for Mac, is AltGraph key on the other
251 // platforms. So, even if MODIFIER_ALT is set, we need to dispatch
252 // eKeyPress event even on web content unless mCharCode is 0.
253 // Therefore, we need to ignore MODIFIER_ALT flag here only on macOS.
254 return mMessage == eKeyPress && mCharCode &&
255 !(mModifiers & (
256 #ifndef XP_MACOSX
257 // So, ignore MODIFIER_ALT only on macOS since
258 // option key is used as AltGraph key on macOS.
259 MODIFIER_ALT |
260 #endif // #ifndef XP_MAXOSX
261 MODIFIER_CONTROL | MODIFIER_META | MODIFIER_OS));
264 bool IsInputtingLineBreak() const {
265 return mMessage == eKeyPress && mKeyNameIndex == KEY_NAME_INDEX_Enter &&
266 !(mModifiers &
267 (MODIFIER_ALT | MODIFIER_CONTROL | MODIFIER_META | MODIFIER_OS));
271 * ShouldKeyPressEventBeFiredOnContent() should be called only when the
272 * instance is eKeyPress event. This returns true when the eKeyPress
273 * event should be fired even on content in the default event group.
275 bool ShouldKeyPressEventBeFiredOnContent() const {
276 MOZ_DIAGNOSTIC_ASSERT(mMessage == eKeyPress);
277 if (IsInputtingText() || IsInputtingLineBreak()) {
278 return true;
280 // Ctrl + Enter won't cause actual input in our editor.
281 // However, the other browsers fire keypress event in any platforms.
282 // So, for compatibility with them, we should fire keypress event for
283 // Ctrl + Enter too.
284 return mMessage == eKeyPress && mKeyNameIndex == KEY_NAME_INDEX_Enter &&
285 !(mModifiers &
286 (MODIFIER_ALT | MODIFIER_META | MODIFIER_OS | MODIFIER_SHIFT));
289 virtual WidgetEvent* Duplicate() const override {
290 MOZ_ASSERT(mClass == eKeyboardEventClass,
291 "Duplicate() must be overridden by sub class");
292 // Not copying widget, it is a weak reference.
293 WidgetKeyboardEvent* result =
294 new WidgetKeyboardEvent(false, mMessage, nullptr);
295 result->AssignKeyEventData(*this, true);
296 result->mEditCommandsForSingleLineEditor = mEditCommandsForSingleLineEditor;
297 result->mEditCommandsForMultiLineEditor = mEditCommandsForMultiLineEditor;
298 result->mEditCommandsForRichTextEditor = mEditCommandsForRichTextEditor;
299 result->mFlags = mFlags;
300 return result;
303 bool CanUserGestureActivateTarget() const {
304 // Printable keys, 'carriage return' and 'space' are supported user gestures
305 // for activating the document. However, if supported key is being pressed
306 // combining with other operation keys, such like alt, control ..etc., we
307 // won't activate the target for them because at that time user might
308 // interact with browser or window manager which doesn't necessarily
309 // demonstrate user's intent to play media.
310 const bool isCombiningWithOperationKeys = (IsControl() && !IsAltGraph()) ||
311 (IsAlt() && !IsAltGraph()) ||
312 IsMeta() || IsOS();
313 const bool isEnterOrSpaceKey =
314 mKeyNameIndex == KEY_NAME_INDEX_Enter || mKeyCode == NS_VK_SPACE;
315 return (PseudoCharCode() || isEnterOrSpaceKey) &&
316 !isCombiningWithOperationKeys;
320 * CanTreatAsUserInput() returns true if the key is pressed for perhaps
321 * doing something on the web app or our UI. This means that when this
322 * returns false, e.g., when user presses a modifier key, user is probably
323 * displeased by opening popup, entering fullscreen mode, etc. Therefore,
324 * only when this returns true, such reactions should be allowed.
326 bool CanTreatAsUserInput() const {
327 if (!IsTrusted()) {
328 return false;
330 switch (mKeyNameIndex) {
331 case KEY_NAME_INDEX_Escape:
332 // modifier keys:
333 case KEY_NAME_INDEX_Alt:
334 case KEY_NAME_INDEX_AltGraph:
335 case KEY_NAME_INDEX_CapsLock:
336 case KEY_NAME_INDEX_Control:
337 case KEY_NAME_INDEX_Fn:
338 case KEY_NAME_INDEX_FnLock:
339 case KEY_NAME_INDEX_Meta:
340 case KEY_NAME_INDEX_NumLock:
341 case KEY_NAME_INDEX_ScrollLock:
342 case KEY_NAME_INDEX_Shift:
343 case KEY_NAME_INDEX_Symbol:
344 case KEY_NAME_INDEX_SymbolLock:
345 // legacy modifier keys:
346 case KEY_NAME_INDEX_Hyper:
347 case KEY_NAME_INDEX_Super:
348 // obsolete modifier key:
349 case KEY_NAME_INDEX_OS:
350 return false;
351 default:
352 return true;
357 * ShouldInteractionTimeRecorded() returns true if the handling time of
358 * the event should be recorded with the telemetry.
360 bool ShouldInteractionTimeRecorded() const {
361 // Let's record only when we can treat the instance is a user input.
362 return CanTreatAsUserInput();
365 // OS translated Unicode chars which are used for accesskey and accelkey
366 // handling. The handlers will try from first character to last character.
367 nsTArray<AlternativeCharCode> mAlternativeCharCodes;
368 // DOM KeyboardEvent.key only when mKeyNameIndex is KEY_NAME_INDEX_USE_STRING.
369 nsString mKeyValue;
370 // DOM KeyboardEvent.code only when mCodeNameIndex is
371 // CODE_NAME_INDEX_USE_STRING.
372 nsString mCodeValue;
374 #ifdef XP_MACOSX
375 // Values given by a native NSEvent, for use with Cocoa NPAPI plugins.
376 nsString mNativeCharacters;
377 nsString mNativeCharactersIgnoringModifiers;
378 // If this is non-empty, create a text event for plugins instead of a
379 // keyboard event.
380 nsString mPluginTextEventString;
381 #endif // #ifdef XP_MACOSX
383 // OS-specific native event can optionally be preserved
384 void* mNativeKeyEvent;
385 // A DOM keyCode value or 0. If a keypress event whose mCharCode is 0, this
386 // should be 0.
387 uint32_t mKeyCode;
388 // If the instance is a keypress event of a printable key, this is a UTF-16
389 // value of the key. Otherwise, 0. This value must not be a control
390 // character when some modifiers are active. Then, this value should be an
391 // unmodified value except Shift and AltGr.
392 uint32_t mCharCode;
393 // mPseudoCharCode is valid only when mMessage is an eKeyDown event.
394 // This stores mCharCode value of keypress event which is fired with same
395 // key value and same modifier state.
396 uint32_t mPseudoCharCode;
397 // One of eKeyLocation*
398 uint32_t mLocation;
399 // Unique id associated with a keydown / keypress event. It's ok if this wraps
400 // over long periods.
401 uint32_t mUniqueId;
403 #ifdef XP_MACOSX
404 // Values given by a native NSEvent, for use with Cocoa NPAPI plugins.
405 uint32_t mNativeModifierFlags;
406 uint16_t mNativeKeyCode;
407 #endif // #ifdef XP_MACOSX
409 // DOM KeyboardEvent.key
410 KeyNameIndex mKeyNameIndex;
411 // DOM KeyboardEvent.code
412 CodeNameIndex mCodeNameIndex;
414 // Indicates whether the event is generated by auto repeat or not.
415 // if this is keyup event, always false.
416 bool mIsRepeat;
417 // Indicates whether the event is generated during IME (or deadkey)
418 // composition. This is initialized by EventStateManager. So, key event
419 // dispatchers don't need to initialize this.
420 bool mIsComposing;
421 // Indicates whether the event is synthesized from Text Input Processor
422 // or an actual event from nsAppShell.
423 bool mIsSynthesizedByTIP;
424 // Indicates whether the event is skippable in remote process.
425 // Don't refer this member directly when you need to check this.
426 // Use CanSkipInRemoteProcess() instead.
427 bool mMaybeSkippableInRemoteProcess;
428 // Indicates whether the event should return legacy keyCode value and
429 // charCode value to web apps (one of them is always 0) or not, when it's
430 // an eKeyPress event.
431 bool mUseLegacyKeyCodeAndCharCodeValues;
433 bool CanSkipInRemoteProcess() const {
434 // If this is a repeat event (i.e., generated by auto-repeat feature of
435 // the platform), remove process may skip to handle it because of
436 // performances reasons.. However, if it's caused by odd keyboard utils,
437 // we should not ignore any key events even marked as repeated since
438 // generated key sequence may be important to input proper text. E.g.,
439 // "SinhalaTamil IME" on Windows emulates dead key like input with
440 // generating WM_KEYDOWN for VK_PACKET (inputting any Unicode characters
441 // without keyboard layout information) and VK_BACK (Backspace) to remove
442 // previous character(s) and those messages may be marked as "repeat" by
443 // their bug.
444 return mIsRepeat && mMaybeSkippableInRemoteProcess;
448 * Retrieves all edit commands from mWidget. This shouldn't be called when
449 * the instance is an untrusted event, doesn't have widget or in non-chrome
450 * process.
452 void InitAllEditCommands();
455 * Retrieves edit commands from mWidget only for aType. This shouldn't be
456 * called when the instance is an untrusted event or doesn't have widget.
458 void InitEditCommandsFor(nsIWidget::NativeKeyBindingsType aType);
461 * PreventNativeKeyBindings() makes the instance to not cause any edit
462 * actions even if it matches with a native key binding.
464 void PreventNativeKeyBindings() {
465 mEditCommandsForSingleLineEditor.Clear();
466 mEditCommandsForMultiLineEditor.Clear();
467 mEditCommandsForRichTextEditor.Clear();
468 mEditCommandsForSingleLineEditorInitialized = true;
469 mEditCommandsForMultiLineEditorInitialized = true;
470 mEditCommandsForRichTextEditorInitialized = true;
474 * EditCommandsConstRef() returns reference to edit commands for aType.
476 const nsTArray<CommandInt>& EditCommandsConstRef(
477 nsIWidget::NativeKeyBindingsType aType) const {
478 return const_cast<WidgetKeyboardEvent*>(this)->EditCommandsRef(aType);
482 * IsEditCommandsInitialized() returns true if edit commands for aType
483 * was already initialized. Otherwise, false.
485 bool IsEditCommandsInitialized(nsIWidget::NativeKeyBindingsType aType) const {
486 return const_cast<WidgetKeyboardEvent*>(this)->IsEditCommandsInitializedRef(
487 aType);
490 #ifdef DEBUG
492 * AreAllEditCommandsInitialized() returns true if edit commands for all
493 * types were already initialized. Otherwise, false.
495 bool AreAllEditCommandsInitialized() const {
496 return mEditCommandsForSingleLineEditorInitialized &&
497 mEditCommandsForMultiLineEditorInitialized &&
498 mEditCommandsForRichTextEditorInitialized;
500 #endif // #ifdef DEBUG
503 * Execute edit commands for aType.
505 * @return true if the caller should do nothing anymore.
506 * false, otherwise.
508 typedef void (*DoCommandCallback)(Command, void*);
509 bool ExecuteEditCommands(nsIWidget::NativeKeyBindingsType aType,
510 DoCommandCallback aCallback, void* aCallbackData);
512 // If the key should cause keypress events, this returns true.
513 // Otherwise, false.
514 bool ShouldCauseKeypressEvents() const;
516 // mCharCode value of non-eKeyPress events is always 0. However, if
517 // non-eKeyPress event has one or more alternative char code values,
518 // its first item should be the mCharCode value of following eKeyPress event.
519 // PseudoCharCode() returns mCharCode value for eKeyPress event,
520 // the first alternative char code value of non-eKeyPress event or 0.
521 uint32_t PseudoCharCode() const {
522 return mMessage == eKeyPress ? mCharCode : mPseudoCharCode;
524 void SetCharCode(uint32_t aCharCode) {
525 if (mMessage == eKeyPress) {
526 mCharCode = aCharCode;
527 } else {
528 mPseudoCharCode = aCharCode;
532 void GetDOMKeyName(nsAString& aKeyName) {
533 if (mKeyNameIndex == KEY_NAME_INDEX_USE_STRING) {
534 aKeyName = mKeyValue;
535 return;
537 GetDOMKeyName(mKeyNameIndex, aKeyName);
539 void GetDOMCodeName(nsAString& aCodeName) {
540 if (mCodeNameIndex == CODE_NAME_INDEX_USE_STRING) {
541 aCodeName = mCodeValue;
542 return;
544 GetDOMCodeName(mCodeNameIndex, aCodeName);
548 * GetFallbackKeyCodeOfPunctuationKey() returns a DOM keyCode value for
549 * aCodeNameIndex. This is keyCode value of the key when active keyboard
550 * layout is ANSI (US), JIS or ABNT keyboard layout (the latter 2 layouts
551 * are used only when ANSI doesn't have the key). The result is useful
552 * if the key doesn't produce ASCII character with active keyboard layout
553 * nor with alternative ASCII capable keyboard layout.
555 static uint32_t GetFallbackKeyCodeOfPunctuationKey(
556 CodeNameIndex aCodeNameIndex);
558 bool IsModifierKeyEvent() const {
559 return GetModifierForKeyName(mKeyNameIndex) != MODIFIER_NONE;
563 * Get the candidates for shortcut key.
565 * @param aCandidates [out] the candidate shortcut key combination list.
566 * the first item is most preferred.
568 void GetShortcutKeyCandidates(ShortcutKeyCandidateArray& aCandidates) const;
571 * Get the candidates for access key.
573 * @param aCandidates [out] the candidate access key list.
574 * the first item is most preferred.
576 void GetAccessKeyCandidates(nsTArray<uint32_t>& aCandidates) const;
579 * Check whether the modifiers match with chrome access key or
580 * content access key.
582 bool ModifiersMatchWithAccessKey(AccessKeyType aType) const;
585 * Return active modifiers which may match with access key.
586 * For example, even if Alt is access key modifier, then, when Control,
587 * CapseLock and NumLock are active, this returns only MODIFIER_CONTROL.
589 Modifiers ModifiersForAccessKeyMatching() const;
592 * Return access key modifiers.
594 static Modifiers AccessKeyModifiers(AccessKeyType aType);
596 static void Shutdown();
599 * ComputeLocationFromCodeValue() returns one of .mLocation value
600 * (eKeyLocation*) which is the most preferred value for the specified code
601 * value.
603 static uint32_t ComputeLocationFromCodeValue(CodeNameIndex aCodeNameIndex);
606 * ComputeKeyCodeFromKeyNameIndex() return a .mKeyCode value which can be
607 * mapped from the specified key value. Note that this returns 0 if the
608 * key name index is KEY_NAME_INDEX_Unidentified or KEY_NAME_INDEX_USE_STRING.
609 * This means that this method is useful only for non-printable keys.
611 static uint32_t ComputeKeyCodeFromKeyNameIndex(KeyNameIndex aKeyNameIndex);
614 * ComputeCodeNameIndexFromKeyNameIndex() returns a code name index which
615 * is typically mapped to given key name index on the platform.
616 * Note that this returns CODE_NAME_INDEX_UNKNOWN if the key name index is
617 * KEY_NAME_INDEX_Unidentified or KEY_NAME_INDEX_USE_STRING.
618 * This means that this method is useful only for non-printable keys.
620 * @param aKeyNameIndex A non-printable key name index.
621 * @param aLocation Should be one of location value. This is
622 * important when aKeyNameIndex may exist in
623 * both Numpad or Standard, or in both Left or
624 * Right. If this is nothing, this method
625 * returns Left or Standard position's code
626 * value.
628 static CodeNameIndex ComputeCodeNameIndexFromKeyNameIndex(
629 KeyNameIndex aKeyNameIndex, const Maybe<uint32_t>& aLocation);
632 * GetModifierForKeyName() returns a value of Modifier which is activated
633 * by the aKeyNameIndex.
635 static Modifier GetModifierForKeyName(KeyNameIndex aKeyNameIndex);
638 * IsLeftOrRightModiferKeyNameIndex() returns true if aKeyNameIndex is a
639 * modifier key which may be in Left and Right location.
641 static bool IsLeftOrRightModiferKeyNameIndex(KeyNameIndex aKeyNameIndex) {
642 switch (aKeyNameIndex) {
643 case KEY_NAME_INDEX_Alt:
644 case KEY_NAME_INDEX_Control:
645 case KEY_NAME_INDEX_Meta:
646 case KEY_NAME_INDEX_OS:
647 case KEY_NAME_INDEX_Shift:
648 return true;
649 default:
650 return false;
655 * IsLockableModifier() returns true if aKeyNameIndex is a lockable modifier
656 * key such as CapsLock and NumLock.
658 static bool IsLockableModifier(KeyNameIndex aKeyNameIndex);
660 static void GetDOMKeyName(KeyNameIndex aKeyNameIndex, nsAString& aKeyName);
661 static void GetDOMCodeName(CodeNameIndex aCodeNameIndex,
662 nsAString& aCodeName);
664 static KeyNameIndex GetKeyNameIndex(const nsAString& aKeyValue);
665 static CodeNameIndex GetCodeNameIndex(const nsAString& aCodeValue);
667 static const char* GetCommandStr(Command aCommand);
669 void AssignKeyEventData(const WidgetKeyboardEvent& aEvent,
670 bool aCopyTargets) {
671 AssignInputEventData(aEvent, aCopyTargets);
673 mKeyCode = aEvent.mKeyCode;
674 mCharCode = aEvent.mCharCode;
675 mPseudoCharCode = aEvent.mPseudoCharCode;
676 mLocation = aEvent.mLocation;
677 mAlternativeCharCodes = aEvent.mAlternativeCharCodes;
678 mIsRepeat = aEvent.mIsRepeat;
679 mIsComposing = aEvent.mIsComposing;
680 mKeyNameIndex = aEvent.mKeyNameIndex;
681 mCodeNameIndex = aEvent.mCodeNameIndex;
682 mKeyValue = aEvent.mKeyValue;
683 mCodeValue = aEvent.mCodeValue;
684 // Don't copy mNativeKeyEvent because it may be referred after its instance
685 // is destroyed.
686 mNativeKeyEvent = nullptr;
687 mUniqueId = aEvent.mUniqueId;
688 #ifdef XP_MACOSX
689 mNativeKeyCode = aEvent.mNativeKeyCode;
690 mNativeModifierFlags = aEvent.mNativeModifierFlags;
691 mNativeCharacters.Assign(aEvent.mNativeCharacters);
692 mNativeCharactersIgnoringModifiers.Assign(
693 aEvent.mNativeCharactersIgnoringModifiers);
694 mPluginTextEventString.Assign(aEvent.mPluginTextEventString);
695 #endif
696 mIsSynthesizedByTIP = aEvent.mIsSynthesizedByTIP;
697 mMaybeSkippableInRemoteProcess = aEvent.mMaybeSkippableInRemoteProcess;
698 mUseLegacyKeyCodeAndCharCodeValues =
699 aEvent.mUseLegacyKeyCodeAndCharCodeValues;
701 // Don't copy mEditCommandsFor*Editor because it may require a lot of
702 // memory space. For example, if the event is dispatched but grabbed by
703 // a JS variable, they are not necessary anymore.
705 mEditCommandsForSingleLineEditorInitialized =
706 aEvent.mEditCommandsForSingleLineEditorInitialized;
707 mEditCommandsForMultiLineEditorInitialized =
708 aEvent.mEditCommandsForMultiLineEditorInitialized;
709 mEditCommandsForRichTextEditorInitialized =
710 aEvent.mEditCommandsForRichTextEditorInitialized;
713 void AssignCommands(const WidgetKeyboardEvent& aEvent) {
714 mEditCommandsForSingleLineEditorInitialized =
715 aEvent.mEditCommandsForSingleLineEditorInitialized;
716 if (mEditCommandsForSingleLineEditorInitialized) {
717 mEditCommandsForSingleLineEditor =
718 aEvent.mEditCommandsForSingleLineEditor;
719 } else {
720 mEditCommandsForSingleLineEditor.Clear();
722 mEditCommandsForMultiLineEditorInitialized =
723 aEvent.mEditCommandsForMultiLineEditorInitialized;
724 if (mEditCommandsForMultiLineEditorInitialized) {
725 mEditCommandsForMultiLineEditor = aEvent.mEditCommandsForMultiLineEditor;
726 } else {
727 mEditCommandsForMultiLineEditor.Clear();
729 mEditCommandsForRichTextEditorInitialized =
730 aEvent.mEditCommandsForRichTextEditorInitialized;
731 if (mEditCommandsForRichTextEditorInitialized) {
732 mEditCommandsForRichTextEditor = aEvent.mEditCommandsForRichTextEditor;
733 } else {
734 mEditCommandsForRichTextEditor.Clear();
738 private:
739 static const char16_t* const kKeyNames[];
740 static const char16_t* const kCodeNames[];
741 typedef nsDataHashtable<nsStringHashKey, KeyNameIndex> KeyNameIndexHashtable;
742 typedef nsDataHashtable<nsStringHashKey, CodeNameIndex>
743 CodeNameIndexHashtable;
744 static KeyNameIndexHashtable* sKeyNameIndexHashtable;
745 static CodeNameIndexHashtable* sCodeNameIndexHashtable;
747 // mEditCommandsFor*Editor store edit commands. This should be initialized
748 // with InitEditCommandsFor().
749 // XXX Ideally, this should be array of Command rather than CommandInt.
750 // However, ParamTraits isn't aware of enum array.
751 nsTArray<CommandInt> mEditCommandsForSingleLineEditor;
752 nsTArray<CommandInt> mEditCommandsForMultiLineEditor;
753 nsTArray<CommandInt> mEditCommandsForRichTextEditor;
755 nsTArray<CommandInt>& EditCommandsRef(
756 nsIWidget::NativeKeyBindingsType aType) {
757 switch (aType) {
758 case nsIWidget::NativeKeyBindingsForSingleLineEditor:
759 return mEditCommandsForSingleLineEditor;
760 case nsIWidget::NativeKeyBindingsForMultiLineEditor:
761 return mEditCommandsForMultiLineEditor;
762 case nsIWidget::NativeKeyBindingsForRichTextEditor:
763 return mEditCommandsForRichTextEditor;
764 default:
765 MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE(
766 "Invalid native key binding type");
770 // mEditCommandsFor*EditorInitialized are set to true when
771 // InitEditCommandsFor() initializes edit commands for the type.
772 bool mEditCommandsForSingleLineEditorInitialized;
773 bool mEditCommandsForMultiLineEditorInitialized;
774 bool mEditCommandsForRichTextEditorInitialized;
776 bool& IsEditCommandsInitializedRef(nsIWidget::NativeKeyBindingsType aType) {
777 switch (aType) {
778 case nsIWidget::NativeKeyBindingsForSingleLineEditor:
779 return mEditCommandsForSingleLineEditorInitialized;
780 case nsIWidget::NativeKeyBindingsForMultiLineEditor:
781 return mEditCommandsForMultiLineEditorInitialized;
782 case nsIWidget::NativeKeyBindingsForRichTextEditor:
783 return mEditCommandsForRichTextEditorInitialized;
784 default:
785 MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE(
786 "Invalid native key binding type");
790 static int32_t GenericAccessModifierKeyPref();
791 static int32_t ChromeAccessModifierMaskPref();
792 static int32_t ContentAccessModifierMaskPref();
795 /******************************************************************************
796 * mozilla::WidgetCompositionEvent
797 ******************************************************************************/
799 class WidgetCompositionEvent : public WidgetGUIEvent {
800 private:
801 friend class mozilla::dom::PBrowserParent;
802 friend class mozilla::dom::PBrowserChild;
804 WidgetCompositionEvent() : mOriginalMessage(eVoidEvent) {}
806 public:
807 virtual WidgetCompositionEvent* AsCompositionEvent() override { return this; }
809 WidgetCompositionEvent(bool aIsTrusted, EventMessage aMessage,
810 nsIWidget* aWidget)
811 : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, eCompositionEventClass),
812 mNativeIMEContext(aWidget),
813 mOriginalMessage(eVoidEvent) {}
815 virtual WidgetEvent* Duplicate() const override {
816 MOZ_ASSERT(mClass == eCompositionEventClass,
817 "Duplicate() must be overridden by sub class");
818 // Not copying widget, it is a weak reference.
819 WidgetCompositionEvent* result =
820 new WidgetCompositionEvent(false, mMessage, nullptr);
821 result->AssignCompositionEventData(*this, true);
822 result->mFlags = mFlags;
823 return result;
826 // The composition string or the commit string. If the instance is a
827 // compositionstart event, this is initialized with selected text by
828 // TextComposition automatically.
829 nsString mData;
831 RefPtr<TextRangeArray> mRanges;
833 // mNativeIMEContext stores the native IME context which causes the
834 // composition event.
835 widget::NativeIMEContext mNativeIMEContext;
837 // If the instance is a clone of another event, mOriginalMessage stores
838 // the another event's mMessage.
839 EventMessage mOriginalMessage;
841 void AssignCompositionEventData(const WidgetCompositionEvent& aEvent,
842 bool aCopyTargets) {
843 AssignGUIEventData(aEvent, aCopyTargets);
845 mData = aEvent.mData;
846 mOriginalMessage = aEvent.mOriginalMessage;
847 mRanges = aEvent.mRanges;
849 // Currently, we don't need to copy the other members because they are
850 // for internal use only (not available from JS).
853 bool IsComposing() const { return mRanges && mRanges->IsComposing(); }
855 uint32_t TargetClauseOffset() const {
856 return mRanges ? mRanges->TargetClauseOffset() : 0;
859 uint32_t TargetClauseLength() const {
860 uint32_t length = UINT32_MAX;
861 if (mRanges) {
862 length = mRanges->TargetClauseLength();
864 return length == UINT32_MAX ? mData.Length() : length;
867 uint32_t RangeCount() const { return mRanges ? mRanges->Length() : 0; }
869 bool CausesDOMTextEvent() const {
870 return mMessage == eCompositionChange || mMessage == eCompositionCommit ||
871 mMessage == eCompositionCommitAsIs;
874 bool CausesDOMCompositionEndEvent() const {
875 return mMessage == eCompositionEnd || mMessage == eCompositionCommit ||
876 mMessage == eCompositionCommitAsIs;
879 bool IsFollowedByCompositionEnd() const {
880 return IsFollowedByCompositionEnd(mOriginalMessage);
883 static bool IsFollowedByCompositionEnd(EventMessage aEventMessage) {
884 return aEventMessage == eCompositionCommit ||
885 aEventMessage == eCompositionCommitAsIs;
889 /******************************************************************************
890 * mozilla::WidgetQueryContentEvent
891 ******************************************************************************/
893 class WidgetQueryContentEvent : public WidgetGUIEvent {
894 private:
895 friend class dom::PBrowserParent;
896 friend class dom::PBrowserChild;
898 WidgetQueryContentEvent()
899 : mSucceeded(false),
900 mUseNativeLineBreak(true),
901 mWithFontRanges(false),
902 mNeedsToFlushLayout(true) {
903 MOZ_CRASH("WidgetQueryContentEvent is created without proper arguments");
906 public:
907 virtual WidgetQueryContentEvent* AsQueryContentEvent() override {
908 return this;
911 WidgetQueryContentEvent(bool aIsTrusted, EventMessage aMessage,
912 nsIWidget* aWidget)
913 : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, eQueryContentEventClass),
914 mSucceeded(false),
915 mUseNativeLineBreak(true),
916 mWithFontRanges(false),
917 mNeedsToFlushLayout(true) {}
919 WidgetQueryContentEvent(EventMessage aMessage,
920 const WidgetQueryContentEvent& aOtherEvent)
921 : WidgetGUIEvent(aOtherEvent.IsTrusted(), aMessage,
922 const_cast<nsIWidget*>(aOtherEvent.mWidget.get()),
923 eQueryContentEventClass),
924 mSucceeded(false),
925 mUseNativeLineBreak(aOtherEvent.mUseNativeLineBreak),
926 mWithFontRanges(false),
927 mNeedsToFlushLayout(aOtherEvent.mNeedsToFlushLayout) {}
929 virtual WidgetEvent* Duplicate() const override {
930 // This event isn't an internal event of any DOM event.
931 NS_ASSERTION(!IsAllowedToDispatchDOMEvent(),
932 "WidgetQueryContentEvent needs to support Duplicate()");
933 MOZ_CRASH("WidgetQueryContentEvent doesn't support Duplicate()");
936 struct Options final {
937 bool mUseNativeLineBreak;
938 bool mRelativeToInsertionPoint;
940 explicit Options()
941 : mUseNativeLineBreak(true), mRelativeToInsertionPoint(false) {}
943 explicit Options(const WidgetQueryContentEvent& aEvent)
944 : mUseNativeLineBreak(aEvent.mUseNativeLineBreak),
945 mRelativeToInsertionPoint(aEvent.mInput.mRelativeToInsertionPoint) {}
948 void Init(const Options& aOptions) {
949 mUseNativeLineBreak = aOptions.mUseNativeLineBreak;
950 mInput.mRelativeToInsertionPoint = aOptions.mRelativeToInsertionPoint;
951 MOZ_ASSERT(mInput.IsValidEventMessage(mMessage));
954 void InitForQueryTextContent(int64_t aOffset, uint32_t aLength,
955 const Options& aOptions = Options()) {
956 NS_ASSERTION(mMessage == eQueryTextContent, "wrong initializer is called");
957 mInput.mOffset = aOffset;
958 mInput.mLength = aLength;
959 Init(aOptions);
960 MOZ_ASSERT(mInput.IsValidOffset());
963 void InitForQueryCaretRect(int64_t aOffset,
964 const Options& aOptions = Options()) {
965 NS_ASSERTION(mMessage == eQueryCaretRect, "wrong initializer is called");
966 mInput.mOffset = aOffset;
967 Init(aOptions);
968 MOZ_ASSERT(mInput.IsValidOffset());
971 void InitForQueryTextRect(int64_t aOffset, uint32_t aLength,
972 const Options& aOptions = Options()) {
973 NS_ASSERTION(mMessage == eQueryTextRect, "wrong initializer is called");
974 mInput.mOffset = aOffset;
975 mInput.mLength = aLength;
976 Init(aOptions);
977 MOZ_ASSERT(mInput.IsValidOffset());
980 void InitForQuerySelectedText(SelectionType aSelectionType,
981 const Options& aOptions = Options()) {
982 MOZ_ASSERT(mMessage == eQuerySelectedText);
983 MOZ_ASSERT(aSelectionType != SelectionType::eNone);
984 mInput.mSelectionType = aSelectionType;
985 Init(aOptions);
988 void InitForQueryDOMWidgetHittest(
989 const mozilla::LayoutDeviceIntPoint& aPoint) {
990 NS_ASSERTION(mMessage == eQueryDOMWidgetHittest,
991 "wrong initializer is called");
992 mRefPoint = aPoint;
995 void InitForQueryTextRectArray(uint32_t aOffset, uint32_t aLength,
996 const Options& aOptions = Options()) {
997 NS_ASSERTION(mMessage == eQueryTextRectArray,
998 "wrong initializer is called");
999 mInput.mOffset = aOffset;
1000 mInput.mLength = aLength;
1001 Init(aOptions);
1004 bool NeedsToFlushLayout() const { return mNeedsToFlushLayout; }
1006 void RequestFontRanges() {
1007 NS_ASSERTION(mMessage == eQueryTextContent, "not querying text content");
1008 mWithFontRanges = true;
1011 uint32_t GetSelectionStart(void) const {
1012 NS_ASSERTION(mMessage == eQuerySelectedText, "not querying selection");
1013 return mReply.mOffset + (mReply.mReversed ? mReply.mString.Length() : 0);
1016 uint32_t GetSelectionEnd(void) const {
1017 NS_ASSERTION(mMessage == eQuerySelectedText, "not querying selection");
1018 return mReply.mOffset + (mReply.mReversed ? 0 : mReply.mString.Length());
1021 mozilla::WritingMode GetWritingMode(void) const {
1022 NS_ASSERTION(mMessage == eQuerySelectedText ||
1023 mMessage == eQueryCaretRect || mMessage == eQueryTextRect,
1024 "not querying selection or text rect");
1025 return mReply.mWritingMode;
1028 bool mSucceeded;
1029 bool mUseNativeLineBreak;
1030 bool mWithFontRanges;
1031 bool mNeedsToFlushLayout;
1032 struct Input final {
1033 uint32_t EndOffset() const {
1034 CheckedInt<uint32_t> endOffset = CheckedInt<uint32_t>(mOffset) + mLength;
1035 return NS_WARN_IF(!endOffset.isValid()) ? UINT32_MAX : endOffset.value();
1038 int64_t mOffset;
1039 uint32_t mLength;
1040 SelectionType mSelectionType;
1041 // If mOffset is true, mOffset is relative to the start offset of
1042 // composition if there is, otherwise, the start of the first selection
1043 // range.
1044 bool mRelativeToInsertionPoint;
1046 Input()
1047 : mOffset(0),
1048 mLength(0),
1049 mSelectionType(SelectionType::eNormal),
1050 mRelativeToInsertionPoint(false) {}
1052 bool IsValidOffset() const {
1053 return mRelativeToInsertionPoint || mOffset >= 0;
1055 bool IsValidEventMessage(EventMessage aEventMessage) const {
1056 if (!mRelativeToInsertionPoint) {
1057 return true;
1059 switch (aEventMessage) {
1060 case eQueryTextContent:
1061 case eQueryCaretRect:
1062 case eQueryTextRect:
1063 return true;
1064 default:
1065 return false;
1068 bool MakeOffsetAbsolute(uint32_t aInsertionPointOffset) {
1069 if (NS_WARN_IF(!mRelativeToInsertionPoint)) {
1070 return true;
1072 mRelativeToInsertionPoint = false;
1073 // If mOffset + aInsertionPointOffset becomes negative value,
1074 // we should assume the absolute offset is 0.
1075 if (mOffset < 0 && -mOffset > aInsertionPointOffset) {
1076 mOffset = 0;
1077 return true;
1079 // Otherwise, we don't allow too large offset.
1080 CheckedInt<uint32_t> absOffset =
1081 CheckedInt<uint32_t>(mOffset) + aInsertionPointOffset;
1082 if (NS_WARN_IF(!absOffset.isValid())) {
1083 mOffset = UINT32_MAX;
1084 return false;
1086 mOffset = absOffset.value();
1087 return true;
1089 } mInput;
1091 struct Reply final {
1092 void* mContentsRoot;
1093 uint32_t mOffset;
1094 // mTentativeCaretOffset is used by only eQueryCharacterAtPoint.
1095 // This is the offset where caret would be if user clicked at the mRefPoint.
1096 uint32_t mTentativeCaretOffset;
1097 nsString mString;
1098 // mRect is used by eQueryTextRect, eQueryCaretRect, eQueryCharacterAtPoint
1099 // and eQueryEditorRect. The coordinates is system coordinates relative to
1100 // the top level widget of mFocusedWidget. E.g., if a <xul:panel> which
1101 // is owned by a window has focused editor, the offset of mRect is relative
1102 // to the owner window, not the <xul:panel>.
1103 mozilla::LayoutDeviceIntRect mRect;
1104 // The return widget has the caret. This is set at all query events.
1105 nsIWidget* mFocusedWidget;
1106 // mozilla::WritingMode value at the end (focus) of the selection
1107 mozilla::WritingMode mWritingMode;
1108 // Used by eQuerySelectionAsTransferable
1109 nsCOMPtr<nsITransferable> mTransferable;
1110 // Used by eQueryTextContent with font ranges requested
1111 AutoTArray<mozilla::FontRange, 1> mFontRanges;
1112 // Used by eQueryTextRectArray
1113 nsTArray<mozilla::LayoutDeviceIntRect> mRectArray;
1114 // true if selection is reversed (end < start)
1115 bool mReversed;
1116 // true if the selection exists
1117 bool mHasSelection;
1118 // true if DOM element under mouse belongs to widget
1119 bool mWidgetIsHit;
1121 Reply()
1122 : mContentsRoot(nullptr),
1123 mOffset(NOT_FOUND),
1124 mTentativeCaretOffset(NOT_FOUND),
1125 mFocusedWidget(nullptr),
1126 mReversed(false),
1127 mHasSelection(false),
1128 mWidgetIsHit(false) {}
1129 } mReply;
1131 enum { NOT_FOUND = UINT32_MAX };
1133 // values of mComputedScrollAction
1134 enum { SCROLL_ACTION_NONE, SCROLL_ACTION_LINE, SCROLL_ACTION_PAGE };
1137 /******************************************************************************
1138 * mozilla::WidgetSelectionEvent
1139 ******************************************************************************/
1141 class WidgetSelectionEvent : public WidgetGUIEvent {
1142 private:
1143 friend class mozilla::dom::PBrowserParent;
1144 friend class mozilla::dom::PBrowserChild;
1146 WidgetSelectionEvent()
1147 : mOffset(0),
1148 mLength(0),
1149 mReversed(false),
1150 mExpandToClusterBoundary(true),
1151 mSucceeded(false),
1152 mUseNativeLineBreak(true),
1153 mReason(nsISelectionListener::NO_REASON) {}
1155 public:
1156 virtual WidgetSelectionEvent* AsSelectionEvent() override { return this; }
1158 WidgetSelectionEvent(bool aIsTrusted, EventMessage aMessage,
1159 nsIWidget* aWidget)
1160 : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, eSelectionEventClass),
1161 mOffset(0),
1162 mLength(0),
1163 mReversed(false),
1164 mExpandToClusterBoundary(true),
1165 mSucceeded(false),
1166 mUseNativeLineBreak(true),
1167 mReason(nsISelectionListener::NO_REASON) {}
1169 virtual WidgetEvent* Duplicate() const override {
1170 // This event isn't an internal event of any DOM event.
1171 NS_ASSERTION(!IsAllowedToDispatchDOMEvent(),
1172 "WidgetSelectionEvent needs to support Duplicate()");
1173 MOZ_CRASH("WidgetSelectionEvent doesn't support Duplicate()");
1174 return nullptr;
1177 // Start offset of selection
1178 uint32_t mOffset;
1179 // Length of selection
1180 uint32_t mLength;
1181 // Selection "anchor" should be in front
1182 bool mReversed;
1183 // Cluster-based or character-based
1184 bool mExpandToClusterBoundary;
1185 // true if setting selection succeeded.
1186 bool mSucceeded;
1187 // true if native line breaks are used for mOffset and mLength
1188 bool mUseNativeLineBreak;
1189 // Fennec provides eSetSelection reason codes for downstream
1190 // use in AccessibleCaret visibility logic.
1191 int16_t mReason;
1194 /******************************************************************************
1195 * mozilla::InternalEditorInputEvent
1196 ******************************************************************************/
1198 class InternalEditorInputEvent : public InternalUIEvent {
1199 private:
1200 InternalEditorInputEvent()
1201 : mData(VoidString()),
1202 mInputType(EditorInputType::eUnknown),
1203 mIsComposing(false) {}
1205 public:
1206 virtual InternalEditorInputEvent* AsEditorInputEvent() override {
1207 return this;
1210 InternalEditorInputEvent(bool aIsTrusted, EventMessage aMessage,
1211 nsIWidget* aWidget = nullptr)
1212 : InternalUIEvent(aIsTrusted, aMessage, aWidget, eEditorInputEventClass),
1213 mData(VoidString()),
1214 mInputType(EditorInputType::eUnknown) {}
1216 virtual WidgetEvent* Duplicate() const override {
1217 MOZ_ASSERT(mClass == eEditorInputEventClass,
1218 "Duplicate() must be overridden by sub class");
1219 // Not copying widget, it is a weak reference.
1220 InternalEditorInputEvent* result =
1221 new InternalEditorInputEvent(false, mMessage, nullptr);
1222 result->AssignEditorInputEventData(*this, true);
1223 result->mFlags = mFlags;
1224 return result;
1227 nsString mData;
1228 RefPtr<dom::DataTransfer> mDataTransfer;
1230 EditorInputType mInputType;
1232 bool mIsComposing;
1234 void AssignEditorInputEventData(const InternalEditorInputEvent& aEvent,
1235 bool aCopyTargets) {
1236 AssignUIEventData(aEvent, aCopyTargets);
1238 mData = aEvent.mData;
1239 mDataTransfer = aEvent.mDataTransfer;
1240 mInputType = aEvent.mInputType;
1241 mIsComposing = aEvent.mIsComposing;
1244 void GetDOMInputTypeName(nsAString& aInputTypeName) {
1245 GetDOMInputTypeName(mInputType, aInputTypeName);
1247 static void GetDOMInputTypeName(EditorInputType aInputType,
1248 nsAString& aInputTypeName);
1249 static EditorInputType GetEditorInputType(const nsAString& aInputType);
1251 static void Shutdown();
1253 private:
1254 static const char16_t* const kInputTypeNames[];
1255 typedef nsDataHashtable<nsStringHashKey, EditorInputType> InputTypeHashtable;
1256 static InputTypeHashtable* sInputTypeHashtable;
1259 } // namespace mozilla
1261 #endif // mozilla_TextEvents_h__