Bug 676195 - IME doesn't work with hardware keyboard on Android. r=jchen
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Sat, 03 Sep 2011 23:14:38 +0900
changeset 76516 b3fa7b442186068a6df6fc232ab90b6cd325de1f
parent 76515 1915c4f1eed6a44fbbb641214d6f365445e036b4
child 76517 d1d3ad947e9fa41a23b1775be9462fe7f1ff2cb3
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewersjchen
bugs676195
milestone9.0a1
Bug 676195 - IME doesn't work with hardware keyboard on Android. r=jchen
embedding/android/GeckoSurfaceView.java
--- a/embedding/android/GeckoSurfaceView.java
+++ b/embedding/android/GeckoSurfaceView.java
@@ -592,27 +592,31 @@ class GeckoSurfaceView
 
     @Override
     public boolean onKeyPreIme(int keyCode, KeyEvent event) {
         if (event.isSystem())
             return super.onKeyPreIme(keyCode, event);
 
         switch (event.getAction()) {
             case KeyEvent.ACTION_DOWN:
-                return onKeyDown(keyCode, event);
+                return processKeyDown(keyCode, event, true);
             case KeyEvent.ACTION_UP:
-                return onKeyUp(keyCode, event);
+                return processKeyUp(keyCode, event, true);
             case KeyEvent.ACTION_MULTIPLE:
                 return onKeyMultiple(keyCode, event.getRepeatCount(), event);
         }
         return super.onKeyPreIme(keyCode, event);
     }
 
     @Override
     public boolean onKeyDown(int keyCode, KeyEvent event) {
+        return processKeyDown(keyCode, event, false);
+    }
+
+    private boolean processKeyDown(int keyCode, KeyEvent event, boolean isPreIme) {
         switch (keyCode) {
             case KeyEvent.KEYCODE_BACK:
                 if (event.getRepeatCount() == 0) {
                     event.startTracking();
                     return true;
                 } else {
                     return false;
                 }
@@ -639,36 +643,50 @@ class GeckoSurfaceView
             case KeyEvent.KEYCODE_ENTER:
                 if ((event.getFlags() & KeyEvent.FLAG_EDITOR_ACTION) != 0 &&
                     mIMEActionHint.equalsIgnoreCase("next"))
                     event = new KeyEvent(event.getAction(), KeyEvent.KEYCODE_TAB);
                 break;
             default:
                 break;
         }
+
+        if (isPreIme && mIMEState != IME_STATE_DISABLED)
+            // Let active IME process pre-IME key events
+            return false;
+
         // KeyListener returns true if it handled the event for us.
         if (mIMEState == IME_STATE_DISABLED ||
             keyCode == KeyEvent.KEYCODE_ENTER ||
             keyCode == KeyEvent.KEYCODE_DEL ||
             (event.getFlags() & KeyEvent.FLAG_SOFT_KEYBOARD) != 0 ||
             !mKeyListener.onKeyDown(this, mEditable, keyCode, event))
             GeckoAppShell.sendEventToGecko(new GeckoEvent(event));
         return true;
     }
 
     @Override
     public boolean onKeyUp(int keyCode, KeyEvent event) {
+        return processKeyUp(keyCode, event, false);
+    }
+
+    private boolean processKeyUp(int keyCode, KeyEvent event, boolean isPreIme) {
         switch (keyCode) {
             case KeyEvent.KEYCODE_BACK:
                 if (!event.isTracking() || event.isCanceled())
                     return false;
                 break;
             default:
                 break;
         }
+
+        if (isPreIme && mIMEState != IME_STATE_DISABLED)
+            // Let active IME process pre-IME key events
+            return false;
+
         if (mIMEState == IME_STATE_DISABLED ||
             keyCode == KeyEvent.KEYCODE_ENTER ||
             keyCode == KeyEvent.KEYCODE_DEL ||
             (event.getFlags() & KeyEvent.FLAG_SOFT_KEYBOARD) != 0 ||
             !mKeyListener.onKeyUp(this, mEditable, keyCode, event))
             GeckoAppShell.sendEventToGecko(new GeckoEvent(event));
         return true;
     }