Bug 1344464 - Part 1 - Restart input after removing autocomplete text for keyboards that require it. r=jchen
authorJan Henning <jh+bugzilla@buttercookie.de>
Sat, 04 Mar 2017 21:09:15 +0100
changeset 346096 960852d0618af7b66f38ae9c4990488b80b413de
parent 346095 08e4e7a7af7db6c071e275fb6f9b004fffd5cec0
child 346097 b83517442e4007dfe644b7fea14716dd3f6270b4
push id31459
push usercbook@mozilla.com
push dateTue, 07 Mar 2017 14:05:14 +0000
treeherdermozilla-central@1fb56ba248d5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjchen
bugs1344464
milestone54.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 1344464 - Part 1 - Restart input after removing autocomplete text for keyboards that require it. r=jchen When we detect text being deleted from the URL bar via setComposingText while we're displaying an autocomplete suggestion, we clear the autocomplete text and prevent the keyboard's delete from having any effect on the URL bar by returning false. Some keyboards might not handle this correctly and assume that they've in fact successfully set the new text, so the next time the user presses a key can lead to weird behaviour. As a workaround, we therefore additionally restart the input for affected keyboards. MozReview-Commit-ID: DucveafL3AB
mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarEditText.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/InputMethods.java
--- a/mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarEditText.java
+++ b/mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarEditText.java
@@ -434,20 +434,17 @@ public class ToolbarEditText extends Cus
             @Override
             public boolean deleteSurroundingText(final int beforeLength, final int afterLength) {
                 if (removeAutocomplete(getText())) {
                     // If we have autocomplete text, the cursor is at the boundary between
                     // regular and autocomplete text. So regardless of which direction we
                     // are deleting, we should delete the autocomplete text first.
                     // Make the IME aware that we interrupted the deleteSurroundingText call,
                     // by restarting the IME.
-                    final InputMethodManager imm = InputMethods.getInputMethodManager(mContext);
-                    if (imm != null) {
-                        imm.restartInput(ToolbarEditText.this);
-                    }
+                    InputMethods.restartInput(mContext, ToolbarEditText.this);
                     return false;
                 }
                 return super.deleteSurroundingText(beforeLength, afterLength);
             }
 
             private boolean removeAutocompleteOnComposing(final CharSequence text) {
                 final Editable editable = getText();
                 final int composingStart = BaseInputConnection.getComposingSpanStart(editable);
@@ -473,16 +470,19 @@ public class ToolbarEditText extends Cus
                     return false;
                 }
                 return super.commitText(text, newCursorPosition);
             }
 
             @Override
             public boolean setComposingText(final CharSequence text, final int newCursorPosition) {
                 if (removeAutocompleteOnComposing(text)) {
+                    if (InputMethods.needsRemoveAutocompleteHack(mContext)) {
+                        InputMethods.restartInput(mContext, ToolbarEditText.this);
+                    }
                     return false;
                 }
                 return super.setComposingText(text, newCursorPosition);
             }
         };
     }
 
     private class SelectionChangeListener implements OnSelectionChangedListener {
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/InputMethods.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/InputMethods.java
@@ -5,29 +5,31 @@
 
 package org.mozilla.gecko;
 
 import java.util.Collection;
 
 import android.content.Context;
 import android.os.Build;
 import android.provider.Settings.Secure;
+import android.view.View;
 import android.view.inputmethod.InputMethodInfo;
 import android.view.inputmethod.InputMethodManager;
 
 final public class InputMethods {
     public static final String METHOD_ANDROID_LATINIME = "com.android.inputmethod.latin/.LatinIME";
     public static final String METHOD_ATOK = "com.justsystems.atokmobile.service/.AtokInputMethodService";
     public static final String METHOD_GOOGLE_JAPANESE_INPUT = "com.google.android.inputmethod.japanese/.MozcService";
     public static final String METHOD_GOOGLE_LATINIME = "com.google.android.inputmethod.latin/com.android.inputmethod.latin.LatinIME";
     public static final String METHOD_HTC_TOUCH_INPUT = "com.htc.android.htcime/.HTCIMEService";
     public static final String METHOD_IWNN = "jp.co.omronsoft.iwnnime.ml/.standardcommon.IWnnLanguageSwitcher";
     public static final String METHOD_OPENWNN_PLUS = "com.owplus.ime.openwnnplus/.OpenWnnJAJP";
     public static final String METHOD_SAMSUNG = "com.sec.android.inputmethod/.SamsungKeypad";
     public static final String METHOD_SIMEJI = "com.adamrocker.android.input.simeji/.OpenWnnSimeji";
+    public static final String METHOD_SONY = "com.sonyericsson.textinput.uxp/.glue.InputMethodServiceGlue";
     public static final String METHOD_SWIFTKEY = "com.touchtype.swiftkey/com.touchtype.KeyboardService";
     public static final String METHOD_SWYPE = "com.swype.android.inputmethod/.SwypeInputMethod";
     public static final String METHOD_SWYPE_BETA = "com.nuance.swype.input/.IME";
     public static final String METHOD_TOUCHPAL_KEYBOARD = "com.cootek.smartinputv5/com.cootek.smartinput5.TouchPalIME";
 
     private InputMethods() {}
 
     public static String getCurrentInputMethod(Context context) {
@@ -45,19 +47,31 @@ final public class InputMethods {
         }
         return null;
     }
 
     public static InputMethodManager getInputMethodManager(Context context) {
         return (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
     }
 
+    public static void restartInput(Context context, View view) {
+        final InputMethodManager imm = getInputMethodManager(context);
+        if (imm != null) {
+            imm.restartInput(view);
+        }
+    }
+
     public static boolean needsSoftResetWorkaround(String inputMethod) {
         // Stock latin IME on Android 4.2 and above
         return Build.VERSION.SDK_INT >= 17 &&
                (METHOD_ANDROID_LATINIME.equals(inputMethod) ||
                 METHOD_GOOGLE_LATINIME.equals(inputMethod));
     }
 
     public static boolean shouldCommitCharAsKey(String inputMethod) {
         return METHOD_HTC_TOUCH_INPUT.equals(inputMethod);
     }
+
+    public static boolean needsRemoveAutocompleteHack(Context context) {
+        String inputMethod = getCurrentInputMethod(context);
+        return METHOD_SONY.equals(inputMethod);
+    }
 }