From bf161904b0aacb6a9070cc1955d56a001a31b8b5 Mon Sep 17 00:00:00 2001 From: Jim Chen Date: Fri, 29 Mar 2013 10:54:01 -0400 Subject: [PATCH] Bug 842013 - Suppress key up events during key down event; r=cpeterson --- mobile/android/base/GeckoEditable.java | 19 +++++++++++++++++-- mobile/android/base/GeckoInputConnection.java | 7 ++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/mobile/android/base/GeckoEditable.java b/mobile/android/base/GeckoEditable.java index b85a5ac3f3f6..7f43ea2e8c52 100644 --- a/mobile/android/base/GeckoEditable.java +++ b/mobile/android/base/GeckoEditable.java @@ -39,6 +39,7 @@ interface GeckoEditableClient { void sendEvent(GeckoEvent event); Editable getEditable(); void setUpdateGecko(boolean update); + void setSuppressKeyUp(boolean suppress); Handler getInputConnectionHandler(); boolean setInputConnectionHandler(Handler handler); } @@ -98,6 +99,7 @@ final class GeckoEditable private int mLastIcUpdateSeqno; private boolean mUpdateGecko; private boolean mFocused; + private volatile boolean mSuppressKeyUp; /* An action that alters the Editable @@ -276,6 +278,9 @@ final class GeckoEditable if (KeyEvent.isModifierKey(event.getKeyCode())) { continue; } + if (event.getAction() == KeyEvent.ACTION_UP && mSuppressKeyUp) { + continue; + } if (DEBUG) { Log.d(LOGTAG, "sending: " + event); } @@ -584,10 +589,20 @@ final class GeckoEditable } @Override - public Handler getInputConnectionHandler() { + public void setSuppressKeyUp(boolean suppress) { if (DEBUG) { - assertOnIcThread(); + // only used by key event handler + ThreadUtils.assertOnUiThread(); } + // Suppress key up event generated as a result of + // translating characters to key events + mSuppressKeyUp = suppress; + } + + @Override + public Handler getInputConnectionHandler() { + // Can be called from either UI thread or IC thread; + // care must be taken to avoid race conditions return mIcRunHandler; } diff --git a/mobile/android/base/GeckoInputConnection.java b/mobile/android/base/GeckoInputConnection.java index df54d5ee0f09..6e3c42c9f3dc 100644 --- a/mobile/android/base/GeckoInputConnection.java +++ b/mobile/android/base/GeckoInputConnection.java @@ -727,7 +727,9 @@ class GeckoInputConnection Handler icHandler = mEditableClient.getInputConnectionHandler(); Editable uiEditable = mThreadUtils.getEditableForUiThread(uiHandler, icHandler); boolean skip = shouldSkipKeyListener(keyCode, event); - + if (down) { + mEditableClient.setSuppressKeyUp(true); + } if (skip || (down && !keyListener.onKeyDown(view, uiEditable, keyCode, event)) || (!down && !keyListener.onKeyUp(view, uiEditable, keyCode, event))) { @@ -740,6 +742,9 @@ class GeckoInputConnection TextKeyListener.adjustMetaAfterKeypress(uiEditable); } } + if (down) { + mEditableClient.setSuppressKeyUp(false); + } return true; }