Bug 810170 - Properly handle extracted text notification and selection notification; r=cpeterson

This commit is contained in:
Jim Chen 2012-11-13 17:26:18 -05:00
Родитель cfce24e060
Коммит c1723ffee1
2 изменённых файлов: 41 добавлений и 15 удалений

Просмотреть файл

@ -553,6 +553,7 @@ final class GeckoEditable
}
} else {
mText.replace(start, oldEnd, text, 0, text.length());
}
geckoPostToUI(new Runnable() {
public void run() {
if (mListener != null) {
@ -561,7 +562,6 @@ final class GeckoEditable
}
});
}
}
// InvocationHandler interface
@ -640,10 +640,8 @@ final class GeckoEditable
}
// Okay to remove immediately
mText.removeSpan(what);
if (mUpdateGecko) {
mActionQueue.offer(new Action(Action.TYPE_REMOVE_SPAN));
}
}
@Override
public void setSpan(Object what, int start, int end, int flags) {

Просмотреть файл

@ -64,6 +64,8 @@ class GeckoInputConnection
protected int mBatchEditCount;
private ExtractedTextRequest mUpdateRequest;
private final ExtractedText mUpdateExtract = new ExtractedText();
private boolean mBatchSelectionChanged;
private boolean mBatchTextChanged;
public static InputConnectionHandler create(View targetView,
GeckoEditableClient editable) {
@ -94,6 +96,16 @@ class GeckoInputConnection
if (mBatchEditCount > 0) {
mBatchEditCount--;
if (mBatchEditCount == 0) {
if (mBatchTextChanged) {
notifyTextChange();
mBatchTextChanged = false;
}
if (mBatchSelectionChanged) {
Editable editable = getEditable();
notifySelectionChange(Selection.getSelectionStart(editable),
Selection.getSelectionEnd(editable));
mBatchSelectionChanged = false;
}
mEditableClient.setUpdateGecko(true);
}
} else {
@ -191,10 +203,20 @@ class GeckoInputConnection
public void onTextChange(String text, int start, int oldEnd, int newEnd) {
if (mBatchEditCount > 0 || mUpdateRequest == null) {
if (mUpdateRequest == null) {
return;
}
if (mBatchEditCount > 0) {
// Delay notification until after the batch edit
mBatchTextChanged = true;
return;
}
notifyTextChange();
}
private void notifyTextChange() {
final InputMethodManager imm = getInputMethodManager();
if (imm == null) {
return;
@ -203,10 +225,9 @@ class GeckoInputConnection
final Editable editable = getEditable();
mUpdateExtract.flags = 0;
// Update from (0, oldEnd) to (0, newEnd) because some IMEs
// assume that updates start at zero, according to jchen.
mUpdateExtract.partialStartOffset = 0;
mUpdateExtract.partialEndOffset = editable.length();
// Update the entire Editable range
mUpdateExtract.partialStartOffset = -1;
mUpdateExtract.partialEndOffset = -1;
mUpdateExtract.selectionStart =
Selection.getSelectionStart(editable);
mUpdateExtract.selectionEnd =
@ -221,8 +242,15 @@ class GeckoInputConnection
public void onSelectionChange(int start, int end) {
if (mBatchEditCount > 0) {
// Delay notification until after the batch edit
mBatchSelectionChanged = true;
return;
}
notifySelectionChange(start, end);
}
private void notifySelectionChange(int start, int end) {
final InputMethodManager imm = getInputMethodManager();
if (imm == null) {
return;