Bug 712018 - Add white list to support IME on physical keyboard. r=cpeterson
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Fri, 26 Oct 2012 15:49:08 +0900
changeset 111630 8586bd3508750056e1b59298a59cad02bf54b29c
parent 111629 2b496b04c1831346a898d288f0c03ab23b5c076f
child 111631 80e4065a329edd3adbc048d7c82813fec34f6333
child 111647 3b558dfe27a3c5205ab192fb52c2927102dbd074
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewerscpeterson
bugs712018
milestone19.0a1
Bug 712018 - Add white list to support IME on physical keyboard. r=cpeterson
mobile/android/base/GeckoInputConnection.java
mobile/android/base/InputMethods.java
--- a/mobile/android/base/GeckoInputConnection.java
+++ b/mobile/android/base/GeckoInputConnection.java
@@ -34,17 +34,16 @@ 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;
@@ -84,17 +83,16 @@ 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;
@@ -866,31 +864,34 @@ class GeckoInputConnection
         // is restored from a VKB popup window (such as for entering accented characters)
         // back to our IME. We want to commit our active composition string. Bug 756429
         if (hasCompositionString()) {
             endComposition();
         }
 
         String prevInputMethod = mCurrentInputMethod;
         mCurrentInputMethod = InputMethods.getCurrentInputMethod(app);
+        if (DEBUG) {
+            Log.d(LOGTAG, "IME: CurrentInputMethod=" + mCurrentInputMethod);
+        }
 
         // If the user has changed IMEs, then notify input method observers.
         if (mCurrentInputMethod != prevInputMethod) {
             FormAssistPopup popup = app.mFormAssistPopup;
             if (popup != null) {
                 popup.onInputMethodChanged(mCurrentInputMethod);
             }
         }
 
         resetCompositionState();
         return this;
     }
 
     public boolean onKeyPreIme(int keyCode, KeyEvent event) {
-        if (hasBuggyHardwareKeyboardLayout())
+        if (InputMethods.canUseInputMethodOnHKB(mCurrentInputMethod))
             return false;
 
         switch (event.getAction()) {
             case KeyEvent.ACTION_DOWN:
                 return processKeyDown(keyCode, event);
             case KeyEvent.ACTION_UP:
                 return processKeyUp(keyCode, event);
             case KeyEvent.ACTION_MULTIPLE:
@@ -1199,28 +1200,16 @@ 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);
         }
--- a/mobile/android/base/InputMethods.java
+++ b/mobile/android/base/InputMethods.java
@@ -1,25 +1,30 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko;
 
 import android.content.Context;
+import android.os.Build;
 import android.provider.Settings.Secure;
 import android.view.inputmethod.InputMethodInfo;
 import android.view.inputmethod.InputMethodManager;
 
+import java.util.Arrays;
 import java.util.Collection;
+import java.util.Locale;
 
 final class InputMethods {
 
+    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_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_SIMEJI = "com.adamrocker.android.input.simeji/.OpenWnnSimeji";
     public static final String METHOD_SWYPE = "com.swype.android.inputmethod/.SwypeInputMethod";
     public static final String METHOD_SWYPE_BETA = "com.nuance.swype.input/.IME";
 
     /* These input method names are currently unused, but kept here for future reference:
     public static final String METHOD_EYES_FREE_KEYBOARD = "com.googlecode.eyesfree.inputmethod.latin/.LatinIME";
     public static final String METHOD_GO_KEYBOARD = "com.jb.gokeyboard/.GoKeyboard";
@@ -27,16 +32,26 @@ final class InputMethods {
     public static final String METHOD_GOOGLE_TALKBACK = "com.google.android.marvin.talkback/com.googlecode.eyesfree.inputmethod.latin.LatinIME";
     public static final String METHOD_HACKERS_KEYBOARD = "org.pocketworkstation.pckeyboard/.LatinIME";
     public static final String METHOD_SAMSUNG_GALAXY_NOTE = "com.samsung.sec.android.inputmethod.axt9/.AxT9IME";
     public static final String METHOD_SLIDE_IT_KEYBOARD = "com.dasur.slideit.vt.lite/com.dasur.slideit.SlideITIME";
     public static final String METHOD_SWIFTKEY_TRIAL = "com.touchtype.swiftkey.phone.trial/com.touchtype.KeyboardService";
     public static final String METHOD_TOUCHPAL_KEYBOARD = "com.cootek.smartinputv5/.TouchPalIME";
     */
 
+    // this is white list of IME support for hardware physical keyboard
+    private static final Collection<String> sHKBWhiteList = Arrays.asList(new String[] {
+                                                            METHOD_ATOK,
+                                                            METHOD_GOOGLE_JAPANESE_INPUT,
+                                                            METHOD_IWNN,
+                                                            METHOD_OPENWNN_PLUS,
+                                                            METHOD_SIMEJI,
+                                                            });
+    private static Boolean sIsPreJellyBeanAsusTransformer;
+
     private InputMethods() {}
 
     public static String getCurrentInputMethod(Context context) {
         return Secure.getString(context.getContentResolver(), Secure.DEFAULT_INPUT_METHOD);
     }
 
     public static InputMethodInfo getInputMethodInfo(Context context, String inputMethod) {
         InputMethodManager imm = getInputMethodManager(context);
@@ -47,9 +62,25 @@ final class InputMethods {
             }
         }
         return null;
     }
 
     public static InputMethodManager getInputMethodManager(Context context) {
         return (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
     }
+
+    public static boolean canUseInputMethodOnHKB(String inputMethod) {
+        if (sHKBWhiteList.contains(inputMethod)) {
+            return true;
+        }
+
+        // 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);
+    }
 }