OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser_window_controller.h" | 5 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <numeric> | 8 #include <numeric> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 967 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
978 // Called to validate menu and toolbar items when this window is key. All the | 978 // Called to validate menu and toolbar items when this window is key. All the |
979 // items we care about have been set with the |-commandDispatch:| or | 979 // items we care about have been set with the |-commandDispatch:| or |
980 // |-commandDispatchUsingKeyModifiers:| actions and a target of FirstResponder | 980 // |-commandDispatchUsingKeyModifiers:| actions and a target of FirstResponder |
981 // in IB. If it's not one of those, let it continue up the responder chain to be | 981 // in IB. If it's not one of those, let it continue up the responder chain to be |
982 // handled elsewhere. We pull out the tag as the cross-platform constant to | 982 // handled elsewhere. We pull out the tag as the cross-platform constant to |
983 // differentiate and dispatch the various commands. | 983 // differentiate and dispatch the various commands. |
984 // NOTE: we might have to handle state for app-wide menu items, | 984 // NOTE: we might have to handle state for app-wide menu items, |
985 // although we could cheat and directly ask the app controller if our | 985 // although we could cheat and directly ask the app controller if our |
986 // command_updater doesn't support the command. This may or may not be an issue, | 986 // command_updater doesn't support the command. This may or may not be an issue, |
987 // too early to tell. | 987 // too early to tell. |
988 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item { | 988 - (BOOL)validateUserInterfaceItem:(NSMenuItem*)item { |
Scott Hess - ex-Googler
2011/10/25 23:40:59
I'm not sure this is only NSMenuItem*. If it defi
Ilya Sherman
2011/10/26 23:22:40
Oh, I missed those below. It seems weird that thi
| |
989 SEL action = [item action]; | 989 SEL action = [item action]; |
990 BOOL enable = NO; | 990 BOOL enable = NO; |
991 if (action == @selector(commandDispatch:) || | 991 if (action == @selector(commandDispatch:) || |
992 action == @selector(commandDispatchUsingKeyModifiers:)) { | 992 action == @selector(commandDispatchUsingKeyModifiers:)) { |
993 NSInteger tag = [item tag]; | 993 NSInteger tag = [item tag]; |
994 if (browser_->command_updater()->SupportsCommand(tag)) { | 994 if (browser_->command_updater()->SupportsCommand(tag)) { |
995 // Generate return value (enabled state) | 995 // Generate return value (enabled state) |
996 enable = browser_->command_updater()->IsCommandEnabled(tag); | 996 enable = browser_->command_updater()->IsCommandEnabled(tag); |
997 switch (tag) { | 997 switch (tag) { |
998 case IDC_CLOSE_TAB: | 998 case IDC_CLOSE_TAB: |
999 // Disable "close tab" if we're not the key window or if there's only | 999 // Disable "close tab" if the receiving window is not tabbed. |
1000 // one tab. | 1000 // We simply check whether the item has a keyboard shortcut set here; |
1001 enable &= [[self window] isKeyWindow]; | 1001 // app_controller_mac.mm actually determines whether the item should |
1002 // be enabled. | |
1003 enable &= !![[item keyEquivalent] length]; | |
1002 break; | 1004 break; |
1003 case IDC_FULLSCREEN: { | 1005 case IDC_FULLSCREEN: { |
1004 enable &= [self supportsFullscreen]; | 1006 enable &= [self supportsFullscreen]; |
1005 if ([static_cast<NSObject*>(item) isKindOfClass:[NSMenuItem class]]) { | 1007 if ([static_cast<NSObject*>(item) isKindOfClass:[NSMenuItem class]]) { |
1006 NSString* menuTitle = l10n_util::GetNSString( | 1008 NSString* menuTitle = l10n_util::GetNSString( |
1007 [self isFullscreen] ? IDS_EXIT_FULLSCREEN_MAC : | 1009 [self isFullscreen] ? IDS_EXIT_FULLSCREEN_MAC : |
1008 IDS_ENTER_FULLSCREEN_MAC); | 1010 IDS_ENTER_FULLSCREEN_MAC); |
1009 [static_cast<NSMenuItem*>(item) setTitle:menuTitle]; | 1011 [static_cast<NSMenuItem*>(item) setTitle:menuTitle]; |
1010 | 1012 |
1011 if (base::mac::IsOSSnowLeopardOrEarlier()) | 1013 if (base::mac::IsOSSnowLeopardOrEarlier()) |
(...skipping 1159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2171 | 2173 |
2172 - (BOOL)supportsBookmarkBar { | 2174 - (BOOL)supportsBookmarkBar { |
2173 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; | 2175 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; |
2174 } | 2176 } |
2175 | 2177 |
2176 - (BOOL)isTabbedWindow { | 2178 - (BOOL)isTabbedWindow { |
2177 return browser_->is_type_tabbed(); | 2179 return browser_->is_type_tabbed(); |
2178 } | 2180 } |
2179 | 2181 |
2180 @end // @implementation BrowserWindowController(WindowType) | 2182 @end // @implementation BrowserWindowController(WindowType) |
OLD | NEW |