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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ash/sticky_keys/sticky_keys_controller.h" | 9 #include "ash/sticky_keys/sticky_keys_controller.h" |
10 #include "ash/wm/window_state.h" | 10 #include "ash/wm/window_state.h" |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 #endif | 175 #endif |
176 return false; | 176 return false; |
177 } | 177 } |
178 | 178 |
179 } // namespace | 179 } // namespace |
180 | 180 |
181 EventRewriter::EventRewriter(ash::StickyKeysController* sticky_keys_controller) | 181 EventRewriter::EventRewriter(ash::StickyKeysController* sticky_keys_controller) |
182 : last_keyboard_device_id_(ui::ED_UNKNOWN_DEVICE), | 182 : last_keyboard_device_id_(ui::ED_UNKNOWN_DEVICE), |
183 ime_keyboard_for_testing_(NULL), | 183 ime_keyboard_for_testing_(NULL), |
184 pref_service_for_testing_(NULL), | 184 pref_service_for_testing_(NULL), |
185 sticky_keys_controller_(sticky_keys_controller) { | 185 sticky_keys_controller_(sticky_keys_controller), |
| 186 active_diamond_modifier_(ui::EF_NONE) { |
186 } | 187 } |
187 | 188 |
188 EventRewriter::~EventRewriter() { | 189 EventRewriter::~EventRewriter() { |
189 } | 190 } |
190 | 191 |
191 EventRewriter::DeviceType EventRewriter::KeyboardDeviceAddedForTesting( | 192 EventRewriter::DeviceType EventRewriter::KeyboardDeviceAddedForTesting( |
192 int device_id, | 193 int device_id, |
193 const std::string& device_name) { | 194 const std::string& device_name) { |
194 // Tests must avoid XI2 reserved device IDs. | 195 // Tests must avoid XI2 reserved device IDs. |
195 DCHECK((device_id < 0) || (device_id > 1)); | 196 DCHECK((device_id < 0) || (device_id > 1)); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 return true; | 319 return true; |
319 | 320 |
320 ash::wm::WindowState* state = ash::wm::GetActiveWindowState(); | 321 ash::wm::WindowState* state = ash::wm::GetActiveWindowState(); |
321 return state ? state->top_row_keys_are_function_keys() : false; | 322 return state ? state->top_row_keys_are_function_keys() : false; |
322 } | 323 } |
323 | 324 |
324 int EventRewriter::GetRemappedModifierMasks(const PrefService& pref_service, | 325 int EventRewriter::GetRemappedModifierMasks(const PrefService& pref_service, |
325 const ui::Event& event, | 326 const ui::Event& event, |
326 int original_flags) const { | 327 int original_flags) const { |
327 int unmodified_flags = original_flags; | 328 int unmodified_flags = original_flags; |
328 int rewritten_flags = 0; | 329 int rewritten_flags = active_diamond_modifier_; |
329 for (size_t i = 0; unmodified_flags && (i < arraysize(kModifierRemappings)); | 330 for (size_t i = 0; unmodified_flags && (i < arraysize(kModifierRemappings)); |
330 ++i) { | 331 ++i) { |
331 const ModifierRemapping* remapped_key = NULL; | 332 const ModifierRemapping* remapped_key = NULL; |
332 if (!(unmodified_flags & kModifierRemappings[i].flag)) | 333 if (!(unmodified_flags & kModifierRemappings[i].flag)) |
333 continue; | 334 continue; |
334 switch (kModifierRemappings[i].flag) { | 335 switch (kModifierRemappings[i].flag) { |
335 case ui::EF_COMMAND_DOWN: | 336 case ui::EF_COMMAND_DOWN: |
336 // Rewrite Command key presses on an Apple keyboard to Control. | 337 // Rewrite Command key presses on an Apple keyboard to Control. |
337 if (IsAppleKeyboard()) { | 338 if (IsAppleKeyboard()) { |
338 DCHECK_EQ(ui::EF_CONTROL_DOWN, kModifierRemappingCtrl->flag); | 339 DCHECK_EQ(ui::EF_CONTROL_DOWN, kModifierRemappingCtrl->flag); |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 switch (incoming.key_code) { | 613 switch (incoming.key_code) { |
613 // On Chrome OS, F15 (XF86XK_Launch6) with NumLock (Mod2Mask) is sent | 614 // On Chrome OS, F15 (XF86XK_Launch6) with NumLock (Mod2Mask) is sent |
614 // when Diamond key is pressed. | 615 // when Diamond key is pressed. |
615 case ui::VKEY_F15: | 616 case ui::VKEY_F15: |
616 // When diamond key is not available, the configuration UI for Diamond | 617 // When diamond key is not available, the configuration UI for Diamond |
617 // key is not shown. Therefore, ignore the kLanguageRemapDiamondKeyTo | 618 // key is not shown. Therefore, ignore the kLanguageRemapDiamondKeyTo |
618 // syncable pref. | 619 // syncable pref. |
619 if (HasDiamondKey()) | 620 if (HasDiamondKey()) |
620 remapped_key = | 621 remapped_key = |
621 GetRemappedKey(prefs::kLanguageRemapDiamondKeyTo, *pref_service); | 622 GetRemappedKey(prefs::kLanguageRemapDiamondKeyTo, *pref_service); |
622 // Default behavior is Ctrl key. | 623 // Default behavior of F15 is Control, even if --has-chromeos-diamond-key |
| 624 // is absent, according to unit test comments. |
623 if (!remapped_key) { | 625 if (!remapped_key) { |
624 DCHECK_EQ(ui::VKEY_CONTROL, kModifierRemappingCtrl->key_code); | 626 DCHECK_EQ(ui::VKEY_CONTROL, kModifierRemappingCtrl->key_code); |
625 remapped_key = kModifierRemappingCtrl; | 627 remapped_key = kModifierRemappingCtrl; |
626 characteristic_flag = ui::EF_CONTROL_DOWN; | 628 } |
| 629 // F15 is not a modifier key, so we need to track its state directly. |
| 630 if (key_event.type() == ui::ET_KEY_PRESSED) { |
| 631 int remapped_flag = remapped_key->flag; |
| 632 if (remapped_key->remap_to == input_method::kCapsLockKey) |
| 633 remapped_flag |= ui::EF_CAPS_LOCK_DOWN; |
| 634 active_diamond_modifier_ = remapped_flag; |
| 635 } else { |
| 636 active_diamond_modifier_ = ui::EF_NONE; |
627 } | 637 } |
628 break; | 638 break; |
629 // On Chrome OS, XF86XK_Launch7 (F16) with Mod3Mask is sent when Caps Lock | 639 // On Chrome OS, XF86XK_Launch7 (F16) with Mod3Mask is sent when Caps Lock |
630 // is pressed (with one exception: when | 640 // is pressed (with one exception: when |
631 // IsISOLevel5ShiftUsedByCurrentInputMethod() is true, the key generates | 641 // IsISOLevel5ShiftUsedByCurrentInputMethod() is true, the key generates |
632 // XK_ISO_Level3_Shift with Mod3Mask, not XF86XK_Launch7). | 642 // XK_ISO_Level3_Shift with Mod3Mask, not XF86XK_Launch7). |
633 case ui::VKEY_F16: | 643 case ui::VKEY_F16: |
634 characteristic_flag = ui::EF_CAPS_LOCK_DOWN; | 644 characteristic_flag = ui::EF_CAPS_LOCK_DOWN; |
635 remapped_key = | 645 remapped_key = |
636 GetRemappedKey(prefs::kLanguageRemapCapsLockKeyTo, *pref_service); | 646 GetRemappedKey(prefs::kLanguageRemapCapsLockKeyTo, *pref_service); |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
937 KeyboardDeviceAddedInternal(device_info[i].deviceid, device_info[i].name); | 947 KeyboardDeviceAddedInternal(device_info[i].deviceid, device_info[i].name); |
938 } | 948 } |
939 | 949 |
940 XIFreeDeviceInfo(device_info); | 950 XIFreeDeviceInfo(device_info); |
941 #else | 951 #else |
942 KeyboardDeviceAddedInternal(device_id, "keyboard"); | 952 KeyboardDeviceAddedInternal(device_id, "keyboard"); |
943 #endif | 953 #endif |
944 } | 954 } |
945 | 955 |
946 } // namespace chromeos | 956 } // namespace chromeos |
OLD | NEW |