Commit e2ba2b44 authored by hclam@chromium.org's avatar hclam@chromium.org

[chromoting] Fix sticky c key with cmd on mac using usb keycode

Switch to use USB keycode for the fix for sticky keys on Mac.

BUG=101937
TEST=Build on Mac and run chromoting and press cmd+c

Review URL: https://chromiumcodereview.appspot.com/10387226

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@138205 0039d316-1c4b-4281-b951-d872f2087c98
parent 14e66abe
...@@ -6,17 +6,21 @@ ...@@ -6,17 +6,21 @@
#include <vector> #include <vector>
#include "base/logging.h"
namespace remoting { namespace remoting {
namespace { namespace {
// A list of known keycodes. const unsigned int kUsbLeftControl = 0x0700e0;
const int kShift = 16; const unsigned int kUsbLeftShift = 0x0700e1;
const int kControl = 17; const unsigned int kUsbLeftOption = 0x0700e2;
const int kOption = 18; const unsigned int kUsbLeftCmd = 0x0700e3;
const int kCapsLock = 20; const unsigned int kUsbRightControl = 0x0700e4;
const int kLeftCmd = 91; const unsigned int kUsbRightShift = 0x0700e5;
const int kRightCmd = 93; const unsigned int kUsbRightOption = 0x0700e6;
const unsigned int kUsbRightCmd = 0x0700e7;
const unsigned int kUsbTab = 0x07002b;
} // namespace } // namespace
...@@ -28,19 +32,32 @@ MacKeyEventProcessor::~MacKeyEventProcessor() { ...@@ -28,19 +32,32 @@ MacKeyEventProcessor::~MacKeyEventProcessor() {
} }
void MacKeyEventProcessor::InjectKeyEvent(const protocol::KeyEvent& event) { void MacKeyEventProcessor::InjectKeyEvent(const protocol::KeyEvent& event) {
if (event.pressed()) { DCHECK(event.has_usb_keycode());
key_pressed_map_[event.keycode()] = event;
} else { bool is_special_key = event.usb_keycode() == kUsbLeftControl ||
key_pressed_map_.erase(event.keycode()); event.usb_keycode() == kUsbLeftShift ||
if (event.keycode() == kLeftCmd || event.keycode() == kRightCmd) event.usb_keycode() == kUsbLeftOption ||
GenerateKeyupEvents(); event.usb_keycode() == kUsbRightControl ||
event.usb_keycode() == kUsbRightShift ||
event.usb_keycode() == kUsbRightOption ||
event.usb_keycode() == kUsbTab;
bool is_cmd_key = event.usb_keycode() == kUsbLeftCmd ||
event.usb_keycode() == kUsbRightCmd;
if (!is_cmd_key && !is_special_key) {
if (event.pressed()) {
key_pressed_map_[event.usb_keycode()] = event;
} else {
key_pressed_map_.erase(event.usb_keycode());
}
} }
InputFilter::InjectKeyEvent(event); if (is_cmd_key && !event.pressed()) {
} GenerateKeyupEvents();
}
int MacKeyEventProcessor::NumberOfPressedKeys() const { InputFilter::InjectKeyEvent(event);
return key_pressed_map_.size();
} }
void MacKeyEventProcessor::GenerateKeyupEvents() { void MacKeyEventProcessor::GenerateKeyupEvents() {
...@@ -52,12 +69,6 @@ void MacKeyEventProcessor::GenerateKeyupEvents() { ...@@ -52,12 +69,6 @@ void MacKeyEventProcessor::GenerateKeyupEvents() {
i != key_pressed_map_.end(); ++i) { i != key_pressed_map_.end(); ++i) {
const int keycode = i->first; const int keycode = i->first;
if (keycode == kCapsLock || keycode == kOption ||
keycode == kControl || keycode == kShift ||
keycode == kLeftCmd || keycode == kRightCmd) {
continue;
}
keycodes.push_back(keycode); keycodes.push_back(keycode);
protocol::KeyEvent event = i->second; protocol::KeyEvent event = i->second;
event.set_pressed(false); event.set_pressed(false);
......
...@@ -12,13 +12,6 @@ ...@@ -12,13 +12,6 @@
// The cause is that CMD + C triggers a system action and Chrome injects only a // The cause is that CMD + C triggers a system action and Chrome injects only a
// keydown event for the C key. Safari shares the same behavior. // keydown event for the C key. Safari shares the same behavior.
// //
// This is a list of sample edge cases:
//
// CMD DOWN, C DOWN, C UP, CMD UP
// CMD DOWN, SHIFT DOWN, C DOWN, C UP, CMD UP, SHIFT UP
// CMD DOWN, CAPS LOCK DOWN, CMD DOWN, CAPS LOCK DOWN
// L CMD DOWN, C DOWN, R CMD DOWN, L CMD UP, C UP, R CMD UP
//
// SOLUTION // SOLUTION
// //
// When a keyup event for CMD key happens we will check all prior keydown // When a keyup event for CMD key happens we will check all prior keydown
...@@ -41,7 +34,8 @@ ...@@ -41,7 +34,8 @@
// CMD DOWN, C DOWN, C UP, CMD UP, C UP // CMD DOWN, C DOWN, C UP, CMD UP, C UP
// //
// Because we artificially generate keyup events the C UP event is duplicated // Because we artificially generate keyup events the C UP event is duplicated
// as user releases the key after CMD key. // as user releases the key after CMD key. This would not be a problem as the
// receiver end will drop this duplicated keyup event.
#ifndef REMOTING_CLIENT_PLUGIN_MAC_KEY_EVENT_PROCESSOR_H_ #ifndef REMOTING_CLIENT_PLUGIN_MAC_KEY_EVENT_PROCESSOR_H_
#define REMOTING_CLIENT_PLUGIN_MAC_KEY_EVENT_PROCESSOR_H_ #define REMOTING_CLIENT_PLUGIN_MAC_KEY_EVENT_PROCESSOR_H_
...@@ -66,12 +60,8 @@ class MacKeyEventProcessor : public protocol::InputFilter { ...@@ -66,12 +60,8 @@ class MacKeyEventProcessor : public protocol::InputFilter {
// InputFilter overrides. // InputFilter overrides.
virtual void InjectKeyEvent(const protocol::KeyEvent& event) OVERRIDE; virtual void InjectKeyEvent(const protocol::KeyEvent& event) OVERRIDE;
// Return the number of keys pressed. This method is used by unit test to
// test correctness of this class.
int NumberOfPressedKeys() const;
private: private:
// Iterate the current pressed keys and generate keyup events. // Generate keyup events for any keys pressed with CMD.
void GenerateKeyupEvents(); void GenerateKeyupEvents();
// A map that stores pressed keycodes and the corresponding key event. // A map that stores pressed keycodes and the corresponding key event.
......
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