Bug 477291 Should not send keypress event before calling interpretKeyEvents r=smichaud
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 05 Oct 2011 11:19:25 +0900
changeset 78781 308f307cababea77ea12160fc981d9a7e9198ec0
parent 78780 7c37f7b456cab2937ac22eabfb0f17138504f4da
child 78782 0cd9ed297f73e19341910c182b3031ef7272a0b8
push id506
push userclegnitto@mozilla.com
push dateWed, 09 Nov 2011 02:03:18 +0000
treeherdermozilla-aurora@63587fc7bb93 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmichaud
bugs477291
milestone10.0a1
Bug 477291 Should not send keypress event before calling interpretKeyEvents r=smichaud
widget/src/cocoa/TextInputHandler.mm
--- a/widget/src/cocoa/TextInputHandler.mm
+++ b/widget/src/cocoa/TextInputHandler.mm
@@ -1049,40 +1049,16 @@ TextInputHandler::HandleKeyDownEvent(NSE
         ("%p TextInputHandler::HandleKeyDownEvent, "
          "context menu event dispatched, handled=%s%s",
          this, TrueOrFalse(cmEventHandled),
          Destroyed() ? " and widget was destroyed" : ""));
       [mView maybeInitContextMenuTracking];
       // Bail, there is nothing else to do here.
       return (cmEventHandled || currentKeyEvent->KeyDownOrPressHandled());
     }
-
-    nsKeyEvent keypressEvent(true, NS_KEY_PRESS, mWidget);
-    InitKeyEvent(aNativeEvent, keypressEvent);
-
-    // if this is a non-letter keypress, or the control key is down,
-    // dispatch the keydown to gecko, so that we trap delete,
-    // control-letter combinations etc before Cocoa tries to use
-    // them for keybindings.
-    // XXX This is wrong. IME may be handle the non-letter keypress event as
-    //     its owning shortcut key.  See bug 477291.
-    if ((!keypressEvent.isChar || keypressEvent.isControl) &&
-        !IsIMEComposing()) {
-      if (currentKeyEvent->mKeyDownHandled) {
-        keypressEvent.flags |= NS_EVENT_FLAG_NO_DEFAULT;
-      }
-      currentKeyEvent->mKeyPressHandled = DispatchEvent(keypressEvent);
-      currentKeyEvent->mKeyPressDispatched = true;
-      if (Destroyed()) {
-        PR_LOG(gLog, PR_LOG_ALWAYS,
-          ("%p TextInputHandler::HandleKeyDownEvent, "
-           "widget was destroyed by keypress event", this));
-        return currentKeyEvent->KeyDownOrPressHandled();
-      }
-    }
   }
 
   // Let Cocoa interpret the key events, caching IsIMEComposing first.
   bool wasComposing = IsIMEComposing();
   bool interpretKeyEventsCalled = false;
   if (IsIMEEnabled() || IsASCIICapableOnly()) {
     PR_LOG(gLog, PR_LOG_ALWAYS,
       ("%p TextInputHandler::HandleKeyDownEvent, calling interpretKeyEvents",
@@ -1411,27 +1387,45 @@ TextInputHandler::InsertText(NSAttribute
   }
 
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
 bool
 TextInputHandler::DoCommandBySelector(const char* aSelector)
 {
+  nsRefPtr<nsChildView> kungFuDeathGrip(mWidget);
+
   KeyEventState* currentKeyEvent = GetCurrentKeyEvent();
 
   PR_LOG(gLog, PR_LOG_ALWAYS,
     ("%p TextInputHandler::DoCommandBySelector, aSelector=\"%s\", "
      "Destroyed()=%s, keypressHandled=%s, causedOtherKeyEvents=%s",
      this, aSelector ? aSelector : "", TrueOrFalse(Destroyed()),
      currentKeyEvent ?
        TrueOrFalse(currentKeyEvent->mKeyPressHandled) : "N/A",
      currentKeyEvent ?
        TrueOrFalse(currentKeyEvent->mCausedOtherKeyEvents) : "N/A"));
 
+  if (currentKeyEvent && !currentKeyEvent->mKeyPressDispatched) {
+    nsKeyEvent keypressEvent(true, NS_KEY_PRESS, mWidget);
+    InitKeyEvent(currentKeyEvent->mKeyEvent, keypressEvent);
+    if (currentKeyEvent->mKeyDownHandled ||
+        currentKeyEvent->mCausedOtherKeyEvents) {
+      keypressEvent.flags |= NS_EVENT_FLAG_NO_DEFAULT;
+    }
+    currentKeyEvent->mKeyPressHandled = DispatchEvent(keypressEvent);
+    currentKeyEvent->mKeyPressDispatched = true;
+    PR_LOG(gLog, PR_LOG_ALWAYS,
+      ("%p TextInputHandler::DoCommandBySelector, keypress event "
+       "dispatched, Destroyed()=%s, keypressHandled=%s",
+       this, TrueOrFalse(Destroyed()),
+       TrueOrFalse(currentKeyEvent->mKeyPressHandled)));
+  }
+
   return !Destroyed() && currentKeyEvent &&
          (currentKeyEvent->mKeyPressHandled ||
           currentKeyEvent->mCausedOtherKeyEvents);
 }
 
 
 #pragma mark -