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 "chrome/browser/ui/ash/event_rewriter.h" | 5 #include "chrome/browser/ui/ash/event_rewriter.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 unsigned int native_modifier; | 78 unsigned int native_modifier; |
| 79 int flag; | 79 int flag; |
| 80 const char* pref_name; | 80 const char* pref_name; |
| 81 } kModifierFlagToPrefName[] = { | 81 } kModifierFlagToPrefName[] = { |
| 82 // TODO(yusukes): When the device has a Chrome keyboard (i.e. the one without | 82 // TODO(yusukes): When the device has a Chrome keyboard (i.e. the one without |
| 83 // Caps Lock), we should not check kLanguageRemapCapsLockKeyTo. | 83 // Caps Lock), we should not check kLanguageRemapCapsLockKeyTo. |
| 84 { Mod3Mask, 0, prefs::kLanguageRemapCapsLockKeyTo }, | 84 { Mod3Mask, 0, prefs::kLanguageRemapCapsLockKeyTo }, |
| 85 { Mod4Mask, 0, prefs::kLanguageRemapSearchKeyTo }, | 85 { Mod4Mask, 0, prefs::kLanguageRemapSearchKeyTo }, |
| 86 { ControlMask, ui::EF_CONTROL_DOWN, prefs::kLanguageRemapControlKeyTo }, | 86 { ControlMask, ui::EF_CONTROL_DOWN, prefs::kLanguageRemapControlKeyTo }, |
| 87 { Mod1Mask, ui::EF_ALT_DOWN, prefs::kLanguageRemapAltKeyTo }, | 87 { Mod1Mask, ui::EF_ALT_DOWN, prefs::kLanguageRemapAltKeyTo }, |
| 88 { Mod2Mask, 0, prefs::kLanguageRemapDiamondKeyTo }, | |
| 88 }; | 89 }; |
| 89 | 90 |
| 90 // Gets a remapped key for |pref_name| key. For example, to find out which | 91 // Gets a remapped key for |pref_name| key. For example, to find out which |
| 91 // key Search is currently remapped to, call the function with | 92 // key Search is currently remapped to, call the function with |
| 92 // prefs::kLanguageRemapSearchKeyTo. | 93 // prefs::kLanguageRemapSearchKeyTo. |
| 93 const ModifierRemapping* GetRemappedKey(const std::string& pref_name, | 94 const ModifierRemapping* GetRemappedKey(const std::string& pref_name, |
| 94 const PrefService& pref_service) { | 95 const PrefService& pref_service) { |
| 95 if (!pref_service.FindPreference(pref_name.c_str())) | 96 if (!pref_service.FindPreference(pref_name.c_str())) |
| 96 return NULL; // The |pref_name| hasn't been registered. On login screen? | 97 return NULL; // The |pref_name| hasn't been registered. On login screen? |
| 97 const int value = pref_service.GetInteger(pref_name.c_str()); | 98 const int value = pref_service.GetInteger(pref_name.c_str()); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 115 break; | 116 break; |
| 116 } | 117 } |
| 117 return false; | 118 return false; |
| 118 } | 119 } |
| 119 | 120 |
| 120 bool HasChromeOSKeyboard() { | 121 bool HasChromeOSKeyboard() { |
| 121 return CommandLine::ForCurrentProcess()->HasSwitch( | 122 return CommandLine::ForCurrentProcess()->HasSwitch( |
| 122 switches::kHasChromeOSKeyboard); | 123 switches::kHasChromeOSKeyboard); |
| 123 } | 124 } |
| 124 | 125 |
| 126 bool HasDiamondKey() { | |
| 127 return CommandLine::ForCurrentProcess()->HasSwitch( | |
| 128 switches::kHasChromeOSDiamondKey); | |
| 129 } | |
| 130 | |
| 125 bool IsMod3UsedByCurrentInputMethod() { | 131 bool IsMod3UsedByCurrentInputMethod() { |
| 126 // Since both German Neo2 XKB layout and Caps Lock depend on Mod3Mask, | 132 // Since both German Neo2 XKB layout and Caps Lock depend on Mod3Mask, |
| 127 // it's not possible to make both features work. For now, we don't remap | 133 // it's not possible to make both features work. For now, we don't remap |
| 128 // Mod3Mask when Neo2 is in use. | 134 // Mod3Mask when Neo2 is in use. |
| 129 // TODO(yusukes): Remove the restriction. | 135 // TODO(yusukes): Remove the restriction. |
| 130 return GetInputMethodManager()->GetCurrentInputMethod().id() == kNeo2LayoutId; | 136 return GetInputMethodManager()->GetCurrentInputMethod().id() == kNeo2LayoutId; |
| 131 } | 137 } |
| 132 #endif | 138 #endif |
| 133 | 139 |
| 134 const PrefService* GetPrefService() { | 140 const PrefService* GetPrefService() { |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 419 *remapped_native_modifiers |= | 425 *remapped_native_modifiers |= |
| 420 kModifierFlagToPrefName[i].native_modifier; | 426 kModifierFlagToPrefName[i].native_modifier; |
| 421 } | 427 } |
| 422 } | 428 } |
| 423 } | 429 } |
| 424 | 430 |
| 425 *remapped_flags = | 431 *remapped_flags = |
| 426 (original_flags & ~(ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN)) | | 432 (original_flags & ~(ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN)) | |
| 427 *remapped_flags; | 433 *remapped_flags; |
| 428 | 434 |
| 429 unsigned int native_mask = Mod4Mask | ControlMask | Mod1Mask; | 435 unsigned int native_mask = Mod4Mask | ControlMask | Mod1Mask | Mod2Mask; |
| 430 if (!skip_mod3) | 436 if (!skip_mod3) |
| 431 native_mask |= Mod3Mask; | 437 native_mask |= Mod3Mask; |
| 432 *remapped_native_modifiers = | 438 *remapped_native_modifiers = |
| 433 (original_native_modifiers & ~native_mask) | | 439 (original_native_modifiers & ~native_mask) | |
| 434 *remapped_native_modifiers; | 440 *remapped_native_modifiers; |
| 435 #endif | 441 #endif |
| 436 } | 442 } |
| 437 | 443 |
| 438 bool EventRewriter::RewriteModifiers(ui::KeyEvent* event) { | 444 bool EventRewriter::RewriteModifiers(ui::KeyEvent* event) { |
| 439 // Do nothing if we have just logged in as guest but have not restarted chrome | 445 // Do nothing if we have just logged in as guest but have not restarted chrome |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 460 XEvent* xev = event->native_event(); | 466 XEvent* xev = event->native_event(); |
| 461 XKeyEvent* xkey = &(xev->xkey); | 467 XKeyEvent* xkey = &(xev->xkey); |
| 462 KeySym keysym = XLookupKeysym(xkey, 0); | 468 KeySym keysym = XLookupKeysym(xkey, 0); |
| 463 | 469 |
| 464 ui::KeyboardCode remapped_keycode = event->key_code(); | 470 ui::KeyboardCode remapped_keycode = event->key_code(); |
| 465 KeyCode remapped_native_keycode = xkey->keycode; | 471 KeyCode remapped_native_keycode = xkey->keycode; |
| 466 | 472 |
| 467 // First, remap |keysym|. | 473 // First, remap |keysym|. |
| 468 const ModifierRemapping* remapped_key = NULL; | 474 const ModifierRemapping* remapped_key = NULL; |
| 469 switch (keysym) { | 475 switch (keysym) { |
| 476 // On Chrome OS, XF86XK_Launch6 (F15) with Mod2Mask is sent when Diamond | |
| 477 // key is pressed. | |
| 478 case XF86XK_Launch6: | |
| 479 // When diamond key is not available, the configuration UI for Diamond | |
| 480 // key is not shown. Therefore, ignore the kLanguageRemapDiamondKeyTo | |
| 481 // syncable pref. | |
| 482 if (HasDiamondKey()) | |
| 483 remapped_key = | |
| 484 GetRemappedKey(prefs::kLanguageRemapDiamondKeyTo, *pref_service); | |
| 485 if (!remapped_key) | |
| 486 remapped_key = kModifierRemappingCtrl; | |
| 487 break; | |
| 470 // On Chrome OS, XF86XK_Launch7 (F16) with Mod3Mask is sent when Caps Lock | 488 // On Chrome OS, XF86XK_Launch7 (F16) with Mod3Mask is sent when Caps Lock |
| 471 // is pressed (with one exception: when IsMod3UsedByCurrentInputMethod() is | 489 // is pressed (with one exception: when IsMod3UsedByCurrentInputMethod() is |
| 472 // true, the key generates XK_ISO_Level3_Shift with Mod3Mask, not | 490 // true, the key generates XK_ISO_Level3_Shift with Mod3Mask, not |
| 473 // XF86XK_Launch7). | 491 // XF86XK_Launch7). |
| 474 case XF86XK_Launch7: | 492 case XF86XK_Launch7: |
| 475 // When a Chrome OS keyboard is available, the configuration UI for Caps | 493 // When a Chrome OS keyboard is available, the configuration UI for Caps |
| 476 // Lock is not shown. Therefore, ignore the kLanguageRemapCapsLockKeyTo | 494 // Lock is not shown. Therefore, ignore the kLanguageRemapCapsLockKeyTo |
| 477 // syncable pref. | 495 // syncable pref. |
| 478 if (HasChromeOSKeyboard()) | 496 if (!HasChromeOSKeyboard()) |
| 479 remapped_key = kModifierRemappingCapsLock; | |
| 480 else | |
| 481 remapped_key = | 497 remapped_key = |
| 482 GetRemappedKey(prefs::kLanguageRemapCapsLockKeyTo, *pref_service); | 498 GetRemappedKey(prefs::kLanguageRemapCapsLockKeyTo, *pref_service); |
| 499 if (!remapped_key) | |
| 500 remapped_key = kModifierRemappingCapsLock; | |
| 483 break; | 501 break; |
| 484 case XK_Super_L: | 502 case XK_Super_L: |
| 485 case XK_Super_R: | 503 case XK_Super_R: |
| 486 // Rewrite Command-L/R key presses on an Apple keyboard to Control-L/R. | 504 // Rewrite Command-L/R key presses on an Apple keyboard to Control-L/R. |
| 487 if (IsAppleKeyboard()) | 505 if (IsAppleKeyboard()) |
| 488 remapped_key = kModifierRemappingCtrl; | 506 remapped_key = kModifierRemappingCtrl; |
| 489 else | 507 else |
| 490 remapped_key = | 508 remapped_key = |
| 491 GetRemappedKey(prefs::kLanguageRemapSearchKeyTo, *pref_service); | 509 GetRemappedKey(prefs::kLanguageRemapSearchKeyTo, *pref_service); |
|
Yusuke Sato
2013/01/25 06:17:08
as we talked offline, please handle null-return ca
yoshiki
2013/01/25 06:43:36
I think, in contrast with F15/F16 key, the super k
Yusuke Sato
2013/01/25 06:46:46
Sorry, I added the previous comment at the wrong l
| |
| 492 break; | 510 break; |
| 493 case XK_Control_L: | 511 case XK_Control_L: |
| 494 case XK_Control_R: | 512 case XK_Control_R: |
| 495 remapped_key = | 513 remapped_key = |
| 496 GetRemappedKey(prefs::kLanguageRemapControlKeyTo, *pref_service); | 514 GetRemappedKey(prefs::kLanguageRemapControlKeyTo, *pref_service); |
| 497 break; | 515 break; |
| 498 case XK_Alt_L: | 516 case XK_Alt_L: |
| 499 case XK_Alt_R: | 517 case XK_Alt_R: |
| 500 case XK_Meta_L: | 518 case XK_Meta_L: |
| 501 case XK_Meta_R: | 519 case XK_Meta_R: |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 986 const DeviceType type = EventRewriter::GetDeviceType(device_name); | 1004 const DeviceType type = EventRewriter::GetDeviceType(device_name); |
| 987 if (type == kDeviceAppleKeyboard) { | 1005 if (type == kDeviceAppleKeyboard) { |
| 988 VLOG(1) << "Apple keyboard '" << device_name << "' connected: " | 1006 VLOG(1) << "Apple keyboard '" << device_name << "' connected: " |
| 989 << "id=" << device_id; | 1007 << "id=" << device_id; |
| 990 } | 1008 } |
| 991 // Always overwrite the existing device_id since the X server may reuse a | 1009 // Always overwrite the existing device_id since the X server may reuse a |
| 992 // device id for an unattached device. | 1010 // device id for an unattached device. |
| 993 device_id_to_type_[device_id] = type; | 1011 device_id_to_type_[device_id] = type; |
| 994 return type; | 1012 return type; |
| 995 } | 1013 } |
| OLD | NEW |