diff options
author | Moonchild <moonchild@palemoon.org> | 2022-10-17 12:07:37 +0000 |
---|---|---|
committer | Moonchild <moonchild@palemoon.org> | 2022-10-17 12:28:26 +0000 |
commit | 74b3ce90d73f576a36888c06e413b99b61687b80 (patch) | |
tree | 81949969871ddf07f10d27a85a352ef2bbc09f22 /widget | |
parent | ebd7672d6ba8617c99f80f026b1415a6aafe00a5 (diff) | |
download | uxp-74b3ce90d73f576a36888c06e413b99b61687b80.tar.gz |
Issue #2019 - Do not dispatch keypress event for non-printable keys.
This will prevent the keypress DOM event from firing on keypresses
that do not produce printable keys (e.g. editing nav keys) in content.
This should not affect any chrome events that are in use.
Event dispatch can be re-enabled if necessary with the added pref.
Diffstat (limited to 'widget')
-rw-r--r-- | widget/TextEventDispatcher.cpp | 12 | ||||
-rw-r--r-- | widget/TextEventDispatcher.h | 4 | ||||
-rw-r--r-- | widget/TextEvents.h | 24 |
3 files changed, 40 insertions, 0 deletions
diff --git a/widget/TextEventDispatcher.cpp b/widget/TextEventDispatcher.cpp index 6c54376a48..2b058ba9c3 100644 --- a/widget/TextEventDispatcher.cpp +++ b/widget/TextEventDispatcher.cpp @@ -21,6 +21,7 @@ namespace widget { *****************************************************************************/ bool TextEventDispatcher::sDispatchKeyEventsDuringComposition = false; +bool TextEventDispatcher::sDispatchKeyPressEventNonPrintableInContent = false; TextEventDispatcher::TextEventDispatcher(nsIWidget* aWidget) : mWidget(aWidget) @@ -36,6 +37,10 @@ TextEventDispatcher::TextEventDispatcher(nsIWidget* aWidget) &sDispatchKeyEventsDuringComposition, "dom.keyboardevent.dispatch_during_composition", false); + Preferences::AddBoolVarCache( + &sDispatchKeyPressEventNonPrintableInContent, + "dom.keyboardevent.keypress.dispatch_non_printable_in_content", + false); sInitialized = true; } } @@ -531,6 +536,13 @@ TextEventDispatcher::DispatchKeyboardEventInternal( } } + if (!sDispatchKeyPressEventNonPrintableInContent && + keyEvent.mMessage == eKeyPress && + !keyEvent.IsInputtingText() && + !keyEvent.IsInputtingLineBreak()) { + keyEvent.mFlags.mOnlySystemGroupDispatchInContent = true; + } + DispatchInputEvent(mWidget, keyEvent, aStatus); return true; } diff --git a/widget/TextEventDispatcher.h b/widget/TextEventDispatcher.h index 1bed15a3bf..5d26127c71 100644 --- a/widget/TextEventDispatcher.h +++ b/widget/TextEventDispatcher.h @@ -399,6 +399,10 @@ private: // is a composition. static bool sDispatchKeyEventsDuringComposition; + // If this is true, keypress events for non-printable keys are dispatched to
+ // event listeners of the system event group in web content.
+ static bool sDispatchKeyPressEventNonPrintableInContent; + nsresult BeginInputTransactionInternal( TextEventDispatcherListener* aListener, InputTransactionType aType); diff --git a/widget/TextEvents.h b/widget/TextEvents.h index 6c29341144..59aa91b2e0 100644 --- a/widget/TextEvents.h +++ b/widget/TextEvents.h @@ -183,6 +183,30 @@ public: return IsKeyEventOnPlugin(mMessage); } + bool IsInputtingText() const + { + // NOTE: On some keyboard layouts, some characters are put in with Control + // or Alt keys, but at that time, widget unsets the modifier flag + // from the eKeyPress event, so it does not count as a modifier in + // this check. + return mMessage == eKeyPress && + mCharCode && + !(mModifiers & (MODIFIER_ALT | + MODIFIER_CONTROL | + MODIFIER_META | + MODIFIER_OS)); + } + + bool IsInputtingLineBreak() const + { + return mMessage == eKeyPress && + mKeyNameIndex == KEY_NAME_INDEX_Enter && + !(mModifiers & (MODIFIER_ALT | + MODIFIER_CONTROL | + MODIFIER_META | + MODIFIER_OS)); + } + virtual WidgetEvent* Duplicate() const override { MOZ_ASSERT(mClass == eKeyboardEventClass, |