OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/chromeos/events/event_rewriter.h" | 5 #include "chrome/browser/chromeos/events/event_rewriter.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 namespace chromeos { | 50 namespace chromeos { |
51 | 51 |
52 namespace { | 52 namespace { |
53 | 53 |
54 // Hotrod controller vendor/product ids. | 54 // Hotrod controller vendor/product ids. |
55 const int kHotrodRemoteVendorId = 0x0471; | 55 const int kHotrodRemoteVendorId = 0x0471; |
56 const int kHotrodRemoteProductId = 0x21cc; | 56 const int kHotrodRemoteProductId = 0x21cc; |
57 const int kUnknownVendorId = -1; | 57 const int kUnknownVendorId = -1; |
58 const int kUnknownProductId = -1; | 58 const int kUnknownProductId = -1; |
59 | 59 |
60 // Table of properties of remappable keys and/or remapping targets. | 60 // Table of properties of remappable keys and/or remapping targets (not |
| 61 // strictly limited to "modifiers"). |
61 // | 62 // |
62 // This is used in two distinct ways: for rewriting key up/down events, | 63 // This is used in two distinct ways: for rewriting key up/down events, |
63 // and for rewriting modifier EventFlags on any kind of event. | 64 // and for rewriting modifier EventFlags on any kind of event. |
64 // | 65 // |
65 // For the first case, rewriting key up/down events, |RewriteModifierKeys()| | 66 // For the first case, rewriting key up/down events, |RewriteModifierKeys()| |
66 // determines the preference name |prefs::kLanguageRemap...KeyTo| for the | 67 // determines the preference name |prefs::kLanguageRemap...KeyTo| for the |
67 // incoming key and, using |GetRemappedKey()|, gets the user preference | 68 // incoming key and, using |GetRemappedKey()|, gets the user preference |
68 // value |input_method::k...Key| for the incoming key, and finally finds that | 69 // value |input_method::k...Key| for the incoming key, and finally finds that |
69 // value in this table to obtain the |result| properties of the target key. | 70 // value in this table to obtain the |result| properties of the target key. |
70 // | 71 // |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 input_method::kVoidKey, | 105 input_method::kVoidKey, |
105 nullptr, | 106 nullptr, |
106 {ui::EF_NONE, ui::DomCode::NONE, ui::DomKey::NONE, ui::VKEY_UNKNOWN}}, | 107 {ui::EF_NONE, ui::DomCode::NONE, ui::DomKey::NONE, ui::VKEY_UNKNOWN}}, |
107 {ui::EF_MOD3_DOWN, | 108 {ui::EF_MOD3_DOWN, |
108 input_method::kCapsLockKey, | 109 input_method::kCapsLockKey, |
109 prefs::kLanguageRemapCapsLockKeyTo, | 110 prefs::kLanguageRemapCapsLockKeyTo, |
110 {ui::EF_MOD3_DOWN, ui::DomCode::CAPS_LOCK, ui::DomKey::CAPS_LOCK, | 111 {ui::EF_MOD3_DOWN, ui::DomCode::CAPS_LOCK, ui::DomKey::CAPS_LOCK, |
111 ui::VKEY_CAPITAL}}, | 112 ui::VKEY_CAPITAL}}, |
112 {ui::EF_NONE, | 113 {ui::EF_NONE, |
113 input_method::kEscapeKey, | 114 input_method::kEscapeKey, |
114 nullptr, | 115 prefs::kLanguageRemapEscapeKeyTo, |
115 {ui::EF_NONE, ui::DomCode::ESCAPE, ui::DomKey::ESCAPE, ui::VKEY_ESCAPE}}, | 116 {ui::EF_NONE, ui::DomCode::ESCAPE, ui::DomKey::ESCAPE, ui::VKEY_ESCAPE}}, |
116 {ui::EF_NONE, | 117 {ui::EF_NONE, |
117 input_method::kBackspaceKey, | 118 input_method::kBackspaceKey, |
118 nullptr, | 119 prefs::kLanguageRemapBackspaceKeyTo, |
119 {ui::EF_NONE, ui::DomCode::BACKSPACE, ui::DomKey::BACKSPACE, | 120 {ui::EF_NONE, ui::DomCode::BACKSPACE, ui::DomKey::BACKSPACE, |
120 ui::VKEY_BACK}}, | 121 ui::VKEY_BACK}}, |
121 {ui::EF_NONE, | 122 {ui::EF_NONE, |
122 input_method::kNumModifierKeys, | 123 input_method::kNumModifierKeys, |
123 prefs::kLanguageRemapDiamondKeyTo, | 124 prefs::kLanguageRemapDiamondKeyTo, |
124 {ui::EF_NONE, ui::DomCode::F15, ui::DomKey::F15, ui::VKEY_F15}}}; | 125 {ui::EF_NONE, ui::DomCode::F15, ui::DomKey::F15, ui::VKEY_F15}}}; |
125 | 126 |
126 const ModifierRemapping* kModifierRemappingCtrl = &kModifierRemappings[0]; | 127 const ModifierRemapping* kModifierRemappingCtrl = &kModifierRemappings[0]; |
127 const ModifierRemapping* kModifierRemappingNeoMod3 = &kModifierRemappings[1]; | 128 const ModifierRemapping* kModifierRemappingNeoMod3 = &kModifierRemappings[1]; |
128 | 129 |
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 // when user logs in as guest. | 662 // when user logs in as guest. |
662 // TODO(kpschoedel): check whether this is still necessary. | 663 // TODO(kpschoedel): check whether this is still necessary. |
663 if (user_manager::UserManager::Get()->IsLoggedInAsGuest() && | 664 if (user_manager::UserManager::Get()->IsLoggedInAsGuest() && |
664 LoginDisplayHost::default_host()) | 665 LoginDisplayHost::default_host()) |
665 return false; | 666 return false; |
666 | 667 |
667 const PrefService* pref_service = GetPrefService(); | 668 const PrefService* pref_service = GetPrefService(); |
668 if (!pref_service) | 669 if (!pref_service) |
669 return false; | 670 return false; |
670 | 671 |
| 672 // Preserve a copy of the original before rewriting |state| based on |
| 673 // user preferences, device configuration, and certain IME properties. |
671 MutableKeyState incoming = *state; | 674 MutableKeyState incoming = *state; |
672 state->flags = ui::EF_NONE; | 675 state->flags = ui::EF_NONE; |
673 int characteristic_flag = ui::EF_NONE; | 676 int characteristic_flag = ui::EF_NONE; |
674 bool exact_event = false; | 677 bool exact_event = false; |
675 | 678 |
676 // First, remap the key code. | 679 // First, remap the key code. |
677 const ModifierRemapping* remapped_key = NULL; | 680 const ModifierRemapping* remapped_key = NULL; |
678 // Remapping based on DomKey. | 681 // Remapping based on DomKey. |
679 switch (incoming.key) { | 682 switch (incoming.key) { |
680 // On Chrome OS, F15 (XF86XK_Launch6) with NumLock (Mod2Mask) is sent | 683 // On Chrome OS, F15 (XF86XK_Launch6) with NumLock (Mod2Mask) is sent |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 remapped_key = | 773 remapped_key = |
771 GetRemappedKey(prefs::kLanguageRemapControlKeyTo, *pref_service); | 774 GetRemappedKey(prefs::kLanguageRemapControlKeyTo, *pref_service); |
772 break; | 775 break; |
773 case ui::DomCode::ALT_LEFT: | 776 case ui::DomCode::ALT_LEFT: |
774 case ui::DomCode::ALT_RIGHT: | 777 case ui::DomCode::ALT_RIGHT: |
775 // ALT key | 778 // ALT key |
776 characteristic_flag = ui::EF_ALT_DOWN; | 779 characteristic_flag = ui::EF_ALT_DOWN; |
777 remapped_key = | 780 remapped_key = |
778 GetRemappedKey(prefs::kLanguageRemapAltKeyTo, *pref_service); | 781 GetRemappedKey(prefs::kLanguageRemapAltKeyTo, *pref_service); |
779 break; | 782 break; |
| 783 case ui::DomCode::ESCAPE: |
| 784 remapped_key = |
| 785 GetRemappedKey(prefs::kLanguageRemapEscapeKeyTo, *pref_service); |
| 786 break; |
| 787 case ui::DomCode::BACKSPACE: |
| 788 remapped_key = |
| 789 GetRemappedKey(prefs::kLanguageRemapBackspaceKeyTo, *pref_service); |
| 790 break; |
780 default: | 791 default: |
781 break; | 792 break; |
782 } | 793 } |
783 | 794 |
784 if (remapped_key) { | 795 if (remapped_key) { |
785 state->key_code = remapped_key->result.key_code; | 796 state->key_code = remapped_key->result.key_code; |
786 state->code = remapped_key->result.code; | 797 state->code = remapped_key->result.code; |
787 state->key = remapped_key->result.key; | 798 state->key = remapped_key->result.key; |
788 incoming.flags |= characteristic_flag; | 799 incoming.flags |= characteristic_flag; |
789 characteristic_flag = remapped_key->flag; | 800 characteristic_flag = remapped_key->flag; |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1144 for (const auto& keyboard : keyboard_devices) { | 1155 for (const auto& keyboard : keyboard_devices) { |
1145 if (keyboard.id == device_id) { | 1156 if (keyboard.id == device_id) { |
1146 return KeyboardDeviceAddedInternal( | 1157 return KeyboardDeviceAddedInternal( |
1147 keyboard.id, keyboard.name, keyboard.vendor_id, keyboard.product_id); | 1158 keyboard.id, keyboard.name, keyboard.vendor_id, keyboard.product_id); |
1148 } | 1159 } |
1149 } | 1160 } |
1150 return kDeviceUnknown; | 1161 return kDeviceUnknown; |
1151 } | 1162 } |
1152 | 1163 |
1153 } // namespace chromeos | 1164 } // namespace chromeos |
OLD | NEW |