Bug 810821 - Only change focus if awesomebar text field responded to key press; r=cpeterson a=akeybl
☠☠ backed out by ef6e99740705 ☠ ☠
authorJim Chen <nchen@mozilla.com>
Mon, 17 Dec 2012 11:36:42 -0500
changeset 118887 aef21af0f7ae80cbb5e07acd0d74fe2604d1f83c
parent 118886 1736e9ff15760a5306b3bfaf2fd2655d9b917432
child 118888 ef6e99740705329c7215adc4cdec67fddaf12202
push idunknown
push userunknown
push dateunknown
reviewerscpeterson, akeybl
bugs810821
milestone19.0a2
Bug 810821 - Only change focus if awesomebar text field responded to key press; r=cpeterson a=akeybl
mobile/android/base/AwesomeBar.java
--- a/mobile/android/base/AwesomeBar.java
+++ b/mobile/android/base/AwesomeBar.java
@@ -420,38 +420,30 @@ public class AwesomeBar extends GeckoAct
             return super.onKeyDown(keyCode, event);
         } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
              mText.setText("");
              mText.requestFocus();
              InputMethodManager imm = (InputMethodManager) mText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
              imm.showSoftInput(mText, InputMethodManager.SHOW_IMPLICIT);
              return true;
         } else {
-            int selStart = -1;
-            int selEnd = -1;
-            if (mText.hasSelection()) {
-                selStart = mText.getSelectionStart();
-                selEnd = mText.getSelectionEnd();
-            }
+            int prevSelStart = mText.getSelectionStart();
+            int prevSelEnd = mText.getSelectionEnd();
+
+            // Manually dispatch the key event to the AwesomeBar. If selection changed as
+            // a result of the key event, then give focus back to mText
+            mText.dispatchKeyEvent(event);
 
-            if (selStart >= 0) {
+            int curSelStart = mText.getSelectionStart();
+            int curSelEnd = mText.getSelectionEnd();
+            if (prevSelStart != curSelStart || prevSelEnd != curSelEnd) {
+                mText.requestFocusFromTouch();
                 // Restore the selection, which gets lost due to the focus switch
-                mText.setSelection(selStart, selEnd);
+                mText.setSelection(curSelStart, curSelEnd);
             }
-
-            // Manually dispatch the key event to the AwesomeBar before restoring (default) input
-            // focus. dispatchKeyEvent() will update AwesomeBar's cursor position.
-            mText.dispatchKeyEvent(event);
-            int newCursorPos = mText.getSelectionEnd();
-
-            // requestFocusFromTouch() will select all AwesomeBar text, so we must restore cursor
-            // position so subsequent typing does not overwrite all text.
-            mText.requestFocusFromTouch();
-            mText.setSelection(newCursorPos);
-
             return true;
         }
     }
 
     @Override
     public void onResume() {
         super.onResume();
         if (mText != null && mText.getText() != null)