Commit a9a6608f authored by Ryan Landay's avatar Ryan Landay Committed by Commit Bot

Make DPAD_CENTER key events show soft input on keyup, not keydown

When a native Android EditText widget is focused, the DPAD_CENTER keyboard event
(e.g. from the center button on the Nexus Player remote) causes the on-screen
keyboard to show on keyup. Currently in WebView, we're showing the keyboard on
keydown, and then the on-screen keyboard is receiving the keyup event. In
Android Oreo, the keyboard was rewritten and when the new keyboard receives this
keyup event, it types the character selected by default on the keyboard (usually
'1').

The fix is to not show the keyboard until keyup, to match the behavior of
Android EditText. Despite no longer doing anything in response to the keydown
event, we still want to make the event prevent default instead of passing it to
the web app, since passing it to the web app would cause compatibility problems.
E.g. the Facebook app for Android TV would blur the input element in response to
the keydown immediately after the keyboard is opened (which causes the keyboard
to close again).

Bug: 776591
Change-Id: Icf893f8d2ef27825d78d2bc264575a62b0e77648
Reviewed-on: https://chromium-review.googlesource.com/729281Reviewed-by: default avatarAlexandre Elias <aelias@chromium.org>
Reviewed-by: default avatarChangwan Ryu <changwan@chromium.org>
Commit-Queue: Ryan Landay <rlanday@chromium.org>
Cr-Commit-Position: refs/heads/master@{#510277}
parent e2b0341f
......@@ -1252,12 +1252,37 @@ public class ImeTest {
@SmallTest
@Feature({"TextInput", "Main"})
public void testDpadKeyCodesWhileSwipingText() throws Throwable {
int showCount = mRule.getInputMethodManagerWrapper().getShowSoftInputCounter();
mRule.focusElement("textarea");
// DPAD_CENTER should cause keyboard to appear
// focusElement() calls showSoftInput().
CriteriaHelper.pollUiThread(Criteria.equals(showCount + 1, new Callable<Integer>() {
@Override
public Integer call() {
return mRule.getInputMethodManagerWrapper().getShowSoftInputCounter();
}
}));
// DPAD_CENTER should cause keyboard to appear on keyup.
mRule.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_CENTER));
// TODO(changwan): should really check this.
// Should not have called showSoftInput() on keydown.
CriteriaHelper.pollUiThread(Criteria.equals(showCount + 1, new Callable<Integer>() {
@Override
public Integer call() {
return mRule.getInputMethodManagerWrapper().getShowSoftInputCounter();
}
}));
mRule.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_CENTER));
// Should have called showSoftInput() on keyup.
CriteriaHelper.pollUiThread(Criteria.equals(showCount + 2, new Callable<Integer>() {
@Override
public Integer call() {
return mRule.getInputMethodManagerWrapper().getShowSoftInputCounter();
}
}));
}
@Test
......
......@@ -241,7 +241,13 @@ void RenderWidgetInputHandler::HandleInputEvent(
static_cast<const WebKeyboardEvent&>(input_event);
if (key_event.native_key_code == AKEYCODE_DPAD_CENTER &&
widget_->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) {
// Show the keyboard on keyup (not keydown) to match the behavior of
// Android's TextView.
if (key_event.GetType() == WebInputEvent::kKeyUp)
widget_->ShowVirtualKeyboardOnElementFocus();
// Prevent default for both keydown and keyup (letting the keydown go
// through to the web app would cause compatibility problems since
// DPAD_CENTER is also used as a "confirm" button).
prevent_default = true;
}
#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