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 // Default behavior is Ctrl key. |
| 486 if (!remapped_key) |
| 487 remapped_key = kModifierRemappingCtrl; |
| 488 break; |
470 // On Chrome OS, XF86XK_Launch7 (F16) with Mod3Mask is sent when Caps Lock | 489 // On Chrome OS, XF86XK_Launch7 (F16) with Mod3Mask is sent when Caps Lock |
471 // is pressed (with one exception: when IsMod3UsedByCurrentInputMethod() is | 490 // is pressed (with one exception: when IsMod3UsedByCurrentInputMethod() is |
472 // true, the key generates XK_ISO_Level3_Shift with Mod3Mask, not | 491 // true, the key generates XK_ISO_Level3_Shift with Mod3Mask, not |
473 // XF86XK_Launch7). | 492 // XF86XK_Launch7). |
474 case XF86XK_Launch7: | 493 case XF86XK_Launch7: |
475 // When a Chrome OS keyboard is available, the configuration UI for Caps | 494 // When a Chrome OS keyboard is available, the configuration UI for Caps |
476 // Lock is not shown. Therefore, ignore the kLanguageRemapCapsLockKeyTo | 495 // Lock is not shown. Therefore, ignore the kLanguageRemapCapsLockKeyTo |
477 // syncable pref. | 496 // syncable pref. |
478 if (HasChromeOSKeyboard()) | 497 if (!HasChromeOSKeyboard()) |
479 remapped_key = kModifierRemappingCapsLock; | |
480 else | |
481 remapped_key = | 498 remapped_key = |
482 GetRemappedKey(prefs::kLanguageRemapCapsLockKeyTo, *pref_service); | 499 GetRemappedKey(prefs::kLanguageRemapCapsLockKeyTo, *pref_service); |
| 500 // Default behavior is Caps Lock key. |
| 501 if (!remapped_key) |
| 502 remapped_key = kModifierRemappingCapsLock; |
483 break; | 503 break; |
484 case XK_Super_L: | 504 case XK_Super_L: |
485 case XK_Super_R: | 505 case XK_Super_R: |
486 // Rewrite Command-L/R key presses on an Apple keyboard to Control-L/R. | 506 // Rewrite Command-L/R key presses on an Apple keyboard to Control-L/R. |
487 if (IsAppleKeyboard()) | 507 if (IsAppleKeyboard()) |
488 remapped_key = kModifierRemappingCtrl; | 508 remapped_key = kModifierRemappingCtrl; |
489 else | 509 else |
490 remapped_key = | 510 remapped_key = |
491 GetRemappedKey(prefs::kLanguageRemapSearchKeyTo, *pref_service); | 511 GetRemappedKey(prefs::kLanguageRemapSearchKeyTo, *pref_service); |
| 512 // Default behavior is Super key, hence don't remap the event if the pref |
| 513 // is unavailable. |
492 break; | 514 break; |
493 case XK_Control_L: | 515 case XK_Control_L: |
494 case XK_Control_R: | 516 case XK_Control_R: |
495 remapped_key = | 517 remapped_key = |
496 GetRemappedKey(prefs::kLanguageRemapControlKeyTo, *pref_service); | 518 GetRemappedKey(prefs::kLanguageRemapControlKeyTo, *pref_service); |
497 break; | 519 break; |
498 case XK_Alt_L: | 520 case XK_Alt_L: |
499 case XK_Alt_R: | 521 case XK_Alt_R: |
500 case XK_Meta_L: | 522 case XK_Meta_L: |
501 case XK_Meta_R: | 523 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); | 1008 const DeviceType type = EventRewriter::GetDeviceType(device_name); |
987 if (type == kDeviceAppleKeyboard) { | 1009 if (type == kDeviceAppleKeyboard) { |
988 VLOG(1) << "Apple keyboard '" << device_name << "' connected: " | 1010 VLOG(1) << "Apple keyboard '" << device_name << "' connected: " |
989 << "id=" << device_id; | 1011 << "id=" << device_id; |
990 } | 1012 } |
991 // Always overwrite the existing device_id since the X server may reuse a | 1013 // Always overwrite the existing device_id since the X server may reuse a |
992 // device id for an unattached device. | 1014 // device id for an unattached device. |
993 device_id_to_type_[device_id] = type; | 1015 device_id_to_type_[device_id] = type; |
994 return type; | 1016 return type; |
995 } | 1017 } |
OLD | NEW |