Bug 1236643 - Let GeckoInputConnection keep its view. r=esawin, a=sylvestre
authorJim Chen <nchen@mozilla.com>
Wed, 06 Jan 2016 21:33:18 -0500
changeset 310780 b0fbc87bf36137a4982f553e5e709e54b31690af
parent 310779 786ce281aa07bf6b5e07772969b635e6ffdd2dec
child 310781 af3852b5e3699bacbe04078a8f57b2a2aa5bad80
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersesawin, sylvestre
bugs1236643
milestone45.0a2
Bug 1236643 - Let GeckoInputConnection keep its view. r=esawin, a=sylvestre 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;
         }