| 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 current_diamond_key_modifier_flags_(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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 return true; | 324 return true; |
| 324 | 325 |
| 325 ash::wm::WindowState* state = ash::wm::GetActiveWindowState(); | 326 ash::wm::WindowState* state = ash::wm::GetActiveWindowState(); |
| 326 return state ? state->top_row_keys_are_function_keys() : false; | 327 return state ? state->top_row_keys_are_function_keys() : false; |
| 327 } | 328 } |
| 328 | 329 |
| 329 int EventRewriter::GetRemappedModifierMasks(const PrefService& pref_service, | 330 int EventRewriter::GetRemappedModifierMasks(const PrefService& pref_service, |
| 330 const ui::Event& event, | 331 const ui::Event& event, |
| 331 int original_flags) const { | 332 int original_flags) const { |
| 332 int unmodified_flags = original_flags; | 333 int unmodified_flags = original_flags; |
| 333 int rewritten_flags = 0; | 334 int rewritten_flags = current_diamond_key_modifier_flags_; |
| 334 for (size_t i = 0; unmodified_flags && (i < arraysize(kModifierRemappings)); | 335 for (size_t i = 0; unmodified_flags && (i < arraysize(kModifierRemappings)); |
| 335 ++i) { | 336 ++i) { |
| 336 const ModifierRemapping* remapped_key = NULL; | 337 const ModifierRemapping* remapped_key = NULL; |
| 337 if (!(unmodified_flags & kModifierRemappings[i].flag)) | 338 if (!(unmodified_flags & kModifierRemappings[i].flag)) |
| 338 continue; | 339 continue; |
| 339 switch (kModifierRemappings[i].flag) { | 340 switch (kModifierRemappings[i].flag) { |
| 340 case ui::EF_COMMAND_DOWN: | 341 case ui::EF_COMMAND_DOWN: |
| 341 // Rewrite Command key presses on an Apple keyboard to Control. | 342 // Rewrite Command key presses on an Apple keyboard to Control. |
| 342 if (IsAppleKeyboard()) { | 343 if (IsAppleKeyboard()) { |
| 343 DCHECK_EQ(ui::EF_CONTROL_DOWN, kModifierRemappingCtrl->flag); | 344 DCHECK_EQ(ui::EF_CONTROL_DOWN, kModifierRemappingCtrl->flag); |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 switch (incoming.key_code) { | 618 switch (incoming.key_code) { |
| 618 // On Chrome OS, F15 (XF86XK_Launch6) with NumLock (Mod2Mask) is sent | 619 // On Chrome OS, F15 (XF86XK_Launch6) with NumLock (Mod2Mask) is sent |
| 619 // when Diamond key is pressed. | 620 // when Diamond key is pressed. |
| 620 case ui::VKEY_F15: | 621 case ui::VKEY_F15: |
| 621 // When diamond key is not available, the configuration UI for Diamond | 622 // When diamond key is not available, the configuration UI for Diamond |
| 622 // key is not shown. Therefore, ignore the kLanguageRemapDiamondKeyTo | 623 // key is not shown. Therefore, ignore the kLanguageRemapDiamondKeyTo |
| 623 // syncable pref. | 624 // syncable pref. |
| 624 if (HasDiamondKey()) | 625 if (HasDiamondKey()) |
| 625 remapped_key = | 626 remapped_key = |
| 626 GetRemappedKey(prefs::kLanguageRemapDiamondKeyTo, *pref_service); | 627 GetRemappedKey(prefs::kLanguageRemapDiamondKeyTo, *pref_service); |
| 627 // Default behavior is Ctrl key. | 628 // Default behavior of F15 is Control, even if --has-chromeos-diamond-key |
| 629 // is absent, according to unit test comments. |
| 628 if (!remapped_key) { | 630 if (!remapped_key) { |
| 629 DCHECK_EQ(ui::VKEY_CONTROL, kModifierRemappingCtrl->key_code); | 631 DCHECK_EQ(ui::VKEY_CONTROL, kModifierRemappingCtrl->key_code); |
| 630 remapped_key = kModifierRemappingCtrl; | 632 remapped_key = kModifierRemappingCtrl; |
| 631 characteristic_flag = ui::EF_CONTROL_DOWN; | 633 } |
| 634 // F15 is not a modifier key, so we need to track its state directly. |
| 635 if (key_event.type() == ui::ET_KEY_PRESSED) { |
| 636 int remapped_flag = remapped_key->flag; |
| 637 if (remapped_key->remap_to == input_method::kCapsLockKey) |
| 638 remapped_flag |= ui::EF_CAPS_LOCK_DOWN; |
| 639 current_diamond_key_modifier_flags_ = remapped_flag; |
| 640 } else { |
| 641 current_diamond_key_modifier_flags_ = ui::EF_NONE; |
| 632 } | 642 } |
| 633 break; | 643 break; |
| 634 // On Chrome OS, XF86XK_Launch7 (F16) with Mod3Mask is sent when Caps Lock | 644 // On Chrome OS, XF86XK_Launch7 (F16) with Mod3Mask is sent when Caps Lock |
| 635 // is pressed (with one exception: when | 645 // is pressed (with one exception: when |
| 636 // IsISOLevel5ShiftUsedByCurrentInputMethod() is true, the key generates | 646 // IsISOLevel5ShiftUsedByCurrentInputMethod() is true, the key generates |
| 637 // XK_ISO_Level3_Shift with Mod3Mask, not XF86XK_Launch7). | 647 // XK_ISO_Level3_Shift with Mod3Mask, not XF86XK_Launch7). |
| 638 case ui::VKEY_F16: | 648 case ui::VKEY_F16: |
| 639 characteristic_flag = ui::EF_CAPS_LOCK_DOWN; | 649 characteristic_flag = ui::EF_CAPS_LOCK_DOWN; |
| 640 remapped_key = | 650 remapped_key = |
| 641 GetRemappedKey(prefs::kLanguageRemapCapsLockKeyTo, *pref_service); | 651 GetRemappedKey(prefs::kLanguageRemapCapsLockKeyTo, *pref_service); |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 942 KeyboardDeviceAddedInternal(device_info[i].deviceid, device_info[i].name); | 952 KeyboardDeviceAddedInternal(device_info[i].deviceid, device_info[i].name); |
| 943 } | 953 } |
| 944 | 954 |
| 945 XIFreeDeviceInfo(device_info); | 955 XIFreeDeviceInfo(device_info); |
| 946 #else | 956 #else |
| 947 KeyboardDeviceAddedInternal(device_id, "keyboard"); | 957 KeyboardDeviceAddedInternal(device_id, "keyboard"); |
| 948 #endif | 958 #endif |
| 949 } | 959 } |
| 950 | 960 |
| 951 } // namespace chromeos | 961 } // namespace chromeos |
| OLD | NEW |