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

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

Issue 24195023: Switch to sending IME selection updates early. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Set DEBUG to false Created 7 years, 3 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
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 59427b294edde84788eafdb5481fca4e9f0eef2b..941fb85bb831d4d3eb47886dd43e36800d2c29be 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
@@ -36,7 +36,6 @@ public class AdapterInputConnection extends BaseInputConnection {
private boolean mSingleLine;
private int mNumNestedBatchEdits = 0;
- private boolean mIgnoreTextInputStateUpdates = false;
private int mLastUpdateSelectionStart = INVALID_SELECTION;
private int mLastUpdateSelectionEnd = INVALID_SELECTION;
@@ -119,11 +118,13 @@ public class AdapterInputConnection extends BaseInputConnection {
* if there is no selection
*/
public void setEditableText(String text, int selectionStart, int selectionEnd,
- int compositionStart, int compositionEnd) {
+ int compositionStart, int compositionEnd, boolean requireAck) {
nyquist 2013/09/27 18:02:36 Add javadoc for requireAck
aurimas (slooooooooow) 2013/09/27 21:06:05 Done.
if (DEBUG) {
Log.w(TAG, "setEditableText [" + text + "] [" + selectionStart + " " + selectionEnd
- + "] [" + compositionStart + " " + compositionEnd + "]");
+ + "] [" + compositionStart + " " + compositionEnd + "] [" + requireAck + "]");
}
+ if (!requireAck) return;
+
// Non-breaking spaces can cause the IME to get confused. Replace with normal spaces.
text = text.replace('\u00A0', ' ');
@@ -140,19 +141,6 @@ public class AdapterInputConnection extends BaseInputConnection {
editable.replace(0, editable.length(), text);
}
- int prevSelectionStart = Selection.getSelectionStart(editable);
- int prevSelectionEnd = Selection.getSelectionEnd(editable);
- int prevCompositionStart = getComposingSpanStart(editable);
- int prevCompositionEnd = getComposingSpanEnd(editable);
-
- if (prevSelectionStart == selectionStart && prevSelectionEnd == selectionEnd
- && prevCompositionStart == compositionStart
- && prevCompositionEnd == compositionEnd) {
- if (mIgnoreTextInputStateUpdates) return;
- updateSelection(selectionStart, selectionEnd, compositionStart, compositionEnd);
- return;
- }
-
Selection.setSelection(editable, selectionStart, selectionEnd);
if (compositionStart == compositionEnd) {
@@ -160,8 +148,16 @@ public class AdapterInputConnection extends BaseInputConnection {
} else {
super.setComposingRegion(compositionStart, compositionEnd);
}
+ updateSelection();
+ }
- if (mIgnoreTextInputStateUpdates) return;
+ private void updateSelection() {
nyquist 2013/09/27 18:02:36 How about updateSelectionIfNotNested? Or do you fe
aurimas (slooooooooow) 2013/09/27 21:06:05 Done.
+ if (mNumNestedBatchEdits != 0) return;
+ Editable editable = getEditable();
+ int selectionStart = Selection.getSelectionStart(editable);
+ int selectionEnd = Selection.getSelectionEnd(editable);
+ int compositionStart = getComposingSpanStart(editable);
+ int compositionEnd = getComposingSpanEnd(editable);
updateSelection(selectionStart, selectionEnd, compositionStart, compositionEnd);
}
@@ -196,6 +192,7 @@ public class AdapterInputConnection extends BaseInputConnection {
public boolean setComposingText(CharSequence text, int newCursorPosition) {
if (DEBUG) Log.w(TAG, "setComposingText [" + text + "] [" + newCursorPosition + "]");
super.setComposingText(text, newCursorPosition);
+ updateSelection();
return mImeAdapter.checkCompositionQueueAndCallNative(text.toString(),
newCursorPosition, false);
}
@@ -207,6 +204,7 @@ public class AdapterInputConnection extends BaseInputConnection {
public boolean commitText(CharSequence text, int newCursorPosition) {
if (DEBUG) Log.w(TAG, "commitText [" + text + "] [" + newCursorPosition + "]");
super.commitText(text, newCursorPosition);
+ updateSelection();
return mImeAdapter.checkCompositionQueueAndCallNative(text.toString(),
newCursorPosition, text.length() > 0);
}
@@ -274,10 +272,8 @@ public class AdapterInputConnection extends BaseInputConnection {
@Override
public boolean beginBatchEdit() {
if (DEBUG) Log.w(TAG, "beginBatchEdit [" + (mNumNestedBatchEdits == 0) + "]");
- if (mNumNestedBatchEdits == 0) mImeAdapter.batchStateChanged(true);
-
mNumNestedBatchEdits++;
- return false;
+ return true;
}
/**
@@ -285,12 +281,11 @@ public class AdapterInputConnection extends BaseInputConnection {
*/
@Override
public boolean endBatchEdit() {
- if (mNumNestedBatchEdits == 0) return false;
-
+ if (mNumNestedBatchEdits == 0) return true;
nyquist 2013/09/27 18:02:36 return false here?
aurimas (slooooooooow) 2013/09/27 21:06:05 Done.
--mNumNestedBatchEdits;
if (DEBUG) Log.w(TAG, "endBatchEdit [" + (mNumNestedBatchEdits == 0) + "]");
- if (mNumNestedBatchEdits == 0) mImeAdapter.batchStateChanged(false);
- return false;
+ if (mNumNestedBatchEdits == 0) updateSelection();
+ return true;
nyquist 2013/09/27 18:02:36 return mNumNestedBatchEdits != 0; ?
aurimas (slooooooooow) 2013/09/27 21:06:05 Done.
}
/**
@@ -307,6 +302,7 @@ public class AdapterInputConnection extends BaseInputConnection {
beforeLength = Math.min(beforeLength, availableBefore);
afterLength = Math.min(afterLength, availableAfter);
super.deleteSurroundingText(beforeLength, afterLength);
+ updateSelection();
return mImeAdapter.deleteSurroundingText(beforeLength, afterLength);
}
@@ -366,6 +362,7 @@ public class AdapterInputConnection extends BaseInputConnection {
}
super.finishComposingText();
+ updateSelection();
mImeAdapter.finishComposingText();
return true;
@@ -380,6 +377,7 @@ public class AdapterInputConnection extends BaseInputConnection {
int textLength = getEditable().length();
if (start < 0 || end < 0 || start > textLength || end > textLength) return true;
super.setSelection(start, end);
+ updateSelection();
return mImeAdapter.setEditableSelectionOffsets(start, end);
}
@@ -390,7 +388,6 @@ public class AdapterInputConnection extends BaseInputConnection {
void restartInput() {
if (DEBUG) Log.w(TAG, "restartInput");
getInputMethodManagerWrapper().restartInput(mInternalView);
- mIgnoreTextInputStateUpdates = false;
mNumNestedBatchEdits = 0;
}
@@ -413,6 +410,7 @@ public class AdapterInputConnection extends BaseInputConnection {
} else {
super.setComposingRegion(a, b);
}
+ updateSelection();
return mImeAdapter.setComposingRegion(a, b);
}
@@ -420,20 +418,9 @@ public class AdapterInputConnection extends BaseInputConnection {
return getInputMethodManagerWrapper().isActive(mInternalView);
}
- public void setIgnoreTextInputStateUpdates(boolean shouldIgnore) {
- mIgnoreTextInputStateUpdates = shouldIgnore;
- if (shouldIgnore) return;
-
- Editable editable = getEditable();
- updateSelection(Selection.getSelectionStart(editable),
- Selection.getSelectionEnd(editable),
- getComposingSpanStart(editable),
- getComposingSpanEnd(editable));
- }
-
@VisibleForTesting
protected boolean isIgnoringTextInputStateUpdates() {
- return mIgnoreTextInputStateUpdates;
+ return false;
}
private InputMethodManagerWrapper getInputMethodManagerWrapper() {

Powered by Google App Engine
This is Rietveld 408576698