commit 03c8946b9c54dc2387e9b8f22c2a6092bd4088b9
parent 68e4f843e64be5b82273e3b48cfc3522abf6a503
Author: Makoto Kato <m_kato@ga2.so-net.ne.jp>
Date: Thu, 20 Nov 2025 23:46:06 +0000
Bug 2000491 - Don't call toggleSoftInput twice during icRestartInput. r=geckoview-reviewers,ohall
`GeckoEditable.icRestartInput` might call `toggleSoftInput` twice. One
is by `TextInputDelegate.restartInput`. Another is a fallback path if
`restartInput` doesn't call `toggleSoftInput`.
Currently, even if `restatInput` calls `toggleSoftInput` via
`onCreateInputConnection`, we call toggleSoftInput after that. It is
unnecessary to call it twice, so we should avoid unnecessary calls.
Differential Revision: https://phabricator.services.mozilla.com/D272827
Diffstat:
1 file changed, 27 insertions(+), 2 deletions(-)
diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoEditable.java b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoEditable.java
@@ -112,6 +112,7 @@ import org.mozilla.geckoview.SessionTextInput.EditableListener.IMEState;
private String mIMEAutocapitalize = ""; // Used by IC thread.
private boolean mIMEAutocorrect = false; // Used by IC thread.
@IMEContextFlags private int mIMEFlags; // Used by IC thread.
+ private volatile boolean mIsNewICCreated = false; // Used by IC and UI
private boolean mIgnoreSelectionChange; // Used by Gecko thread
// Combined offsets from the previous batch of onTextChange calls; valid
@@ -1844,10 +1845,21 @@ import org.mozilla.geckoview.SessionTextInput.EditableListener.IMEState;
new Runnable() {
@Override
public void run() {
- if (DEBUG) {
- Log.d(LOGTAG, "restartInput(" + reason + ", " + toggleSoftInput + ')');
+ if (LOGGING) {
+ final StringBuilder sb = new StringBuilder("restartInput(reason=");
+ sb.append(
+ getConstantName(
+ GeckoSession.TextInputDelegate.class, "RESTART_REASON_", reason))
+ .append(", toggleSoftInput=")
+ .append(toggleSoftInput)
+ .append(")");
+ MozLog.d(LOGTAG, sb.toString());
}
+ // Avoid multiple toggleSoftInput call. If this becomes true, onCreateInputConnection is
+ // called.
+ mIsNewICCreated = false;
+
final GeckoSession session = mSession.get();
if (session != null) {
session.getTextInput().getDelegate().restartInput(session, reason);
@@ -1867,6 +1879,16 @@ import org.mozilla.geckoview.SessionTextInput.EditableListener.IMEState;
// mIMEState is not up-to-date here and we need to override it.
state = SessionTextInput.EditableListener.IME_STATE_DISABLED;
}
+ if (state != SessionTextInput.EditableListener.IME_STATE_DISABLED
+ && mIsNewICCreated) {
+ // If state isn't disabled, and new InputConnection is created during
+ // icRestartInput, we don't call toggleSoftInput twice.
+ return;
+ }
+
+ // Unnecessary to track onCreateInputConnection.
+ mIsNewICCreated = true;
+
toggleSoftInput(/* force */ false, state);
}
});
@@ -1883,6 +1905,9 @@ import org.mozilla.geckoview.SessionTextInput.EditableListener.IMEState;
boolean autocorrect = mIMEAutocorrect;
final int flags = mIMEFlags;
+ // New InputConnection is created.
+ mIsNewICCreated = true;
+
// Some keyboards require us to fill out outAttrs even if we return null.
outAttrs.imeOptions = EditorInfo.IME_ACTION_NONE;
outAttrs.actionLabel = null;