Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1835)

Unified Diff: content/public/android/java/src/org/chromium/content/browser/input/AdapterInputConnection.java

Issue 289863013: [Android] Add a workaround for setting empty IME compositions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Ted's nits Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/android/java/src/org/chromium/content/browser/input/AdapterInputConnection.java
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 65958083eb8888ab89729cac576bbfd74be4458d..f2ae82906223fa1bbd9e267a65018cf07fdfa879 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
@@ -8,6 +8,7 @@ import android.os.SystemClock;
import android.text.Editable;
import android.text.InputType;
import android.text.Selection;
+import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
@@ -212,6 +213,7 @@ public class AdapterInputConnection extends BaseInputConnection {
@Override
public boolean setComposingText(CharSequence text, int newCursorPosition) {
if (DEBUG) Log.w(TAG, "setComposingText [" + text + "] [" + newCursorPosition + "]");
+ if (maybePerformEmptyCompositionWorkaround(text)) return true;
super.setComposingText(text, newCursorPosition);
updateSelectionIfRequired();
return mImeAdapter.checkCompositionQueueAndCallNative(text.toString(),
@@ -224,6 +226,7 @@ public class AdapterInputConnection extends BaseInputConnection {
@Override
public boolean commitText(CharSequence text, int newCursorPosition) {
if (DEBUG) Log.w(TAG, "commitText [" + text + "] [" + newCursorPosition + "]");
+ if (maybePerformEmptyCompositionWorkaround(text)) return true;
super.commitText(text, newCursorPosition);
updateSelectionIfRequired();
return mImeAdapter.checkCompositionQueueAndCallNative(text.toString(),
@@ -446,6 +449,33 @@ public class AdapterInputConnection extends BaseInputConnection {
return mImeAdapter.getInputMethodManagerWrapper();
}
+ /**
+ * This method works around the issue crbug.com/373934 where Blink does not cancel
+ * the composition when we send a commit with the empty text.
+ *
+ * TODO(aurimas) Remove this once crbug.com/373934 is fixed.
+ *
+ * @param text Text that software keyboard requested to commit.
+ * @return Whether the workaround was performed.
+ */
+ private boolean maybePerformEmptyCompositionWorkaround(CharSequence text) {
+ int selectionStart = Selection.getSelectionStart(mEditable);
+ int selectionEnd = Selection.getSelectionEnd(mEditable);
+ int compositionStart = getComposingSpanStart(mEditable);
+ int compositionEnd = getComposingSpanEnd(mEditable);
+ if (TextUtils.isEmpty(text) && (selectionStart == selectionEnd)
+ && compositionStart != INVALID_COMPOSITION
+ && compositionEnd != INVALID_COMPOSITION) {
+ beginBatchEdit();
+ finishComposingText();
+ int selection = Selection.getSelectionStart(mEditable);
+ deleteSurroundingText(selection - compositionStart, selection - compositionEnd);
+ endBatchEdit();
+ return true;
+ }
+ return false;
+ }
+
@VisibleForTesting
static class ImeState {
public final String text;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698