OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/cocoa/extensions/extension_keybinding_registry_cocoa .h" | 5 #include "chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa .h" |
6 | 6 |
7 #include "chrome/browser/extensions/api/commands/command_service.h" | 7 #include "chrome/browser/extensions/api/commands/command_service.h" |
8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/cocoa/accelerators_cocoa.h" | |
10 #include "chrome/common/extensions/extension.h" | 11 #include "chrome/common/extensions/extension.h" |
11 #include "chrome/common/chrome_notification_types.h" | 12 #include "chrome/common/chrome_notification_types.h" |
12 #include "chrome/common/extensions/extension_manifest_constants.h" | 13 #include "chrome/common/extensions/extension_manifest_constants.h" |
13 #include "content/public/browser/native_web_keyboard_event.h" | 14 #include "content/public/browser/native_web_keyboard_event.h" |
14 #include "content/public/browser/notification_service.h" | 15 #include "content/public/browser/notification_service.h" |
16 #include "ui/base/accelerators/platform_accelerator_cocoa.h" | |
17 #include "ui/base/keycodes/keyboard_code_conversion_mac.h" | |
15 | 18 |
16 namespace values = extension_manifest_values; | 19 namespace values = extension_manifest_values; |
17 | 20 |
18 // static | 21 // static |
19 void extensions::ExtensionKeybindingRegistry::SetShortcutHandlingSuspended( | 22 void extensions::ExtensionKeybindingRegistry::SetShortcutHandlingSuspended( |
20 bool suspended) { | 23 bool suspended) { |
21 ExtensionKeybindingRegistryCocoa::set_shortcut_handling_suspended(suspended); | 24 ExtensionKeybindingRegistryCocoa::set_shortcut_handling_suspended(suspended); |
22 } | 25 } |
23 | 26 |
27 // static | |
28 bool extensions::ExtensionKeybindingRegistry::IsChromeAccelerator( | |
Nico
2013/04/09 16:10:18
Is this supposed to return true if a shortcut is u
| |
29 const ui::Accelerator& accelerator) { | |
30 // The |accelerator| passed in contains a Windows key code but no platform | |
31 // accelerator info. The Accelerator list is the opposite: It has accelerators | |
32 // that have key_code() == VKEY_UNKNOWN but they contain a platform | |
33 // accelerator. We find common ground by converting the passed in Windows key | |
34 // code to a character and use that when comparing against the Accelerator | |
35 // list. | |
36 unichar character; | |
37 unichar characterIgnoringModifiers; | |
38 ui::MacKeyCodeForWindowsKeyCode(accelerator.key_code(), | |
39 0, | |
40 &character, | |
41 &characterIgnoringModifiers); | |
42 NSString* characters = | |
43 [[[NSString alloc] initWithCharacters:&character length:1] autorelease]; | |
44 | |
45 NSUInteger modifiers = | |
46 (accelerator.IsCtrlDown() ? NSControlKeyMask : 0) | | |
47 (accelerator.IsCmdDown() ? NSCommandKeyMask : 0) | | |
48 (accelerator.IsAltDown() ? NSAlternateKeyMask : 0) | | |
49 (accelerator.IsShiftDown() ? NSShiftKeyMask : 0); | |
50 | |
51 AcceleratorsCocoa* accelerators = AcceleratorsCocoa::GetInstance(); | |
52 for (AcceleratorsCocoa::const_iterator iter = accelerators->begin(); | |
53 iter != accelerators->end(); ++iter) { | |
54 const ui::PlatformAcceleratorCocoa* platform_accelerator = | |
55 static_cast<const ui::PlatformAcceleratorCocoa*>( | |
56 iter->second.platform_accelerator()); | |
57 if ([characters isEqualToString:platform_accelerator->characters()] && | |
58 modifiers == platform_accelerator->modifier_mask()) | |
59 return true; | |
60 } | |
61 return false; | |
62 } | |
63 | |
24 bool ExtensionKeybindingRegistryCocoa::shortcut_handling_suspended_ = false; | 64 bool ExtensionKeybindingRegistryCocoa::shortcut_handling_suspended_ = false; |
25 | 65 |
26 ExtensionKeybindingRegistryCocoa::ExtensionKeybindingRegistryCocoa( | 66 ExtensionKeybindingRegistryCocoa::ExtensionKeybindingRegistryCocoa( |
27 Profile* profile, | 67 Profile* profile, |
28 gfx::NativeWindow window, | 68 gfx::NativeWindow window, |
29 ExtensionFilter extension_filter, | 69 ExtensionFilter extension_filter, |
30 Delegate* delegate) | 70 Delegate* delegate) |
31 : ExtensionKeybindingRegistry(profile, extension_filter, delegate), | 71 : ExtensionKeybindingRegistry(profile, extension_filter, delegate), |
32 profile_(profile), | 72 profile_(profile), |
33 window_(window) { | 73 window_(window) { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 const extensions::Extension* extension, | 179 const extensions::Extension* extension, |
140 const std::string& command_name) { | 180 const std::string& command_name) { |
141 EventTargets::iterator iter = event_targets_.begin(); | 181 EventTargets::iterator iter = event_targets_.begin(); |
142 while (iter != event_targets_.end()) { | 182 while (iter != event_targets_.end()) { |
143 EventTargets::iterator old = iter++; | 183 EventTargets::iterator old = iter++; |
144 if (old->second.first == extension->id() && | 184 if (old->second.first == extension->id() && |
145 (command_name.empty() || (old->second.second == command_name))) | 185 (command_name.empty() || (old->second.second == command_name))) |
146 event_targets_.erase(old); | 186 event_targets_.erase(old); |
147 } | 187 } |
148 } | 188 } |
OLD | NEW |