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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 { XK_Control_L, XK_Control_R, XK_Control_L, XK_Control_R }}, | 63 { XK_Control_L, XK_Control_R, XK_Control_L, XK_Control_R }}, |
64 { chromeos::input_method::kAltKey, ui::EF_ALT_DOWN, Mod1Mask, | 64 { chromeos::input_method::kAltKey, ui::EF_ALT_DOWN, Mod1Mask, |
65 ui::VKEY_MENU, { XK_Alt_L, XK_Alt_R, XK_Meta_L, XK_Meta_R }}, | 65 ui::VKEY_MENU, { XK_Alt_L, XK_Alt_R, XK_Meta_L, XK_Meta_R }}, |
66 { chromeos::input_method::kVoidKey, 0, 0U, ui::VKEY_UNKNOWN, | 66 { chromeos::input_method::kVoidKey, 0, 0U, ui::VKEY_UNKNOWN, |
67 { XK_VoidSymbol, XK_VoidSymbol, XK_VoidSymbol, XK_VoidSymbol }}, | 67 { XK_VoidSymbol, XK_VoidSymbol, XK_VoidSymbol, XK_VoidSymbol }}, |
68 { chromeos::input_method::kCapsLockKey, 0, 0U, ui::VKEY_CAPITAL, | 68 { chromeos::input_method::kCapsLockKey, 0, 0U, ui::VKEY_CAPITAL, |
69 { XK_Caps_Lock, XK_Caps_Lock, XK_Caps_Lock, XK_Caps_Lock }}, | 69 { XK_Caps_Lock, XK_Caps_Lock, XK_Caps_Lock, XK_Caps_Lock }}, |
70 }; | 70 }; |
71 | 71 |
72 const ModifierRemapping* kModifierRemappingCtrl = &kModifierRemappings[1]; | 72 const ModifierRemapping* kModifierRemappingCtrl = &kModifierRemappings[1]; |
73 const ModifierRemapping* kModifierRemappingCapsLock = &kModifierRemappings[4]; | |
74 | 73 |
75 // A structure for converting |native_modifier| to a pair of |flag| and | 74 // A structure for converting |native_modifier| to a pair of |flag| and |
76 // |pref_name|. | 75 // |pref_name|. |
77 const struct ModifierFlagToPrefName { | 76 const struct ModifierFlagToPrefName { |
78 unsigned int native_modifier; | 77 unsigned int native_modifier; |
79 int flag; | 78 int flag; |
80 const char* pref_name; | 79 const char* pref_name; |
81 } kModifierFlagToPrefName[] = { | 80 } kModifierFlagToPrefName[] = { |
82 // TODO(yusukes): When the device has a Chrome keyboard (i.e. the one without | 81 // TODO(yusukes): When the device has a Chrome keyboard (i.e. the one without |
83 // Caps Lock), we should not check kLanguageRemapCapsLockKeyTo. | 82 // Caps Lock), we should not check kLanguageRemapCapsLockKeyTo. |
(...skipping 27 matching lines...) Expand all Loading... |
111 case XK_Meta_R: | 110 case XK_Meta_R: |
112 case XK_Shift_R: | 111 case XK_Shift_R: |
113 case XK_Super_R: | 112 case XK_Super_R: |
114 return true; | 113 return true; |
115 default: | 114 default: |
116 break; | 115 break; |
117 } | 116 } |
118 return false; | 117 return false; |
119 } | 118 } |
120 | 119 |
121 bool HasChromeOSKeyboard() { | |
122 return CommandLine::ForCurrentProcess()->HasSwitch( | |
123 switches::kHasChromeOSKeyboard); | |
124 } | |
125 | |
126 bool HasDiamondKey() { | 120 bool HasDiamondKey() { |
127 return CommandLine::ForCurrentProcess()->HasSwitch( | 121 return CommandLine::ForCurrentProcess()->HasSwitch( |
128 switches::kHasChromeOSDiamondKey); | 122 switches::kHasChromeOSDiamondKey); |
129 } | 123 } |
130 | 124 |
131 bool IsMod3UsedByCurrentInputMethod() { | 125 bool IsMod3UsedByCurrentInputMethod() { |
132 // Since both German Neo2 XKB layout and Caps Lock depend on Mod3Mask, | 126 // Since both German Neo2 XKB layout and Caps Lock depend on Mod3Mask, |
133 // it's not possible to make both features work. For now, we don't remap | 127 // it's not possible to make both features work. For now, we don't remap |
134 // Mod3Mask when Neo2 is in use. | 128 // Mod3Mask when Neo2 is in use. |
135 // TODO(yusukes): Remove the restriction. | 129 // TODO(yusukes): Remove the restriction. |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 | 388 |
395 const PrefService* pref_service = | 389 const PrefService* pref_service = |
396 pref_service_ ? pref_service_ : GetPrefService(); | 390 pref_service_ ? pref_service_ : GetPrefService(); |
397 if (!pref_service) | 391 if (!pref_service) |
398 return; | 392 return; |
399 | 393 |
400 // When a diamond key is not available, a Mod2Mask should not treated as a | 394 // When a diamond key is not available, a Mod2Mask should not treated as a |
401 // configurable modifier because Mod2Mask may be worked as NumLock mask. | 395 // configurable modifier because Mod2Mask may be worked as NumLock mask. |
402 // (cf. http://crbug.com/173956) | 396 // (cf. http://crbug.com/173956) |
403 const bool skip_mod2 = !HasDiamondKey(); | 397 const bool skip_mod2 = !HasDiamondKey(); |
404 // When a Chrome OS keyboard is available, the configuration UI for Caps Lock | 398 // If Mod3 is used by the current input method, don't allow the CapsLock |
405 // is not shown. Therefore, ignore the kLanguageRemapCapsLockKeyTo syncable | 399 // pref to remap it, or the keyboard behavior will be broken. |
406 // pref. If Mod3 is in use, don't check the pref either. | 400 const bool skip_mod3 = IsMod3UsedByCurrentInputMethod(); |
407 const bool skip_mod3 = | |
408 HasChromeOSKeyboard() || IsMod3UsedByCurrentInputMethod(); | |
409 | 401 |
410 for (size_t i = 0; i < arraysize(kModifierFlagToPrefName); ++i) { | 402 for (size_t i = 0; i < arraysize(kModifierFlagToPrefName); ++i) { |
411 if ((skip_mod2 && kModifierFlagToPrefName[i].native_modifier == Mod2Mask) || | 403 if ((skip_mod2 && kModifierFlagToPrefName[i].native_modifier == Mod2Mask) || |
412 (skip_mod3 && kModifierFlagToPrefName[i].native_modifier == Mod3Mask)) { | 404 (skip_mod3 && kModifierFlagToPrefName[i].native_modifier == Mod3Mask)) { |
413 continue; | 405 continue; |
414 } | 406 } |
415 if (original_native_modifiers & | 407 if (original_native_modifiers & |
416 kModifierFlagToPrefName[i].native_modifier) { | 408 kModifierFlagToPrefName[i].native_modifier) { |
417 const ModifierRemapping* remapped_key = | 409 const ModifierRemapping* remapped_key = |
418 GetRemappedKey(kModifierFlagToPrefName[i].pref_name, *pref_service); | 410 GetRemappedKey(kModifierFlagToPrefName[i].pref_name, *pref_service); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 GetRemappedKey(prefs::kLanguageRemapDiamondKeyTo, *pref_service); | 482 GetRemappedKey(prefs::kLanguageRemapDiamondKeyTo, *pref_service); |
491 // Default behavior is Ctrl key. | 483 // Default behavior is Ctrl key. |
492 if (!remapped_key) | 484 if (!remapped_key) |
493 remapped_key = kModifierRemappingCtrl; | 485 remapped_key = kModifierRemappingCtrl; |
494 break; | 486 break; |
495 // On Chrome OS, XF86XK_Launch7 (F16) with Mod3Mask is sent when Caps Lock | 487 // On Chrome OS, XF86XK_Launch7 (F16) with Mod3Mask is sent when Caps Lock |
496 // is pressed (with one exception: when IsMod3UsedByCurrentInputMethod() is | 488 // is pressed (with one exception: when IsMod3UsedByCurrentInputMethod() is |
497 // true, the key generates XK_ISO_Level3_Shift with Mod3Mask, not | 489 // true, the key generates XK_ISO_Level3_Shift with Mod3Mask, not |
498 // XF86XK_Launch7). | 490 // XF86XK_Launch7). |
499 case XF86XK_Launch7: | 491 case XF86XK_Launch7: |
500 // When a Chrome OS keyboard is available, the configuration UI for Caps | 492 remapped_key = |
501 // Lock is not shown. Therefore, ignore the kLanguageRemapCapsLockKeyTo | 493 GetRemappedKey(prefs::kLanguageRemapCapsLockKeyTo, *pref_service); |
502 // syncable pref. | |
503 if (!HasChromeOSKeyboard()) | |
504 remapped_key = | |
505 GetRemappedKey(prefs::kLanguageRemapCapsLockKeyTo, *pref_service); | |
506 // Default behavior is Caps Lock key. | |
507 if (!remapped_key) | |
508 remapped_key = kModifierRemappingCapsLock; | |
509 break; | 494 break; |
510 case XK_Super_L: | 495 case XK_Super_L: |
511 case XK_Super_R: | 496 case XK_Super_R: |
512 // Rewrite Command-L/R key presses on an Apple keyboard to Control-L/R. | 497 // Rewrite Command-L/R key presses on an Apple keyboard to Control-L/R. |
513 if (IsAppleKeyboard()) | 498 if (IsAppleKeyboard()) |
514 remapped_key = kModifierRemappingCtrl; | 499 remapped_key = kModifierRemappingCtrl; |
515 else | 500 else |
516 remapped_key = | 501 remapped_key = |
517 GetRemappedKey(prefs::kLanguageRemapSearchKeyTo, *pref_service); | 502 GetRemappedKey(prefs::kLanguageRemapSearchKeyTo, *pref_service); |
518 // Default behavior is Super key, hence don't remap the event if the pref | 503 // Default behavior is Super key, hence don't remap the event if the pref |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1014 const DeviceType type = EventRewriter::GetDeviceType(device_name); | 999 const DeviceType type = EventRewriter::GetDeviceType(device_name); |
1015 if (type == kDeviceAppleKeyboard) { | 1000 if (type == kDeviceAppleKeyboard) { |
1016 VLOG(1) << "Apple keyboard '" << device_name << "' connected: " | 1001 VLOG(1) << "Apple keyboard '" << device_name << "' connected: " |
1017 << "id=" << device_id; | 1002 << "id=" << device_id; |
1018 } | 1003 } |
1019 // Always overwrite the existing device_id since the X server may reuse a | 1004 // Always overwrite the existing device_id since the X server may reuse a |
1020 // device id for an unattached device. | 1005 // device id for an unattached device. |
1021 device_id_to_type_[device_id] = type; | 1006 device_id_to_type_[device_id] = type; |
1022 return type; | 1007 return type; |
1023 } | 1008 } |
OLD | NEW |