Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow asking the soft keyboard from outside the window widget #1278

Merged
merged 2 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void showSoftInput(final View view, int flags, ResultReceiver resultRecei
EditorInfo outAttrs = new EditorInfo();
view.onCreateInputConnection(outAttrs);
if (mDelegate != null)
mDelegate.showSoftInput(mSession);
mDelegate.showSoftInput(mSession, (View) mSession.getContentView());

// We don't take content space for the keyboard, and we report back to the ImeAdapter
// that the keyboard was always showing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void restartInput(@NonNull GeckoSession session, int reason) {

@Override
public void showSoftInput(@NonNull GeckoSession session) {
mDelegate.showSoftInput(mSession);
mDelegate.showSoftInput(mSession, null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.os.Build;
import android.view.PointerIcon;
import android.view.Surface;
import android.view.View;
import android.view.inputmethod.CursorAnchorInfo;
import android.view.inputmethod.ExtractedText;
import android.view.inputmethod.ExtractedTextRequest;
Expand Down Expand Up @@ -1761,10 +1762,16 @@ default void restartInput(
* This method is always called, even in viewless mode.
*
* @param session Session instance.
* @param requestView View requesting the soft input. This can be set to allow the soft
* keyboard to be requested from a view that exist outside a hierarchy of
* the window widget which the keyboard widget is attached to.
* If this is null, this method will treat the focused view is the window
* widget.
* @see #hideSoftInput
*/

@UiThread
default void showSoftInput(@NonNull final WSession session) {}
default void showSoftInput(@NonNull final WSession session, @Nullable View requestView) {}

/**
* Hide the soft input. May be called consecutively, even if the soft input is already hidden.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import androidx.preference.PreferenceManager;
import android.util.Log;
import android.view.Surface;
import android.view.View;
import android.view.inputmethod.CursorAnchorInfo;
import android.view.inputmethod.ExtractedText;
import android.view.inputmethod.ExtractedTextRequest;
Expand Down Expand Up @@ -1433,11 +1434,11 @@ public void restartInput(@NonNull WSession aSession, int reason) {
}

@Override
public void showSoftInput(@NonNull WSession aSession) {
public void showSoftInput(@NonNull WSession aSession, @Nullable View requestView) {
if (mState.mSession == aSession) {
mState.mIsInputActive = true;
for (WSession.TextInputDelegate listener : mTextInputListeners) {
listener.showSoftInput(aSession);
listener.showSoftInput(aSession, requestView);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public class KeyboardWidget extends UIWidget implements CustomKeyboardView.OnKey
private Drawable mShiftDisabledIcon;
private Drawable mCapsLockOnIcon;
private View mFocusedView;
private View mExternalFocusedView;
private LinearLayout mKeyboardLayout;
private RelativeLayout mKeyboardContainer;
private WindowWidget mAttachedWindow;
Expand Down Expand Up @@ -1373,9 +1374,12 @@ public void restartInput(@NonNull WSession session, int reason) {
}

@Override
public void showSoftInput(@NonNull WSession session) {
public void showSoftInput(@NonNull WSession session, View requestView) {
mExternalFocusedView = requestView;
if (mFocusedView != mAttachedWindow || getVisibility() != View.VISIBLE || mInputRestarted) {
post(() -> updateFocusedView(mAttachedWindow));
post(() -> {
updateFocusedView(mAttachedWindow);
});
}
mInputRestarted = false;
}
Expand Down Expand Up @@ -1409,7 +1413,10 @@ public void run() {

@Override
public void onGlobalFocusChanged(View oldFocus, View newFocus) {
updateFocusedView(newFocus);
if (mExternalFocusedView == newFocus)
updateFocusedView(mAttachedWindow);
else
updateFocusedView(newFocus);
}


Expand Down