Bug 726393 - Fetch Android's cached TextKeyListener on key down/up events to avoid nulls. r=blassey, f=gbrown
authorChris Peterson <cpeterson@mozilla.com>
Mon, 12 Mar 2012 16:02:06 -0700
changeset 89408 30a16e96d2f9ce527516df0f154a39ff87b6e9d5
parent 89407 11a5cc8bb70a5804bd2df8e21b54636a3d5e0bbd
child 89409 cb66ae517284fae3162cedeb78a3687fbfa0173d
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersblassey
bugs726393
milestone14.0a1
Bug 726393 - Fetch Android's cached TextKeyListener on key down/up events to avoid nulls. r=blassey, f=gbrown
mobile/android/base/GeckoInputConnection.java
--- a/mobile/android/base/GeckoInputConnection.java
+++ b/mobile/android/base/GeckoInputConnection.java
@@ -95,17 +95,16 @@ public class GeckoInputConnection
     private static int mIMEState;
     private static String mIMETypeHint;
     private static String mIMEActionHint;
     private static boolean mIMELandscapeFS;
 
     // Is a composition active?
     private boolean mComposing;
     private int mCompositionStart = -1;
-    private KeyListener mKeyListener;
     private Editable mEditable;
     private Editable.Factory mEditableFactory;
     private boolean mBatchMode;
     private ExtractedTextRequest mUpdateRequest;
     private final ExtractedText mUpdateExtract = new ExtractedText();
     private int mSelectionStart;
     private int mSelectionLength;
     private final SynchronousQueue<String> mQueryResult = new SynchronousQueue<String>();
@@ -706,17 +705,16 @@ public class GeckoInputConnection
 
     public void beforeTextChanged(CharSequence s, int start, int count, int after) {
     }
 
     public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
         outAttrs.inputType = InputType.TYPE_CLASS_TEXT;
         outAttrs.imeOptions = EditorInfo.IME_ACTION_NONE;
         outAttrs.actionLabel = null;
-        mKeyListener = TextKeyListener.getInstance();
 
         if (mIMEState == IME_STATE_PASSWORD)
             outAttrs.inputType |= InputType.TYPE_TEXT_VARIATION_PASSWORD;
         else if (mIMETypeHint.equalsIgnoreCase("url"))
             outAttrs.inputType |= InputType.TYPE_TEXT_VARIATION_URI;
         else if (mIMETypeHint.equalsIgnoreCase("email"))
             outAttrs.inputType |= InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
         else if (mIMETypeHint.equalsIgnoreCase("search"))
@@ -801,25 +799,26 @@ public class GeckoInputConnection
                 break;
         }
 
         if (isPreIme && mIMEState != IME_STATE_DISABLED &&
             (event.getMetaState() & KeyEvent.META_ALT_ON) != 0)
             // Let active IME process pre-IME key events
             return false;
 
-        View v = GeckoApp.mAppContext.getLayerController().getView();
+        View view = GeckoApp.mAppContext.getLayerController().getView();
+        KeyListener keyListener = TextKeyListener.getInstance();
 
         // KeyListener returns true if it handled the event for us.
         if (mIMEState == IME_STATE_DISABLED ||
                 keyCode == KeyEvent.KEYCODE_ENTER ||
                 keyCode == KeyEvent.KEYCODE_DEL ||
                 keyCode == KeyEvent.KEYCODE_TAB ||
                 (event.getFlags() & KeyEvent.FLAG_SOFT_KEYBOARD) != 0 ||
-                !mKeyListener.onKeyDown(v, mEditable, keyCode, event)) {
+                !keyListener.onKeyDown(view, mEditable, keyCode, event)) {
             // Make sure selection in Gecko is up-to-date
             final Editable content = getEditable();
             clampSelection();
             int a = Selection.getSelectionStart(content);
             int b = Selection.getSelectionEnd(content);
             GeckoAppShell.sendEventToGecko(
                 GeckoEvent.createIMEEvent(GeckoEvent.IME_SET_SELECTION, a, b - a));
 
@@ -847,24 +846,27 @@ public class GeckoInputConnection
                 break;
         }
 
         if (isPreIme && mIMEState != IME_STATE_DISABLED &&
             (event.getMetaState() & KeyEvent.META_ALT_ON) != 0)
             // Let active IME process pre-IME key events
             return false;
 
-        View v = GeckoApp.mAppContext.getLayerController().getView();
+        View view = GeckoApp.mAppContext.getLayerController().getView();
+        KeyListener keyListener = TextKeyListener.getInstance();
 
         if (mIMEState == IME_STATE_DISABLED ||
             keyCode == KeyEvent.KEYCODE_ENTER ||
             keyCode == KeyEvent.KEYCODE_DEL ||
             (event.getFlags() & KeyEvent.FLAG_SOFT_KEYBOARD) != 0 ||
-            !mKeyListener.onKeyUp(v, mEditable, keyCode, event))
+            !keyListener.onKeyUp(view, mEditable, keyCode, event)) {
             GeckoAppShell.sendEventToGecko(GeckoEvent.createKeyEvent(event));
+        }
+
         return true;
     }
 
     public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
         GeckoAppShell.sendEventToGecko(GeckoEvent.createKeyEvent(event));
         return true;
     }