diff --git a/mobile/android/base/GeckoEvent.java b/mobile/android/base/GeckoEvent.java index a778233c3ec..fb3050045a5 100644 --- a/mobile/android/base/GeckoEvent.java +++ b/mobile/android/base/GeckoEvent.java @@ -184,9 +184,9 @@ public class GeckoEvent { return new GeckoEvent(NOOP); } - public static GeckoEvent createKeyEvent(KeyEvent k) { + public static GeckoEvent createKeyEvent(KeyEvent k, int metaState) { GeckoEvent event = new GeckoEvent(KEY_EVENT); - event.initKeyEvent(k); + event.initKeyEvent(k, metaState); return event; } @@ -198,10 +198,14 @@ public class GeckoEvent { return new GeckoEvent(COMPOSITOR_RESUME); } - private void initKeyEvent(KeyEvent k) { + private void initKeyEvent(KeyEvent k, int metaState) { mAction = k.getAction(); mTime = k.getEventTime(); - mMetaState = k.getMetaState(); + // Normally we expect k.getMetaState() to reflect the current meta-state; however, + // some software-generated key events may not have k.getMetaState() set, e.g. key + // events from Swype. Therefore, it's necessary to combine the key's meta-states + // with the meta-states that we keep separately in KeyListener + mMetaState = k.getMetaState() | metaState; mFlags = k.getFlags(); mKeyCode = k.getKeyCode(); mUnicodeChar = k.getUnicodeChar(); diff --git a/mobile/android/base/GeckoInputConnection.java b/mobile/android/base/GeckoInputConnection.java index 06407d1630a..995cea08c8d 100644 --- a/mobile/android/base/GeckoInputConnection.java +++ b/mobile/android/base/GeckoInputConnection.java @@ -716,7 +716,7 @@ class GeckoInputConnection View view = getView(); if (view == null) { - mEditableClient.sendEvent(GeckoEvent.createKeyEvent(event)); + mEditableClient.sendEvent(GeckoEvent.createKeyEvent(event, 0)); return true; } @@ -731,7 +731,8 @@ class GeckoInputConnection if (skip || (down && !keyListener.onKeyDown(view, uiEditable, keyCode, event)) || (!down && !keyListener.onKeyUp(view, uiEditable, keyCode, event))) { - mEditableClient.sendEvent(GeckoEvent.createKeyEvent(event)); + mEditableClient.sendEvent( + GeckoEvent.createKeyEvent(event, TextKeyListener.getMetaState(uiEditable))); if (skip && down) { // Usually, the down key listener call above adjusts meta states for us. // However, if we skip that call above, we have to manually adjust meta