Commit d21e6ffc authored by bcwhite's avatar bcwhite Committed by Commit bot

Always guard against IME events for all KeyPress.

Previously, only BS/DEL set this guard but there are cases with keyboards
that send single characters immediately followed by a composition (e.g.
swiping words on stock Google keyboard) and we want to make sure that
there is no race condition where the actions taken in response to the
KeyPress don't cancel the following composition.

BUG=408678

Review URL: https://codereview.chromium.org/518123002

Cr-Commit-Position: refs/heads/master@{#293562}
parent 41fb6e1f
......@@ -460,13 +460,52 @@ public class ImeTest extends ContentShellTestBase {
assertEquals("", mConnection.getTextBeforeCursor(9, 0));
}
@SmallTest
@Feature({"TextInput", "Main"})
public void testKeyCodesWhileSwipingText() throws Throwable {
DOMUtils.focusNode(mContentViewCore, "textarea");
assertWaitForKeyboardStatus(true);
// The calls below are a reflection of what the stock Google Keyboard (Android 4.4) sends
// when the word is swiped on the soft keyboard. Exercise care when altering to make sure
// that the test reflects reality. If this test breaks, it's possible that code has
// changed and different calls need to be made instead.
mConnection = (TestAdapterInputConnection) getAdapterInputConnection();
waitAndVerifyEditableCallback(mConnection.mImeUpdateQueue, 0, "", 0, 0, -1, -1);
// "three"
expectUpdateStateCall(mConnection);
setComposingText(mConnection, "three", 1);
assertEquals(KeyEvent.KEYCODE_UNKNOWN, mImeAdapter.mLastSyntheticKeyCode);
assertUpdateStateCall(mConnection, 1000);
assertEquals("three", mConnection.getTextBeforeCursor(99, 0));
// "word"
commitText(mConnection, "three", 1);
commitText(mConnection, " ", 1);
expectUpdateStateCall(mConnection);
setComposingText(mConnection, "word", 1);
assertEquals(KeyEvent.KEYCODE_UNKNOWN, mImeAdapter.mLastSyntheticKeyCode);
assertUpdateStateCall(mConnection, 1000);
assertEquals("three word", mConnection.getTextBeforeCursor(99, 0));
// "test"
commitText(mConnection, "word", 1);
commitText(mConnection, " ", 1);
expectUpdateStateCall(mConnection);
setComposingText(mConnection, "test", 1);
assertEquals(KeyEvent.KEYCODE_UNKNOWN, mImeAdapter.mLastSyntheticKeyCode);
assertUpdateStateCall(mConnection, 1000);
assertEquals("three word test", mConnection.getTextBeforeCursor(99, 0));
}
@SmallTest
@Feature({"TextInput", "Main"})
public void testKeyCodesWhileTypingText() throws Throwable {
DOMUtils.focusNode(mContentViewCore, "textarea");
assertWaitForKeyboardStatus(true);
// The calls below are a reflection of what the Hacker's Keyboard sends when the noted
// The calls below are a reflection of what the Hacker's Keyboard sends when the noted
// key is touched on screen. Exercise care when altering to make sure that the test
// reflects reality.
mConnection = (TestAdapterInputConnection) getAdapterInputConnection();
......
......@@ -934,7 +934,7 @@ void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event,
base::AutoReset<WebInputEvent::Type> handling_event_type_resetter(
&handling_event_type_, input_event->type);
#if defined(OS_ANDROID)
// On Android, when the delete key or forward delete key is pressed using IME,
// On Android, when a key is pressed or sent from the Keyboard using IME,
// |AdapterInputConnection| generates input key events to make sure all JS
// listeners that monitor KeyUp and KeyDown events receive the proper key
// code. Since this input key event comes from IME, we need to set the
......@@ -944,10 +944,9 @@ void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event,
if (WebInputEvent::isKeyboardEventType(input_event->type)) {
const WebKeyboardEvent& key_event =
*static_cast<const WebKeyboardEvent*>(input_event);
if (key_event.nativeKeyCode == AKEYCODE_FORWARD_DEL ||
key_event.nativeKeyCode == AKEYCODE_DEL) {
// Some keys are special and it's essential that no events get blocked.
if (key_event.nativeKeyCode != AKEYCODE_TAB)
ime_event_guard_maybe.reset(new ImeEventGuard(this));
}
}
#endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment