Bug 842013 - Suppress key up events during key down event; r=cpeterson

This commit is contained in:
Jim Chen 2013-03-29 10:54:01 -04:00
parent 91d7b77155
commit bf42ff4640
2 changed files with 23 additions and 3 deletions

View File

@ -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;
}

View File

@ -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;
}