Bug 945521 - Make sure button text type is consistent with keyboard text type. r=mcomella, a=lsblakk
authorJim Chen <nchen@mozilla.com>
Fri, 20 Dec 2013 17:48:59 -0500
changeset 175535 35e2fe893f945fb0df758e6e0c0214b9073a5933
parent 175534 97d982371403f6ff5ab74525193d016bffcf9e30
child 175536 5a1f8b015361e6e87213a0f7229ba523f3572ab0
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcomella, lsblakk
bugs945521
milestone28.0a2
Bug 945521 - Make sure button text type is consistent with keyboard text type. r=mcomella, a=lsblakk
mobile/android/base/InputMethods.java
mobile/android/base/toolbar/ToolbarEditText.java
--- a/mobile/android/base/InputMethods.java
+++ b/mobile/android/base/InputMethods.java
@@ -61,16 +61,17 @@ final public class InputMethods {
 
     public static boolean shouldCommitCharAsKey(String inputMethod) {
         return METHOD_HTC_TOUCH_INPUT.equals(inputMethod);
     }
 
     @RobocopTarget
     public static boolean shouldDisableUrlBarUpdate(Context context) {
         String inputMethod = getCurrentInputMethod(context);
+        // HTC Touch Input does not react well to restarting during input (bug 909940)
         return METHOD_HTC_TOUCH_INPUT.equals(inputMethod);
     }
 
     public static boolean shouldDelayUrlBarUpdate(Context context) {
         String inputMethod = getCurrentInputMethod(context);
         return METHOD_SAMSUNG.equals(inputMethod) ||
                METHOD_SWIFTKEY.equals(inputMethod);
     }
--- a/mobile/android/base/toolbar/ToolbarEditText.java
+++ b/mobile/android/base/toolbar/ToolbarEditText.java
@@ -42,17 +42,20 @@ public class ToolbarEditText extends Cus
     }
 
     interface OnTextTypeChangeListener {
         public void onTextTypeChange(ToolbarEditText editText, TextType textType);
     }
 
     private final Context mContext;
 
-    private TextType mTextType;
+    // Type of the URL bar go/search button
+    private TextType mToolbarTextType;
+    // Type of the keyboard go/search button (cannot be EMPTY)
+    private TextType mKeyboardTextType;
 
     private OnCommitListener mCommitListener;
     private OnDismissListener mDismissListener;
     private OnFilterListener mFilterListener;
     private OnTextTypeChangeListener mTextTypeListener;
 
     // The previous autocomplete result returned to us
     private String mAutoCompleteResult = "";
@@ -61,17 +64,18 @@ public class ToolbarEditText extends Cus
     private String mAutoCompletePrefix = null;
 
     private boolean mDelayRestartInput;
 
     public ToolbarEditText(Context context, AttributeSet attrs) {
         super(context, attrs);
         mContext = context;
 
-        mTextType = TextType.EMPTY;
+        mToolbarTextType = TextType.EMPTY;
+        mKeyboardTextType = TextType.URL;
     }
 
     void setOnCommitListener(OnCommitListener listener) {
         mCommitListener = listener;
     }
 
     void setOnDismissListener(OnDismissListener listener) {
         mDismissListener = listener;
@@ -167,30 +171,35 @@ public class ToolbarEditText extends Cus
                 }
             }
         }
 
         return false;
     }
 
     private void setTextType(TextType textType) {
-        mTextType = textType;
+        mToolbarTextType = textType;
 
+        if (textType != TextType.EMPTY) {
+            mKeyboardTextType = textType;
+        }
         if (mTextTypeListener != null) {
-            mTextTypeListener.onTextTypeChange(this, mTextType);
+            mTextTypeListener.onTextTypeChange(this, textType);
         }
     }
 
     private void updateTextTypeFromText(String text) {
         if (text.length() == 0) {
             setTextType(TextType.EMPTY);
             return;
         }
 
         if (InputMethods.shouldDisableUrlBarUpdate(mContext)) {
+            // Set button type to match the previous keyboard type
+            setTextType(mKeyboardTextType);
             return;
         }
 
         final int actionBits = getImeOptions() & EditorInfo.IME_MASK_ACTION;
 
         final int imeAction;
         if (StringUtils.isSearchQuery(text, actionBits == EditorInfo.IME_ACTION_SEARCH)) {
             imeAction = EditorInfo.IME_ACTION_SEARCH;
@@ -217,20 +226,26 @@ public class ToolbarEditText extends Cus
         } else if (mDelayRestartInput) {
             // Only call delayed restartInput when actionBits == imeAction
             // so if there are two restarts in a row, the first restarts will
             // be discarded and the second restart will be properly delayed
             mDelayRestartInput = false;
             restartInput = true;
         }
 
-        if (restartInput) {
-            updateKeyboardInputType();
-            imm.restartInput(ToolbarEditText.this);
+        if (!restartInput) {
+            // If the text content was previously empty, the toolbar text type
+            // is empty as well. Since the keyboard text type cannot be empty,
+            // the two text types are now inconsistent. Reset the toolbar text
+            // type here to the keyboard text type to ensure consistency.
+            setTextType(mKeyboardTextType);
+            return;
         }
+        updateKeyboardInputType();
+        imm.restartInput(ToolbarEditText.this);
 
         setTextType(imeAction == EditorInfo.IME_ACTION_GO ?
                     TextType.URL : TextType.SEARCH_QUERY);
     }
 
     private class TextChangeListener implements TextWatcher {
         @Override
         public void afterTextChanged(final Editable s) {