Bug 1358958 part.1 Don't consume command when neither keydown nor keypress event was consumed r=m_kato

When typing Enter key when active keyboard layout is Korean IME and it has composition string, the composition string is committed and then, "insertNewline:" command is sent. However, TextInputHandler::DoCommandBySelector() consumes the command because the key event has already modified the composition string.

This patch makes TextInputHandler::DoCommandBySelector() consume the command if it's not handling keydown or neither dispatched keydown event nor dispatched keypress event (if it does) is consumed. Therefore, insertNewline:sender of nsChildView will be called later, then, it causes inserting a line break with a set of composition events.

MozReview-Commit-ID: Afr1FKZbUtL

--HG--
extra : rebase_source : 0c43986907553750b63bed0c95b3d5aaa1b16bea
This commit is contained in:
Masayuki Nakano 2017-04-26 20:39:13 +09:00
parent bf97b2a40a
commit e12339e622
2 changed files with 28 additions and 4 deletions

View File

@ -593,6 +593,11 @@ protected:
return !mKeyPressDispatched && !IsDefaultPrevented();
}
bool CanHandleCommand() const
{
return !mKeyDownHandled && !mKeyPressHandled;
}
void InitKeyEvent(TextInputHandlerBase* aHandler,
WidgetKeyboardEvent& aKeyEvent);

View File

@ -2373,14 +2373,26 @@ TextInputHandler::DoCommandBySelector(const char* aSelector)
currentKeyEvent ?
TrueOrFalse(currentKeyEvent->mCausedOtherKeyEvents) : "N/A"));
if (currentKeyEvent && currentKeyEvent->CanDispatchKeyPressEvent()) {
// If the command isn't caused by key operation, the command should
// be handled in the super class of the caller.
if (!currentKeyEvent) {
return Destroyed();
}
// If the key operation causes this command, should dispatch a keypress
// event.
// XXX This must be worng. Even if this command is caused by the key
// operation, its our default action can be different from the
// command. So, in this case, we should dispatch a keypress event
// which have the command and editor should handle it.
if (currentKeyEvent->CanDispatchKeyPressEvent()) {
nsresult rv = mDispatcher->BeginNativeInputTransaction();
if (NS_WARN_IF(NS_FAILED(rv))) {
MOZ_LOG(gLog, LogLevel::Error,
("%p IMEInputHandler::DoCommandBySelector, "
"FAILED, due to BeginNativeInputTransaction() failure "
"at dispatching keypress", this));
return false;
return Destroyed();
}
WidgetKeyboardEvent keypressEvent(true, eKeyPress, widget);
@ -2397,10 +2409,17 @@ TextInputHandler::DoCommandBySelector(const char* aSelector)
"dispatched, Destroyed()=%s, keypressHandled=%s",
this, TrueOrFalse(Destroyed()),
TrueOrFalse(currentKeyEvent->mKeyPressHandled)));
// This command is now dispatched with keypress event.
// So, this shouldn't be handled by nobody anymore.
return true;
}
return (!Destroyed() && currentKeyEvent &&
currentKeyEvent->IsDefaultPrevented());
// If the key operation didn't cause keypress event or caused keypress event
// but not prevented its default, we need to honor the command. For example,
// Korean IME sends "insertNewline:" when committing existing composition
// with Enter key press. In such case, the key operation has been consumed
// by the committing composition but we still need to handle the command.
return Destroyed() || !currentKeyEvent->CanHandleCommand();
}