Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Convert commitText("\n") to synthetic Enter key press.
Browse files Browse the repository at this point in the history
One known WebView app has come to rely on examining KeyDown key code in
JS to detect Enter key presses.  To avoid breaking it, restore the
conversion to KeyDown/KeyUp pair that was removed in
http://crrev.com/1403453002.

BUG=577967

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

Cr-Commit-Position: refs/heads/master@{#370284}
  • Loading branch information
alexelias authored and Commit bot committed Jan 20, 2016
1 parent 52619d6 commit c705f32
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,15 @@ protected void sendSyntheticKeyPress(int keyCode, int flags) {

boolean sendCompositionToNative(CharSequence text, int newCursorPosition, boolean isCommit) {
if (mNativeImeAdapterAndroid == 0) return false;
mViewEmbedder.onImeEvent();

// One WebView app detects Enter in JS by looking at KeyDown (http://crbug/577967).
if (text.equals("\n")) {
sendSyntheticKeyPress(KeyEvent.KEYCODE_ENTER,
KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE);
return true;
}

mViewEmbedder.onImeEvent();
long timestampMs = SystemClock.uptimeMillis();
nativeSendSyntheticKeyEvent(mNativeImeAdapterAndroid, WebInputEventType.RawKeyDown,
timestampMs, COMPOSITION_KEY_CODE, 0, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,24 @@ public void testCommitWhileComposingText() throws Throwable {
waitAndVerifyStates(3, "hel", 3, 3, -1, -1);
}

@SmallTest
@Feature({"TextInput", "Main"})
public void testCommitEnterKeyWhileComposingText() throws Throwable {
focusElementAndWaitForStateUpdate("textarea");

setComposingText("hello", 1);
waitAndVerifyStatesAndCalls(0, "hello", 5, 5, 0, 5);

// Cancel the current composition and replace it with enter.
commitText("\n", 1);
// The second new line is not a user visible/editable one, it is a side-effect of Blink
// using <br> internally. This only happens when \n is at the end.
waitAndVerifyStatesAndCalls(1, "\n\n", 1, 1, -1, -1);

commitText("world", 1);
waitAndVerifyStatesAndCalls(2, "\nworld", 6, 6, -1, -1);
}

@SmallTest
@Feature({"TextInput"})
public void testImeCopy() throws Exception {
Expand Down

0 comments on commit c705f32

Please sign in to comment.