Bug 1699022 - Set surrounding text on onCreateInputConnection. r=geckoview-reviewers,agi

Android R+ has new API to set initial surrounding text.

According to Android commit log [*], it can improve IME start up performance
when setting initial surrounding text that is new API from Android API 30.

* c486acc4d2

Differential Revision: https://phabricator.services.mozilla.com/D108736
This commit is contained in:
Makoto Kato 2021-03-18 03:18:37 +00:00
parent 9a4563134c
commit 2f96cd0e52

View File

@ -24,6 +24,7 @@ import org.mozilla.gecko.util.ThreadUtils;
import org.mozilla.gecko.util.ThreadUtils.AssertBehavior;
import android.graphics.RectF;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
@ -1696,6 +1697,13 @@ import android.view.inputmethod.EditorInfo;
outAttrs.imeOptions |= InputMethods.IME_FLAG_NO_PERSONALIZED_LEARNING;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
final Spanned currentText = mText.getCurrentText();
outAttrs.initialSelStart = Selection.getSelectionStart(currentText);
outAttrs.initialSelEnd = Selection.getSelectionEnd(currentText);
outAttrs.setInitialSurroundingText(currentText);
}
toggleSoftInput(/* force */ false, state);
}