| 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" |
| 11 #include "ash/wm/window_util.h" | 11 #include "ash/wm/window_util.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "base/sys_info.h" | 17 #include "base/sys_info.h" |
| 18 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" | 18 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" |
| 19 #include "chrome/browser/extensions/extension_commands_global_registry.h" | |
| 20 #include "chrome/browser/profiles/profile_manager.h" | 19 #include "chrome/browser/profiles/profile_manager.h" |
| 21 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 22 #include "chromeos/chromeos_switches.h" | 21 #include "chromeos/chromeos_switches.h" |
| 23 #include "chromeos/ime/ime_keyboard.h" | 22 #include "chromeos/ime/ime_keyboard.h" |
| 24 #include "chromeos/ime/input_method_manager.h" | 23 #include "chromeos/ime/input_method_manager.h" |
| 25 #include "components/user_manager/user_manager.h" | 24 #include "components/user_manager/user_manager.h" |
| 26 #include "ui/events/event.h" | 25 #include "ui/events/event.h" |
| 27 #include "ui/events/event_utils.h" | 26 #include "ui/events/event_utils.h" |
| 28 #include "ui/events/keycodes/keyboard_code_conversion.h" | 27 #include "ui/events/keycodes/keyboard_code_conversion.h" |
| 29 #include "ui/wm/core/window_util.h" | 28 #include "ui/wm/core/window_util.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 bool IsISOLevel5ShiftUsedByCurrentInputMethod() { | 97 bool IsISOLevel5ShiftUsedByCurrentInputMethod() { |
| 99 // Since both German Neo2 XKB layout and Caps Lock depend on Mod3Mask, | 98 // Since both German Neo2 XKB layout and Caps Lock depend on Mod3Mask, |
| 100 // it's not possible to make both features work. For now, we don't remap | 99 // it's not possible to make both features work. For now, we don't remap |
| 101 // Mod3Mask when Neo2 is in use. | 100 // Mod3Mask when Neo2 is in use. |
| 102 // TODO(yusukes): Remove the restriction. | 101 // TODO(yusukes): Remove the restriction. |
| 103 input_method::InputMethodManager* manager = | 102 input_method::InputMethodManager* manager = |
| 104 input_method::InputMethodManager::Get(); | 103 input_method::InputMethodManager::Get(); |
| 105 return manager->IsISOLevel5ShiftUsedByCurrentInputMethod(); | 104 return manager->IsISOLevel5ShiftUsedByCurrentInputMethod(); |
| 106 } | 105 } |
| 107 | 106 |
| 108 bool IsExtensionCommandRegistered(const ui::KeyEvent& key_event) { | |
| 109 // Some keyboard events for ChromeOS get rewritten, such as: | |
| 110 // Search+Shift+Left gets converted to Shift+Home (BeginDocument). | |
| 111 // This doesn't make sense if the user has assigned that shortcut | |
| 112 // to an extension. Because: | |
| 113 // 1) The extension would, upon seeing a request for Ctrl+Shift+Home have | |
| 114 // to register for Shift+Home, instead. | |
| 115 // 2) The conversion is unnecessary, because Shift+Home (BeginDocument) isn't | |
| 116 // going to be executed. | |
| 117 // Therefore, we skip converting the accelerator if an extension has | |
| 118 // registered for this shortcut. | |
| 119 Profile* profile = ProfileManager::GetActiveUserProfile(); | |
| 120 if (!profile || !extensions::ExtensionCommandsGlobalRegistry::Get(profile)) | |
| 121 return false; | |
| 122 | |
| 123 int modifiers = key_event.flags() & (ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | | |
| 124 ui::EF_ALT_DOWN | ui::EF_COMMAND_DOWN); | |
| 125 ui::Accelerator accelerator(key_event.key_code(), modifiers); | |
| 126 return extensions::ExtensionCommandsGlobalRegistry::Get(profile) | |
| 127 ->IsRegistered(accelerator); | |
| 128 } | |
| 129 | |
| 130 EventRewriter::DeviceType GetDeviceType(const std::string& device_name) { | 107 EventRewriter::DeviceType GetDeviceType(const std::string& device_name) { |
| 131 std::vector<std::string> tokens; | 108 std::vector<std::string> tokens; |
| 132 Tokenize(device_name, " .", &tokens); | 109 Tokenize(device_name, " .", &tokens); |
| 133 | 110 |
| 134 // If the |device_name| contains the two words, "apple" and "keyboard", treat | 111 // If the |device_name| contains the two words, "apple" and "keyboard", treat |
| 135 // it as an Apple keyboard. | 112 // it as an Apple keyboard. |
| 136 bool found_apple = false; | 113 bool found_apple = false; |
| 137 bool found_keyboard = false; | 114 bool found_keyboard = false; |
| 138 for (size_t i = 0; i < tokens.size(); ++i) { | 115 for (size_t i = 0; i < tokens.size(); ++i) { |
| 139 if (!found_apple && LowerCaseEqualsASCII(tokens[i], "apple")) | 116 if (!found_apple && LowerCaseEqualsASCII(tokens[i], "apple")) |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 remapped_state->key_code = map.output_key_code; | 353 remapped_state->key_code = map.output_key_code; |
| 377 remapped_state->flags = (input.flags & ~map.input_flags) | map.output_flags; | 354 remapped_state->flags = (input.flags & ~map.input_flags) | map.output_flags; |
| 378 return true; | 355 return true; |
| 379 } | 356 } |
| 380 return false; | 357 return false; |
| 381 } | 358 } |
| 382 | 359 |
| 383 ui::EventRewriteStatus EventRewriter::RewriteKeyEvent( | 360 ui::EventRewriteStatus EventRewriter::RewriteKeyEvent( |
| 384 const ui::KeyEvent& key_event, | 361 const ui::KeyEvent& key_event, |
| 385 scoped_ptr<ui::Event>* rewritten_event) { | 362 scoped_ptr<ui::Event>* rewritten_event) { |
| 386 if (IsExtensionCommandRegistered(key_event)) | |
| 387 return ui::EVENT_REWRITE_CONTINUE; | |
| 388 if (key_event.source_device_id() != ui::ED_UNKNOWN_DEVICE) | 363 if (key_event.source_device_id() != ui::ED_UNKNOWN_DEVICE) |
| 389 DeviceKeyPressedOrReleased(key_event.source_device_id()); | 364 DeviceKeyPressedOrReleased(key_event.source_device_id()); |
| 390 MutableKeyState state = {key_event.flags(), key_event.key_code()}; | 365 MutableKeyState state = {key_event.flags(), key_event.key_code()}; |
| 391 // Do not rewrite an event sent by ui_controls::SendKeyPress(). See | 366 // Do not rewrite an event sent by ui_controls::SendKeyPress(). See |
| 392 // crbug.com/136465. | 367 // crbug.com/136465. |
| 393 if (!(key_event.flags() & ui::EF_FINAL)) { | 368 if (!(key_event.flags() & ui::EF_FINAL)) { |
| 394 RewriteModifierKeys(key_event, &state); | 369 RewriteModifierKeys(key_event, &state); |
| 395 RewriteNumPadKeys(key_event, &state); | 370 RewriteNumPadKeys(key_event, &state); |
| 396 } | 371 } |
| 397 ui::EventRewriteStatus status = ui::EVENT_REWRITE_CONTINUE; | 372 ui::EventRewriteStatus status = ui::EVENT_REWRITE_CONTINUE; |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 886 KeyboardDeviceAddedInternal(device_info[i].deviceid, device_info[i].name); | 861 KeyboardDeviceAddedInternal(device_info[i].deviceid, device_info[i].name); |
| 887 } | 862 } |
| 888 | 863 |
| 889 XIFreeDeviceInfo(device_info); | 864 XIFreeDeviceInfo(device_info); |
| 890 #else | 865 #else |
| 891 KeyboardDeviceAddedInternal(device_id, "keyboard"); | 866 KeyboardDeviceAddedInternal(device_id, "keyboard"); |
| 892 #endif | 867 #endif |
| 893 } | 868 } |
| 894 | 869 |
| 895 } // namespace chromeos | 870 } // namespace chromeos |
| OLD | NEW |