OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/cocoa/browser_window_controller.h" | 5 #import "chrome/browser/cocoa/browser_window_controller.h" |
6 | 6 |
7 #include <Carbon/Carbon.h> | 7 #include <Carbon/Carbon.h> |
8 | 8 |
9 #include "app/l10n_util_mac.h" | 9 #include "app/l10n_util_mac.h" |
10 #include "base/mac_util.h" | 10 #include "base/mac_util.h" |
(...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
911 // belong to a background window, yet this controller gets it because it is | 911 // belong to a background window, yet this controller gets it because it is |
912 // the foreground window's controller and thus in the responder chain. Some | 912 // the foreground window's controller and thus in the responder chain. Some |
913 // senders don't have this problem (for example, menus only operate on the | 913 // senders don't have this problem (for example, menus only operate on the |
914 // foreground window), so this is only an issue for senders that are part of | 914 // foreground window), so this is only an issue for senders that are part of |
915 // windows. | 915 // windows. |
916 BrowserWindowController* targetController = self; | 916 BrowserWindowController* targetController = self; |
917 if ([sender respondsToSelector:@selector(window)]) | 917 if ([sender respondsToSelector:@selector(window)]) |
918 targetController = [[sender window] windowController]; | 918 targetController = [[sender window] windowController]; |
919 DCHECK([targetController isKindOfClass:[BrowserWindowController class]]); | 919 DCHECK([targetController isKindOfClass:[BrowserWindowController class]]); |
920 DCHECK(targetController->browser_.get()); | 920 DCHECK(targetController->browser_.get()); |
921 targetController->browser_->ExecuteCommand([sender tag]); | 921 NSInteger command; |
| 922 if ([sender respondsToSelector:@selector(command)]) |
| 923 command = [sender command]; |
| 924 else |
| 925 command = [sender tag]; |
| 926 targetController->browser_->ExecuteCommand(command); |
922 } | 927 } |
923 | 928 |
924 // Same as |-commandDispatch:|, but executes commands using a disposition | 929 // Same as |-commandDispatch:|, but executes commands using a disposition |
925 // determined by the key flags. If the window is in the background and the | 930 // determined by the key flags. If the window is in the background and the |
926 // command key is down, ignore the command key, but process any other modifiers. | 931 // command key is down, ignore the command key, but process any other modifiers. |
927 - (void)commandDispatchUsingKeyModifiers:(id)sender { | 932 - (void)commandDispatchUsingKeyModifiers:(id)sender { |
928 DCHECK(sender); | 933 DCHECK(sender); |
929 // See comment above for why we do this. | 934 // See comment above for why we do this. |
930 BrowserWindowController* targetController = self; | 935 BrowserWindowController* targetController = self; |
931 if ([sender respondsToSelector:@selector(window)]) | 936 if ([sender respondsToSelector:@selector(window)]) |
932 targetController = [[sender window] windowController]; | 937 targetController = [[sender window] windowController]; |
933 DCHECK([targetController isKindOfClass:[BrowserWindowController class]]); | 938 DCHECK([targetController isKindOfClass:[BrowserWindowController class]]); |
934 NSInteger command = [sender tag]; | 939 NSInteger command; |
| 940 if ([sender respondsToSelector:@selector(command)]) |
| 941 command = [sender command]; |
| 942 else |
| 943 command = [sender tag]; |
935 NSUInteger modifierFlags = [[NSApp currentEvent] modifierFlags]; | 944 NSUInteger modifierFlags = [[NSApp currentEvent] modifierFlags]; |
936 if ((command == IDC_RELOAD) && (modifierFlags & NSShiftKeyMask)) { | 945 if ((command == IDC_RELOAD) && (modifierFlags & NSShiftKeyMask)) { |
937 command = IDC_RELOAD_IGNORING_CACHE; | 946 command = IDC_RELOAD_IGNORING_CACHE; |
938 // Mask off shift so it isn't interpreted as affecting the disposition | 947 // Mask off shift so it isn't interpreted as affecting the disposition |
939 // below. | 948 // below. |
940 modifierFlags &= ~NSShiftKeyMask; | 949 modifierFlags &= ~NSShiftKeyMask; |
941 } | 950 } |
942 if (![[sender window] isMainWindow]) { | 951 if (![[sender window] isMainWindow]) { |
943 // Remove the command key from the flags, it means "keep the window in | 952 // Remove the command key from the flags, it means "keep the window in |
944 // the background" in this case. | 953 // the background" in this case. |
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1860 | 1869 |
1861 - (BOOL)supportsBookmarkBar { | 1870 - (BOOL)supportsBookmarkBar { |
1862 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; | 1871 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; |
1863 } | 1872 } |
1864 | 1873 |
1865 - (BOOL)isNormalWindow { | 1874 - (BOOL)isNormalWindow { |
1866 return browser_->type() == Browser::TYPE_NORMAL; | 1875 return browser_->type() == Browser::TYPE_NORMAL; |
1867 } | 1876 } |
1868 | 1877 |
1869 @end // @implementation BrowserWindowController(WindowType) | 1878 @end // @implementation BrowserWindowController(WindowType) |
OLD | NEW |