Bug 477291 Should not send keypress event before calling interpretKeyEvents r=smichaud

This commit is contained in:
Masayuki Nakano 2011-10-05 11:19:25 +09:00
Родитель e756688298
Коммит 318761046e
1 изменённых файлов: 18 добавлений и 24 удалений

Просмотреть файл

@ -1054,30 +1054,6 @@ TextInputHandler::HandleKeyDownEvent(NSEvent* aNativeEvent)
// Bail, there is nothing else to do here. // Bail, there is nothing else to do here.
return (cmEventHandled || currentKeyEvent->KeyDownOrPressHandled()); 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. // Let Cocoa interpret the key events, caching IsIMEComposing first.
@ -1416,6 +1392,8 @@ TextInputHandler::InsertText(NSAttributedString *aAttrString)
bool bool
TextInputHandler::DoCommandBySelector(const char* aSelector) TextInputHandler::DoCommandBySelector(const char* aSelector)
{ {
nsRefPtr<nsChildView> kungFuDeathGrip(mWidget);
KeyEventState* currentKeyEvent = GetCurrentKeyEvent(); KeyEventState* currentKeyEvent = GetCurrentKeyEvent();
PR_LOG(gLog, PR_LOG_ALWAYS, PR_LOG(gLog, PR_LOG_ALWAYS,
@ -1427,6 +1405,22 @@ TextInputHandler::DoCommandBySelector(const char* aSelector)
currentKeyEvent ? currentKeyEvent ?
TrueOrFalse(currentKeyEvent->mCausedOtherKeyEvents) : "N/A")); 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 && return !Destroyed() && currentKeyEvent &&
(currentKeyEvent->mKeyPressHandled || (currentKeyEvent->mKeyPressHandled ||
currentKeyEvent->mCausedOtherKeyEvents); currentKeyEvent->mCausedOtherKeyEvents);