зеркало из https://github.com/mozilla/gecko-dev.git
Bug 810170 - Properly handle extracted text notification and selection notification; r=cpeterson
This commit is contained in:
Родитель
cfce24e060
Коммит
c1723ffee1
|
@ -553,14 +553,14 @@ final class GeckoEditable
|
|||
}
|
||||
} else {
|
||||
mText.replace(start, oldEnd, text, 0, text.length());
|
||||
geckoPostToUI(new Runnable() {
|
||||
public void run() {
|
||||
if (mListener != null) {
|
||||
mListener.onTextChange(text, start, oldEnd, newEnd);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
geckoPostToUI(new Runnable() {
|
||||
public void run() {
|
||||
if (mListener != null) {
|
||||
mListener.onTextChange(text, start, oldEnd, newEnd);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// InvocationHandler interface
|
||||
|
@ -640,9 +640,7 @@ final class GeckoEditable
|
|||
}
|
||||
// Okay to remove immediately
|
||||
mText.removeSpan(what);
|
||||
if (mUpdateGecko) {
|
||||
mActionQueue.offer(new Action(Action.TYPE_REMOVE_SPAN));
|
||||
}
|
||||
mActionQueue.offer(new Action(Action.TYPE_REMOVE_SPAN));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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;
|
||||
|
|
Загрузка…
Ссылка в новой задаче