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

Side by Side Diff: chrome/browser/ui/cocoa/nsmenuitem_additions.mm

Issue 5576002: Fix BrowserKeyEventsTest.ReservedAccelerators on Mac 10.6 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add cr_firesForKeyEventIfEnabled. Created 10 years 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
« no previous file with comments | « chrome/browser/ui/cocoa/nsmenuitem_additions.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 #import "chrome/browser/ui/cocoa/nsmenuitem_additions.h" 5 #import "chrome/browser/ui/cocoa/nsmenuitem_additions.h"
6 6
7 #include <Carbon/Carbon.h> 7 #include <Carbon/Carbon.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 10
11 @implementation NSMenuItem(ChromeAdditions) 11 @implementation NSMenuItem(ChromeAdditions)
12 12
13 - (BOOL)cr_firesForKeyEvent:(NSEvent*)event { 13 - (BOOL)cr_firesForKeyEvent:(NSEvent*)event {
Ilya Sherman 2010/12/06 18:45:27 nit: It seems weird to me to leave this function a
14 DCHECK([event type] == NSKeyDown);
15 if (![self isEnabled]) 14 if (![self isEnabled])
16 return NO; 15 return NO;
16 return [self cr_firesForKeyEventIfEnabled:event];
17 }
17 18
19 - (BOOL)cr_firesForKeyEventIfEnabled:(NSEvent*)event {
20 DCHECK([event type] == NSKeyDown);
18 // In System Preferences->Keyboard->Keyboard Shortcuts, it is possible to add 21 // In System Preferences->Keyboard->Keyboard Shortcuts, it is possible to add
19 // arbitrary keyboard shortcuts to applications. It is not documented how this 22 // arbitrary keyboard shortcuts to applications. It is not documented how this
20 // works in detail, but |NSMenuItem| has a method |userKeyEquivalent| that 23 // works in detail, but |NSMenuItem| has a method |userKeyEquivalent| that
21 // sounds related. 24 // sounds related.
22 // However, it looks like |userKeyEquivalent| is equal to |keyEquivalent| when 25 // However, it looks like |userKeyEquivalent| is equal to |keyEquivalent| when
23 // a user shortcut is set in system preferences, i.e. Cocoa automatically 26 // a user shortcut is set in system preferences, i.e. Cocoa automatically
24 // sets/overwrites |keyEquivalent| as well. Hence, this method can ignore 27 // sets/overwrites |keyEquivalent| as well. Hence, this method can ignore
25 // |userKeyEquivalent| and check |keyEquivalent| only. 28 // |userKeyEquivalent| and check |keyEquivalent| only.
26 29
27 // Menu item key equivalents are nearly all stored without modifiers. The 30 // Menu item key equivalents are nearly all stored without modifiers. The
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 eventModifiers &= NSCommandKeyMask | 97 eventModifiers &= NSCommandKeyMask |
95 NSControlKeyMask | 98 NSControlKeyMask |
96 NSAlternateKeyMask | 99 NSAlternateKeyMask |
97 NSShiftKeyMask; 100 NSShiftKeyMask;
98 101
99 return [eventString isEqualToString:[self keyEquivalent]] 102 return [eventString isEqualToString:[self keyEquivalent]]
100 && eventModifiers == [self keyEquivalentModifierMask]; 103 && eventModifiers == [self keyEquivalentModifierMask];
101 } 104 }
102 105
103 @end 106 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/nsmenuitem_additions.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698