Bug 1344464 - Part 1: Restart input after removing autocomplete text for keyboards that require it. r=jchen, a=ritu
authorJan Henning <jh+bugzilla@buttercookie.de>
Sat, 04 Mar 2017 21:09:15 +0100
changeset 378979 72774ba28bbb000b0456dbc9cbf3250142b799de
parent 378978 27b7ba43c5af090e4fa138038ff3fa774e486595
child 378980 725b9ae87b49c35f61063a856547d88b897a663d
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjchen, ritu
bugs1344464
milestone53.0
Bug 1344464 - Part 1: Restart input after removing autocomplete text for keyboards that require it. r=jchen, a=ritu 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);
+    }
 }