Bug 1152123 - Handle commit/cancel composition events in GeckoEditable; r=esawin

This commit is contained in:
Jim Chen 2015-04-15 15:21:32 -04:00
parent c3f6324cdd
commit e07d962143
2 changed files with 48 additions and 23 deletions

View File

@ -729,6 +729,46 @@ final class GeckoEditable
}
}
private void notifyCommitComposition() {
// Gecko already committed its composition, and
// we should remove the composition on our side as well.
boolean wasComposing = false;
final Object[] spans = mText.getSpans(0, mText.length(), Object.class);
for (Object span : spans) {
if ((mText.getSpanFlags(span) & Spanned.SPAN_COMPOSING) != 0) {
mText.removeSpan(span);
wasComposing = true;
}
}
if (!wasComposing) {
return;
}
// Generate a text change notification if we actually cleared the composition.
final CharSequence text = TextUtils.stringOrSpannedString(mText);
geckoPostToIc(new Runnable() {
@Override
public void run() {
mListener.onTextChange(text, 0, text.length(), text.length());
}
});
}
private void notifyCancelComposition() {
// Composition should have been cancelled on our side
// through text update notifications; verify that here.
if (DEBUG) {
final Object[] spans = mText.getSpans(0, mText.length(), Object.class);
for (Object span : spans) {
if ((mText.getSpanFlags(span) & Spanned.SPAN_COMPOSING) != 0) {
throw new IllegalStateException("composition not cancelled");
}
}
}
}
@Override
public void notifyIME(final int type) {
if (DEBUG) {
@ -741,6 +781,7 @@ final class GeckoEditable
")");
}
}
if (type == NOTIFY_IME_REPLY_EVENT) {
try {
if (mGeckoFocused) {
@ -756,7 +797,14 @@ final class GeckoEditable
mActionQueue.poll();
}
return;
} else if (type == NOTIFY_IME_TO_COMMIT_COMPOSITION) {
notifyCommitComposition();
return;
} else if (type == NOTIFY_IME_TO_CANCEL_COMPOSITION) {
notifyCancelComposition();
return;
}
geckoPostToIc(new Runnable() {
@Override
public void run() {

View File

@ -227,7 +227,6 @@ class GeckoInputConnection
private final ExtractedText mUpdateExtract = new ExtractedText();
private boolean mBatchSelectionChanged;
private boolean mBatchTextChanged;
private long mLastRestartInputTime;
private final InputConnection mKeyInputConnection;
public static GeckoEditableListener create(View targetView,
@ -383,19 +382,8 @@ class GeckoInputConnection
}
}
private void tryRestartInput() {
// Coalesce restartInput calls because InputMethodManager.restartInput()
// is expensive and successive calls to it can lock up the keyboard
if (SystemClock.uptimeMillis() < mLastRestartInputTime + 200) {
return;
}
restartInput();
}
private void restartInput() {
mLastRestartInputTime = SystemClock.uptimeMillis();
final InputMethodManager imm = getInputMethodManager();
if (imm == null) {
return;
@ -916,17 +904,6 @@ class GeckoInputConnection
public void notifyIME(int type) {
switch (type) {
case NOTIFY_IME_TO_CANCEL_COMPOSITION:
// Set composition to empty and end composition
setComposingText("", 0);
// Fall through
case NOTIFY_IME_TO_COMMIT_COMPOSITION:
// Commit and end composition
finishComposingText();
tryRestartInput();
break;
case NOTIFY_IME_OF_FOCUS:
case NOTIFY_IME_OF_BLUR:
// Showing/hiding vkb is done in notifyIMEContext