| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/extensions/global_shortcut_listener_win.h" | 5 #include "chrome/browser/extensions/global_shortcut_listener_win.h" |
| 6 | 6 |
| 7 #include "base/win/win_util.h" | 7 #include "base/win/win_util.h" |
| 8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
| 9 #include "ui/base/accelerators/accelerator.h" | 9 #include "ui/base/accelerators/accelerator.h" |
| 10 #include "ui/events/event_constants.h" | 10 #include "ui/events/event_constants.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 modifiers |= (LOWORD(lparam) & MOD_CONTROL) ? ui::EF_CONTROL_DOWN : 0; | 65 modifiers |= (LOWORD(lparam) & MOD_CONTROL) ? ui::EF_CONTROL_DOWN : 0; |
| 66 ui::Accelerator accelerator( | 66 ui::Accelerator accelerator( |
| 67 ui::KeyboardCodeForWindowsKeyCode(key_code), modifiers); | 67 ui::KeyboardCodeForWindowsKeyCode(key_code), modifiers); |
| 68 | 68 |
| 69 instance.Get().NotifyKeyPressed(accelerator); | 69 instance.Get().NotifyKeyPressed(accelerator); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void GlobalShortcutListenerWin::RegisterAccelerator( | 72 void GlobalShortcutListenerWin::RegisterAccelerator( |
| 73 const ui::Accelerator& accelerator, | 73 const ui::Accelerator& accelerator, |
| 74 GlobalShortcutListener::Observer* observer) { | 74 GlobalShortcutListener::Observer* observer) { |
| 75 if (hotkey_ids_.find(accelerator) != hotkey_ids_.end()) { |
| 76 // The shortcut has already been registered. Some shortcuts, such as |
| 77 // MediaKeys can have multiple targets, all keyed off of the same |
| 78 // accelerator. |
| 79 return; |
| 80 } |
| 81 |
| 75 int modifiers = 0; | 82 int modifiers = 0; |
| 76 modifiers |= accelerator.IsShiftDown() ? MOD_SHIFT : 0; | 83 modifiers |= accelerator.IsShiftDown() ? MOD_SHIFT : 0; |
| 77 modifiers |= accelerator.IsCtrlDown() ? MOD_CONTROL : 0; | 84 modifiers |= accelerator.IsCtrlDown() ? MOD_CONTROL : 0; |
| 78 modifiers |= accelerator.IsAltDown() ? MOD_ALT : 0; | 85 modifiers |= accelerator.IsAltDown() ? MOD_ALT : 0; |
| 79 static int hotkey_id = 0; | 86 static int hotkey_id = 0; |
| 80 bool success = !!RegisterHotKey( | 87 bool success = !!RegisterHotKey( |
| 81 gfx::SingletonHwnd::GetInstance()->hwnd(), | 88 gfx::SingletonHwnd::GetInstance()->hwnd(), |
| 82 hotkey_id, | 89 hotkey_id, |
| 83 modifiers, | 90 modifiers, |
| 84 accelerator.key_code()); | 91 accelerator.key_code()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 107 gfx::SingletonHwnd::GetInstance()->hwnd(), it->second); | 114 gfx::SingletonHwnd::GetInstance()->hwnd(), it->second); |
| 108 // This call should always succeed, as long as we pass in the right HWND and | 115 // This call should always succeed, as long as we pass in the right HWND and |
| 109 // an id we've used to register before. | 116 // an id we've used to register before. |
| 110 DCHECK(success); | 117 DCHECK(success); |
| 111 | 118 |
| 112 hotkey_ids_.erase(it); | 119 hotkey_ids_.erase(it); |
| 113 GlobalShortcutListener::UnregisterAccelerator(accelerator, observer); | 120 GlobalShortcutListener::UnregisterAccelerator(accelerator, observer); |
| 114 } | 121 } |
| 115 | 122 |
| 116 } // namespace extensions | 123 } // namespace extensions |
| OLD | NEW |