mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-06 23:37:31 +09:00
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.
This commit is contained in:
parent
2f0896ab31
commit
1392f5f223
6 changed files with 48 additions and 15 deletions
|
|
@ -664,8 +664,7 @@ HTMLEditor::HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent)
|
||||||
return TypedText(NS_LITERAL_STRING("\t"), eTypedText);
|
return TypedText(NS_LITERAL_STRING("\t"), eTypedText);
|
||||||
}
|
}
|
||||||
case NS_VK_RETURN:
|
case NS_VK_RETURN:
|
||||||
if (nativeKeyEvent->IsControl() || nativeKeyEvent->IsAlt() ||
|
if (!nativeKeyEvent->IsInputtingLineBreak()) {
|
||||||
nativeKeyEvent->IsMeta() || nativeKeyEvent->IsOS()) {
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
aKeyEvent->AsEvent()->PreventDefault(); // consumed
|
aKeyEvent->AsEvent()->PreventDefault(); // consumed
|
||||||
|
|
@ -677,11 +676,7 @@ HTMLEditor::HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent)
|
||||||
return TypedText(EmptyString(), eTypedBreak);
|
return TypedText(EmptyString(), eTypedBreak);
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: On some keyboard layout, some characters are inputted with Control
|
if (!nativeKeyEvent->IsInputtingText()) {
|
||||||
// key or Alt key, but at that time, widget sets FALSE to these keys.
|
|
||||||
if (!nativeKeyEvent->mCharCode || nativeKeyEvent->IsControl() ||
|
|
||||||
nativeKeyEvent->IsAlt() || nativeKeyEvent->IsMeta() ||
|
|
||||||
nativeKeyEvent->IsOS()) {
|
|
||||||
// we don't PreventDefault() here or keybindings like control-x won't work
|
// we don't PreventDefault() here or keybindings like control-x won't work
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -397,20 +397,14 @@ TextEditor::HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent)
|
||||||
return TypedText(NS_LITERAL_STRING("\t"), eTypedText);
|
return TypedText(NS_LITERAL_STRING("\t"), eTypedText);
|
||||||
}
|
}
|
||||||
case NS_VK_RETURN:
|
case NS_VK_RETURN:
|
||||||
if (IsSingleLineEditor() || nativeKeyEvent->IsControl() ||
|
if (IsSingleLineEditor() || !nativeKeyEvent->IsInputtingLineBreak()) {
|
||||||
nativeKeyEvent->IsAlt() || nativeKeyEvent->IsMeta() ||
|
|
||||||
nativeKeyEvent->IsOS()) {
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
aKeyEvent->AsEvent()->PreventDefault();
|
aKeyEvent->AsEvent()->PreventDefault();
|
||||||
return TypedText(EmptyString(), eTypedBreak);
|
return TypedText(EmptyString(), eTypedBreak);
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: On some keyboard layout, some characters are inputted with Control
|
if (!nativeKeyEvent->IsInputtingText()) {
|
||||||
// key or Alt key, but at that time, widget sets FALSE to these keys.
|
|
||||||
if (!nativeKeyEvent->mCharCode || nativeKeyEvent->IsControl() ||
|
|
||||||
nativeKeyEvent->IsAlt() || nativeKeyEvent->IsMeta() ||
|
|
||||||
nativeKeyEvent->IsOS()) {
|
|
||||||
// we don't PreventDefault() here or keybindings like control-x won't work
|
// we don't PreventDefault() here or keybindings like control-x won't work
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -231,6 +231,10 @@ pref("dom.keyboardevent.code.enabled", true);
|
||||||
// even if this is true).
|
// even if this is true).
|
||||||
pref("dom.keyboardevent.dispatch_during_composition", false);
|
pref("dom.keyboardevent.dispatch_during_composition", false);
|
||||||
|
|
||||||
|
// If this is true, TextEventDispatcher dispatches keypress events
|
||||||
|
// for the input of non-printable characters (content only).
|
||||||
|
pref("dom.keyboardevent.keypress.dispatch_non_printable_in_content", false);
|
||||||
|
|
||||||
// Whether URL,Location,Link::GetHash should be percent encoded
|
// Whether URL,Location,Link::GetHash should be percent encoded
|
||||||
// in setter and percent decoded in getter (old behaviour = true)
|
// in setter and percent decoded in getter (old behaviour = true)
|
||||||
pref("dom.url.encode_decode_hash", true);
|
pref("dom.url.encode_decode_hash", true);
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ namespace widget {
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
bool TextEventDispatcher::sDispatchKeyEventsDuringComposition = false;
|
bool TextEventDispatcher::sDispatchKeyEventsDuringComposition = false;
|
||||||
|
bool TextEventDispatcher::sDispatchKeyPressEventNonPrintableInContent = false;
|
||||||
|
|
||||||
TextEventDispatcher::TextEventDispatcher(nsIWidget* aWidget)
|
TextEventDispatcher::TextEventDispatcher(nsIWidget* aWidget)
|
||||||
: mWidget(aWidget)
|
: mWidget(aWidget)
|
||||||
|
|
@ -36,6 +37,10 @@ TextEventDispatcher::TextEventDispatcher(nsIWidget* aWidget)
|
||||||
&sDispatchKeyEventsDuringComposition,
|
&sDispatchKeyEventsDuringComposition,
|
||||||
"dom.keyboardevent.dispatch_during_composition",
|
"dom.keyboardevent.dispatch_during_composition",
|
||||||
false);
|
false);
|
||||||
|
Preferences::AddBoolVarCache(
|
||||||
|
&sDispatchKeyPressEventNonPrintableInContent,
|
||||||
|
"dom.keyboardevent.keypress.dispatch_non_printable_in_content",
|
||||||
|
false);
|
||||||
sInitialized = true;
|
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);
|
DispatchInputEvent(mWidget, keyEvent, aStatus);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -399,6 +399,10 @@ private:
|
||||||
// is a composition.
|
// is a composition.
|
||||||
static bool sDispatchKeyEventsDuringComposition;
|
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(
|
nsresult BeginInputTransactionInternal(
|
||||||
TextEventDispatcherListener* aListener,
|
TextEventDispatcherListener* aListener,
|
||||||
InputTransactionType aType);
|
InputTransactionType aType);
|
||||||
|
|
|
||||||
|
|
@ -183,6 +183,30 @@ public:
|
||||||
return IsKeyEventOnPlugin(mMessage);
|
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
|
virtual WidgetEvent* Duplicate() const override
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mClass == eKeyboardEventClass,
|
MOZ_ASSERT(mClass == eKeyboardEventClass,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue