From 318761046ec74a00a50d4645cf9edccec624a5f8 Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Wed, 5 Oct 2011 11:19:25 +0900 Subject: [PATCH] Bug 477291 Should not send keypress event before calling interpretKeyEvents r=smichaud --- widget/src/cocoa/TextInputHandler.mm | 42 ++++++++++++---------------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/widget/src/cocoa/TextInputHandler.mm b/widget/src/cocoa/TextInputHandler.mm index 83033554979..19ca08a2705 100644 --- a/widget/src/cocoa/TextInputHandler.mm +++ b/widget/src/cocoa/TextInputHandler.mm @@ -1054,30 +1054,6 @@ TextInputHandler::HandleKeyDownEvent(NSEvent* aNativeEvent) // 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. @@ -1416,6 +1392,8 @@ TextInputHandler::InsertText(NSAttributedString *aAttrString) bool TextInputHandler::DoCommandBySelector(const char* aSelector) { + nsRefPtr kungFuDeathGrip(mWidget); + KeyEventState* currentKeyEvent = GetCurrentKeyEvent(); PR_LOG(gLog, PR_LOG_ALWAYS, @@ -1427,6 +1405,22 @@ TextInputHandler::DoCommandBySelector(const char* aSelector) 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);