mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1152123 - Handle commit/cancel composition events in GeckoEditable; r=esawin
This commit is contained in:
parent
c3f6324cdd
commit
e07d962143
@ -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() {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user