Bug 1343451 - part 5: Make GeckoEditableSupport dispatch dummy eKeyDown and eKeyUp event during composition always r?jchen draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 27 Feb 2018 17:24:35 +0900
changeset 762368 59e1833f8bb4782573fbebb800338cae37b49ef7
parent 762367 a7b388528b45d436892767c9667672f6b055200b
push id101161
push usermasayuki@d-toybox.com
push dateFri, 02 Mar 2018 09:53:57 +0000
reviewersjchen
bugs1343451, 354358
milestone60.0a1
Bug 1343451 - part 5: Make GeckoEditableSupport dispatch dummy eKeyDown and eKeyUp event during composition always r?jchen On Android, GeckoEditableSupport has already dispatched eKeyDown event and eKeyUp event even during composition. I.e., the pref which will be enabled by bug 354358 has already been set to true only on Android. On the other hand, GeckoEditableSupport does not dispatch them if content listens to "input", "compositionstart", "compositionupdate" or "compositionend". So, different from the other platforms, we cannot test this behind pref ("dom.keyboardevent.dispatch_during_composition") even in Nightly. Therefore, this patch enables new behavior only when it's Nightly build or early Beta. And sets mKeyCode and mKeyNameIndex of the dummy KeyboardEvents to NS_VK_PROCESSKEY and KEY_NAME_INDEX_Process. MozReview-Commit-ID: Fuy0Ir2xiO5
widget/android/GeckoEditableSupport.cpp
--- a/widget/android/GeckoEditableSupport.cpp
+++ b/widget/android/GeckoEditableSupport.cpp
@@ -663,27 +663,31 @@ GeckoEditableSupport::OnKeyEvent(int32_t
     } else {
         dispatcher->MaybeDispatchKeypressEvents(pressEvent, status);
     }
 }
 
 /*
  * Send dummy key events for pages that are unaware of input events,
  * to provide web compatibility for pages that depend on key events.
- * Our dummy key events have 0 as the keycode.
  */
 void
 GeckoEditableSupport::SendIMEDummyKeyEvent(nsIWidget* aWidget, EventMessage msg)
 {
     nsEventStatus status = nsEventStatus_eIgnore;
     MOZ_ASSERT(mDispatcher);
 
     WidgetKeyboardEvent event(true, msg, aWidget);
     event.mTime = PR_Now() / 1000;
-    MOZ_ASSERT(event.mKeyCode == 0);
+    // TODO: If we can know scan code of the key event which caused replacing
+    //       composition string, we should set mCodeNameIndex here.  Then,
+    //       we should rename this method because it becomes not a "dummy"
+    //       keyboard event.
+    event.mKeyCode = NS_VK_PROCESSKEY;
+    event.mKeyNameIndex = KEY_NAME_INDEX_Process;
     NS_ENSURE_SUCCESS_VOID(BeginInputTransaction(mDispatcher));
     mDispatcher->DispatchKeyboardEvent(msg, event, status);
 }
 
 void
 GeckoEditableSupport::AddIMETextChange(const IMETextChange& aChange)
 {
     mIMETextChanges.AppendElement(aChange);
@@ -1022,39 +1026,54 @@ GeckoEditableSupport::OnImeReplaceText(i
          * change notification. However, the Java side still expects
          * one, so we manually generate a notification. */
         IMETextChange dummyChange;
         dummyChange.mStart = aStart;
         dummyChange.mOldEnd = dummyChange.mNewEnd = aEnd;
         AddIMETextChange(dummyChange);
     }
 
+    // Until fixing bug 354358 in release channel, we should always ignore
+    // "intl.ime.hack.on_ime_unaware_apps.fire_key_events_for_composition"
+    // pref in Nightly and early Beta for testing new regressions.
+#ifndef EARLY_BETA_OR_EARLIER
     if (mInputContext.mMayBeIMEUnaware) {
+#endif // #ifndef EARLY_BETA_OR_EARLIER
         SendIMEDummyKeyEvent(widget, eKeyDown);
         if (!mDispatcher || widget->Destroyed()) {
             return;
         }
+#ifndef EARLY_BETA_OR_EARLIER
     }
+#endif // #ifndef EARLY_BETA_OR_EARLIER
 
     if (composing) {
         mDispatcher->SetPendingComposition(string, mIMERanges);
         mDispatcher->FlushPendingComposition(status);
         // Ensure IME ranges are empty.
         mIMERanges->Clear();
     } else if (!string.IsEmpty() || mDispatcher->IsComposing()) {
         mDispatcher->CommitComposition(status, &string);
     }
     if (!mDispatcher || widget->Destroyed()) {
         return;
     }
 
+    // XXX This works fine if user inputs with virtual keyboard.  However,
+    //     if user inputs with hardware keyboard, keyup event may come later.
+    //     So, perhaps, we need to record actual keyboard events before
+    //     this replacement of composition string.
+#ifndef EARLY_BETA_OR_EARLIER
     if (mInputContext.mMayBeIMEUnaware) {
+#endif // #ifndef EARLY_BETA_OR_EARLIER
         SendIMEDummyKeyEvent(widget, eKeyUp);
         // Widget may be destroyed after dispatching the above event.
+#ifndef EARLY_BETA_OR_EARLIER
     }
+#endif // #ifndef EARLY_BETA_OR_EARLIER
 }
 
 void
 GeckoEditableSupport::OnImeAddCompositionRange(
         int32_t aStart, int32_t aEnd, int32_t aRangeType, int32_t aRangeStyle,
         int32_t aRangeLineStyle, bool aRangeBoldLine, int32_t aRangeForeColor,
         int32_t aRangeBackColor, int32_t aRangeLineColor)
 {