| OLD | NEW |
| 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 #include <stddef.h> |
| 6 |
| 5 #import "chrome/browser/ui/cocoa/multi_key_equivalent_button.h" | 7 #import "chrome/browser/ui/cocoa/multi_key_equivalent_button.h" |
| 6 | 8 |
| 7 @implementation MultiKeyEquivalentButton | 9 @implementation MultiKeyEquivalentButton |
| 8 | 10 |
| 9 - (void)addKeyEquivalent:(KeyEquivalentAndModifierMask)key { | 11 - (void)addKeyEquivalent:(KeyEquivalentAndModifierMask)key { |
| 10 extraKeys_.push_back(key); | 12 extraKeys_.push_back(key); |
| 11 } | 13 } |
| 12 | 14 |
| 13 - (BOOL)performKeyEquivalent:(NSEvent*)event { | 15 - (BOOL)performKeyEquivalent:(NSEvent*)event { |
| 14 NSWindow* modalWindow = [NSApp modalWindow]; | 16 NSWindow* modalWindow = [NSApp modalWindow]; |
| 15 NSWindow* window = [self window]; | 17 NSWindow* window = [self window]; |
| 16 | 18 |
| 17 if ([self isEnabled] && | 19 if ([self isEnabled] && |
| 18 (!modalWindow || modalWindow == window || [window worksWhenModal])) { | 20 (!modalWindow || modalWindow == window || [window worksWhenModal])) { |
| 19 for (size_t index = 0; index < extraKeys_.size(); ++index) { | 21 for (size_t index = 0; index < extraKeys_.size(); ++index) { |
| 20 KeyEquivalentAndModifierMask key = extraKeys_[index]; | 22 KeyEquivalentAndModifierMask key = extraKeys_[index]; |
| 21 if (key.charCode && | 23 if (key.charCode && |
| 22 [key.charCode isEqualToString:[event charactersIgnoringModifiers]] && | 24 [key.charCode isEqualToString:[event charactersIgnoringModifiers]] && |
| 23 ([event modifierFlags] & key.mask) == key.mask) { | 25 ([event modifierFlags] & key.mask) == key.mask) { |
| 24 [self performClick:self]; | 26 [self performClick:self]; |
| 25 return YES; | 27 return YES; |
| 26 } | 28 } |
| 27 } | 29 } |
| 28 } | 30 } |
| 29 | 31 |
| 30 return [super performKeyEquivalent:event]; | 32 return [super performKeyEquivalent:event]; |
| 31 } | 33 } |
| 32 | 34 |
| 33 @end | 35 @end |
| OLD | NEW |