Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/host/event_executor.h" | 5 #include "remoting/host/event_executor.h" |
| 6 | 6 |
| 7 #include <ApplicationServices/ApplicationServices.h> | 7 #include <ApplicationServices/ApplicationServices.h> |
| 8 #include <Carbon/Carbon.h> | 8 #include <Carbon/Carbon.h> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/mac/scoped_cftyperef.h" | 12 #include "base/mac/scoped_cftyperef.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "remoting/host/capturer.h" | 14 #include "remoting/host/capturer.h" |
| 15 #include "remoting/proto/internal.pb.h" | 15 #include "remoting/proto/internal.pb.h" |
| 16 #include "remoting/protocol/message_decoder.h" | 16 #include "remoting/protocol/message_decoder.h" |
| 17 | 17 |
| 18 namespace remoting { | 18 namespace remoting { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 // USB to Mac keycode mapping table. | |
| 23 #define USB_KEYMAP(usb, xkb, win, mac) {usb, mac} | |
| 24 #include "remoting/host/usb_keycode_map.h" | |
| 25 #define INVALID_KEYCODE 0xffff | |
|
Wez
2012/03/14 17:55:29
nit: It seems strange to define INVALID_KEYCODE an
garykac
2012/03/14 18:25:44
I did initially, but it made the table look heavy
Wez
2012/03/14 20:38:01
This was a nit; if it makes the table heavy then f
| |
| 26 | |
| 22 using protocol::MouseEvent; | 27 using protocol::MouseEvent; |
| 23 using protocol::KeyEvent; | 28 using protocol::KeyEvent; |
| 24 | 29 |
| 25 // A class to generate events on Mac. | 30 // A class to generate events on Mac. |
| 26 class EventExecutorMac : public EventExecutor { | 31 class EventExecutorMac : public EventExecutor { |
| 27 public: | 32 public: |
| 28 EventExecutorMac(MessageLoop* message_loop, Capturer* capturer); | 33 EventExecutorMac(MessageLoop* message_loop, Capturer* capturer); |
| 29 virtual ~EventExecutorMac() {} | 34 virtual ~EventExecutorMac() {} |
| 30 | 35 |
| 31 virtual void InjectKeyEvent(const KeyEvent& event) OVERRIDE; | 36 virtual void InjectKeyEvent(const KeyEvent& event) OVERRIDE; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 49 // Hard-coded mapping from Virtual Key codes to Mac KeySyms. | 54 // Hard-coded mapping from Virtual Key codes to Mac KeySyms. |
| 50 // This mapping is only valid if both client and host are using a | 55 // This mapping is only valid if both client and host are using a |
| 51 // US English keyboard layout. | 56 // US English keyboard layout. |
| 52 // Because we're passing VK codes on the wire, with no Scancode, | 57 // Because we're passing VK codes on the wire, with no Scancode, |
| 53 // "extended" flag, etc, things like distinguishing left & right | 58 // "extended" flag, etc, things like distinguishing left & right |
| 54 // Shift keys doesn't work. | 59 // Shift keys doesn't work. |
| 55 // | 60 // |
| 56 // TODO(wez): Replace this with something more closely tied to what | 61 // TODO(wez): Replace this with something more closely tied to what |
| 57 // WebInputEventFactory does on Linux/GTK, and which respects the | 62 // WebInputEventFactory does on Linux/GTK, and which respects the |
| 58 // host's keyboard layout. | 63 // host's keyboard layout. |
| 64 // | |
| 65 // TODO(garykac): Remove this table once we switch to using USB | |
| 66 // keycodes. | |
| 59 const int kUsVkeyToKeysym[256] = { | 67 const int kUsVkeyToKeysym[256] = { |
| 60 // 0x00 - 0x07 | 68 // 0x00 - 0x07 |
| 61 -1, -1, -1, -1, | 69 0xffff, 0xffff, 0xffff, 0xffff, |
| 62 // 0x04 - 0x07 | 70 // 0x04 - 0x07 |
| 63 -1, -1, -1, -1, | 71 0xffff, 0xffff, 0xffff, 0xffff, |
| 64 // 0x08 - 0x0B | 72 // 0x08 - 0x0B |
| 65 kVK_Delete, kVK_Tab, -1, -1, | 73 kVK_Delete, kVK_Tab, 0xffff, 0xffff, |
| 66 // 0x0C - 0x0F | 74 // 0x0C - 0x0F |
| 67 -1, kVK_Return, -1, -1, | 75 0xffff, kVK_Return, 0xffff, 0xffff, |
| 68 | 76 |
| 69 // 0x10 - 0x13 | 77 // 0x10 - 0x13 |
| 70 kVK_Shift, kVK_Control, kVK_Option, -1, | 78 kVK_Shift, kVK_Control, kVK_Option, 0xffff, |
| 71 // 0x14 - 0x17 | 79 // 0x14 - 0x17 |
| 72 kVK_CapsLock, kVK_JIS_Kana, /* VKEY_HANGUL */ -1, /* VKEY_JUNJA */ -1, | 80 kVK_CapsLock, kVK_JIS_Kana, /* VKEY_HANGUL */ 0xffff, /* VKEY_JUNJA */ 0xffff, |
| 73 // 0x18 - 0x1B | 81 // 0x18 - 0x1B |
| 74 /* VKEY_FINAL */ -1, /* VKEY_Kanji */ -1, -1, kVK_Escape, | 82 /* VKEY_FINAL */ 0xffff, /* VKEY_Kanji */ 0xffff, 0xffff, kVK_Escape, |
| 75 // 0x1C - 0x1F | 83 // 0x1C - 0x1F |
| 76 /* VKEY_CONVERT */ -1, /* VKEY_NONCONVERT */ -1, | 84 /* VKEY_CONVERT */ 0xffff, /* VKEY_NONCONVERT */ 0xffff, |
| 77 /* VKEY_ACCEPT */ -1, /* VKEY_MODECHANGE */ -1, | 85 /* VKEY_ACCEPT */ 0xffff, /* VKEY_MODECHANGE */ 0xffff, |
| 78 | 86 |
| 79 // 0x20 - 0x23 | 87 // 0x20 - 0x23 |
| 80 kVK_Space, kVK_PageUp, kVK_PageDown, kVK_End, | 88 kVK_Space, kVK_PageUp, kVK_PageDown, kVK_End, |
| 81 // 0x24 - 0x27 | 89 // 0x24 - 0x27 |
| 82 kVK_Home, kVK_LeftArrow, kVK_UpArrow, kVK_RightArrow, | 90 kVK_Home, kVK_LeftArrow, kVK_UpArrow, kVK_RightArrow, |
| 83 // 0x28 - 0x2B | 91 // 0x28 - 0x2B |
| 84 kVK_DownArrow, /* VKEY_SELECT */ -1, /* VKEY_PRINT */ -1, | 92 kVK_DownArrow, /* VKEY_SELECT */ 0xffff, /* VKEY_PRINT */ 0xffff, |
| 85 /* VKEY_EXECUTE */ -1, | 93 /* VKEY_EXECUTE */ 0xffff, |
| 86 // 0x2C - 0x2F | 94 // 0x2C - 0x2F |
| 87 /* VKEY_SNAPSHOT */ -1, /* XK_INSERT */ -1, kVK_ForwardDelete, kVK_Help, | 95 /* VKEY_SNAPSHOT */ 0xffff, /* XK_INSERT */ 0xffff, |
| 96 kVK_ForwardDelete, kVK_Help, | |
| 88 | 97 |
| 89 // 0x30 - 0x33 | 98 // 0x30 - 0x33 |
| 90 kVK_ANSI_0, kVK_ANSI_1, kVK_ANSI_2, kVK_ANSI_3, | 99 kVK_ANSI_0, kVK_ANSI_1, kVK_ANSI_2, kVK_ANSI_3, |
| 91 // 0x34 - 0x37 | 100 // 0x34 - 0x37 |
| 92 kVK_ANSI_4, kVK_ANSI_5, kVK_ANSI_6, kVK_ANSI_7, | 101 kVK_ANSI_4, kVK_ANSI_5, kVK_ANSI_6, kVK_ANSI_7, |
| 93 // 0x38 - 0x3B | 102 // 0x38 - 0x3B |
| 94 kVK_ANSI_8, kVK_ANSI_9, -1, -1, | 103 kVK_ANSI_8, kVK_ANSI_9, 0xffff, 0xffff, |
| 95 // 0x3C - 0x3F | 104 // 0x3C - 0x3F |
| 96 -1, -1, -1, -1, | 105 0xffff, 0xffff, 0xffff, 0xffff, |
| 97 | 106 |
| 98 // 0x40 - 0x43 | 107 // 0x40 - 0x43 |
| 99 -1, kVK_ANSI_A, kVK_ANSI_B, kVK_ANSI_C, | 108 0xffff, kVK_ANSI_A, kVK_ANSI_B, kVK_ANSI_C, |
| 100 // 0x44 - 0x47 | 109 // 0x44 - 0x47 |
| 101 kVK_ANSI_D, kVK_ANSI_E, kVK_ANSI_F, kVK_ANSI_G, | 110 kVK_ANSI_D, kVK_ANSI_E, kVK_ANSI_F, kVK_ANSI_G, |
| 102 // 0x48 - 0x4B | 111 // 0x48 - 0x4B |
| 103 kVK_ANSI_H, kVK_ANSI_I, kVK_ANSI_J, kVK_ANSI_K, | 112 kVK_ANSI_H, kVK_ANSI_I, kVK_ANSI_J, kVK_ANSI_K, |
| 104 // 0x4C - 0x4F | 113 // 0x4C - 0x4F |
| 105 kVK_ANSI_L, kVK_ANSI_M, kVK_ANSI_N, kVK_ANSI_O, | 114 kVK_ANSI_L, kVK_ANSI_M, kVK_ANSI_N, kVK_ANSI_O, |
| 106 | 115 |
| 107 // 0x50 - 0x53 | 116 // 0x50 - 0x53 |
| 108 kVK_ANSI_P, kVK_ANSI_Q, kVK_ANSI_R, kVK_ANSI_S, | 117 kVK_ANSI_P, kVK_ANSI_Q, kVK_ANSI_R, kVK_ANSI_S, |
| 109 // 0x54 - 0x57 | 118 // 0x54 - 0x57 |
| 110 kVK_ANSI_T, kVK_ANSI_U, kVK_ANSI_V, kVK_ANSI_W, | 119 kVK_ANSI_T, kVK_ANSI_U, kVK_ANSI_V, kVK_ANSI_W, |
| 111 // 0x58 - 0x5B | 120 // 0x58 - 0x5B |
| 112 kVK_ANSI_X, kVK_ANSI_Y, kVK_ANSI_Z, kVK_Command, | 121 kVK_ANSI_X, kVK_ANSI_Y, kVK_ANSI_Z, kVK_Command, |
| 113 // 0x5C - 0x5F | 122 // 0x5C - 0x5F |
| 114 kVK_Command, kVK_Command, -1, /* VKEY_SLEEP */ -1, | 123 kVK_Command, kVK_Command, 0xffff, /* VKEY_SLEEP */ 0xffff, |
| 115 | 124 |
| 116 // 0x60 - 0x63 | 125 // 0x60 - 0x63 |
| 117 kVK_ANSI_Keypad0, kVK_ANSI_Keypad1, kVK_ANSI_Keypad2, kVK_ANSI_Keypad3, | 126 kVK_ANSI_Keypad0, kVK_ANSI_Keypad1, kVK_ANSI_Keypad2, kVK_ANSI_Keypad3, |
| 118 // 0x64 - 0x67 | 127 // 0x64 - 0x67 |
| 119 kVK_ANSI_Keypad4, kVK_ANSI_Keypad5, kVK_ANSI_Keypad6, kVK_ANSI_Keypad7, | 128 kVK_ANSI_Keypad4, kVK_ANSI_Keypad5, kVK_ANSI_Keypad6, kVK_ANSI_Keypad7, |
| 120 // 0x68 - 0x6B | 129 // 0x68 - 0x6B |
| 121 kVK_ANSI_Keypad8, kVK_ANSI_Keypad9, kVK_ANSI_KeypadMultiply, | 130 kVK_ANSI_Keypad8, kVK_ANSI_Keypad9, kVK_ANSI_KeypadMultiply, |
| 122 kVK_ANSI_KeypadPlus, | 131 kVK_ANSI_KeypadPlus, |
| 123 // 0x6C - 0x6F | 132 // 0x6C - 0x6F |
| 124 /* VKEY_SEPARATOR */ -1, kVK_ANSI_KeypadMinus, | 133 /* VKEY_SEPARATOR */ 0xffff, kVK_ANSI_KeypadMinus, |
| 125 kVK_ANSI_KeypadDecimal, kVK_ANSI_KeypadDivide, | 134 kVK_ANSI_KeypadDecimal, kVK_ANSI_KeypadDivide, |
| 126 | 135 |
| 127 // 0x70 - 0x73 | 136 // 0x70 - 0x73 |
| 128 kVK_F1, kVK_F2, kVK_F3, kVK_F4, | 137 kVK_F1, kVK_F2, kVK_F3, kVK_F4, |
| 129 // 0x74 - 0x77 | 138 // 0x74 - 0x77 |
| 130 kVK_F5, kVK_F6, kVK_F7, kVK_F8, | 139 kVK_F5, kVK_F6, kVK_F7, kVK_F8, |
| 131 // 0x78 - 0x7B | 140 // 0x78 - 0x7B |
| 132 kVK_F9, kVK_F10, kVK_F11, kVK_F12, | 141 kVK_F9, kVK_F10, kVK_F11, kVK_F12, |
| 133 // 0x7C - 0x7F | 142 // 0x7C - 0x7F |
| 134 kVK_F13, kVK_F14, kVK_F15, kVK_F16, | 143 kVK_F13, kVK_F14, kVK_F15, kVK_F16, |
| 135 | 144 |
| 136 // 0x80 - 0x83 | 145 // 0x80 - 0x83 |
| 137 kVK_F17, kVK_F18, kVK_F19, kVK_F20, | 146 kVK_F17, kVK_F18, kVK_F19, kVK_F20, |
| 138 // 0x84 - 0x87 | 147 // 0x84 - 0x87 |
| 139 /* VKEY_F21 */ -1, /* VKEY_F22 */ -1, /* VKEY_F23 */ -1, /* XKEY_F24 */ -1, | 148 /* VKEY_F21 */ 0xffff, /* VKEY_F22 */ 0xffff, |
| 149 /* VKEY_F23 */ 0xffff, /* XKEY_F24 */ 0xffff, | |
| 140 // 0x88 - 0x8B | 150 // 0x88 - 0x8B |
| 141 -1, -1, -1, -1, | 151 0xffff, 0xffff, 0xffff, 0xffff, |
| 142 // 0x8C - 0x8F | 152 // 0x8C - 0x8F |
| 143 -1, -1, -1, -1, | 153 0xffff, 0xffff, 0xffff, 0xffff, |
| 144 | 154 |
| 145 // 0x90 - 0x93 | 155 // 0x90 - 0x93 |
| 146 /* VKEY_NUMLOCK */ -1, /* VKEY_SCROLL */ -1, -1, -1, | 156 /* VKEY_NUMLOCK */ 0xffff, /* VKEY_SCROLL */ 0xffff, 0xffff, 0xffff, |
| 147 // 0x94 - 0x97 | 157 // 0x94 - 0x97 |
| 148 -1, -1, -1, -1, | 158 0xffff, 0xffff, 0xffff, 0xffff, |
| 149 // 0x98 - 0x9B | 159 // 0x98 - 0x9B |
| 150 -1, -1, -1, -1, | 160 0xffff, 0xffff, 0xffff, 0xffff, |
| 151 // 0x9C - 0x9F | 161 // 0x9C - 0x9F |
| 152 -1, -1, -1, -1, | 162 0xffff, 0xffff, 0xffff, 0xffff, |
| 153 | 163 |
| 154 // 0xA0 - 0xA3 | 164 // 0xA0 - 0xA3 |
| 155 kVK_Shift, kVK_RightShift, kVK_Control, kVK_RightControl, | 165 kVK_Shift, kVK_RightShift, kVK_Control, kVK_RightControl, |
| 156 // 0xA4 - 0xA7 | 166 // 0xA4 - 0xA7 |
| 157 kVK_Option, kVK_RightOption, /* XF86kVK_Back */ -1, /* XF86kVK_Forward */ -1, | 167 kVK_Option, kVK_RightOption, |
| 168 /* XF86kVK_Back */ 0xffff, /* XF86kVK_Forward */ 0xffff, | |
| 158 // 0xA8 - 0xAB | 169 // 0xA8 - 0xAB |
| 159 /* XF86kVK_Refresh */ -1, /* XF86kVK_Stop */ -1, /* XF86kVK_Search */ -1, | 170 /* XF86kVK_Refresh */ 0xffff, /* XF86kVK_Stop */ 0xffff, |
| 160 /* XF86kVK_Favorites */ -1, | 171 /* XF86kVK_Search */ 0xffff, /* XF86kVK_Favorites */ 0xffff, |
| 161 // 0xAC - 0xAF | 172 // 0xAC - 0xAF |
| 162 /* XF86kVK_HomePage */ -1, kVK_Mute, kVK_VolumeDown, kVK_VolumeUp, | 173 /* XF86kVK_HomePage */ 0xffff, kVK_Mute, kVK_VolumeDown, kVK_VolumeUp, |
| 163 | 174 |
| 164 // 0xB0 - 0xB3 | 175 // 0xB0 - 0xB3 |
| 165 /* XF86kVK_AudioNext */ -1, /* XF86kVK_AudioPrev */ -1, | 176 /* XF86kVK_AudioNext */ 0xffff, /* XF86kVK_AudioPrev */ 0xffff, |
| 166 /* XF86kVK_AudioStop */ -1, /* XF86kVK_AudioPause */ -1, | 177 /* XF86kVK_AudioStop */ 0xffff, /* XF86kVK_AudioPause */ 0xffff, |
| 167 // 0xB4 - 0xB7 | 178 // 0xB4 - 0xB7 |
| 168 /* XF86kVK_Mail */ -1, /* XF86kVK_AudioMedia */ -1, /* XF86kVK_Launch0 */ -1, | 179 /* XF86kVK_Mail */ 0xffff, /* XF86kVK_AudioMedia */ 0xffff, |
| 169 /* XF86kVK_Launch1 */ -1, | 180 /* XF86kVK_Launch0 */ 0xffff, /* XF86kVK_Launch1 */ 0xffff, |
| 170 // 0xB8 - 0xBB | 181 // 0xB8 - 0xBB |
| 171 -1, -1, kVK_ANSI_Semicolon, kVK_ANSI_Equal, | 182 0xffff, 0xffff, kVK_ANSI_Semicolon, kVK_ANSI_Equal, |
| 172 // 0xBC - 0xBF | 183 // 0xBC - 0xBF |
| 173 kVK_ANSI_Comma, kVK_ANSI_Minus, kVK_ANSI_Period, kVK_ANSI_Slash, | 184 kVK_ANSI_Comma, kVK_ANSI_Minus, kVK_ANSI_Period, kVK_ANSI_Slash, |
| 174 | 185 |
| 175 // 0xC0 - 0xC3 | 186 // 0xC0 - 0xC3 |
| 176 kVK_ANSI_Grave, -1, -1, -1, | 187 kVK_ANSI_Grave, 0xffff, 0xffff, 0xffff, |
| 177 // 0xC4 - 0xC7 | 188 // 0xC4 - 0xC7 |
| 178 -1, -1, -1, -1, | 189 0xffff, 0xffff, 0xffff, 0xffff, |
| 179 // 0xC8 - 0xCB | 190 // 0xC8 - 0xCB |
| 180 -1, -1, -1, -1, | 191 0xffff, 0xffff, 0xffff, 0xffff, |
| 181 // 0xCC - 0xCF | 192 // 0xCC - 0xCF |
| 182 -1, -1, -1, -1, | 193 0xffff, 0xffff, 0xffff, 0xffff, |
| 183 | 194 |
| 184 // 0xD0 - 0xD3 | 195 // 0xD0 - 0xD3 |
| 185 -1, -1, -1, -1, | 196 0xffff, 0xffff, 0xffff, 0xffff, |
| 186 // 0xD4 - 0xD7 | 197 // 0xD4 - 0xD7 |
| 187 -1, -1, -1, -1, | 198 0xffff, 0xffff, 0xffff, 0xffff, |
| 188 // 0xD8 - 0xDB | 199 // 0xD8 - 0xDB |
| 189 -1, -1, -1, kVK_ANSI_LeftBracket, | 200 0xffff, 0xffff, 0xffff, kVK_ANSI_LeftBracket, |
| 190 // 0xDC - 0xDF | 201 // 0xDC - 0xDF |
| 191 kVK_ANSI_Backslash, kVK_ANSI_RightBracket, kVK_ANSI_Quote, | 202 kVK_ANSI_Backslash, kVK_ANSI_RightBracket, kVK_ANSI_Quote, |
| 192 /* VKEY_OEM_8 */ -1, | 203 /* VKEY_OEM_8 */ 0xffff, |
| 193 | 204 |
| 194 // 0xE0 - 0xE3 | 205 // 0xE0 - 0xE3 |
| 195 -1, -1, /* VKEY_OEM_102 */ -1, -1, | 206 0xffff, 0xffff, /* VKEY_OEM_102 */ 0xffff, 0xffff, |
| 196 // 0xE4 - 0xE7 | 207 // 0xE4 - 0xE7 |
| 197 -1, /* VKEY_PROCESSKEY */ -1, -1, /* VKEY_PACKET */ -1, | 208 0xffff, /* VKEY_PROCESSKEY */ 0xffff, 0xffff, /* VKEY_PACKET */ 0xffff, |
| 198 // 0xE8 - 0xEB | 209 // 0xE8 - 0xEB |
| 199 -1, -1, -1, -1, | 210 0xffff, 0xffff, 0xffff, 0xffff, |
| 200 // 0xEC - 0xEF | 211 // 0xEC - 0xEF |
| 201 -1, -1, -1, -1, | 212 0xffff, 0xffff, 0xffff, 0xffff, |
| 202 | 213 |
| 203 // 0xF0 - 0xF3 | 214 // 0xF0 - 0xF3 |
| 204 -1, -1, -1, -1, | 215 0xffff, 0xffff, 0xffff, 0xffff, |
| 205 // 0xF4 - 0xF7 | 216 // 0xF4 - 0xF7 |
| 206 -1, -1, /* VKEY_ATTN */ -1, /* VKEY_CRSEL */ -1, | 217 0xffff, 0xffff, /* VKEY_ATTN */ 0xffff, /* VKEY_CRSEL */ 0xffff, |
| 207 // 0xF8 - 0xFB | 218 // 0xF8 - 0xFB |
| 208 /* VKEY_EXSEL */ -1, /* VKEY_EREOF */ -1, /* VKEY_PLAY */ -1, | 219 /* VKEY_EXSEL */ 0xffff, /* VKEY_EREOF */ 0xffff, /* VKEY_PLAY */ 0xffff, |
| 209 /* VKEY_ZOOM */ -1, | 220 /* VKEY_ZOOM */ 0xffff, |
| 210 // 0xFC - 0xFF | 221 // 0xFC - 0xFF |
| 211 /* VKEY_NONAME */ -1, /* VKEY_PA1 */ -1, /* VKEY_OEM_CLEAR */ -1, -1 | 222 /* VKEY_NONAME */ 0xffff, /* VKEY_PA1 */ 0xffff, |
| 223 /* VKEY_OEM_CLEAR */ 0xffff, 0xffff | |
| 212 }; | 224 }; |
| 213 | 225 |
| 226 uint16_t UsbKeycodeToMacKeycode(uint32_t usb_keycode) { | |
| 227 if (usb_keycode == 0) | |
|
Wez
2012/03/14 17:55:29
Wrong indentation, throughout this function.
garykac
2012/03/14 18:25:44
Damn Xcode text editor (I didn't have it set up pr
| |
| 228 return INVALID_KEYCODE; | |
| 229 | |
| 230 for (uint i = 0; i < arraysize(usb_keycode_map); i++) | |
|
Wez
2012/03/14 17:55:29
Use braces for this "for".
garykac
2012/03/14 18:25:44
Done.
| |
| 231 if (usb_keycode_map[i].usb_keycode == usb_keycode) | |
| 232 return usb_keycode_map[i].native_keycode; | |
| 233 | |
| 234 return INVALID_KEYCODE; | |
| 235 } | |
| 236 | |
| 214 void EventExecutorMac::InjectKeyEvent(const KeyEvent& event) { | 237 void EventExecutorMac::InjectKeyEvent(const KeyEvent& event) { |
| 215 int key_code = event.keycode(); | 238 int win_keycode = event.keycode(); |
|
Wez
2012/03/14 17:55:29
nit: Move this inside the else block, since it's o
garykac
2012/03/14 18:25:44
Done.
| |
| 216 if (key_code >= 0 && key_code < 256) { | 239 int keycode = 0; |
| 217 int key_sym = kUsVkeyToKeysym[key_code]; | 240 if (event.has_usb_keycode() && event.usb_keycode() != INVALID_KEYCODE) { |
| 218 if (key_sym != -1) { | 241 keycode = UsbKeycodeToMacKeycode(event.usb_keycode()); |
| 219 // We use the deprecated event injection API because the new one doesn't | 242 VLOG(1) << "USB keycode: " << std::hex << event.usb_keycode() |
| 220 // work with switched-out sessions (curtain mode). | 243 << " to Mac keycode: " << keycode << std::dec; |
| 221 CGError error = CGPostKeyboardEvent(0, key_sym, event.pressed()); | 244 } else { |
| 222 if (error != kCGErrorSuccess) { | 245 if (win_keycode >= 0 && win_keycode < 256) { |
| 223 LOG(WARNING) << "CGPostKeyboardEvent error " << error; | 246 keycode = kUsVkeyToKeysym[win_keycode]; |
| 224 } | 247 } |
| 248 } | |
| 249 | |
| 250 if (keycode != INVALID_KEYCODE) { | |
| 251 // We use the deprecated event injection API because the new one doesn't | |
| 252 // work with switched-out sessions (curtain mode). | |
| 253 CGError error = CGPostKeyboardEvent(0, keycode, event.pressed()); | |
| 254 if (error != kCGErrorSuccess) { | |
| 255 LOG(WARNING) << "CGPostKeyboardEvent error " << error; | |
| 225 } | 256 } |
| 226 } | 257 } |
| 227 } | 258 } |
| 228 | 259 |
| 229 void EventExecutorMac::InjectMouseEvent(const MouseEvent& event) { | 260 void EventExecutorMac::InjectMouseEvent(const MouseEvent& event) { |
| 230 if (event.has_x() && event.has_y()) { | 261 if (event.has_x() && event.has_y()) { |
| 231 // TODO(wez): Checking the validity of the MouseEvent should be done in core | 262 // TODO(wez): Checking the validity of the MouseEvent should be done in core |
| 232 // cross-platform code, not here! | 263 // cross-platform code, not here! |
| 233 // TODO(wez): This code assumes that MouseEvent(0,0) (top-left of client vie w) | 264 // TODO(wez): This code assumes that MouseEvent(0,0) (top-left of client vie w) |
| 234 // corresponds to local (0,0) (top-left of primary monitor). That won't in | 265 // corresponds to local (0,0) (top-left of primary monitor). That won't in |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 289 | 320 |
| 290 } // namespace | 321 } // namespace |
| 291 | 322 |
| 292 scoped_ptr<protocol::InputStub> EventExecutor::Create(MessageLoop* message_loop, | 323 scoped_ptr<protocol::InputStub> EventExecutor::Create(MessageLoop* message_loop, |
| 293 Capturer* capturer) { | 324 Capturer* capturer) { |
| 294 return scoped_ptr<protocol::InputStub>( | 325 return scoped_ptr<protocol::InputStub>( |
| 295 new EventExecutorMac(message_loop, capturer)); | 326 new EventExecutorMac(message_loop, capturer)); |
| 296 } | 327 } |
| 297 | 328 |
| 298 } // namespace remoting | 329 } // namespace remoting |
| OLD | NEW |