Bug 1309515 part.2 TextInputHandler::InsertText() should consume current key event when it dispatches composition events r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 13 Oct 2016 13:18:58 +0900
changeset 425059 f1d8791e6818fb67c9cc7f303f67e7234066258c
parent 425058 11b3d794d4d7505b34f1ca5fe76ff660eb9ed891
child 533833 83de6ebb641d54b3e897fc738da6a0a02579da78
push id32330
push usermasayuki@d-toybox.com
push dateFri, 14 Oct 2016 04:14:07 +0000
reviewersm_kato
bugs1309515
milestone52.0a1
Bug 1309515 part.2 TextInputHandler::InsertText() should consume current key event when it dispatches composition events r?m_kato The cause of bug 1309515 is, HandleKeyDownEvent() dispatches eKeyPress events even after InsertText() dispatches composition events via InsertTextAsCommittingComposition(). Therefore, this patch consumes the current key event after dispatching composition events. Note that for consistency with Windows, InsertText() should use eKeyPress events rather than composition events at least in this case. However, changing the behavior has some risk. So, we should fix this bug with the safest hack for uplift. MozReview-Commit-ID: 7FYR5N2lATe
widget/cocoa/TextInputHandler.mm
--- a/widget/cocoa/TextInputHandler.mm
+++ b/widget/cocoa/TextInputHandler.mm
@@ -2185,16 +2185,24 @@ TextInputHandler::InsertText(NSAttribute
     DispatchEvent(deleteCommandEvent);
     NS_ENSURE_TRUE_VOID(deleteCommandEvent.mSucceeded);
     // Be aware! The widget might be destroyed here.
     return;
   }
 
   if (str.Length() != 1 || IsIMEComposing()) {
     InsertTextAsCommittingComposition(aAttrString, aReplacementRange);
+    // For now, consume keypress events when we dispatch the string with a
+    // composition for preventing to dispatch keypress events later.
+    // TODO: When there is a currentKeyEvent, we should dispatch keypress
+    //       events even if the length of the string is over 1.
+    if (currentKeyEvent) {
+      currentKeyEvent->mKeyPressHandled = true;
+      currentKeyEvent->mKeyPressDispatched = true;
+    }
     return;
   }
 
   // Don't let the same event be fired twice when hitting
   // enter/return! (Bug 420502)
   if (currentKeyEvent && !currentKeyEvent->CanDispatchKeyPressEvent()) {
     return;
   }