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