summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraurimas@chromium.org <aurimas@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-23 22:17:51 +0000
committeraurimas@chromium.org <aurimas@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-23 22:17:51 +0000
commita3fd8d7e559e3cf75e455069e45ecafb7757c020 (patch)
tree6b2f9f9851d2b9f87749df6d7a6262c01a874d3c
parent69cb3774452d873ab04342909326a9d8817504ee (diff)
downloadchromium_src-a3fd8d7e559e3cf75e455069e45ecafb7757c020.zip
chromium_src-a3fd8d7e559e3cf75e455069e45ecafb7757c020.tar.gz
chromium_src-a3fd8d7e559e3cf75e455069e45ecafb7757c020.tar.bz2
[Android] Add a workaround for setting empty IME compositions.
This is a tempory workaround where Blink does not cancel the composition when we send a commit with the empty text. BUG=373934 Review URL: https://codereview.chromium.org/289863013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272615 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/public/android/java/src/org/chromium/content/browser/input/AdapterInputConnection.java30
1 files changed, 30 insertions, 0 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 6595808..f2ae829 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;