diff options
author | Alexandre Elias <aelias@chromium.org> | 2016-01-19 17:58:19 -0800 |
---|---|---|
committer | Alexandre Elias <aelias@chromium.org> | 2016-01-20 02:00:13 +0000 |
commit | 586f25c0a06fe85ddf1b92ba5e82cc717e342f4b (patch) | |
tree | 6c03b5598aa787474eba58df35ebb8933525fc57 | |
parent | ace13e7d61e9e3e59a8eeaf1ca421f3afb06b8ba (diff) | |
download | chromium_src-586f25c0a06fe85ddf1b92ba5e82cc717e342f4b.zip chromium_src-586f25c0a06fe85ddf1b92ba5e82cc717e342f4b.tar.gz chromium_src-586f25c0a06fe85ddf1b92ba5e82cc717e342f4b.tar.bz2 |
Revert of Consider newCursorPosition better when composing or commiting text (patchset #1 id:1 of https://codereview.chromium.org/1576303002/ )
and dependent fix "Fix possible out-of-range access in setComposingText()."
(https://codereview.chromium.org/1594323003)
Reason for revert:
Caused regression http://crbug.com/579136
BUG=579136,570920, 578762
Original issue's description:
> Consider newCursorPosition better when composing or commiting text
>
> commitText isn't considering the case of newCursorPosition != 1. We don't
> have native code to handle it, but since
>
> commitText = setComposingText + finishComposingText,
>
> we can replace it as such.
>
> Also, as for setComposingText, there is an error in BaseInputConnection
> (Android framework), so we need to correct the selection after calling
> super.setComposingText().
>
> BUG=570920
>
> Committed: https://crrev.com/d39e5f75823eae74b92ac8dd3b39a0ee740f8cc5
> Cr-Commit-Position: refs/heads/master@{#368809}
TBR=changwan@chromium.org
Review URL: https://codereview.chromium.org/1601243004
Cr-Commit-Position: refs/heads/master@{#370247}
(cherry picked from commit 714a024070f9999029e907cbb4b8e383c5e6405d)
Review URL: https://codereview.chromium.org/1602383002 .
Cr-Commit-Position: refs/branch-heads/2623@{#13}
Cr-Branched-From: 92d77538a86529ca35f9220bd3cd512cbea1f086-refs/heads/master@{#369907}
3 files changed, 11 insertions, 122 deletions
diff --git a/content/public/android/java/src/org/chromium/content/browser/input/AdapterInputConnection.java b/content/public/android/java/src/org/chromium/content/browser/input/AdapterInputConnection.java index b0f8f3f..2376c47 100644 --- a/content/public/android/java/src/org/chromium/content/browser/input/AdapterInputConnection.java +++ b/content/public/android/java/src/org/chromium/content/browser/input/AdapterInputConnection.java @@ -254,31 +254,9 @@ public class AdapterInputConnection extends BaseInputConnection { public boolean setComposingText(CharSequence text, int newCursorPosition) { Log.d(TAG, "setComposingText [%s] [%d]", text, newCursorPosition); mPendingAccent = 0; - - Editable editable = getEditableInternal(); - int selectionStartAfterReplacement = BaseInputConnection.getComposingSpanStart(editable); - if (selectionStartAfterReplacement == INVALID_COMPOSITION) { - selectionStartAfterReplacement = Selection.getSelectionStart(editable); - } - int selectionEndAfterReplacement = selectionStartAfterReplacement + text.length(); - super.setComposingText(text, newCursorPosition); - - // Due to an error in BaseInputConnection (b/21476564), the new cursor position - // may not be correct when newCursorPosition != 1. We fix it here: - if (newCursorPosition > 1) { - int newPos = selectionEndAfterReplacement - 1 + newCursorPosition; - int len = editable.length(); - if (newPos > len) newPos = len; - Selection.setSelection(editable, newPos); - } else if (newCursorPosition <= 0) { - int newPos = selectionStartAfterReplacement + newCursorPosition; - if (newPos < 0) newPos = 0; - Selection.setSelection(editable, newPos); - } - updateSelectionIfRequired(); - return mImeAdapter.setComposingText(text, newCursorPosition); + return mImeAdapter.sendCompositionToNative(text, newCursorPosition, false); } /** @@ -288,18 +266,9 @@ public class AdapterInputConnection extends BaseInputConnection { public boolean commitText(CharSequence text, int newCursorPosition) { Log.d(TAG, "commitText [%s] [%d]", text, newCursorPosition); mPendingAccent = 0; - if (newCursorPosition == 1) { - super.commitText(text, newCursorPosition); - updateSelectionIfRequired(); - return mImeAdapter.commitText(text); - } - - // This takes slightly longer, but commitText with newCursorPosition != 1 isn't - // implemented in the native side. - beginBatchEdit(); - boolean result = setComposingText(text, newCursorPosition) && finishComposingText(); - endBatchEdit(); - return result; + super.commitText(text, newCursorPosition); + updateSelectionIfRequired(); + return mImeAdapter.sendCompositionToNative(text, newCursorPosition, text.length() > 0); } /** diff --git a/content/public/android/java/src/org/chromium/content/browser/input/ImeAdapter.java b/content/public/android/java/src/org/chromium/content/browser/input/ImeAdapter.java index 61aceec..bdfd587 100644 --- a/content/public/android/java/src/org/chromium/content/browser/input/ImeAdapter.java +++ b/content/public/android/java/src/org/chromium/content/browser/input/ImeAdapter.java @@ -450,7 +450,7 @@ public class ImeAdapter { flags)); } - boolean commitText(CharSequence text) { + boolean sendCompositionToNative(CharSequence text, int newCursorPosition, boolean isCommit) { if (mNativeImeAdapterAndroid == 0) return false; mViewEmbedder.onImeEvent(); @@ -458,22 +458,12 @@ public class ImeAdapter { nativeSendSyntheticKeyEvent(mNativeImeAdapterAndroid, WebInputEventType.RawKeyDown, timestampMs, COMPOSITION_KEY_CODE, 0, 0); - nativeCommitText(mNativeImeAdapterAndroid, text.toString()); - - nativeSendSyntheticKeyEvent(mNativeImeAdapterAndroid, WebInputEventType.KeyUp, timestampMs, - COMPOSITION_KEY_CODE, 0, 0); - return true; - } - - boolean setComposingText(CharSequence text, int newCursorPosition) { - if (mNativeImeAdapterAndroid == 0) return false; - mViewEmbedder.onImeEvent(); - - long timestampMs = SystemClock.uptimeMillis(); - nativeSendSyntheticKeyEvent(mNativeImeAdapterAndroid, WebInputEventType.RawKeyDown, - timestampMs, COMPOSITION_KEY_CODE, 0, 0); - - nativeSetComposingText(mNativeImeAdapterAndroid, text, text.toString(), newCursorPosition); + if (isCommit) { + nativeCommitText(mNativeImeAdapterAndroid, text.toString()); + } else { + nativeSetComposingText( + mNativeImeAdapterAndroid, text, text.toString(), newCursorPosition); + } nativeSendSyntheticKeyEvent(mNativeImeAdapterAndroid, WebInputEventType.KeyUp, timestampMs, COMPOSITION_KEY_CODE, 0, 0); diff --git a/content/public/android/javatests/src/org/chromium/content/browser/input/ImeTest.java b/content/public/android/javatests/src/org/chromium/content/browser/input/ImeTest.java index 5276a36..7f24809 100644 --- a/content/public/android/javatests/src/org/chromium/content/browser/input/ImeTest.java +++ b/content/public/android/javatests/src/org/chromium/content/browser/input/ImeTest.java @@ -1000,76 +1000,6 @@ public class ImeTest extends ContentShellTestBase { assertNoFurtherStateUpdate(1); } - @MediumTest - @Feature({"TextInput"}) - public void testCommitTextWithDifferentCursorPositions() throws Throwable { - // Out of bound, treat this as commitText("ab", 1); - commitText("ab", 2); - assertEquals("ab", getTextBeforeCursor(10, 0)); - assertEquals("", getTextAfterCursor(10, 0)); - waitAndVerifyStatesAndCalls(1, "ab", 2, 2, -1, -1); - - commitText("cd", 0); - assertEquals("ab", getTextBeforeCursor(10, 0)); - assertEquals("cd", getTextAfterCursor(10, 0)); - waitAndVerifyStatesAndCalls(3, "abcd", 2, 2, -1, -1); - - commitText("ef", -1); - assertEquals("a", getTextBeforeCursor(10, 0)); - assertEquals("befcd", getTextAfterCursor(10, 0)); - waitAndVerifyStatesAndCalls(5, "abefcd", 1, 1, -1, -1); - } - - @MediumTest - @Feature({"TextInput"}) - public void testSetComposingTextWithDifferentCursorPositions() throws Throwable { - // Out of bound, treat this as commitText("ab", 1); - setComposingText("ab", 2); - finishComposingText(); - assertEquals("ab", getTextBeforeCursor(10, 0)); - assertEquals("", getTextAfterCursor(10, 0)); - waitAndVerifyStatesAndCalls(1, "ab", 2, 2, -1, -1); - - setComposingText("cd", 0); - finishComposingText(); - assertEquals("ab", getTextBeforeCursor(10, 0)); - assertEquals("cd", getTextAfterCursor(10, 0)); - waitAndVerifyStatesAndCalls(3, "abcd", 2, 2, -1, -1); - - setComposingText("ef", -1); - finishComposingText(); - assertEquals("a", getTextBeforeCursor(10, 0)); - assertEquals("befcd", getTextAfterCursor(10, 0)); - waitAndVerifyStatesAndCalls(5, "abefcd", 1, 1, -1, -1); - - setComposingText("gh", 1); - setComposingText("i", 0); - finishComposingText(); - assertEquals("a", getTextBeforeCursor(10, 0)); - assertEquals("ibefcd", getTextAfterCursor(10, 0)); - waitAndVerifyStatesAndCalls(8, "aibefcd", 1, 1, -1, -1); - } - - private CharSequence getTextBeforeCursor(final int length, final int flags) - throws ExecutionException { - return ThreadUtils.runOnUiThreadBlocking(new Callable<CharSequence>() { - @Override - public CharSequence call() { - return mConnection.getTextBeforeCursor(length, flags); - } - }); - } - - private CharSequence getTextAfterCursor(final int length, final int flags) - throws ExecutionException { - return ThreadUtils.runOnUiThreadBlocking(new Callable<CharSequence>() { - @Override - public CharSequence call() { - return mConnection.getTextAfterCursor(length, flags); - } - }); - } - private void performGo(TestCallbackHelperContainer testCallbackHelperContainer) throws Throwable { final AdapterInputConnection inputConnection = mConnection; |