2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 09:49:37 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-05-16 07:24:18 +00:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2014-03-16 00:30:26 +00:00
|
|
|
#include "atom/browser/ui/accelerator_util.h"
|
2013-05-16 07:24:18 +00:00
|
|
|
|
|
|
|
#include "ui/base/accelerators/accelerator.h"
|
|
|
|
#import "ui/base/accelerators/platform_accelerator_cocoa.h"
|
2013-12-11 07:48:19 +00:00
|
|
|
#import "ui/events/keycodes/keyboard_code_conversion_mac.h"
|
2013-05-16 07:24:18 +00:00
|
|
|
|
|
|
|
namespace accelerator_util {
|
|
|
|
|
|
|
|
void SetPlatformAccelerator(ui::Accelerator* accelerator) {
|
|
|
|
unichar character;
|
|
|
|
unichar characterIgnoringModifiers;
|
|
|
|
|
2018-04-20 18:47:04 +00:00
|
|
|
NSUInteger modifiers = (accelerator->IsCtrlDown() ? NSControlKeyMask : 0) |
|
|
|
|
(accelerator->IsCmdDown() ? NSCommandKeyMask : 0) |
|
|
|
|
(accelerator->IsAltDown() ? NSAlternateKeyMask : 0) |
|
|
|
|
(accelerator->IsShiftDown() ? NSShiftKeyMask : 0);
|
|
|
|
|
|
|
|
ui::MacKeyCodeForWindowsKeyCode(accelerator->key_code(), modifiers,
|
|
|
|
&character, &characterIgnoringModifiers);
|
2016-04-26 03:23:16 +00:00
|
|
|
|
|
|
|
if (character != characterIgnoringModifiers) {
|
2017-06-16 17:52:19 +00:00
|
|
|
if (isdigit(characterIgnoringModifiers)) {
|
2017-06-13 10:29:54 +00:00
|
|
|
// The character is a number so lets not mutate it with the modifiers
|
|
|
|
character = characterIgnoringModifiers;
|
|
|
|
} else {
|
|
|
|
modifiers ^= NSShiftKeyMask;
|
|
|
|
}
|
2016-04-26 03:23:16 +00:00
|
|
|
}
|
|
|
|
|
2016-06-21 19:33:02 +00:00
|
|
|
if (character == NSDeleteFunctionKey) {
|
|
|
|
character = NSDeleteCharacter;
|
|
|
|
}
|
|
|
|
|
2016-04-26 03:23:16 +00:00
|
|
|
NSString* characters =
|
|
|
|
[[[NSString alloc] initWithCharacters:&character length:1] autorelease];
|
|
|
|
|
2016-05-23 01:59:39 +00:00
|
|
|
std::unique_ptr<ui::PlatformAccelerator> platform_accelerator(
|
2013-05-16 07:24:18 +00:00
|
|
|
new ui::PlatformAcceleratorCocoa(characters, modifiers));
|
2016-03-08 14:28:53 +00:00
|
|
|
accelerator->set_platform_accelerator(std::move(platform_accelerator));
|
2013-05-16 07:24:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace accelerator_util
|