Commit 127e4d29 authored by sergeyu@chromium.org's avatar sergeyu@chromium.org

Fix Desktop.dispatchKeyEvent() to return correct result.

Previously Desktop.dispatchKeyEvent() was sending keyboard events to
the host and then pretending that it didn't handle the event. Now it
returns correct result telling the caller when the event was handled.

BUG=385972

Review URL: https://codereview.chromium.org/341693004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278331 0039d316-1c4b-4281-b951-d872f2087c98
parent e11d89d1
......@@ -210,40 +210,38 @@ public class Desktop extends Activity implements View.OnSystemUiVisibilityChange
mPressedTextKeys.add(keyCode);
int[] codePoints = { unicode };
JniInterface.sendTextEvent(new String(codePoints, 0, 1));
return super.dispatchKeyEvent(event);
return true;
}
if (!pressed && mPressedTextKeys.contains(keyCode)) {
mPressedTextKeys.remove(keyCode);
return super.dispatchKeyEvent(event);
return true;
}
switch (keyCode) {
case KeyEvent.KEYCODE_AT:
JniInterface.sendKeyEvent(KeyEvent.KEYCODE_SHIFT_LEFT, pressed);
JniInterface.sendKeyEvent(KeyEvent.KEYCODE_2, pressed);
break;
return true;
case KeyEvent.KEYCODE_POUND:
JniInterface.sendKeyEvent(KeyEvent.KEYCODE_SHIFT_LEFT, pressed);
JniInterface.sendKeyEvent(KeyEvent.KEYCODE_3, pressed);
break;
return true;
case KeyEvent.KEYCODE_STAR:
JniInterface.sendKeyEvent(KeyEvent.KEYCODE_SHIFT_LEFT, pressed);
JniInterface.sendKeyEvent(KeyEvent.KEYCODE_8, pressed);
break;
return true;
case KeyEvent.KEYCODE_PLUS:
JniInterface.sendKeyEvent(KeyEvent.KEYCODE_SHIFT_LEFT, pressed);
JniInterface.sendKeyEvent(KeyEvent.KEYCODE_EQUALS, pressed);
break;
return true;
default:
// We try to send all other key codes to the host directly.
JniInterface.sendKeyEvent(keyCode, pressed);
return JniInterface.sendKeyEvent(keyCode, pressed);
}
return super.dispatchKeyEvent(event);
}
}
......@@ -322,16 +322,16 @@ public class JniInterface {
private static native void nativeSendMouseWheelEvent(int deltaX, int deltaY);
/** Presses or releases the specified (nonnegative) key. Called on the UI thread. */
public static void sendKeyEvent(int keyCode, boolean keyDown) {
public static boolean sendKeyEvent(int keyCode, boolean keyDown) {
if (!sConnected) {
return;
return false;
}
nativeSendKeyEvent(keyCode, keyDown);
return nativeSendKeyEvent(keyCode, keyDown);
}
/** Passes key press information to the native handling code. */
private static native void nativeSendKeyEvent(int keyCode, boolean keyDown);
private static native boolean nativeSendKeyEvent(int keyCode, boolean keyDown);
/** Sends TextEvent to the host. Called on the UI thread. */
public static void sendTextEvent(String text) {
......
......@@ -210,23 +210,15 @@ void ChromotingJniInstance::SendMouseWheelEvent(int delta_x, int delta_y) {
connection_->input_stub()->InjectMouseEvent(event);
}
void ChromotingJniInstance::SendKeyEvent(int key_code, bool key_down) {
if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) {
jni_runtime_->network_task_runner()->PostTask(
FROM_HERE, base::Bind(&ChromotingJniInstance::SendKeyEvent,
this, key_code, key_down));
return;
}
uint32 usb_code = AndroidKeycodeToUsbKeycode(key_code);
if (usb_code) {
protocol::KeyEvent event;
event.set_usb_keycode(usb_code);
event.set_pressed(key_down);
connection_->input_stub()->InjectKeyEvent(event);
} else {
bool ChromotingJniInstance::SendKeyEvent(int key_code, bool key_down) {
uint32 usb_key_code = AndroidKeycodeToUsbKeycode(key_code);
if (!usb_key_code) {
LOG(WARNING) << "Ignoring unknown keycode: " << key_code;
return false;
}
SendKeyEventInternal(usb_key_code, key_down);
return true;
}
void ChromotingJniInstance::SendTextEvent(const std::string& text) {
......@@ -449,6 +441,22 @@ void ChromotingJniInstance::SetDeviceName(const std::string& device_name) {
device_name_ = device_name;
}
void ChromotingJniInstance::SendKeyEventInternal(int usb_key_code,
bool key_down) {
if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) {
jni_runtime_->network_task_runner()->PostTask(
FROM_HERE, base::Bind(&ChromotingJniInstance::SendKeyEventInternal,
this, usb_key_code, key_down));
return;
}
protocol::KeyEvent event;
event.set_usb_keycode(usb_key_code);
event.set_pressed(key_down);
connection_->input_stub()->InjectKeyEvent(event);
}
void ChromotingJniInstance::EnableStatsLogging(bool enabled) {
DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread());
......
......@@ -87,7 +87,7 @@ class ChromotingJniInstance
void SendMouseWheelEvent(int delta_x, int delta_y);
// Sends the provided keyboard scan code to the host.
void SendKeyEvent(int key_code, bool key_down);
bool SendKeyEvent(int key_code, bool key_down);
void SendTextEvent(const std::string& text);
......@@ -136,6 +136,8 @@ class ChromotingJniInstance
// Sets the device name. Can be called on any thread.
void SetDeviceName(const std::string& device_name);
void SendKeyEventInternal(int usb_key_code, bool key_down);
// Enables or disables periodic logging of performance statistics. Called on
// the network thread.
void EnableStatsLogging(bool enabled);
......
......@@ -129,11 +129,11 @@ static void SendMouseWheelEvent(JNIEnv* env,
delta_x, delta_y);
}
static void SendKeyEvent(JNIEnv* env,
static jboolean SendKeyEvent(JNIEnv* env,
jclass clazz,
jint keyCode,
jboolean keyDown) {
remoting::ChromotingJniRuntime::GetInstance()->session()->SendKeyEvent(
return remoting::ChromotingJniRuntime::GetInstance()->session()->SendKeyEvent(
keyCode, keyDown);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment