Bug 1236643 - Let GeckoInputConnection keep its view; r=esawin
authorJim Chen <nchen@mozilla.com>
Wed, 06 Jan 2016 21:33:18 -0500
changeset 278908 ef20ed15509bd0a7f528a58bc2785db93be5de5c
parent 278907 df4a07a432dc657a8f73c593c56d931d22d2e0f0
child 278909 a7af5278a65735cbb9982a723c39889fccf1c367
push id29860
push usercbook@mozilla.com
push dateThu, 07 Jan 2016 10:51:20 +0000
treeherdermozilla-central@e0bcd16e1d4b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersesawin
bugs1236643
milestone46.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 1236643 - Let GeckoInputConnection keep its view; r=esawin Right now GeckoInputConnection uses GeckoAppShell to get its view, but it should be keeping its own View reference to support multiple GeckoViews.
mobile/android/base/java/org/mozilla/gecko/GeckoInputConnection.java
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoInputConnection.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoInputConnection.java
@@ -217,16 +217,17 @@ class GeckoInputConnection
     // Managed only by notifyIMEContext; see comments in notifyIMEContext
     private int mIMEState;
     private String mIMETypeHint = "";
     private String mIMEModeHint = "";
     private String mIMEActionHint = "";
 
     private String mCurrentInputMethod = "";
 
+    private final View mView;
     private final GeckoEditableClient mEditableClient;
     protected int mBatchEditCount;
     private ExtractedTextRequest mUpdateRequest;
     private final ExtractedText mUpdateExtract = new ExtractedText();
     private boolean mBatchSelectionChanged;
     private boolean mBatchTextChanged;
     private final InputConnection mKeyInputConnection;
 
@@ -236,16 +237,17 @@ class GeckoInputConnection
             return DebugGeckoInputConnection.create(targetView, editable);
         else
             return new GeckoInputConnection(targetView, editable);
     }
 
     protected GeckoInputConnection(View targetView,
                                    GeckoEditableClient editable) {
         super(targetView, true);
+        mView = targetView;
         mEditableClient = editable;
         mIMEState = IME_STATE_DISABLED;
         // InputConnection that sends keys for plugins, which don't have full editors
         mKeyInputConnection = new BaseInputConnection(targetView, false);
     }
 
     @Override
     public synchronized boolean beginBatchEdit() {
@@ -372,30 +374,30 @@ class GeckoInputConnection
         if ((req.flags & GET_TEXT_WITH_STYLES) != 0) {
             extract.text = new SpannableString(editable);
         } else {
             extract.text = editable.toString();
         }
         return extract;
     }
 
-    private static View getView() {
-        return GeckoAppShell.getLayerView();
+    private View getView() {
+        return mView;
     }
 
-    private static InputMethodManager getInputMethodManager() {
+    private InputMethodManager getInputMethodManager() {
         View view = getView();
         if (view == null) {
             return null;
         }
         Context context = view.getContext();
         return InputMethods.getInputMethodManager(context);
     }
 
-    private static void showSoftInput() {
+    private void showSoftInput() {
         final InputMethodManager imm = getInputMethodManager();
         if (imm != null) {
             final View v = getView();
 
             if (v.hasFocus() && !imm.isActive(v)) {
                 // Workaround: The view has focus but it is not the active view for the input method. (Bug 1211848)
                 refocusAndShowSoftInput(imm, v);
             } else {
@@ -411,17 +413,17 @@ class GeckoInputConnection
                 v.clearFocus();
                 v.requestFocus();
 
                 imm.showSoftInput(v, 0);
             }
         });
     }
 
-    private static void hideSoftInput() {
+    private void hideSoftInput() {
         final InputMethodManager imm = getInputMethodManager();
         if (imm != null) {
             final View v = getView();
             imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
         }
     }
 
     private void restartInput() {
@@ -679,17 +681,17 @@ class GeckoInputConnection
         else if (mIMEActionHint.equalsIgnoreCase("send"))
             outAttrs.imeOptions = EditorInfo.IME_ACTION_SEND;
         else if (mIMEActionHint.length() > 0) {
             if (DEBUG)
                 Log.w(LOGTAG, "Unexpected mIMEActionHint=\"" + mIMEActionHint + "\"");
             outAttrs.actionLabel = mIMEActionHint;
         }
 
-        Context context = GeckoAppShell.getContext();
+        Context context = getView().getContext();
         DisplayMetrics metrics = context.getResources().getDisplayMetrics();
         if (Math.min(metrics.widthPixels, metrics.heightPixels) > INLINE_IME_MIN_DISPLAY_SIZE) {
             // prevent showing full-screen keyboard only when the screen is tall enough
             // to show some reasonable amount of the page (see bug 752709)
             outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_EXTRACT_UI
                                    | EditorInfo.IME_FLAG_NO_FULLSCREEN;
         }