diff options
author | Moonchild <moonchild@palemoon.org> | 2023-03-23 22:35:03 +0100 |
---|---|---|
committer | Moonchild <moonchild@palemoon.org> | 2023-03-23 22:35:03 +0100 |
commit | 434379eb34335131bb44dfd229c06db42fcb208e (patch) | |
tree | 71700b2f58a62208067f2d487788e92fdfa61855 /widget | |
parent | 2f3f8e13eba0228515693dcb498412cf2b27ef84 (diff) | |
download | uxp-434379eb34335131bb44dfd229c06db42fcb208e.tar.gz |
Issue #2161 - Ctrl + Enter should cause keypress event even though the
key combination doesn't input any character
Currently, we dispatch keypress event when Enter is pressed without
modifiers or only with the Shift key (line break).
However, other browsers dispatch keypress events for Ctrl + Enter also
even if it doesn't cause any text input.
So, we should fire keypress events for Ctrl + Enter, even in strict
keypress dispatching mode. Note that with other modifiers, it depends on
the browser and/or platform and we can't dispatch the event for
consistent behavior.
This means web developers shouldn't rely one keypress events to catch
Alt + Enter, Meta + Enter and two or more modifiers + Enter.
Based on BZ 1438133
Resolves #2161
Diffstat (limited to 'widget')
-rw-r--r-- | widget/TextEventDispatcher.cpp | 3 | ||||
-rw-r--r-- | widget/TextEvents.h | 30 |
2 files changed, 31 insertions, 2 deletions
diff --git a/widget/TextEventDispatcher.cpp b/widget/TextEventDispatcher.cpp index 2b058ba9c3..a69e5ce0ac 100644 --- a/widget/TextEventDispatcher.cpp +++ b/widget/TextEventDispatcher.cpp @@ -538,8 +538,7 @@ TextEventDispatcher::DispatchKeyboardEventInternal( if (!sDispatchKeyPressEventNonPrintableInContent && keyEvent.mMessage == eKeyPress && - !keyEvent.IsInputtingText() && - !keyEvent.IsInputtingLineBreak()) { + !keyEvent.ShouldKeyPressEventBeFiredOnContent()) { keyEvent.mFlags.mOnlySystemGroupDispatchInContent = true; } diff --git a/widget/TextEvents.h b/widget/TextEvents.h index 59aa91b2e0..53233b8844 100644 --- a/widget/TextEvents.h +++ b/widget/TextEvents.h @@ -207,6 +207,36 @@ public: MODIFIER_OS)); } + /** + * ShouldKeyPressEventBeFiredOnContent() should be called only when the + * instance is eKeyPress event. This returns true when the eKeyPress + * event should be fired even on content in the default event group. + */ + bool ShouldKeyPressEventBeFiredOnContent() const + { + MOZ_DIAGNOSTIC_ASSERT(mMessage == eKeyPress); + // Case 1: Inputting text or a line break: always fire keypress event. + if (IsInputtingText() || IsInputtingLineBreak()) { + return true; + } + // Case 2: Ctrl + Enter + // Ctrl + Enter won't cause actual input in our editor so should not fire the event if people would be consistent + // in setting rules for themselves (foreshadowing... ;P). + // However, the other browsers fire the keypress event in this case (but not with other modifiers). + // So, for compatibility with them, we should fire the keypress event for Ctrl + Enter too. + if (mMessage == eKeyPress && + mKeyNameIndex == KEY_NAME_INDEX_Enter && + !(mModifiers & (MODIFIER_ALT | + MODIFIER_META | + MODIFIER_OS | + MODIFIER_SHIFT))) { + return true; + } + + // Default: dont't fire in the default event group. + return false; + } + virtual WidgetEvent* Duplicate() const override { MOZ_ASSERT(mClass == eKeyboardEventClass, |