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 been registered. Some shortcuts, such as MediaKeys can | |
Finnur
2013/11/13 10:22:24
nit: add the word 'already' in front of 'been'.
zhchbin
2013/11/13 16:05:11
Done.
| |
77 // have multiple targets, all keyed off of the same accelerator. | |
78 return; | |
79 } | |
80 | |
75 int modifiers = 0; | 81 int modifiers = 0; |
76 modifiers |= accelerator.IsShiftDown() ? MOD_SHIFT : 0; | 82 modifiers |= accelerator.IsShiftDown() ? MOD_SHIFT : 0; |
77 modifiers |= accelerator.IsCtrlDown() ? MOD_CONTROL : 0; | 83 modifiers |= accelerator.IsCtrlDown() ? MOD_CONTROL : 0; |
78 modifiers |= accelerator.IsAltDown() ? MOD_ALT : 0; | 84 modifiers |= accelerator.IsAltDown() ? MOD_ALT : 0; |
79 static int hotkey_id = 0; | 85 static int hotkey_id = 0; |
80 bool success = !!RegisterHotKey( | 86 bool success = !!RegisterHotKey( |
81 gfx::SingletonHwnd::GetInstance()->hwnd(), | 87 gfx::SingletonHwnd::GetInstance()->hwnd(), |
82 hotkey_id, | 88 hotkey_id, |
83 modifiers, | 89 modifiers, |
84 accelerator.key_code()); | 90 accelerator.key_code()); |
(...skipping 22 matching lines...) Expand all Loading... | |
107 gfx::SingletonHwnd::GetInstance()->hwnd(), it->second); | 113 gfx::SingletonHwnd::GetInstance()->hwnd(), it->second); |
108 // This call should always succeed, as long as we pass in the right HWND and | 114 // This call should always succeed, as long as we pass in the right HWND and |
109 // an id we've used to register before. | 115 // an id we've used to register before. |
110 DCHECK(success); | 116 DCHECK(success); |
111 | 117 |
112 hotkey_ids_.erase(it); | 118 hotkey_ids_.erase(it); |
113 GlobalShortcutListener::UnregisterAccelerator(accelerator, observer); | 119 GlobalShortcutListener::UnregisterAccelerator(accelerator, observer); |
114 } | 120 } |
115 | 121 |
116 } // namespace extensions | 122 } // namespace extensions |
OLD | NEW |