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 if (HasDiamondKey()) | |
| 480 remapped_key = | |
| 481 GetRemappedKey(prefs::kLanguageRemapDiamondKeyTo, *pref_service); | |
| 482 if (!remapped_key) | |
|
Yusuke Sato
2013/01/24 20:46:01
why not else?
do you mean that GetRemappedKey may
yoshiki
2013/01/25 01:33:10
I want to make the default behaviour as ctrl key w
Yusuke Sato
2013/01/25 01:49:32
hrm.. this might be a silly question but could you
yoshiki
2013/01/25 01:53:29
The comment in GetRemappedKey() says 'On login scr
| |
| 483 remapped_key = kModifierRemappingCtrl; | |
| 484 break; | |
| 470 // On Chrome OS, XF86XK_Launch7 (F16) with Mod3Mask is sent when Caps Lock | 485 // On Chrome OS, XF86XK_Launch7 (F16) with Mod3Mask is sent when Caps Lock |
| 471 // is pressed (with one exception: when IsMod3UsedByCurrentInputMethod() is | 486 // is pressed (with one exception: when IsMod3UsedByCurrentInputMethod() is |
| 472 // true, the key generates XK_ISO_Level3_Shift with Mod3Mask, not | 487 // true, the key generates XK_ISO_Level3_Shift with Mod3Mask, not |
| 473 // XF86XK_Launch7). | 488 // XF86XK_Launch7). |
| 474 case XF86XK_Launch7: | 489 case XF86XK_Launch7: |
| 475 // When a Chrome OS keyboard is available, the configuration UI for Caps | 490 // When a Chrome OS keyboard is available, the configuration UI for Caps |
| 476 // Lock is not shown. Therefore, ignore the kLanguageRemapCapsLockKeyTo | 491 // Lock is not shown. Therefore, ignore the kLanguageRemapCapsLockKeyTo |
| 477 // syncable pref. | 492 // syncable pref. |
| 478 if (HasChromeOSKeyboard()) | 493 if (HasChromeOSKeyboard()) |
| 479 remapped_key = kModifierRemappingCapsLock; | 494 remapped_key = kModifierRemappingCapsLock; |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 986 const DeviceType type = EventRewriter::GetDeviceType(device_name); | 1001 const DeviceType type = EventRewriter::GetDeviceType(device_name); |
| 987 if (type == kDeviceAppleKeyboard) { | 1002 if (type == kDeviceAppleKeyboard) { |
| 988 VLOG(1) << "Apple keyboard '" << device_name << "' connected: " | 1003 VLOG(1) << "Apple keyboard '" << device_name << "' connected: " |
| 989 << "id=" << device_id; | 1004 << "id=" << device_id; |
| 990 } | 1005 } |
| 991 // Always overwrite the existing device_id since the X server may reuse a | 1006 // Always overwrite the existing device_id since the X server may reuse a |
| 992 // device id for an unattached device. | 1007 // device id for an unattached device. |
| 993 device_id_to_type_[device_id] = type; | 1008 device_id_to_type_[device_id] = type; |
| 994 return type; | 1009 return type; |
| 995 } | 1010 } |
| OLD | NEW |