| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 991 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 const std::string encoding = current_tab->GetEncoding(); | 1002 const std::string encoding = current_tab->GetEncoding(); |
| 1003 | 1003 |
| 1004 bool toggled = encoding_controller.IsItemChecked(profile, encoding, tag); | 1004 bool toggled = encoding_controller.IsItemChecked(profile, encoding, tag); |
| 1005 NSInteger oldState = [item state]; | 1005 NSInteger oldState = [item state]; |
| 1006 NSInteger newState = toggled ? NSOnState : NSOffState; | 1006 NSInteger newState = toggled ? NSOnState : NSOffState; |
| 1007 if (oldState != newState) | 1007 if (oldState != newState) |
| 1008 [item setState:newState]; | 1008 [item setState:newState]; |
| 1009 } | 1009 } |
| 1010 } | 1010 } |
| 1011 | 1011 |
| 1012 - (BOOL)supportsFullscreen { | |
| 1013 // TODO(avi, thakis): GTMWindowSheetController has no api to move | |
| 1014 // tabsheets between windows. Until then, we have to prevent having to | |
| 1015 // move a tabsheet between windows, e.g. no fullscreen toggling | |
| 1016 NSArray* a = [[tabStripController_ sheetController] viewsWithAttachedSheets]; | |
| 1017 return [a count] == 0; | |
| 1018 } | |
| 1019 | |
| 1020 // Called to validate menu and toolbar items when this window is key. All the | 1012 // Called to validate menu and toolbar items when this window is key. All the |
| 1021 // items we care about have been set with the |-commandDispatch:| or | 1013 // items we care about have been set with the |-commandDispatch:| or |
| 1022 // |-commandDispatchUsingKeyModifiers:| actions and a target of FirstResponder | 1014 // |-commandDispatchUsingKeyModifiers:| actions and a target of FirstResponder |
| 1023 // in IB. If it's not one of those, let it continue up the responder chain to be | 1015 // in IB. If it's not one of those, let it continue up the responder chain to be |
| 1024 // handled elsewhere. We pull out the tag as the cross-platform constant to | 1016 // handled elsewhere. We pull out the tag as the cross-platform constant to |
| 1025 // differentiate and dispatch the various commands. | 1017 // differentiate and dispatch the various commands. |
| 1026 // NOTE: we might have to handle state for app-wide menu items, | 1018 // NOTE: we might have to handle state for app-wide menu items, |
| 1027 // although we could cheat and directly ask the app controller if our | 1019 // although we could cheat and directly ask the app controller if our |
| 1028 // command_updater doesn't support the command. This may or may not be an issue, | 1020 // command_updater doesn't support the command. This may or may not be an issue, |
| 1029 // too early to tell. | 1021 // too early to tell. |
| 1030 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item { | 1022 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item { |
| 1031 SEL action = [item action]; | 1023 SEL action = [item action]; |
| 1032 BOOL enable = NO; | 1024 BOOL enable = NO; |
| 1033 if (action == @selector(commandDispatch:) || | 1025 if (action == @selector(commandDispatch:) || |
| 1034 action == @selector(commandDispatchUsingKeyModifiers:)) { | 1026 action == @selector(commandDispatchUsingKeyModifiers:)) { |
| 1035 NSInteger tag = [item tag]; | 1027 NSInteger tag = [item tag]; |
| 1036 if (chrome::SupportsCommand(browser_.get(), tag)) { | 1028 if (chrome::SupportsCommand(browser_.get(), tag)) { |
| 1037 // Generate return value (enabled state) | 1029 // Generate return value (enabled state) |
| 1038 enable = chrome::IsCommandEnabled(browser_.get(), tag); | 1030 enable = chrome::IsCommandEnabled(browser_.get(), tag); |
| 1039 switch (tag) { | 1031 switch (tag) { |
| 1040 case IDC_CLOSE_TAB: | 1032 case IDC_CLOSE_TAB: |
| 1041 // Disable "close tab" if the receiving window is not tabbed. | 1033 // Disable "close tab" if the receiving window is not tabbed. |
| 1042 // We simply check whether the item has a keyboard shortcut set here; | 1034 // We simply check whether the item has a keyboard shortcut set here; |
| 1043 // app_controller_mac.mm actually determines whether the item should | 1035 // app_controller_mac.mm actually determines whether the item should |
| 1044 // be enabled. | 1036 // be enabled. |
| 1045 if ([static_cast<NSObject*>(item) isKindOfClass:[NSMenuItem class]]) | 1037 if ([static_cast<NSObject*>(item) isKindOfClass:[NSMenuItem class]]) |
| 1046 enable &= !![[static_cast<NSMenuItem*>(item) keyEquivalent] length]; | 1038 enable &= !![[static_cast<NSMenuItem*>(item) keyEquivalent] length]; |
| 1047 break; | 1039 break; |
| 1048 case IDC_FULLSCREEN: { | 1040 case IDC_FULLSCREEN: { |
| 1049 enable &= [self supportsFullscreen]; | |
| 1050 if ([static_cast<NSObject*>(item) isKindOfClass:[NSMenuItem class]]) { | 1041 if ([static_cast<NSObject*>(item) isKindOfClass:[NSMenuItem class]]) { |
| 1051 NSString* menuTitle = l10n_util::GetNSString( | 1042 NSString* menuTitle = l10n_util::GetNSString( |
| 1052 [self isFullscreen] && ![self inPresentationMode] ? | 1043 [self isFullscreen] && ![self inPresentationMode] ? |
| 1053 IDS_EXIT_FULLSCREEN_MAC : | 1044 IDS_EXIT_FULLSCREEN_MAC : |
| 1054 IDS_ENTER_FULLSCREEN_MAC); | 1045 IDS_ENTER_FULLSCREEN_MAC); |
| 1055 [static_cast<NSMenuItem*>(item) setTitle:menuTitle]; | 1046 [static_cast<NSMenuItem*>(item) setTitle:menuTitle]; |
| 1056 | 1047 |
| 1057 if (base::mac::IsOSSnowLeopard()) | 1048 if (base::mac::IsOSSnowLeopard()) |
| 1058 [static_cast<NSMenuItem*>(item) setHidden:YES]; | 1049 [static_cast<NSMenuItem*>(item) setHidden:YES]; |
| 1059 } | 1050 } |
| 1060 break; | 1051 break; |
| 1061 } | 1052 } |
| 1062 case IDC_PRESENTATION_MODE: { | 1053 case IDC_PRESENTATION_MODE: { |
| 1063 enable &= [self supportsFullscreen]; | |
| 1064 if ([static_cast<NSObject*>(item) isKindOfClass:[NSMenuItem class]]) { | 1054 if ([static_cast<NSObject*>(item) isKindOfClass:[NSMenuItem class]]) { |
| 1065 NSString* menuTitle = l10n_util::GetNSString( | 1055 NSString* menuTitle = l10n_util::GetNSString( |
| 1066 [self inPresentationMode] ? IDS_EXIT_PRESENTATION_MAC : | 1056 [self inPresentationMode] ? IDS_EXIT_PRESENTATION_MAC : |
| 1067 IDS_ENTER_PRESENTATION_MAC); | 1057 IDS_ENTER_PRESENTATION_MAC); |
| 1068 [static_cast<NSMenuItem*>(item) setTitle:menuTitle]; | 1058 [static_cast<NSMenuItem*>(item) setTitle:menuTitle]; |
| 1069 } | 1059 } |
| 1070 break; | 1060 break; |
| 1071 } | 1061 } |
| 1072 case IDC_SHOW_SYNC_SETUP: { | 1062 case IDC_SHOW_SYNC_SETUP: { |
| 1073 Profile* original_profile = | 1063 Profile* original_profile = |
| (...skipping 904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1978 // On Lion, this method is called by either the Lion fullscreen button or the | 1968 // On Lion, this method is called by either the Lion fullscreen button or the |
| 1979 // "Enter Full Screen" menu item. On Snow Leopard, this function is never | 1969 // "Enter Full Screen" menu item. On Snow Leopard, this function is never |
| 1980 // called by the UI directly, but it provides the implementation for | 1970 // called by the UI directly, but it provides the implementation for |
| 1981 // |-setPresentationMode:|. | 1971 // |-setPresentationMode:|. |
| 1982 - (void)setFullscreen:(BOOL)fullscreen | 1972 - (void)setFullscreen:(BOOL)fullscreen |
| 1983 url:(const GURL&)url | 1973 url:(const GURL&)url |
| 1984 bubbleType:(FullscreenExitBubbleType)bubbleType { | 1974 bubbleType:(FullscreenExitBubbleType)bubbleType { |
| 1985 if (fullscreen == [self isFullscreen]) | 1975 if (fullscreen == [self isFullscreen]) |
| 1986 return; | 1976 return; |
| 1987 | 1977 |
| 1988 if (![self supportsFullscreen]) | 1978 if (!chrome::IsCommandEnabled(browser_.get(), IDC_FULLSCREEN)) |
| 1989 return; | 1979 return; |
| 1990 | 1980 |
| 1991 if (base::mac::IsOSLionOrLater()) { | 1981 if (base::mac::IsOSLionOrLater()) { |
| 1992 enteredPresentationModeFromFullscreen_ = YES; | 1982 enteredPresentationModeFromFullscreen_ = YES; |
| 1993 if ([[self window] isKindOfClass:[FramedBrowserWindow class]]) | 1983 if ([[self window] isKindOfClass:[FramedBrowserWindow class]]) |
| 1994 [static_cast<FramedBrowserWindow*>([self window]) toggleSystemFullScreen]; | 1984 [static_cast<FramedBrowserWindow*>([self window]) toggleSystemFullScreen]; |
| 1995 } else { | 1985 } else { |
| 1996 if (fullscreen) | 1986 if (fullscreen) |
| 1997 [self enterFullscreenForSnowLeopard]; | 1987 [self enterFullscreenForSnowLeopard]; |
| 1998 else | 1988 else |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2214 | 2204 |
| 2215 - (BOOL)supportsBookmarkBar { | 2205 - (BOOL)supportsBookmarkBar { |
| 2216 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; | 2206 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; |
| 2217 } | 2207 } |
| 2218 | 2208 |
| 2219 - (BOOL)isTabbedWindow { | 2209 - (BOOL)isTabbedWindow { |
| 2220 return browser_->is_type_tabbed(); | 2210 return browser_->is_type_tabbed(); |
| 2221 } | 2211 } |
| 2222 | 2212 |
| 2223 @end // @implementation BrowserWindowController(WindowType) | 2213 @end // @implementation BrowserWindowController(WindowType) |
| OLD | NEW |