Bug 1396951 - 2. Don't use getLayerView() in GeckoInputConnection; r?esawin draft
authorJim Chen <nchen@mozilla.com>
Fri, 22 Sep 2017 14:35:22 -0400
changeset 669223 751c731fbc6ee85b972e29a8a02abfcacaf16f6a
parent 669222 017ef992e6f0a04fb7792619754802614c675eba
child 669224 27aa264d8a3493f6a2df6a38a5394991825ad995
push id81260
push userbmo:nchen@mozilla.com
push dateFri, 22 Sep 2017 18:35:47 +0000
reviewersesawin
bugs1396951
milestone58.0a1
Bug 1396951 - 2. Don't use getLayerView() in GeckoInputConnection; r?esawin In GeckoInputConnection, use the current view available through `getView()`, instead of using `GeckoAppShell.getLayerView()`. MozReview-Commit-ID: Hc9AUz5SNEs
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoInputConnection.java
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoInputConnection.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoInputConnection.java
@@ -67,36 +67,36 @@ class GeckoInputConnection
     private String mIMEModeHint = "";
     private String mIMEActionHint = "";
     private boolean mInPrivateBrowsing;
     private boolean mIsUserAction;
     private boolean mFocused;
 
     private String mCurrentInputMethod = "";
 
-    private final View mView;
+    private final GeckoView mView;
     private final GeckoEditableClient mEditableClient;
     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;
 
-    public static GeckoEditableListener create(View targetView,
+    public static GeckoEditableListener create(GeckoView targetView,
                                                GeckoEditableClient editable) {
         if (DEBUG)
             return DebugGeckoInputConnection.create(targetView, editable);
         else
             return new GeckoInputConnection(targetView, editable);
     }
 
-    protected GeckoInputConnection(View targetView,
+    protected GeckoInputConnection(GeckoView 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);
     }
@@ -199,17 +199,17 @@ class GeckoInputConnection
         if ((req.flags & GET_TEXT_WITH_STYLES) != 0) {
             extract.text = new SpannableString(editable);
         } else {
             extract.text = editable.toString();
         }
         return extract;
     }
 
-    private View getView() {
+    private GeckoView getView() {
         return mView;
     }
 
     private InputMethodManager getInputMethodManager() {
         View view = getView();
         if (view == null) {
             return null;
         }
@@ -231,17 +231,20 @@ class GeckoInputConnection
             @Override
             public void run() {
                 if (v.hasFocus() && !imm.isActive(v)) {
                     // Marshmallow workaround: The view has focus but it is not the active
                     // view for the input method. (Bug 1211848)
                     v.clearFocus();
                     v.requestFocus();
                 }
-                GeckoAppShell.getLayerView().getDynamicToolbarAnimator().showToolbar(/*immediately*/true);
+                final GeckoView view = getView();
+                if (view != null) {
+                    view.getDynamicToolbarAnimator().showToolbar(/*immediately*/ true);
+                }
                 mSoftInputReentrancyGuard = true;
                 imm.showSoftInput(v, 0);
                 mSoftInputReentrancyGuard = false;
             }
         });
     }
 
     private void hideSoftInput() {
@@ -354,28 +357,28 @@ class GeckoInputConnection
         }
 
         if (mCursorAnchorInfoBuilder == null) {
             mCursorAnchorInfoBuilder = new CursorAnchorInfo.Builder();
         }
         mCursorAnchorInfoBuilder.reset();
 
         // Calculate Gecko logical coords to screen coords
-        final View v = getView();
-        if (v == null) {
+        final GeckoView view = getView();
+        if (view == null) {
             return;
         }
 
         int[] viewCoords = new int[2];
-        v.getLocationOnScreen(viewCoords);
+        view.getLocationOnScreen(viewCoords);
 
-        DynamicToolbarAnimator animator = GeckoAppShell.getLayerView().getDynamicToolbarAnimator();
-        float toolbarHeight = (float)animator.getCurrentToolbarHeight();
+        DynamicToolbarAnimator animator = view.getDynamicToolbarAnimator();
+        float toolbarHeight = (float) animator.getCurrentToolbarHeight();
 
-        Matrix matrix = GeckoAppShell.getLayerView().getMatrixForLayerRectToViewRect();
+        Matrix matrix = view.getMatrixForLayerRectToViewRect();
         if (matrix == null) {
             if (DEBUG) {
                 Log.d(LOGTAG, "Cannot get Matrix to convert from Gecko coords to layer view coords");
             }
             return;
         }
         matrix.postTranslate(viewCoords[0], viewCoords[1] + toolbarHeight);
         mCursorAnchorInfoBuilder.setMatrix(matrix);
@@ -1029,23 +1032,23 @@ class GeckoInputConnection
 
 final class DebugGeckoInputConnection
         extends GeckoInputConnection
         implements InvocationHandler {
 
     private InputConnection mProxy;
     private final StringBuilder mCallLevel;
 
-    private DebugGeckoInputConnection(View targetView,
+    private DebugGeckoInputConnection(GeckoView targetView,
                                       GeckoEditableClient editable) {
         super(targetView, editable);
         mCallLevel = new StringBuilder();
     }
 
-    public static GeckoEditableListener create(View targetView,
+    public static GeckoEditableListener create(GeckoView targetView,
                                                GeckoEditableClient editable) {
         final Class<?>[] PROXY_INTERFACES = { InputConnection.class,
                 InputConnectionListener.class,
                 GeckoEditableListener.class };
         DebugGeckoInputConnection dgic =
                 new DebugGeckoInputConnection(targetView, editable);
         dgic.mProxy = (InputConnection)Proxy.newProxyInstance(
                 GeckoInputConnection.class.getClassLoader(),