Bug 1256147 - Show/hide keyboard in onCreateInputConnection; r=esawin
authorJim Chen <nchen@mozilla.com>
Mon, 25 Apr 2016 12:51:12 -0400
changeset 294806 3ef32a2ed627d81db3eceeab8edfc7722096862a
parent 294805 de2849584be2b8aeb93259b2d543e25f5da1e22d
child 294807 9ee4cd959c9616c11054557c9cc81f6e63712235
push id30211
push userkwierso@gmail.com
push dateTue, 26 Apr 2016 00:12:12 +0000
treeherdermozilla-central@cfc7ebe59293 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersesawin
bugs1256147
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1256147 - Show/hide keyboard in onCreateInputConnection; r=esawin Showing and hiding the keyboard in onCreatInputConnection avoids a possible race with resetInput in notifyIMEContext, and it replaces the "show keyboard on window refocus" hack that we had before.
mobile/android/base/java/org/mozilla/gecko/GeckoInputConnection.java
mobile/android/base/java/org/mozilla/gecko/GeckoView.java
mobile/android/base/java/org/mozilla/gecko/InputConnectionListener.java
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoInputConnection.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoInputConnection.java
@@ -467,21 +467,20 @@ class GeckoInputConnection
 
         if (isPhysicalKeyboardPresent()) {
             return mEditableClient.setInputConnectionHandler(defHandler);
         }
 
         return mEditableClient.setInputConnectionHandler(getBackgroundHandler());
     }
 
-    private boolean mIsVisible = false;
-
     @Override
     public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
         if (mIMEState == IME_STATE_DISABLED) {
+            hideSoftInput();
             return null;
         }
 
         outAttrs.inputType = InputType.TYPE_CLASS_TEXT;
         outAttrs.imeOptions = EditorInfo.IME_ACTION_NONE;
         outAttrs.actionLabel = null;
 
         if (mIMEState == IME_STATE_PASSWORD ||
@@ -582,22 +581,17 @@ class GeckoInputConnection
             outAttrs.initialSelStart = 0;
             outAttrs.initialSelEnd = 0;
             return mKeyInputConnection;
         }
         Editable editable = getEditable();
         outAttrs.initialSelStart = Selection.getSelectionStart(editable);
         outAttrs.initialSelEnd = Selection.getSelectionEnd(editable);
 
-        if (mIsVisible) {
-            // The app has been brought to the foreground and the Soft Keyboard
-            // was previously visible, so request that it be shown again.
-            showSoftInput();
-        }
-
+        showSoftInput();
         return this;
     }
 
     private boolean replaceComposingSpanWithSelection() {
         final Editable content = getEditable();
         if (content == null) {
             return false;
         }
@@ -793,26 +787,16 @@ class GeckoInputConnection
         return processKey(KeyEvent.ACTION_DOWN, keyCode, event);
     }
 
     @Override
     public boolean onKeyUp(int keyCode, KeyEvent event) {
         return processKey(KeyEvent.ACTION_UP, keyCode, event);
     }
 
-    @Override
-    public void onWindowVisibilityChanged (int visibility) {
-        if (visibility == View.VISIBLE) {
-            mIsVisible = true;
-        } else {
-            mIsVisible = false;
-            hideSoftInput();
-        }
-    }
-
     /**
      * Get a key that represents a given character.
      */
     private KeyEvent getCharKeyEvent(final char c) {
         final long time = SystemClock.uptimeMillis();
         return new KeyEvent(time, time, KeyEvent.ACTION_MULTIPLE,
                             KeyEvent.KEYCODE_UNKNOWN, /* repeat */ 0) {
             @Override
@@ -931,21 +915,16 @@ class GeckoInputConnection
         if (v == null || !v.hasFocus()) {
             // When using Find In Page, we can still receive notifyIMEContext calls due to the
             // selection changing when highlighting. However in this case we don't want to reset/
             // show/hide the keyboard because the find box has the focus and is taking input from
             // the keyboard.
             return;
         }
         restartInput();
-        if (mIMEState == IME_STATE_DISABLED) {
-            hideSoftInput();
-        } else {
-            showSoftInput();
-        }
     }
 }
 
 final class DebugGeckoInputConnection
         extends GeckoInputConnection
         implements InvocationHandler {
 
     private InputConnection mProxy;
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoView.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoView.java
@@ -267,34 +267,18 @@ public class GeckoView extends LayerView
         } else {
             GeckoThread.queueNativeCallUntil(GeckoThread.State.PROFILE_READY,
                     window, "close");
             GeckoThread.queueNativeCallUntil(GeckoThread.State.PROFILE_READY,
                     window, "disposeNative");
         }
     }
 
-    private int mLastVisibility = View.GONE;
-
     /* package */ void setInputConnectionListener(final InputConnectionListener icl) {
         mInputConnectionListener = icl;
-        if (mInputConnectionListener != null) {
-            mInputConnectionListener.onWindowVisibilityChanged(mLastVisibility);
-        }
-    }
-
-    @Override
-    protected void onWindowVisibilityChanged (int visibility) {
-        mLastVisibility = visibility;
-
-        if (mInputConnectionListener != null) {
-            mInputConnectionListener.onWindowVisibilityChanged(visibility);
-        }
-
-        super.onWindowVisibilityChanged(visibility);
     }
 
     @Override
     public Handler getHandler() {
         if (mInputConnectionListener != null) {
             return mInputConnectionListener.getHandler(super.getHandler());
         }
         return super.getHandler();
--- a/mobile/android/base/java/org/mozilla/gecko/InputConnectionListener.java
+++ b/mobile/android/base/java/org/mozilla/gecko/InputConnectionListener.java
@@ -16,11 +16,10 @@ interface InputConnectionListener
 {
     Handler getHandler(Handler defHandler);
     InputConnection onCreateInputConnection(EditorInfo outAttrs);
     boolean onKeyPreIme(int keyCode, KeyEvent event);
     boolean onKeyDown(int keyCode, KeyEvent event);
     boolean onKeyLongPress(int keyCode, KeyEvent event);
     boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event);
     boolean onKeyUp(int keyCode, KeyEvent event);
-    void onWindowVisibilityChanged (int visibility);
     boolean isIMEEnabled();
 }