| 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/extensions/extension_keybinding_registry_tracker.h" |
| 19 #include "chrome/browser/profiles/profile_manager.h" | 21 #include "chrome/browser/profiles/profile_manager.h" |
| 22 #include "chrome/browser/ui/browser.h" |
| 23 #include "chrome/browser/ui/browser_list.h" |
| 24 #include "chrome/browser/ui/browser_window.h" |
| 20 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 21 #include "chromeos/chromeos_switches.h" | 26 #include "chromeos/chromeos_switches.h" |
| 22 #include "chromeos/ime/ime_keyboard.h" | 27 #include "chromeos/ime/ime_keyboard.h" |
| 23 #include "chromeos/ime/input_method_manager.h" | 28 #include "chromeos/ime/input_method_manager.h" |
| 24 #include "components/user_manager/user_manager.h" | 29 #include "components/user_manager/user_manager.h" |
| 25 #include "ui/events/event.h" | 30 #include "ui/events/event.h" |
| 26 #include "ui/events/event_utils.h" | 31 #include "ui/events/event_utils.h" |
| 27 #include "ui/events/keycodes/keyboard_code_conversion.h" | 32 #include "ui/events/keycodes/keyboard_code_conversion.h" |
| 28 #include "ui/wm/core/window_util.h" | 33 #include "ui/wm/core/window_util.h" |
| 29 | 34 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 bool IsISOLevel5ShiftUsedByCurrentInputMethod() { | 102 bool IsISOLevel5ShiftUsedByCurrentInputMethod() { |
| 98 // Since both German Neo2 XKB layout and Caps Lock depend on Mod3Mask, | 103 // Since both German Neo2 XKB layout and Caps Lock depend on Mod3Mask, |
| 99 // it's not possible to make both features work. For now, we don't remap | 104 // it's not possible to make both features work. For now, we don't remap |
| 100 // Mod3Mask when Neo2 is in use. | 105 // Mod3Mask when Neo2 is in use. |
| 101 // TODO(yusukes): Remove the restriction. | 106 // TODO(yusukes): Remove the restriction. |
| 102 input_method::InputMethodManager* manager = | 107 input_method::InputMethodManager* manager = |
| 103 input_method::InputMethodManager::Get(); | 108 input_method::InputMethodManager::Get(); |
| 104 return manager->IsISOLevel5ShiftUsedByCurrentInputMethod(); | 109 return manager->IsISOLevel5ShiftUsedByCurrentInputMethod(); |
| 105 } | 110 } |
| 106 | 111 |
| 112 bool IsExtensionCommandRegistered(const ui::KeyEvent& key_event) { |
| 113 // Some keyboard events for ChromeOS get rewritten, such as: |
| 114 // Search+Shift+Left gets converted to Shift+Home (BeginDocument). |
| 115 // This doesn't make sense if the user has assigned that shortcut |
| 116 // to an extension. Because: |
| 117 // 1) The extension would, upon seeing a request for Ctrl+Shift+Home have |
| 118 // to register for Shift+Home, instead. |
| 119 // 2) The conversion is unnecessary, because Shift+Home (BeginDocument) isn't |
| 120 // going to be executed. |
| 121 // Therefore, we skip converting the accelerator if an extension has |
| 122 // registered for this shortcut. |
| 123 Profile* profile = ProfileManager::GetActiveUserProfile(); |
| 124 if (!profile) |
| 125 return false; |
| 126 |
| 127 extensions::ExtensionKeybindingRegistry* registry = |
| 128 extensions::ExtensionKeybindingRegistryTracker::Get(profile) |
| 129 ->GetActiveRegistry(); |
| 130 if (!registry) |
| 131 return false; |
| 132 |
| 133 int modifiers = ui::EF_NONE; |
| 134 if (key_event.IsShiftDown()) |
| 135 modifiers |= ui::EF_SHIFT_DOWN; |
| 136 if (key_event.IsControlDown()) |
| 137 modifiers |= ui::EF_CONTROL_DOWN; |
| 138 if (key_event.IsAltDown()) |
| 139 modifiers |= ui::EF_ALT_DOWN; |
| 140 if (key_event.IsCommandDown()) |
| 141 modifiers |= ui::EF_COMMAND_DOWN; |
| 142 ui::Accelerator accelerator(key_event.key_code(), modifiers); |
| 143 if (registry->IsAcceleratorRegistered(accelerator) || |
| 144 extensions::ExtensionCommandsGlobalRegistry::Get(profile) |
| 145 ->IsAcceleratorRegistered(accelerator)) |
| 146 return true; |
| 147 return false; |
| 148 } |
| 149 |
| 107 EventRewriter::DeviceType GetDeviceType(const std::string& device_name) { | 150 EventRewriter::DeviceType GetDeviceType(const std::string& device_name) { |
| 108 std::vector<std::string> tokens; | 151 std::vector<std::string> tokens; |
| 109 Tokenize(device_name, " .", &tokens); | 152 Tokenize(device_name, " .", &tokens); |
| 110 | 153 |
| 111 // If the |device_name| contains the two words, "apple" and "keyboard", treat | 154 // If the |device_name| contains the two words, "apple" and "keyboard", treat |
| 112 // it as an Apple keyboard. | 155 // it as an Apple keyboard. |
| 113 bool found_apple = false; | 156 bool found_apple = false; |
| 114 bool found_keyboard = false; | 157 bool found_keyboard = false; |
| 115 for (size_t i = 0; i < tokens.size(); ++i) { | 158 for (size_t i = 0; i < tokens.size(); ++i) { |
| 116 if (!found_apple && LowerCaseEqualsASCII(tokens[i], "apple")) | 159 if (!found_apple && LowerCaseEqualsASCII(tokens[i], "apple")) |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 remapped_state->key_code = map.output_key_code; | 396 remapped_state->key_code = map.output_key_code; |
| 354 remapped_state->flags = (input.flags & ~map.input_flags) | map.output_flags; | 397 remapped_state->flags = (input.flags & ~map.input_flags) | map.output_flags; |
| 355 return true; | 398 return true; |
| 356 } | 399 } |
| 357 return false; | 400 return false; |
| 358 } | 401 } |
| 359 | 402 |
| 360 ui::EventRewriteStatus EventRewriter::RewriteKeyEvent( | 403 ui::EventRewriteStatus EventRewriter::RewriteKeyEvent( |
| 361 const ui::KeyEvent& key_event, | 404 const ui::KeyEvent& key_event, |
| 362 scoped_ptr<ui::Event>* rewritten_event) { | 405 scoped_ptr<ui::Event>* rewritten_event) { |
| 406 if (IsExtensionCommandRegistered(key_event)) |
| 407 return ui::EVENT_REWRITE_CONTINUE; |
| 363 if (key_event.source_device_id() != ui::ED_UNKNOWN_DEVICE) | 408 if (key_event.source_device_id() != ui::ED_UNKNOWN_DEVICE) |
| 364 DeviceKeyPressedOrReleased(key_event.source_device_id()); | 409 DeviceKeyPressedOrReleased(key_event.source_device_id()); |
| 365 MutableKeyState state = {key_event.flags(), key_event.key_code()}; | 410 MutableKeyState state = {key_event.flags(), key_event.key_code()}; |
| 366 // Do not rewrite an event sent by ui_controls::SendKeyPress(). See | 411 // Do not rewrite an event sent by ui_controls::SendKeyPress(). See |
| 367 // crbug.com/136465. | 412 // crbug.com/136465. |
| 368 if (!(key_event.flags() & ui::EF_FINAL)) { | 413 if (!(key_event.flags() & ui::EF_FINAL)) { |
| 369 RewriteModifierKeys(key_event, &state); | 414 RewriteModifierKeys(key_event, &state); |
| 370 RewriteNumPadKeys(key_event, &state); | 415 RewriteNumPadKeys(key_event, &state); |
| 371 } | 416 } |
| 372 ui::EventRewriteStatus status = ui::EVENT_REWRITE_CONTINUE; | 417 ui::EventRewriteStatus status = ui::EVENT_REWRITE_CONTINUE; |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 KeyboardDeviceAddedInternal(device_info[i].deviceid, device_info[i].name); | 906 KeyboardDeviceAddedInternal(device_info[i].deviceid, device_info[i].name); |
| 862 } | 907 } |
| 863 | 908 |
| 864 XIFreeDeviceInfo(device_info); | 909 XIFreeDeviceInfo(device_info); |
| 865 #else | 910 #else |
| 866 KeyboardDeviceAddedInternal(device_id, "keyboard"); | 911 KeyboardDeviceAddedInternal(device_id, "keyboard"); |
| 867 #endif | 912 #endif |
| 868 } | 913 } |
| 869 | 914 |
| 870 } // namespace chromeos | 915 } // namespace chromeos |
| OLD | NEW |