Bug 1279170 TextInputHandler::InsertText() should set keypress event's .key value property when it replaces specified range with a character r?m_kato
TextEventDispatcher::MaybeDispatchKeypressEvents() dispatches keypress events with passed event's mKeyNameIndex and mKeyValue values. I.e., setting mCharCode doesn't make sense in this case. Similarly, mKeyCode value is also ignored (overwritten by 0) if it's printable key's key event (mKeyNameIndex == KEY_NAME_INDEX_USE_STRING).
MozReview-Commit-ID: bdBQOlVKTs
--- a/widget/cocoa/TextInputHandler.mm
+++ b/widget/cocoa/TextInputHandler.mm
@@ -2208,35 +2208,35 @@ TextInputHandler::InsertText(NSAttribute
MOZ_LOG(gLog, LogLevel::Error,
("%p IMEInputHandler::HandleKeyUpEvent, "
"FAILED, due to BeginNativeInputTransaction() failure", this));
return;
}
// Dispatch keypress event with char instead of compositionchange event
WidgetKeyboardEvent keypressEvent(true, eKeyPress, mWidget);
+ // XXX Why do we need to dispatch keypress event for not inputting any
+ // string? If it wants to delete the specified range, should we
+ // dispatch an eContentCommandDelete event instead? Because this
+ // must not be caused by a key operation, a part of IME's processing.
keypressEvent.mIsChar = IsPrintableChar(str.CharAt(0));
// Don't set other modifiers from the current event, because here in
// -insertText: they've already been taken into account in creating
// the input string.
if (currentKeyEvent) {
NSEvent* keyEvent = currentKeyEvent->mKeyEvent;
InitKeyEvent(keyEvent, keypressEvent, &str);
} else {
nsCocoaUtils::InitInputEvent(keypressEvent, static_cast<NSEvent*>(nullptr));
- if (keypressEvent.mIsChar) {
- keypressEvent.mCharCode = str.CharAt(0);
- }
- // Note that insertText is not called only at key pressing.
- if (!keypressEvent.mCharCode) {
- keypressEvent.mKeyCode =
- WidgetUtils::ComputeKeyCodeFromChar(keypressEvent.mCharCode);
- }
+ keypressEvent.mKeyNameIndex = KEY_NAME_INDEX_USE_STRING;
+ keypressEvent.mKeyValue = str;
+ // FYI: TextEventDispatcher will set mKeyCode to 0 for printable key's
+ // keypress events even if they don't cause inputting non-empty string.
}
// Remove basic modifiers from keypress event because if they are included,
// nsPlaintextEditor ignores the event.
keypressEvent.mModifiers &= ~(MODIFIER_CONTROL |
MODIFIER_ALT |
MODIFIER_META);