Bug 477291 Should not send keypress event before calling interpretKeyEvents r=smichaud
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 30 Sep 2011 15:17:33 +0900
changeset 77906 10298b25af4e
parent 77905 e734bd300268
child 77907 8232007db7e5
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
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(PR_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 = PR_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(PR_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 = PR_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 -