Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: trunk/src/chrome/browser/ui/cocoa/accelerator_utils_cocoa.mm

Issue 14096026: Revert 194594 "Make sure manifest specified shortcut for Extensi..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/profiles/profile.h"
6 #include "chrome/browser/ui/cocoa/accelerators_cocoa.h"
7 #import "chrome/browser/ui/cocoa/browser_window_utils.h"
8 #include "content/public/browser/native_web_keyboard_event.h"
9 #include "ui/base/accelerators/accelerator.h"
10 #import "ui/base/accelerators/platform_accelerator_cocoa.h"
11 #import "ui/base/keycodes/keyboard_code_conversion_mac.h"
12
13 namespace chrome {
14
15 bool IsChromeAccelerator(const ui::Accelerator& accelerator, Profile* profile) {
16 // The |accelerator| passed in contains a Windows key code but no platform
17 // accelerator info. The Accelerator list is the opposite: It has accelerators
18 // that have key_code() == VKEY_UNKNOWN but they contain a platform
19 // accelerator. We find common ground by converting the passed in Windows key
20 // code to a character and use that when comparing against the Accelerator
21 // list.
22 unichar character;
23 unichar characterIgnoringModifiers;
24 ui::MacKeyCodeForWindowsKeyCode(accelerator.key_code(),
25 0,
26 &character,
27 &characterIgnoringModifiers);
28 NSString* characters =
29 [[[NSString alloc] initWithCharacters:&character length:1] autorelease];
30
31 NSUInteger modifiers =
32 (accelerator.IsCtrlDown() ? NSControlKeyMask : 0) |
33 (accelerator.IsCmdDown() ? NSCommandKeyMask : 0) |
34 (accelerator.IsAltDown() ? NSAlternateKeyMask : 0) |
35 (accelerator.IsShiftDown() ? NSShiftKeyMask : 0);
36
37 NSEvent* event = [NSEvent keyEventWithType:NSKeyDown
38 location:NSZeroPoint
39 modifierFlags:modifiers
40 timestamp:0
41 windowNumber:0
42 context:nil
43 characters:characters
44 charactersIgnoringModifiers:characters
45 isARepeat:NO
46 keyCode:accelerator.key_code()];
47
48 content::NativeWebKeyboardEvent keyboard_event(event);
49 int id = [BrowserWindowUtils getCommandId:keyboard_event];
50 return id != -1;
51 }
52
53 } // namespace chrome
OLDNEW
« no previous file with comments | « trunk/src/chrome/browser/ui/accelerator_utils.h ('k') | trunk/src/chrome/browser/ui/cocoa/accelerators_cocoa.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698