Bug 805162 - g. Reimplement key events in GeckoInputConnection using GeckoEditable; r=cpeterson
authorJim Chen <nchen@mozilla.com>
Wed, 31 Oct 2012 17:35:32 -0400
changeset 111959 c9ef1b41b8292027dfc9b05601090ba1c95de8bb
parent 111958 d3a825311d11e8b23fea810a9f9f2a9d743efb54
child 111960 ad5554e1345d8fdfe9453e05d2dd91bcc05645d3
push id17349
push usernchen@mozilla.com
push dateWed, 31 Oct 2012 21:36:42 +0000
treeherdermozilla-inbound@533faa3c50ed [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpeterson
bugs805162
milestone19.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 805162 - g. Reimplement key events in GeckoInputConnection using GeckoEditable; r=cpeterson
mobile/android/base/GeckoInputConnection.java
--- a/mobile/android/base/GeckoInputConnection.java
+++ b/mobile/android/base/GeckoInputConnection.java
@@ -211,36 +211,16 @@ class GeckoInputConnection
         // The UI thread does not need to post Runnables to itself.
         GeckoApp.mAppContext.mMainHandler.post(runnable);
     }
 
     private static View getView() {
         return GeckoApp.mAppContext.getLayerView();
     }
 
-    public boolean onKeyDel() {
-        // Some IMEs don't update us on deletions
-        // In that case we are not updated when a composition
-        // is destroyed, and Bad Things happen
-
-        if (!hasCompositionString())
-            return false;
-
-        String text = getComposingText();
-
-        if (text != null && text.length() > 1) {
-            text = text.substring(0, text.length() - 1);
-            replaceText(text, 1, false);
-            return false;
-        }
-
-        commitText(null, 1);
-        return true;
-    }
-
     private static InputMethodManager getInputMethodManager() {
         View view = getView();
         if (view == null) {
             return null;
         }
         Context context = view.getContext();
         return InputMethods.getInputMethodManager(context);
     }
@@ -380,55 +360,34 @@ class GeckoInputConnection
             }
         }
 
         resetCompositionState();
         return this;
     }
 
     public boolean onKeyPreIme(int keyCode, KeyEvent event) {
-        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:
-                return onKeyMultiple(keyCode, event.getRepeatCount(), event);
-        }
         return false;
     }
 
     public boolean onKeyDown(int keyCode, KeyEvent event) {
         return processKeyDown(keyCode, event);
     }
 
     private boolean processKeyDown(int keyCode, KeyEvent event) {
-        if (DEBUG) {
-            Log.d(LOGTAG, "IME: processKeyDown(keyCode=" + keyCode + ", event=" + event + ")");
-        }
-
         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:
             case KeyEvent.KEYCODE_SEARCH:
                 return false;
-            case KeyEvent.KEYCODE_DEL:
-                // See comments in GeckoInputConnection.onKeyDel
-                if (onKeyDel()) {
-                    return true;
-                }
-                break;
             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;
         }
@@ -437,36 +396,27 @@ class GeckoInputConnection
         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 ||
-                !keyListener.onKeyDown(view, mEditable, keyCode, event)) {
-            // Make sure selection in Gecko is up-to-date
-            Span selection = getSelection();
-            GeckoAppShell.sendEventToGecko(GeckoEvent.createIMEEvent(GeckoEvent.IME_SET_SELECTION,
-                                                                     selection.start,
-                                                                     selection.length));
-            GeckoAppShell.sendEventToGecko(GeckoEvent.createKeyEvent(event));
+                !keyListener.onKeyDown(view, getEditable(), keyCode, event)) {
+            mEditableClient.sendEvent(GeckoEvent.createKeyEvent(event));
         }
         return true;
     }
 
     public boolean onKeyUp(int keyCode, KeyEvent event) {
         return processKeyUp(keyCode, event);
     }
 
     private boolean processKeyUp(int keyCode, KeyEvent event) {
-        if (DEBUG) {
-            Log.d(LOGTAG, "IME: processKeyUp(keyCode=" + keyCode + ", event=" + event + ")");
-        }
-
         if (keyCode > KeyEvent.getMaxKeyCode())
             return false;
 
         switch (keyCode) {
             case KeyEvent.KEYCODE_BACK:
             case KeyEvent.KEYCODE_SEARCH:
             case KeyEvent.KEYCODE_MENU:
                 return false;
@@ -476,25 +426,30 @@ class GeckoInputConnection
 
         View view = 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 ||
-            !keyListener.onKeyUp(view, mEditable, keyCode, event)) {
-            GeckoAppShell.sendEventToGecko(GeckoEvent.createKeyEvent(event));
+            !keyListener.onKeyUp(view, getEditable(), keyCode, event)) {
+            mEditableClient.sendEvent(GeckoEvent.createKeyEvent(event));
         }
 
         return true;
     }
 
     public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
-        GeckoAppShell.sendEventToGecko(GeckoEvent.createKeyEvent(event));
+        while ((repeatCount--) != 0) {
+            if (!processKeyDown(keyCode, event) ||
+                !processKeyUp(keyCode, event)) {
+                return false;
+            }
+        }
         return true;
     }
 
     public boolean onKeyLongPress(int keyCode, KeyEvent event) {
         View v = getView();
         switch (keyCode) {
             case KeyEvent.KEYCODE_MENU:
                 InputMethodManager imm = getInputMethodManager();