diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-28 07:49:56 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-28 07:49:56 +0000 |
commit | f02f6f5e35504369f8537b783766b9591dce4c35 (patch) | |
tree | 31d539242a1dbd16062c6e82189b6c43c610d5ba /remoting/android | |
parent | e5b822b5da1f0fce7d388cdb577af581c69e739d (diff) | |
download | chromium_src-f02f6f5e35504369f8537b783766b9591dce4c35.zip chromium_src-f02f6f5e35504369f8537b783766b9591dce4c35.tar.gz chromium_src-f02f6f5e35504369f8537b783766b9591dce4c35.tar.bz2 |
Send TextEvent message from Android client
The new message is currently used only for keys for which Android
generates ACTION_MULTIPLE events.
BUG=265945,270356
R=lambroslambrou@chromium.org
Review URL: https://codereview.chromium.org/214173002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260088 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/android')
3 files changed, 53 insertions, 24 deletions
diff --git a/remoting/android/java/src/org/chromium/chromoting/Desktop.java b/remoting/android/java/src/org/chromium/chromoting/Desktop.java index b75d97d..570fd80 100644 --- a/remoting/android/java/src/org/chromium/chromoting/Desktop.java +++ b/remoting/android/java/src/org/chromium/chromoting/Desktop.java @@ -103,10 +103,10 @@ public class Desktop extends Activity { KeyEvent.KEYCODE_FORWARD_DEL, }; for (int key : keys) { - JniInterface.keyboardAction(key, true); + JniInterface.sendKeyEvent(key, true); } for (int key : keys) { - JniInterface.keyboardAction(key, false); + JniInterface.sendKeyEvent(key, false); } } return true; @@ -127,32 +127,48 @@ public class Desktop extends Activity { */ @Override public boolean dispatchKeyEvent(KeyEvent event) { + // Send ACTION_MULTIPLE event as TextEvent. + // + // TODO(sergeyu): For all keys on English keyboard Android generates + // ACTION_DOWN/ACTION_UP events, so they are sent as KeyEvent instead of + // TextEvent. As result the host may handle them as non-English chars + // when it has non-English layout selected, which might be confusing for + // the user. This code should be fixed to send all text input events as + // TextEvent, but it cannot be done now because not all hosts support + // TextEvent. Also, to handle keyboard shortcuts properly this code will + // need to track the state of modifier keys (such as Ctrl or Alt) and + // send KeyEvents in the case any of the modifier keys are pressed. + if (event.getAction() == KeyEvent.ACTION_MULTIPLE) { + JniInterface.sendTextEvent(event.getCharacters()); + return super.dispatchKeyEvent(event); + } + boolean depressed = event.getAction() == KeyEvent.ACTION_DOWN; switch (event.getKeyCode()) { case KeyEvent.KEYCODE_AT: - JniInterface.keyboardAction(KeyEvent.KEYCODE_SHIFT_LEFT, depressed); - JniInterface.keyboardAction(KeyEvent.KEYCODE_2, depressed); + JniInterface.sendKeyEvent(KeyEvent.KEYCODE_SHIFT_LEFT, depressed); + JniInterface.sendKeyEvent(KeyEvent.KEYCODE_2, depressed); break; case KeyEvent.KEYCODE_POUND: - JniInterface.keyboardAction(KeyEvent.KEYCODE_SHIFT_LEFT, depressed); - JniInterface.keyboardAction(KeyEvent.KEYCODE_3, depressed); + JniInterface.sendKeyEvent(KeyEvent.KEYCODE_SHIFT_LEFT, depressed); + JniInterface.sendKeyEvent(KeyEvent.KEYCODE_3, depressed); break; case KeyEvent.KEYCODE_STAR: - JniInterface.keyboardAction(KeyEvent.KEYCODE_SHIFT_LEFT, depressed); - JniInterface.keyboardAction(KeyEvent.KEYCODE_8, depressed); + JniInterface.sendKeyEvent(KeyEvent.KEYCODE_SHIFT_LEFT, depressed); + JniInterface.sendKeyEvent(KeyEvent.KEYCODE_8, depressed); break; case KeyEvent.KEYCODE_PLUS: - JniInterface.keyboardAction(KeyEvent.KEYCODE_SHIFT_LEFT, depressed); - JniInterface.keyboardAction(KeyEvent.KEYCODE_EQUALS, depressed); + JniInterface.sendKeyEvent(KeyEvent.KEYCODE_SHIFT_LEFT, depressed); + JniInterface.sendKeyEvent(KeyEvent.KEYCODE_EQUALS, depressed); break; default: // We try to send all other key codes to the host directly. - JniInterface.keyboardAction(event.getKeyCode(), depressed); + JniInterface.sendKeyEvent(event.getKeyCode(), depressed); } return super.dispatchKeyEvent(event); diff --git a/remoting/android/java/src/org/chromium/chromoting/DesktopView.java b/remoting/android/java/src/org/chromium/chromoting/DesktopView.java index 53741c1..94f19a8 100644 --- a/remoting/android/java/src/org/chromium/chromoting/DesktopView.java +++ b/remoting/android/java/src/org/chromium/chromoting/DesktopView.java @@ -344,7 +344,7 @@ public class DesktopView extends SurfaceView implements DesktopViewInterface, return; } - JniInterface.mouseAction(x, y, button, pressed); + JniInterface.sendMouseEvent(x, y, button, pressed); if (cursorMoved) { // TODO(lambroslambrou): Optimize this by only repainting the affected areas. requestRepaint(); @@ -353,7 +353,7 @@ public class DesktopView extends SurfaceView implements DesktopViewInterface, @Override public void injectMouseWheelDeltaEvent(int deltaX, int deltaY) { - JniInterface.mouseWheelDeltaAction(deltaX, deltaY); + JniInterface.sendMouseWheelEvent(deltaX, deltaY); } @Override diff --git a/remoting/android/java/src/org/chromium/chromoting/jni/JniInterface.java b/remoting/android/java/src/org/chromium/chromoting/jni/JniInterface.java index 79533a3..472c19c 100644 --- a/remoting/android/java/src/org/chromium/chromoting/jni/JniInterface.java +++ b/remoting/android/java/src/org/chromium/chromoting/jni/JniInterface.java @@ -281,7 +281,7 @@ public class JniInterface { * is true. */ private static native void nativeAuthenticationResponse(String pin, boolean createPair, - String deviceName); + String deviceName); /** Saves newly-received pairing credentials to permanent storage. Called on the UI thread. */ @CalledByNative @@ -296,40 +296,53 @@ public class JniInterface { * Moves the mouse cursor, possibly while clicking the specified (nonnegative) button. Called * on the UI thread. */ - public static void mouseAction(int x, int y, int whichButton, boolean buttonDown) { + public static void sendMouseEvent(int x, int y, int whichButton, boolean buttonDown) { if (!sConnected) { return; } - nativeMouseAction(x, y, whichButton, buttonDown); + nativeSendMouseEvent(x, y, whichButton, buttonDown); } /** Passes mouse information to the native handling code. */ - private static native void nativeMouseAction(int x, int y, int whichButton, boolean buttonDown); + private static native void nativeSendMouseEvent(int x, int y, int whichButton, + boolean buttonDown); /** Injects a mouse-wheel event with delta values. Called on the UI thread. */ - public static void mouseWheelDeltaAction(int deltaX, int deltaY) { + public static void sendMouseWheelEvent(int deltaX, int deltaY) { if (!sConnected) { return; } - nativeMouseWheelDeltaAction(deltaX, deltaY); + nativeSendMouseWheelEvent(deltaX, deltaY); } /** Passes mouse-wheel information to the native handling code. */ - private static native void nativeMouseWheelDeltaAction(int deltaX, int deltaY); + private static native void nativeSendMouseWheelEvent(int deltaX, int deltaY); - /** Presses and releases the specified (nonnegative) key. Called on the UI thread. */ - public static void keyboardAction(int keyCode, boolean keyDown) { + /** Presses or releases the specified (nonnegative) key. Called on the UI thread. */ + public static void sendKeyEvent(int keyCode, boolean keyDown) { if (!sConnected) { return; } - nativeKeyboardAction(keyCode, keyDown); + nativeSendKeyEvent(keyCode, keyDown); } /** Passes key press information to the native handling code. */ - private static native void nativeKeyboardAction(int keyCode, boolean keyDown); + private static native void nativeSendKeyEvent(int keyCode, boolean keyDown); + + /** Sends TextEvent to the host. Called on the UI thread. */ + public static void sendTextEvent(String text) { + if (!sConnected) { + return; + } + + nativeSendTextEvent(text); + } + + /** Passes text event information to the native handling code. */ + private static native void nativeSendTextEvent(String text); /** * Sets the redraw callback to the provided functor. Provide a value of null whenever the |