Bug 1279170 TextInputHandler::InsertText() should set keypress event's .key value property when it replaces specified range with a character r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 16 Jun 2016 12:11:01 +0900
changeset 301952 4e16558233f985125db446de2b3fee7055b2b623
parent 301951 b4867459589df246d85972669074233b8d2e23b8
child 301953 8359dc68212e4f06c300272a19aea77a106fd777
push id30346
push usercbook@mozilla.com
push dateThu, 16 Jun 2016 23:32:32 +0000
treeherdermozilla-central@5f95858f8ddf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1279170
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
widget/cocoa/TextInputHandler.mm
--- 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);