Chromium Code Reviews| Index: content/public/android/java/src/org/chromium/content/browser/ImeAdapter.java |
| diff --git a/content/public/android/java/src/org/chromium/content/browser/ImeAdapter.java b/content/public/android/java/src/org/chromium/content/browser/ImeAdapter.java |
| index 1f73502d70a17ff4705137121f602660c23553eb..255013a9cbff5ff0d0a7b51b57ef300a020802e3 100644 |
| --- a/content/public/android/java/src/org/chromium/content/browser/ImeAdapter.java |
| +++ b/content/public/android/java/src/org/chromium/content/browser/ImeAdapter.java |
| @@ -495,6 +495,7 @@ class ImeAdapter { |
| private boolean mSingleLine; |
| private int mNumNestedBatchEdits = 0; |
| private boolean mIgnoreTextInputStateUpdates = false; |
| + private boolean mPendingUpdate = false; |
| private int mLastUpdateSelectionStart = INVALID_SELECTION; |
| private int mLastUpdateSelectionEnd = INVALID_SELECTION; |
| @@ -548,10 +549,22 @@ class ImeAdapter { |
| return; |
| } |
| - Selection.setSelection(editable, selectionStart, selectionEnd); |
| - super.setComposingRegion(compositionStart, compositionEnd); |
| + if (prevSelectionStart != selectionStart || prevSelectionEnd != selectionEnd) { |
| + Selection.setSelection(editable, selectionStart, selectionEnd); |
| + } |
| + |
| + if (prevCompositionStart != compositionStart || prevCompositionEnd != compositionEnd) { |
| + if (compositionStart == compositionEnd) { |
| + removeComposingSpans(getEditable()); |
| + } else { |
| + super.setComposingRegion(compositionStart, compositionEnd); |
| + } |
| + } |
| - if (mIgnoreTextInputStateUpdates) return; |
| + if (mIgnoreTextInputStateUpdates) { |
| + mPendingUpdate = true; |
| + return; |
| + } |
| updateSelection(selectionStart, selectionEnd, compositionStart, compositionEnd); |
| } |
| @@ -559,6 +572,7 @@ class ImeAdapter { |
| protected void updateSelection( |
| int selectionStart, int selectionEnd, |
| int compositionStart, int compositionEnd) { |
| + mPendingUpdate = false; |
|
aurimas (slooooooooow)
2013/04/09 17:09:26
Can you explain this PendingUpdate flag and why we
|
| // Avoid sending update if we sent an exact update already previously. |
| if (mLastUpdateSelectionStart == selectionStart && |
| mLastUpdateSelectionEnd == selectionEnd && |
| @@ -734,6 +748,7 @@ class ImeAdapter { |
| if (DEBUG) Log.w(TAG, "restartInput"); |
| getInputMethodManagerWrapper().restartInput(mInternalView); |
| mIgnoreTextInputStateUpdates = false; |
| + mPendingUpdate = false; |
| mNumNestedBatchEdits = 0; |
| } |
| @@ -742,7 +757,11 @@ class ImeAdapter { |
| if (DEBUG) Log.w(TAG, "setComposingRegion [" + start + " " + end + "]"); |
| int a = Math.min(start, end); |
| int b = Math.max(start, end); |
| - super.setComposingRegion(a, b); |
| + if (a == b) { |
| + removeComposingSpans(getEditable()); |
| + } else { |
| + super.setComposingRegion(a, b); |
| + } |
| return mImeAdapter.setComposingRegion(a, b); |
| } |
| @@ -752,7 +771,7 @@ class ImeAdapter { |
| void setIgnoreTextInputStateUpdates(boolean shouldIgnore) { |
| mIgnoreTextInputStateUpdates = shouldIgnore; |
| - if (shouldIgnore) return; |
| + if (shouldIgnore || !mPendingUpdate) return; |
| Editable editable = getEditable(); |
| updateSelection(Selection.getSelectionStart(editable), |