Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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 "ui/events/keycodes/platform_key_map_win.h" | 5 #include "ui/events/keycodes/platform_key_map_win.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 return DomKey::ARROW_DOWN; | 132 return DomKey::ARROW_DOWN; |
| 133 case VKEY_INSERT: | 133 case VKEY_INSERT: |
| 134 return DomKey::INSERT; | 134 return DomKey::INSERT; |
| 135 case VKEY_DELETE: | 135 case VKEY_DELETE: |
| 136 return DomKey::DEL; | 136 return DomKey::DEL; |
| 137 default: | 137 default: |
| 138 return DomKey::NONE; | 138 return DomKey::NONE; |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 | 141 |
| 142 // This table must be sorted by |key_code| for binary search. | |
| 143 const struct NonPrintableKeyEntry { | |
| 144 KeyboardCode key_code; | |
| 145 DomKey dom_key; | |
| 146 } kNonPrintableKeyMap[] = { | |
|
Wez
2016/06/01 20:49:04
nit: Are you sure that none of these values has Do
chongz
2016/06/01 23:09:42
I'm not entirely sure, but according to my underst
Wez
2016/06/03 00:00:51
Acknowledged.
| |
| 147 {VKEY_CANCEL, DomKey::CANCEL}, | |
| 148 {VKEY_BACK, DomKey::BACKSPACE}, | |
| 149 {VKEY_TAB, DomKey::TAB}, | |
| 150 {VKEY_CLEAR, DomKey::CLEAR}, | |
| 151 {VKEY_RETURN, DomKey::ENTER}, | |
| 152 {VKEY_SHIFT, DomKey::SHIFT}, | |
| 153 {VKEY_CONTROL, DomKey::CONTROL}, | |
| 154 {VKEY_MENU, DomKey::ALT}, | |
| 155 {VKEY_PAUSE, DomKey::PAUSE}, | |
| 156 {VKEY_CAPITAL, DomKey::CAPS_LOCK}, | |
| 157 // TODO(chongz): Map VKEY_KANA/VKEY_HANGUL based on layout. | |
| 158 // https://crbug.com/612736 | |
| 159 {VKEY_KANA, DomKey::KANA_MODE}, | |
| 160 // {VKEY_HANGUL, DomKey::HANGUL_MODE}, | |
| 161 {VKEY_JUNJA, DomKey::JUNJA_MODE}, | |
| 162 {VKEY_FINAL, DomKey::FINAL_MODE}, | |
| 163 // TODO(chongz): Map VKEY_HANJA/VKEY_KANJI based on layout. | |
|
Wez
2016/06/01 20:49:04
nit: Would it make sense, here and for the previou
chongz
2016/06/01 23:09:42
Will do.
| |
| 164 // https://crbug.com/612736 | |
| 165 {VKEY_HANJA, DomKey::HANJA_MODE}, | |
| 166 // {VKEY_KANJI, DomKey::KANJI_MODE}, | |
| 167 {VKEY_ESCAPE, DomKey::ESCAPE}, | |
| 168 {VKEY_CONVERT, DomKey::CONVERT}, | |
| 169 {VKEY_NONCONVERT, DomKey::NON_CONVERT}, | |
| 170 {VKEY_ACCEPT, DomKey::ACCEPT}, | |
| 171 {VKEY_MODECHANGE, DomKey::MODE_CHANGE}, | |
| 172 // VKEY_SPACE | |
| 173 {VKEY_PRIOR, DomKey::PAGE_UP}, | |
| 174 {VKEY_NEXT, DomKey::PAGE_DOWN}, | |
| 175 {VKEY_END, DomKey::END}, | |
| 176 {VKEY_HOME, DomKey::HOME}, | |
| 177 {VKEY_LEFT, DomKey::ARROW_LEFT}, | |
| 178 {VKEY_UP, DomKey::ARROW_UP}, | |
| 179 {VKEY_RIGHT, DomKey::ARROW_RIGHT}, | |
| 180 {VKEY_DOWN, DomKey::ARROW_DOWN}, | |
| 181 {VKEY_SELECT, DomKey::SELECT}, | |
| 182 {VKEY_PRINT, DomKey::PRINT}, | |
| 183 {VKEY_EXECUTE, DomKey::EXECUTE}, | |
| 184 {VKEY_SNAPSHOT, DomKey::PRINT_SCREEN}, | |
| 185 {VKEY_INSERT, DomKey::INSERT}, | |
| 186 {VKEY_DELETE, DomKey::DEL}, | |
| 187 {VKEY_HELP, DomKey::HELP}, | |
| 188 // VKEY_0..9 | |
| 189 // VKEY_A..Z | |
| 190 {VKEY_LWIN, DomKey::META}, | |
| 191 // VKEY_COMMAND - The same as VKEY_LWIN. | |
| 192 {VKEY_RWIN, DomKey::META}, | |
| 193 {VKEY_APPS, DomKey::CONTEXT_MENU}, | |
| 194 {VKEY_SLEEP, DomKey::STANDBY}, | |
| 195 // VKEY_NUMPAD0..9 - Handled by |NumPadKeyCodeToDomKey()|. | |
|
Wez
2016/06/01 20:49:04
nit: No need for the "Handled by", I don't think;
chongz
2016/06/01 23:09:42
Will change it to
"""
// VKEY_NUMPAD0..9
"""
| |
| 196 // VKEY_MULTIPLY, VKEY_ADD, VKEY_SEPARATOR, VKEY_SUBTRACT, VKEY_DECIMAL, | |
| 197 // VKEY_DIVIDE | |
| 198 {VKEY_F1, DomKey::F1}, | |
| 199 {VKEY_F2, DomKey::F2}, | |
| 200 {VKEY_F3, DomKey::F3}, | |
| 201 {VKEY_F4, DomKey::F4}, | |
| 202 {VKEY_F5, DomKey::F5}, | |
| 203 {VKEY_F6, DomKey::F6}, | |
| 204 {VKEY_F7, DomKey::F7}, | |
| 205 {VKEY_F8, DomKey::F8}, | |
| 206 {VKEY_F9, DomKey::F9}, | |
| 207 {VKEY_F10, DomKey::F10}, | |
| 208 {VKEY_F11, DomKey::F11}, | |
| 209 {VKEY_F12, DomKey::F12}, | |
| 210 {VKEY_F13, DomKey::F13}, | |
| 211 {VKEY_F14, DomKey::F14}, | |
| 212 {VKEY_F15, DomKey::F15}, | |
| 213 {VKEY_F16, DomKey::F16}, | |
| 214 {VKEY_F17, DomKey::F17}, | |
| 215 {VKEY_F18, DomKey::F18}, | |
| 216 {VKEY_F19, DomKey::F19}, | |
| 217 {VKEY_F20, DomKey::F20}, | |
| 218 {VKEY_F21, DomKey::F21}, | |
| 219 {VKEY_F22, DomKey::F22}, | |
| 220 {VKEY_F23, DomKey::F23}, | |
| 221 {VKEY_F24, DomKey::F24}, | |
| 222 {VKEY_NUMLOCK, DomKey::NUM_LOCK}, | |
| 223 {VKEY_SCROLL, DomKey::SCROLL_LOCK}, | |
| 224 {VKEY_LSHIFT, DomKey::SHIFT}, | |
| 225 {VKEY_RSHIFT, DomKey::SHIFT}, | |
| 226 {VKEY_LCONTROL, DomKey::CONTROL}, | |
| 227 {VKEY_RCONTROL, DomKey::CONTROL}, | |
| 228 {VKEY_LMENU, DomKey::ALT}, | |
| 229 {VKEY_RMENU, DomKey::ALT}, | |
| 230 {VKEY_BROWSER_BACK, DomKey::BROWSER_BACK}, | |
| 231 {VKEY_BROWSER_FORWARD, DomKey::BROWSER_FORWARD}, | |
| 232 {VKEY_BROWSER_REFRESH, DomKey::BROWSER_REFRESH}, | |
| 233 {VKEY_BROWSER_STOP, DomKey::BROWSER_STOP}, | |
| 234 {VKEY_BROWSER_SEARCH, DomKey::BROWSER_SEARCH}, | |
| 235 {VKEY_BROWSER_FAVORITES, DomKey::BROWSER_FAVORITES}, | |
| 236 {VKEY_BROWSER_HOME, DomKey::BROWSER_HOME}, | |
| 237 {VKEY_VOLUME_MUTE, DomKey::AUDIO_VOLUME_MUTE}, | |
| 238 {VKEY_VOLUME_DOWN, DomKey::AUDIO_VOLUME_DOWN}, | |
| 239 {VKEY_VOLUME_UP, DomKey::AUDIO_VOLUME_UP}, | |
| 240 {VKEY_MEDIA_NEXT_TRACK, DomKey::MEDIA_TRACK_NEXT}, | |
| 241 {VKEY_MEDIA_PREV_TRACK, DomKey::MEDIA_TRACK_PREVIOUS}, | |
| 242 {VKEY_MEDIA_STOP, DomKey::MEDIA_STOP}, | |
| 243 {VKEY_MEDIA_PLAY_PAUSE, DomKey::MEDIA_PLAY_PAUSE}, | |
| 244 {VKEY_MEDIA_LAUNCH_MAIL, DomKey::LAUNCH_MAIL}, | |
| 245 {VKEY_MEDIA_LAUNCH_MEDIA_SELECT, DomKey::LAUNCH_MEDIA_PLAYER}, | |
| 246 // TODO(chongz): Actually we don't know whether it's mapped to launch | |
| 247 // computer/calculator or not, better use a generic DomKey string. | |
| 248 // https://crbug.com/612743 | |
|
Wez
2016/06/01 20:49:04
Any reason not to make that change directly, here?
chongz
2016/06/01 23:09:42
Because spec says it should be "LaunchMyComputer",
Wez
2016/06/03 00:00:51
nit: Seems that it would be best to avoid leaving
| |
| 249 {VKEY_MEDIA_LAUNCH_APP1, DomKey::LAUNCH_MY_COMPUTER}, | |
| 250 {VKEY_MEDIA_LAUNCH_APP2, DomKey::LAUNCH_CALCULATOR}, | |
| 251 // VKEY_OEM_1..8, 102, PLUS, COMMA, MINUS, PERIOD | |
| 252 {VKEY_ALTGR, DomKey::ALT_GRAPH}, | |
| 253 {VKEY_PROCESSKEY, DomKey::PROCESS}, | |
| 254 // VKEY_PACKET - Used to pass Unicode char, considered as printable key. | |
| 255 | |
| 256 // TODO(chongz): Handle Japanese keyboard layout keys 0xF0..0xF5. | |
| 257 // https://crbug.com/612694 | |
| 258 {VKEY_ATTN, DomKey::ATTN}, | |
| 259 {VKEY_CRSEL, DomKey::CR_SEL}, | |
| 260 {VKEY_EXSEL, DomKey::EX_SEL}, | |
| 261 {VKEY_EREOF, DomKey::ERASE_EOF}, | |
| 262 {VKEY_PLAY, DomKey::PLAY}, | |
| 263 {VKEY_ZOOM, DomKey::ZOOM_TOGGLE}, | |
| 264 // TODO(chongz): Handle VKEY_NONAME, VKEY_PA1 | |
|
Wez
2016/06/01 20:49:04
nit: Is there a bug # for that?
chongz
2016/06/01 23:09:42
Will create one. (But actually no idea what these
Wez
2016/06/03 00:00:51
Hopefully they can be skipped!
| |
| 265 {VKEY_OEM_CLEAR, DomKey::CLEAR}, | |
| 266 }; | |
| 267 | |
| 268 DomKey NonPrintableKeyboardCodeToDomKey(KeyboardCode key_code) { | |
| 269 const NonPrintableKeyEntry* result = std::lower_bound( | |
| 270 std::begin(kNonPrintableKeyMap), std::end(kNonPrintableKeyMap), key_code, | |
| 271 [](const NonPrintableKeyEntry& entry, KeyboardCode needle) { | |
| 272 return entry.key_code < needle; | |
| 273 }); | |
| 274 if (result != std::end(kNonPrintableKeyMap) && result->key_code == key_code) | |
| 275 return result->dom_key; | |
| 276 return DomKey::NONE; | |
| 277 } | |
| 278 | |
| 142 void CleanupKeyMapTls(void* data) { | 279 void CleanupKeyMapTls(void* data) { |
| 143 PlatformKeyMap* key_map = reinterpret_cast<PlatformKeyMap*>(data); | 280 PlatformKeyMap* key_map = reinterpret_cast<PlatformKeyMap*>(data); |
| 144 delete key_map; | 281 delete key_map; |
| 145 } | 282 } |
| 146 | 283 |
| 147 struct PlatformKeyMapInstanceTlsTraits | 284 struct PlatformKeyMapInstanceTlsTraits |
| 148 : public base::DefaultLazyInstanceTraits<base::ThreadLocalStorage::Slot> { | 285 : public base::DefaultLazyInstanceTraits<base::ThreadLocalStorage::Slot> { |
| 149 static base::ThreadLocalStorage::Slot* New(void* instance) { | 286 static base::ThreadLocalStorage::Slot* New(void* instance) { |
| 150 // Use placement new to initialize our instance in our preallocated space. | 287 // Use placement new to initialize our instance in our preallocated space. |
| 151 // TODO(chongz): Use std::default_delete instead of providing own function. | 288 // TODO(chongz): Use std::default_delete instead of providing own function. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 163 | 300 |
| 164 PlatformKeyMap::PlatformKeyMap(HKL layout) { | 301 PlatformKeyMap::PlatformKeyMap(HKL layout) { |
| 165 UpdateLayout(layout); | 302 UpdateLayout(layout); |
| 166 } | 303 } |
| 167 | 304 |
| 168 PlatformKeyMap::~PlatformKeyMap() {} | 305 PlatformKeyMap::~PlatformKeyMap() {} |
| 169 | 306 |
| 170 DomKey PlatformKeyMap::DomKeyFromNativeImpl(DomCode code, | 307 DomKey PlatformKeyMap::DomKeyFromNativeImpl(DomCode code, |
| 171 KeyboardCode key_code, | 308 KeyboardCode key_code, |
| 172 int flags) const { | 309 int flags) const { |
| 310 DomKey key = NonPrintableKeyboardCodeToDomKey(key_code); | |
| 311 if (key != DomKey::NONE) | |
| 312 return key; | |
| 313 | |
| 173 if (KeycodeConverter::DomCodeToLocation(code) == DomKeyLocation::NUMPAD) { | 314 if (KeycodeConverter::DomCodeToLocation(code) == DomKeyLocation::NUMPAD) { |
| 174 // Derived the DOM Key value from |key_code| instead of |code|, to address | 315 // Derived the DOM Key value from |key_code| instead of |code|, to address |
| 175 // Windows Numlock/Shift interaction - see crbug.com/594552. | 316 // Windows Numlock/Shift interaction - see crbug.com/594552. |
| 176 return NumPadKeyCodeToDomKey(key_code); | 317 return NumPadKeyCodeToDomKey(key_code); |
| 177 } | 318 } |
| 178 | 319 |
| 179 const int flags_to_try[] = { | 320 const int flags_to_try[] = { |
| 180 // Trying to match Firefox's behavior and UIEvents DomKey guidelines. | 321 // Trying to match Firefox's behavior and UIEvents DomKey guidelines. |
| 181 // If the combination doesn't produce a printable character, the key value | 322 // If the combination doesn't produce a printable character, the key value |
| 182 // should be the key with no modifiers except for Shift and AltGr. | 323 // should be the key with no modifiers except for Shift and AltGr. |
| 183 // See https://w3c.github.io/uievents/#keys-guidelines | 324 // See https://w3c.github.io/uievents/#keys-guidelines |
| 184 flags, | 325 flags, |
| 185 flags & (EF_SHIFT_DOWN | EF_ALTGR_DOWN | EF_CAPS_LOCK_ON), | 326 flags & (EF_SHIFT_DOWN | EF_ALTGR_DOWN | EF_CAPS_LOCK_ON), |
| 186 flags & (EF_SHIFT_DOWN | EF_CAPS_LOCK_ON), | 327 flags & (EF_SHIFT_DOWN | EF_CAPS_LOCK_ON), |
| 187 EF_NONE, | 328 EF_NONE, |
| 188 }; | 329 }; |
| 189 | 330 |
| 190 DomKey key = DomKey::NONE; | |
| 191 for (auto try_flags : flags_to_try) { | 331 for (auto try_flags : flags_to_try) { |
| 192 const auto& it = code_to_key_.find(std::make_pair(static_cast<int>(code), | 332 const auto& it = code_to_key_.find(std::make_pair(static_cast<int>(code), |
| 193 try_flags)); | 333 try_flags)); |
| 194 if (it != code_to_key_.end()) { | 334 if (it != code_to_key_.end()) { |
| 195 key = it->second; | 335 key = it->second; |
| 196 if (key != DomKey::NONE) | 336 if (key != DomKey::NONE) |
| 197 break; | 337 break; |
| 198 } | 338 } |
| 199 } | 339 } |
| 200 return key; | 340 return key; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 } | 412 } |
| 273 } else { | 413 } else { |
| 274 // TODO(chongz): Handle rv <= -2 and rv >= 2. | 414 // TODO(chongz): Handle rv <= -2 and rv >= 2. |
| 275 } | 415 } |
| 276 } | 416 } |
| 277 } | 417 } |
| 278 ::SetKeyboardState(keyboard_state_to_restore); | 418 ::SetKeyboardState(keyboard_state_to_restore); |
| 279 } | 419 } |
| 280 | 420 |
| 281 } // namespace ui | 421 } // namespace ui |
| OLD | NEW |