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 }, | |
|
Yusuke Sato
2013/01/23 07:12:18
Please add unit tests. This class should be 100% t
yoshiki
2013/01/25 01:33:10
Done.
| |
| 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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 } | 345 } |
| 345 #endif | 346 #endif |
| 346 | 347 |
| 347 void EventRewriter::Rewrite(ui::KeyEvent* event) { | 348 void EventRewriter::Rewrite(ui::KeyEvent* event) { |
| 348 #if defined(OS_CHROMEOS) | 349 #if defined(OS_CHROMEOS) |
| 349 // Do not rewrite an event sent by ui_controls::SendKeyPress(). See | 350 // Do not rewrite an event sent by ui_controls::SendKeyPress(). See |
| 350 // crbug.com/136465. | 351 // crbug.com/136465. |
| 351 if (event->native_event()->xkey.send_event) | 352 if (event->native_event()->xkey.send_event) |
| 352 return; | 353 return; |
| 353 #endif | 354 #endif |
| 354 RewriteModifiers(event); | 355 RewriteModifiers(event); |
|
Yusuke Sato
2013/01/23 07:12:18
this rewriter has to be called before RewriteNumPa
Yusuke Sato
2013/01/24 20:46:01
Please fix.
yoshiki
2013/01/25 01:33:10
Sorry for lack of the explanation.
RewriteNumPadK
Yusuke Sato
2013/01/25 01:45:25
Have you talked to nona today? The removal will un
yoshiki
2013/01/25 01:47:18
No I haven't. I'll talk.
On 2013/01/25 01:45:25,
| |
| 355 RewriteNumPadKeys(event); | 356 RewriteNumPadKeys(event); |
| 356 RewriteExtendedKeys(event); | 357 RewriteExtendedKeys(event); |
| 357 RewriteFunctionKeys(event); | 358 RewriteFunctionKeys(event); |
| 358 } | 359 } |
| 359 | 360 |
| 360 bool EventRewriter::IsAppleKeyboard() const { | 361 bool EventRewriter::IsAppleKeyboard() const { |
| 361 if (last_device_id_ == kBadDeviceId) | 362 if (last_device_id_ == kBadDeviceId) |
| 362 return false; | 363 return false; |
| 363 | 364 |
| 364 // Check which device generated |event|. | 365 // Check which device generated |event|. |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 460 XEvent* xev = event->native_event(); | 461 XEvent* xev = event->native_event(); |
| 461 XKeyEvent* xkey = &(xev->xkey); | 462 XKeyEvent* xkey = &(xev->xkey); |
| 462 KeySym keysym = XLookupKeysym(xkey, 0); | 463 KeySym keysym = XLookupKeysym(xkey, 0); |
| 463 | 464 |
| 464 ui::KeyboardCode remapped_keycode = event->key_code(); | 465 ui::KeyboardCode remapped_keycode = event->key_code(); |
| 465 KeyCode remapped_native_keycode = xkey->keycode; | 466 KeyCode remapped_native_keycode = xkey->keycode; |
| 466 | 467 |
| 467 // First, remap |keysym|. | 468 // First, remap |keysym|. |
| 468 const ModifierRemapping* remapped_key = NULL; | 469 const ModifierRemapping* remapped_key = NULL; |
| 469 switch (keysym) { | 470 switch (keysym) { |
| 471 case XF86XK_Launch6: | |
|
Yusuke Sato
2013/01/23 07:12:18
Add a similar comment to line 475-478.
yoshiki
2013/01/25 01:33:10
Done.
| |
| 472 remapped_key = | |
|
Yusuke Sato
2013/01/23 07:12:18
Shouldn't we check the command line flag here? I t
yoshiki
2013/01/25 01:33:10
Done.
| |
| 473 GetRemappedKey(prefs::kLanguageRemapDiamondKeyTo, *pref_service); | |
| 474 break; | |
| 470 // On Chrome OS, XF86XK_Launch7 (F16) with Mod3Mask is sent when Caps Lock | 475 // On Chrome OS, XF86XK_Launch7 (F16) with Mod3Mask is sent when Caps Lock |
| 471 // is pressed (with one exception: when IsMod3UsedByCurrentInputMethod() is | 476 // is pressed (with one exception: when IsMod3UsedByCurrentInputMethod() is |
| 472 // true, the key generates XK_ISO_Level3_Shift with Mod3Mask, not | 477 // true, the key generates XK_ISO_Level3_Shift with Mod3Mask, not |
| 473 // XF86XK_Launch7). | 478 // XF86XK_Launch7). |
| 474 case XF86XK_Launch7: | 479 case XF86XK_Launch7: |
| 475 // When a Chrome OS keyboard is available, the configuration UI for Caps | 480 // When a Chrome OS keyboard is available, the configuration UI for Caps |
| 476 // Lock is not shown. Therefore, ignore the kLanguageRemapCapsLockKeyTo | 481 // Lock is not shown. Therefore, ignore the kLanguageRemapCapsLockKeyTo |
| 477 // syncable pref. | 482 // syncable pref. |
| 478 if (HasChromeOSKeyboard()) | 483 if (HasChromeOSKeyboard()) |
| 479 remapped_key = kModifierRemappingCapsLock; | 484 remapped_key = kModifierRemappingCapsLock; |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 986 const DeviceType type = EventRewriter::GetDeviceType(device_name); | 991 const DeviceType type = EventRewriter::GetDeviceType(device_name); |
| 987 if (type == kDeviceAppleKeyboard) { | 992 if (type == kDeviceAppleKeyboard) { |
| 988 VLOG(1) << "Apple keyboard '" << device_name << "' connected: " | 993 VLOG(1) << "Apple keyboard '" << device_name << "' connected: " |
| 989 << "id=" << device_id; | 994 << "id=" << device_id; |
| 990 } | 995 } |
| 991 // Always overwrite the existing device_id since the X server may reuse a | 996 // Always overwrite the existing device_id since the X server may reuse a |
| 992 // device id for an unattached device. | 997 // device id for an unattached device. |
| 993 device_id_to_type_[device_id] = type; | 998 device_id_to_type_[device_id] = type; |
| 994 return type; | 999 return type; |
| 995 } | 1000 } |
| OLD | NEW |