| Index: chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa.mm
|
| diff --git a/chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa.mm b/chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa.mm
|
| index 1ee3c0f652ff0796967cc7d8273d8dac7a7211e2..5fd34033a6ce4d159fbcd516c288c713c033ee87 100644
|
| --- a/chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa.mm
|
| +++ b/chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa.mm
|
| @@ -7,11 +7,15 @@
|
| #include "chrome/browser/extensions/api/commands/command_service.h"
|
| #include "chrome/browser/extensions/extension_service.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| +#include "chrome/browser/ui/cocoa/accelerators_cocoa.h"
|
| +#import "chrome/browser/ui/cocoa/browser_window_utils.h"
|
| #include "chrome/common/extensions/extension.h"
|
| #include "chrome/common/chrome_notification_types.h"
|
| #include "chrome/common/extensions/extension_manifest_constants.h"
|
| #include "content/public/browser/native_web_keyboard_event.h"
|
| #include "content/public/browser/notification_service.h"
|
| +#include "ui/base/accelerators/platform_accelerator_cocoa.h"
|
| +#include "ui/base/keycodes/keyboard_code_conversion_mac.h"
|
|
|
| namespace values = extension_manifest_values;
|
|
|
| @@ -21,6 +25,60 @@ void extensions::ExtensionKeybindingRegistry::SetShortcutHandlingSuspended(
|
| ExtensionKeybindingRegistryCocoa::set_shortcut_handling_suspended(suspended);
|
| }
|
|
|
| +// static
|
| +bool extensions::ExtensionKeybindingRegistry::IsChromeAccelerator(
|
| + const ui::Accelerator& accelerator, Profile* profile) {
|
| + // The |accelerator| passed in contains a Windows key code but no platform
|
| + // accelerator info. The Accelerator list is the opposite: It has accelerators
|
| + // that have key_code() == VKEY_UNKNOWN but they contain a platform
|
| + // accelerator. We find common ground by converting the passed in Windows key
|
| + // code to a character and use that when comparing against the Accelerator
|
| + // list.
|
| + unichar character;
|
| + unichar characterIgnoringModifiers;
|
| + ui::MacKeyCodeForWindowsKeyCode(accelerator.key_code(),
|
| + 0,
|
| + &character,
|
| + &characterIgnoringModifiers);
|
| + NSString* characters =
|
| + [[[NSString alloc] initWithCharacters:&character length:1] autorelease];
|
| +
|
| + NSUInteger modifiers =
|
| + (accelerator.IsCtrlDown() ? NSControlKeyMask : 0) |
|
| + (accelerator.IsCmdDown() ? NSCommandKeyMask : 0) |
|
| + (accelerator.IsAltDown() ? NSAlternateKeyMask : 0) |
|
| + (accelerator.IsShiftDown() ? NSShiftKeyMask : 0);
|
| +
|
| + NSEvent* event = [NSEvent keyEventWithType:NSKeyDown
|
| + location:NSZeroPoint
|
| + modifierFlags:modifiers
|
| + timestamp:0
|
| + windowNumber:0
|
| + context:nil
|
| + characters:characters
|
| + charactersIgnoringModifiers:characters
|
| + isARepeat:NO
|
| + keyCode:accelerator.key_code()];
|
| +
|
| + content::NativeWebKeyboardEvent keyboard_event(event);
|
| + int id = [BrowserWindowUtils getCommandId:keyboard_event];
|
| + if (id != -1)
|
| + return true;
|
| +
|
| + AcceleratorsCocoa* accelerators = AcceleratorsCocoa::GetInstance();
|
| + for (AcceleratorsCocoa::const_iterator iter = accelerators->begin();
|
| + iter != accelerators->end(); ++iter) {
|
| + const ui::PlatformAcceleratorCocoa* platform_accelerator =
|
| + static_cast<const ui::PlatformAcceleratorCocoa*>(
|
| + iter->second.platform_accelerator());
|
| + if ([characters isEqualToString:platform_accelerator->characters()] &&
|
| + modifiers == platform_accelerator->modifier_mask())
|
| + return true;
|
| + }
|
| +
|
| + return false;
|
| +}
|
| +
|
| bool ExtensionKeybindingRegistryCocoa::shortcut_handling_suspended_ = false;
|
|
|
| ExtensionKeybindingRegistryCocoa::ExtensionKeybindingRegistryCocoa(
|
|
|