Bug 1438682 - 1. Cache initial selection offsets; r?esawin draft
authorJim Chen <nchen@mozilla.com>
Thu, 15 Feb 2018 18:06:06 -0500
changeset 755909 3242b98e077c39f773457c40685a397b29576361
parent 755345 5adf396b4503aed14034ef3e9bc299c4733d968b
child 755910 27bd59045a7121c1b0026484af69453a05b4a44e
push id99318
push userbmo:nchen@mozilla.com
push dateThu, 15 Feb 2018 23:06:47 +0000
reviewersesawin
bugs1438682
milestone60.0a1
Bug 1438682 - 1. Cache initial selection offsets; r?esawin Getting the selection offsets in onCreateInputConnection can fail because of us being on a wrong thread. The solution is to cache the last selection offsets and use those in onCreateInputConnection. MozReview-Commit-ID: AOlZsuOvzHm
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
@@ -62,16 +62,18 @@ import android.view.inputmethod.InputMet
 
     // Managed only by notifyIMEContext; see comments in notifyIMEContext
     private int mIMEState;
     private String mIMETypeHint = "";
     private String mIMEModeHint = "";
     private String mIMEActionHint = "";
     private int mIMEFlags;
     private boolean mFocused;
+    private int mLastSelectionStart;
+    private int mLastSelectionEnd;
 
     private String mCurrentInputMethod = "";
 
     private final GeckoSession mSession;
     private final View mView;
     private final TextInputController.EditableClient mEditableClient;
     protected int mBatchEditCount;
     private ExtractedTextRequest mUpdateRequest;
@@ -334,18 +336,19 @@ import android.view.inputmethod.InputMet
         imm.updateExtractedText(v, mUpdateRequest.token, mUpdateExtract);
     }
 
     @Override // TextInputController.EditableListener
     public void onSelectionChange() {
 
         final Editable editable = getEditable();
         if (editable != null) {
-            notifySelectionChange(Selection.getSelectionStart(editable),
-                                  Selection.getSelectionEnd(editable));
+            mLastSelectionStart = Selection.getSelectionStart(editable);
+            mLastSelectionEnd = Selection.getSelectionEnd(editable);
+            notifySelectionChange(mLastSelectionStart, mLastSelectionEnd);
         }
     }
 
     private void notifySelectionChange(int start, int end) {
 
         final InputMethodManager imm = getInputMethodManager();
         final View v = getView();
         final Editable editable = getEditable();
@@ -635,19 +638,18 @@ import android.view.inputmethod.InputMet
         }
 
         String prevInputMethod = mCurrentInputMethod;
         mCurrentInputMethod = InputMethods.getCurrentInputMethod(context);
         if (DEBUG) {
             Log.d(LOGTAG, "IME: CurrentInputMethod=" + mCurrentInputMethod);
         }
 
-        Editable editable = getEditable();
-        outAttrs.initialSelStart = Selection.getSelectionStart(editable);
-        outAttrs.initialSelEnd = Selection.getSelectionEnd(editable);
+        outAttrs.initialSelStart = mLastSelectionStart;
+        outAttrs.initialSelEnd = mLastSelectionEnd;
 
         if ((mIMEFlags & IME_FLAG_USER_ACTION) != 0) {
             if ((context instanceof Activity) &&
                     ActivityUtils.isFullScreen((Activity) context)) {
                 showSoftInputWithToolbar(false);
             } else {
                 showSoftInputWithToolbar(true);
             }