Skip to content

Commit

Permalink
Allow asking the soft keyboard from the out side of the window widget
Browse files Browse the repository at this point in the history
This patch fixes the issue that Chromium doesn't type nothing in
the form. The problem was that the focused view notified from the
system is not involved in the window widget which the keyboard
widget is attached to. Since Chromium has a content view outside of
the windows widget's layer, the focus view could be different with
the window widget.

This patch allows asking the soft keyboard from the out side of
the window widget.
  • Loading branch information
MyidShin committed Feb 29, 2024
1 parent 4cc8c33 commit f7719cb
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
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

0 comments on commit f7719cb

Please sign in to comment.