Bug 669361 - Ignore non-en_US HKB KeyEvents for Asus Transformer tablets running Honeycomb or ICS. r=blassey
authorChris Peterson <cpeterson@mozilla.com>
Tue, 11 Sep 2012 10:46:38 -0700
changeset 108046 90dd2e82f891201a185fdf8e9ab0fb760153424b
parent 108045 03639049f2fd700c548e9b5207e4e856fe561c9c
child 108047 50bb2e93c6cdd6cbfe749168373e1f41359f81ad
push id15347
push usercpeterson@mozilla.com
push dateTue, 25 Sep 2012 19:06:46 +0000
treeherdermozilla-inbound@50bb2e93c6cd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersblassey
bugs669361
milestone18.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 669361 - Ignore non-en_US HKB KeyEvents for Asus Transformer tablets running Honeycomb or ICS. r=blassey
mobile/android/base/GeckoInputConnection.java
--- a/mobile/android/base/GeckoInputConnection.java
+++ b/mobile/android/base/GeckoInputConnection.java
@@ -34,16 +34,17 @@ import android.view.View;
 import android.view.inputmethod.BaseInputConnection;
 import android.view.inputmethod.CompletionInfo;
 import android.view.inputmethod.EditorInfo;
 import android.view.inputmethod.ExtractedText;
 import android.view.inputmethod.ExtractedTextRequest;
 import android.view.inputmethod.InputConnection;
 import android.view.inputmethod.InputMethodManager;
 
+import java.util.Locale;
 import java.util.Timer;
 import java.util.TimerTask;
 
 class GeckoInputConnection
     extends BaseInputConnection
     implements TextWatcher, InputConnectionHandler {
 
     private static final boolean DEBUG = false;
@@ -83,16 +84,17 @@ class GeckoInputConnection
     private static final char UNICODE_WHITE_BULLET              = '\u25e6';
     private static final char UNICODE_YEN_SIGN                  = '\u00a5';
 
     private static final Timer mIMETimer = new Timer("GeckoInputConnection Timer");
     private static int mIMEState;
     private static String mIMETypeHint = "";
     private static String mIMEModeHint = "";
     private static String mIMEActionHint = "";
+    private static Boolean sIsPreJellyBeanAsusTransformer;
 
     private String mCurrentInputMethod;
 
     // Is a composition active?
     private int mCompositionStart = NO_COMPOSITION_STRING;
     private boolean mCommittingText;
     private KeyCharacterMap mKeyCharacterMap;
     private final Editable mEditable;
@@ -887,16 +889,19 @@ class GeckoInputConnection
         return processKeyDown(keyCode, event);
     }
 
     private boolean processKeyDown(int keyCode, KeyEvent event) {
         if (DEBUG) {
             Log.d(LOGTAG, "IME: processKeyDown(keyCode=" + keyCode + ", event=" + event + ")");
         }
 
+        if (hasBuggyHardwareKeyboardLayout())
+            return false;
+
         if (keyCode > KeyEvent.getMaxKeyCode())
             return false;
 
         switch (keyCode) {
             case KeyEvent.KEYCODE_MENU:
             case KeyEvent.KEYCODE_BACK:
             case KeyEvent.KEYCODE_VOLUME_UP:
             case KeyEvent.KEYCODE_VOLUME_DOWN:
@@ -941,16 +946,19 @@ class GeckoInputConnection
         return processKeyUp(keyCode, event);
     }
 
     private boolean processKeyUp(int keyCode, KeyEvent event) {
         if (DEBUG) {
             Log.d(LOGTAG, "IME: processKeyUp(keyCode=" + keyCode + ", event=" + event + ")");
         }
 
+        if (hasBuggyHardwareKeyboardLayout())
+            return false;
+
         if (keyCode > KeyEvent.getMaxKeyCode())
             return false;
 
         switch (keyCode) {
             case KeyEvent.KEYCODE_BACK:
             case KeyEvent.KEYCODE_SEARCH:
             case KeyEvent.KEYCODE_MENU:
                 return false;
@@ -968,16 +976,18 @@ class GeckoInputConnection
             !keyListener.onKeyUp(view, mEditable, keyCode, event)) {
             GeckoAppShell.sendEventToGecko(GeckoEvent.createKeyEvent(event));
         }
 
         return true;
     }
 
     public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
+        if (hasBuggyHardwareKeyboardLayout())
+            return false;
         GeckoAppShell.sendEventToGecko(GeckoEvent.createKeyEvent(event));
         return true;
     }
 
     public boolean onKeyLongPress(int keyCode, KeyEvent event) {
         View v = getView();
         switch (keyCode) {
             case KeyEvent.KEYCODE_MENU:
@@ -1162,16 +1172,28 @@ class GeckoInputConnection
         return new Span(start, end, mEditable);
     }
 
     private static String prettyPrintString(CharSequence s) {
         // Quote string and replace newlines with CR arrows.
         return "\"" + s.toString().replace('\n', UNICODE_CRARR) + "\"";
     }
 
+    private static boolean hasBuggyHardwareKeyboardLayout() {
+        // Asus Transformers generate en-US keycodes for HKB keys, regardless of system locale or
+        // keyboard layout. This bug is reportedly fixed in JB. See bug 669361 and bug 712018.
+        if (sIsPreJellyBeanAsusTransformer == null) {
+            sIsPreJellyBeanAsusTransformer = Build.VERSION.SDK_INT < 16 &&
+                                             "asus".equals(Build.BRAND) &&
+                                             "EeePad".equals(Build.BOARD);
+        }
+        // The locale may change while Firefox is running, but the device and OS should not. :)
+        return sIsPreJellyBeanAsusTransformer && !Locale.getDefault().equals(Locale.US);
+    }
+
     private static final class Span {
         public final int start;
         public final int end;
         public final int length;
 
         public static Span clamp(int start, int end, Editable content) {
             return new Span(start, end, content);
         }