summaryrefslogtreecommitdiffstats
path: root/remoting/host/event_executor_linux.cc
diff options
context:
space:
mode:
authorwez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-05 20:17:53 +0000
committerwez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-05 20:17:53 +0000
commit1ab57f0ac1e3355f27484002c7b73fbe62cbb91a (patch)
tree5c3a92651348b1e72fb44d7d522717360455336a /remoting/host/event_executor_linux.cc
parentfe6f29f04e4d87da894e32f056b852e03403696e (diff)
downloadchromium_src-1ab57f0ac1e3355f27484002c7b73fbe62cbb91a.zip
chromium_src-1ab57f0ac1e3355f27484002c7b73fbe62cbb91a.tar.gz
chromium_src-1ab57f0ac1e3355f27484002c7b73fbe62cbb91a.tar.bz2
Clean up the EventExecutor implementations.
* Cope better with malformed input. * Make logging more uniform across platforms. * Make the implementations more consistent looking. BUG=118513 TEST=Manually verify that input events behave as expected. Review URL: http://codereview.chromium.org/9968108 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@130997 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/host/event_executor_linux.cc')
-rw-r--r--remoting/host/event_executor_linux.cc67
1 files changed, 25 insertions, 42 deletions
diff --git a/remoting/host/event_executor_linux.cc b/remoting/host/event_executor_linux.cc
index bf2d518..d6b412e 100644
--- a/remoting/host/event_executor_linux.cc
+++ b/remoting/host/event_executor_linux.cc
@@ -20,15 +20,16 @@
namespace remoting {
+namespace {
+
using protocol::ClipboardEvent;
using protocol::KeyEvent;
using protocol::MouseEvent;
-namespace {
-
// USB to XKB keycode map table.
#define USB_KEYMAP(usb, xkb, win, mac) {usb, xkb}
#include "remoting/host/usb_keycode_map.h"
+#undef USB_KEYMAP
// A class to generate events on Linux.
class EventExecutorLinux : public EventExecutor {
@@ -257,24 +258,12 @@ const int kUsVkeyToKeysym[256] = {
};
int ChromotocolKeycodeToX11Keysym(int32_t keycode) {
- if (keycode < 0 || keycode > 255) {
- return -1;
- }
+ if (keycode < 0 || keycode > 255)
+ return kInvalidKeycode;
return kUsVkeyToKeysym[keycode];
}
-uint16_t UsbKeycodeToXkbKeycode(uint32_t usb_keycode) {
- if (usb_keycode == 0)
- return 0;
-
- for (uint i = 0; i < arraysize(usb_keycode_map); i++)
- if (usb_keycode_map[i].usb_keycode == usb_keycode)
- return usb_keycode_map[i].native_keycode;
-
- return 0;
-}
-
EventExecutorLinux::EventExecutorLinux(MessageLoop* message_loop,
Capturer* capturer)
: message_loop_(message_loop),
@@ -325,6 +314,9 @@ void EventExecutorLinux::InjectClipboardEvent(const ClipboardEvent& event) {
}
void EventExecutorLinux::InjectKeyEvent(const KeyEvent& event) {
+ // HostEventDispatcher should filter events missing the pressed field.
+ DCHECK(event.has_pressed());
+
if (MessageLoop::current() != message_loop_) {
message_loop_->PostTask(
FROM_HERE,
@@ -333,38 +325,29 @@ void EventExecutorLinux::InjectKeyEvent(const KeyEvent& event) {
return;
}
- int keycode = 0;
- if (event.has_usb_keycode() && event.usb_keycode() != 0) {
- keycode = UsbKeycodeToXkbKeycode(event.usb_keycode());
- VLOG(3) << "Got usb keycode: " << std::hex << event.usb_keycode()
- << " to xkb keycode: " << keycode << std::dec;
- } else {
+ // Events which don't specify whether the key is pressed are invalid.
+ if (!event.has_pressed())
+ return;
+
+ int keycode = kInvalidKeycode;
+ if (event.has_usb_keycode()) {
+ keycode = UsbKeycodeToNativeKeycode(event.usb_keycode());
+ VLOG(3) << "Converting USB keycode: " << std::hex << event.usb_keycode()
+ << " to keycode: " << keycode << std::dec;
+ } else if (event.has_keycode()) {
// Fall back to keysym translation.
// TODO(garykac) Remove this once we switch entirely over to USB keycodes.
int keysym = ChromotocolKeycodeToX11Keysym(event.keycode());
-
- VLOG(3) << "Converting Win vkey: " << std::hex << event.keycode()
- << " to xkeysym: " << keysym << std::dec;
- if (keysym == -1) {
- LOG(WARNING) << "Ignoring unknown key: " << event.keycode();
- return;
- }
-
- // Translate the keysym into a keycode understandable by the X display.
keycode = XKeysymToKeycode(display_, keysym);
- VLOG(3) << "Converting xkeysym: " << std::hex << keysym
- << " to x11 keycode: " << keycode << std::dec;
- if (keycode == 0) {
- LOG(WARNING) << "Ignoring undefined keysym: " << keysym
- << " for key: " << event.keycode();
- return;
- }
-
- VLOG(3) << "Got pepper key: " << event.keycode()
- << " sending keysym: " << keysym
- << " to keycode: " << keycode;
+ VLOG(3) << "Converting VKEY: " << std::hex << event.keycode()
+ << " to keysym: " << keysym
+ << " to keycode: " << keycode << std::dec;
}
+ // Ignore events with no VK- or USB-keycode, or which can't be mapped.
+ if (keycode == kInvalidKeycode)
+ return;
+
if (event.pressed()) {
if (pressed_keys_.find(keycode) != pressed_keys_.end()) {
// Key is already held down, so lift the key up to ensure this repeated