Bug 1450142 - Add setShowSoftInputOnFocus() to TextInputController r=jchen,droeh
MozReview-Commit-ID: 81La5KdeA6z
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoInputConnection.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoInputConnection.java
@@ -80,16 +80,17 @@ import java.lang.reflect.Proxy;
protected int mBatchEditCount;
private ExtractedTextRequest mUpdateRequest;
private final ExtractedText mUpdateExtract = new ExtractedText();
private final InputConnection mKeyInputConnection;
private CursorAnchorInfo.Builder mCursorAnchorInfoBuilder;
// Prevent showSoftInput and hideSoftInput from causing reentrant calls on some devices.
private volatile boolean mSoftInputReentrancyGuard;
+ private boolean mShowSoftInputOnFocus = true;
public static SessionTextInput.Delegate create(
final GeckoSession session,
final View targetView,
final SessionTextInput.EditableClient editable) {
SessionTextInput.Delegate ic = new GeckoInputConnection(session, targetView, editable);
if (DEBUG) {
ic = wrapForDebug(ic);
@@ -281,16 +282,19 @@ import java.lang.reflect.Proxy;
if (view == null) {
return null;
}
Context context = view.getContext();
return InputMethods.getInputMethodManager(context);
}
private void showSoftInputWithToolbar(final boolean showToolbar) {
+ if (!mShowSoftInputOnFocus) {
+ return;
+ }
if (mSoftInputReentrancyGuard) {
return;
}
final View v = getView();
final InputMethodManager imm = getInputMethodManager();
if (v == null || imm == null) {
return;
}
@@ -968,32 +972,40 @@ import java.lang.reflect.Proxy;
return true;
}
@Override // SessionTextInput.Delegate
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
View v = getView();
switch (keyCode) {
case KeyEvent.KEYCODE_MENU:
+ if (!mShowSoftInputOnFocus) {
+ return false;
+ }
InputMethodManager imm = getInputMethodManager();
imm.toggleSoftInputFromWindow(v.getWindowToken(),
InputMethodManager.SHOW_FORCED, 0);
return true;
default:
break;
}
return false;
}
@Override // SessionTextInput.Delegate
public synchronized boolean isInputActive() {
// Make sure this picks up PASSWORD state as well.
return mIMEState != IME_STATE_DISABLED;
}
+ @Override // SessionTextInput.Delegate
+ public void setShowSoftInputOnFocus(final boolean showSoftInputOnFocus) {
+ mShowSoftInputOnFocus = showSoftInputOnFocus;
+ }
+
@Override // SessionTextInput.EditableListener
public void notifyIME(int type) {
switch (type) {
case NOTIFY_IME_OF_FOCUS:
// Showing/hiding vkb is done in notifyIMEContext
mFocused = true;
resetInputConnection();
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/SessionTextInput.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/SessionTextInput.java
@@ -35,16 +35,17 @@ public final class SessionTextInput {
Handler getHandler(Handler defHandler);
InputConnection onCreateInputConnection(EditorInfo attrs);
boolean onKeyPreIme(int keyCode, KeyEvent event);
boolean onKeyDown(int keyCode, KeyEvent event);
boolean onKeyUp(int keyCode, KeyEvent event);
boolean onKeyLongPress(int keyCode, KeyEvent event);
boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event);
boolean isInputActive();
+ void setShowSoftInputOnFocus(boolean showSoftInputOnFocus);
}
// Interface to access GeckoEditable from GeckoInputConnection.
/* package */ interface EditableClient {
// The following value is used by requestCursorUpdates
// ONE_SHOT calls updateCompositionRects() after getting current composing
// character rects.
@WrapForJNI final int ONE_SHOT = 1;
@@ -91,16 +92,17 @@ public final class SessionTextInput {
void onDefaultKeyEvent(KeyEvent event);
void updateCompositionRects(final RectF[] aRects);
}
private final GeckoSession mSession;
private final NativeQueue mQueue;
private final GeckoEditable mEditable = new GeckoEditable();
private final GeckoEditableChild mEditableChild = new GeckoEditableChild(mEditable);
+ private boolean mShowSoftInputOnFocus = true;
private Delegate mInputConnection;
/* package */ SessionTextInput(final @NonNull GeckoSession session,
final @NonNull NativeQueue queue) {
mSession = session;
mQueue = queue;
mEditable.setDefaultEditableChild(mEditableChild);
}
@@ -145,16 +147,17 @@ public final class SessionTextInput {
if (!mQueue.isReady()) {
return false;
}
if (mInputConnection == null) {
mInputConnection = GeckoInputConnection.create(mSession,
/* view */ null,
mEditable);
+ mInputConnection.setShowSoftInputOnFocus(mShowSoftInputOnFocus);
mEditable.setListener((EditableListener) mInputConnection);
}
return true;
}
/**
* Get the current View for text input.
*
@@ -174,16 +177,17 @@ public final class SessionTextInput {
*/
public synchronized void setView(final @Nullable View view) {
ThreadUtils.assertOnUiThread();
if (view == null) {
mInputConnection = null;
} else if (mInputConnection == null || mInputConnection.getView() != view) {
mInputConnection = GeckoInputConnection.create(mSession, view, mEditable);
+ mInputConnection.setShowSoftInputOnFocus(mShowSoftInputOnFocus);
}
mEditable.setListener((EditableListener) mInputConnection);
}
/**
* Get an InputConnection instance. For full functionality, call {@link
* #setView(View)} first before calling this method.
*
@@ -280,9 +284,21 @@ public final class SessionTextInput {
* focused input field.
*
* @return True if input is active.
*/
public boolean isInputActive() {
ThreadUtils.assertOnUiThread();
return mInputConnection != null && mInputConnection.isInputActive();
}
+
+ /**
+ * Prevent soft input when gaining focus
+ *
+ * @param showSoftInputOnFocus If true, soft input will be shown on focus
+ */
+ public void setShowSoftInputOnFocus(boolean showSoftInputOnFocus) {
+ mShowSoftInputOnFocus = showSoftInputOnFocus;
+ if (mInputConnection != null) {
+ mInputConnection.setShowSoftInputOnFocus(showSoftInputOnFocus);
+ }
+ }
}