Chromium Code Reviews| Index: chrome/browser/chromeos/events/event_rewriter.cc |
| diff --git a/chrome/browser/chromeos/events/event_rewriter.cc b/chrome/browser/chromeos/events/event_rewriter.cc |
| index 314a3ecd272cc4987b081631fbc14a31bac25219..f194f0fd5ae6f96e97765e06af8d059a3cf24f1c 100644 |
| --- a/chrome/browser/chromeos/events/event_rewriter.cc |
| +++ b/chrome/browser/chromeos/events/event_rewriter.cc |
| @@ -16,6 +16,7 @@ |
| #include "base/strings/string_util.h" |
| #include "base/sys_info.h" |
| #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" |
| +#include "chrome/browser/extensions/extension_commands_global_registry.h" |
| #include "chrome/browser/profiles/profile_manager.h" |
| #include "chrome/common/pref_names.h" |
| #include "chromeos/chromeos_switches.h" |
| @@ -104,6 +105,36 @@ bool IsISOLevel5ShiftUsedByCurrentInputMethod() { |
| return manager->IsISOLevel5ShiftUsedByCurrentInputMethod(); |
| } |
| +bool IsExtensionCommandRegistered(const ui::KeyEvent& key_event) { |
| + // Some keyboard events for ChromeOS get rewritten, such as: |
| + // Search+Shift+Left gets converted to Shift+Home (BeginDocument). |
| + // This doesn't make sense if the user has assigned that shortcut |
| + // to an extension. Because: |
| + // 1) The extension would, upon seeing a request for Ctrl+Shift+Home have |
| + // to register for Shift+Home, instead. |
| + // 2) The conversion is unnecessary, because Shift+Home (BeginDocument) isn't |
| + // going to be executed. |
| + // Therefore, we skip converting the accelerator if an extension has |
| + // registered for this shortcut. |
| + Profile* profile = ProfileManager::GetActiveUserProfile(); |
| + if (!profile) |
| + return false; |
| + |
| + int modifiers = ui::EF_NONE; |
| + if (key_event.IsShiftDown()) |
|
sky
2014/09/16 02:34:48
Isn't this the same as looking at flags(), eg
flag
sky
2014/09/16 16:44:35
It doesn't seem like you addressed this comment.
David Tseng
2014/09/16 20:42:57
That would indeed simplify this logic. Done.
|
| + modifiers |= ui::EF_SHIFT_DOWN; |
| + if (key_event.IsControlDown()) |
| + modifiers |= ui::EF_CONTROL_DOWN; |
| + if (key_event.IsAltDown()) |
| + modifiers |= ui::EF_ALT_DOWN; |
| + if (key_event.IsCommandDown()) |
| + modifiers |= ui::EF_COMMAND_DOWN; |
| + ui::Accelerator accelerator(key_event.key_code(), modifiers); |
| + |
| + return extensions::ExtensionCommandsGlobalRegistry::Get(profile) |
|
sky
2014/09/16 02:34:48
Is the global registry always non-NULL?
David Tseng
2014/09/16 04:11:52
Turned out the ProfileManager above can be NULL in
|
| + ->IsRegisteredForActiveWindow(accelerator); |
| +} |
| + |
| EventRewriter::DeviceType GetDeviceType(const std::string& device_name) { |
| std::vector<std::string> tokens; |
| Tokenize(device_name, " .", &tokens); |
| @@ -360,6 +391,8 @@ bool EventRewriter::RewriteWithKeyboardRemappingsByKeyCode( |
| ui::EventRewriteStatus EventRewriter::RewriteKeyEvent( |
| const ui::KeyEvent& key_event, |
| scoped_ptr<ui::Event>* rewritten_event) { |
| + if (IsExtensionCommandRegistered(key_event)) |
| + return ui::EVENT_REWRITE_CONTINUE; |
| if (key_event.source_device_id() != ui::ED_UNKNOWN_DEVICE) |
| DeviceKeyPressedOrReleased(key_event.source_device_id()); |
| MutableKeyState state = {key_event.flags(), key_event.key_code()}; |