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 978 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
989 const std::string encoding = current_tab->GetEncoding(); | 989 const std::string encoding = current_tab->GetEncoding(); |
990 | 990 |
991 bool toggled = encoding_controller.IsItemChecked(profile, encoding, tag); | 991 bool toggled = encoding_controller.IsItemChecked(profile, encoding, tag); |
992 NSInteger oldState = [item state]; | 992 NSInteger oldState = [item state]; |
993 NSInteger newState = toggled ? NSOnState : NSOffState; | 993 NSInteger newState = toggled ? NSOnState : NSOffState; |
994 if (oldState != newState) | 994 if (oldState != newState) |
995 [item setState:newState]; | 995 [item setState:newState]; |
996 } | 996 } |
997 } | 997 } |
998 | 998 |
999 - (BOOL)supportsFullscreen { | |
1000 // TODO(avi, thakis): GTMWindowSheetController has no api to move | |
1001 // tabsheets between windows. Until then, we have to prevent having to | |
1002 // move a tabsheet between windows, e.g. no fullscreen toggling | |
1003 NSArray* a = [[tabStripController_ sheetController] viewsWithAttachedSheets]; | |
1004 return [a count] == 0; | |
1005 } | |
1006 | |
1007 // Called to validate menu and toolbar items when this window is key. All the | 999 // Called to validate menu and toolbar items when this window is key. All the |
1008 // items we care about have been set with the |-commandDispatch:| or | 1000 // items we care about have been set with the |-commandDispatch:| or |
1009 // |-commandDispatchUsingKeyModifiers:| actions and a target of FirstResponder | 1001 // |-commandDispatchUsingKeyModifiers:| actions and a target of FirstResponder |
1010 // in IB. If it's not one of those, let it continue up the responder chain to be | 1002 // in IB. If it's not one of those, let it continue up the responder chain to be |
1011 // handled elsewhere. We pull out the tag as the cross-platform constant to | 1003 // handled elsewhere. We pull out the tag as the cross-platform constant to |
1012 // differentiate and dispatch the various commands. | 1004 // differentiate and dispatch the various commands. |
1013 // NOTE: we might have to handle state for app-wide menu items, | 1005 // NOTE: we might have to handle state for app-wide menu items, |
1014 // although we could cheat and directly ask the app controller if our | 1006 // although we could cheat and directly ask the app controller if our |
1015 // command_updater doesn't support the command. This may or may not be an issue, | 1007 // command_updater doesn't support the command. This may or may not be an issue, |
1016 // too early to tell. | 1008 // too early to tell. |
1017 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item { | 1009 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item { |
1018 SEL action = [item action]; | 1010 SEL action = [item action]; |
1019 BOOL enable = NO; | 1011 BOOL enable = NO; |
1020 if (action == @selector(commandDispatch:) || | 1012 if (action == @selector(commandDispatch:) || |
1021 action == @selector(commandDispatchUsingKeyModifiers:)) { | 1013 action == @selector(commandDispatchUsingKeyModifiers:)) { |
1022 NSInteger tag = [item tag]; | 1014 NSInteger tag = [item tag]; |
1023 if (chrome::SupportsCommand(browser_.get(), tag)) { | 1015 if (chrome::SupportsCommand(browser_.get(), tag)) { |
1024 // Generate return value (enabled state) | 1016 // Generate return value (enabled state) |
1025 enable = chrome::IsCommandEnabled(browser_.get(), tag); | 1017 enable = chrome::IsCommandEnabled(browser_.get(), tag); |
1026 switch (tag) { | 1018 switch (tag) { |
1027 case IDC_CLOSE_TAB: | 1019 case IDC_CLOSE_TAB: |
1028 // Disable "close tab" if the receiving window is not tabbed. | 1020 // Disable "close tab" if the receiving window is not tabbed. |
1029 // We simply check whether the item has a keyboard shortcut set here; | 1021 // We simply check whether the item has a keyboard shortcut set here; |
1030 // app_controller_mac.mm actually determines whether the item should | 1022 // app_controller_mac.mm actually determines whether the item should |
1031 // be enabled. | 1023 // be enabled. |
1032 if ([static_cast<NSObject*>(item) isKindOfClass:[NSMenuItem class]]) | 1024 if ([static_cast<NSObject*>(item) isKindOfClass:[NSMenuItem class]]) |
1033 enable &= !![[static_cast<NSMenuItem*>(item) keyEquivalent] length]; | 1025 enable &= !![[static_cast<NSMenuItem*>(item) keyEquivalent] length]; |
1034 break; | 1026 break; |
1035 case IDC_FULLSCREEN: { | 1027 case IDC_FULLSCREEN: { |
1036 enable &= [self supportsFullscreen]; | |
1037 if ([static_cast<NSObject*>(item) isKindOfClass:[NSMenuItem class]]) { | 1028 if ([static_cast<NSObject*>(item) isKindOfClass:[NSMenuItem class]]) { |
1038 NSString* menuTitle = l10n_util::GetNSString( | 1029 NSString* menuTitle = l10n_util::GetNSString( |
1039 [self isFullscreen] && ![self inPresentationMode] ? | 1030 [self isFullscreen] && ![self inPresentationMode] ? |
1040 IDS_EXIT_FULLSCREEN_MAC : | 1031 IDS_EXIT_FULLSCREEN_MAC : |
1041 IDS_ENTER_FULLSCREEN_MAC); | 1032 IDS_ENTER_FULLSCREEN_MAC); |
1042 [static_cast<NSMenuItem*>(item) setTitle:menuTitle]; | 1033 [static_cast<NSMenuItem*>(item) setTitle:menuTitle]; |
1043 | 1034 |
1044 if (base::mac::IsOSSnowLeopard()) | 1035 if (base::mac::IsOSSnowLeopard()) |
1045 [static_cast<NSMenuItem*>(item) setHidden:YES]; | 1036 [static_cast<NSMenuItem*>(item) setHidden:YES]; |
1046 } | 1037 } |
1047 break; | 1038 break; |
1048 } | 1039 } |
1049 case IDC_PRESENTATION_MODE: { | 1040 case IDC_PRESENTATION_MODE: { |
1050 enable &= [self supportsFullscreen]; | |
1051 if ([static_cast<NSObject*>(item) isKindOfClass:[NSMenuItem class]]) { | 1041 if ([static_cast<NSObject*>(item) isKindOfClass:[NSMenuItem class]]) { |
1052 NSString* menuTitle = l10n_util::GetNSString( | 1042 NSString* menuTitle = l10n_util::GetNSString( |
1053 [self inPresentationMode] ? IDS_EXIT_PRESENTATION_MAC : | 1043 [self inPresentationMode] ? IDS_EXIT_PRESENTATION_MAC : |
1054 IDS_ENTER_PRESENTATION_MAC); | 1044 IDS_ENTER_PRESENTATION_MAC); |
1055 [static_cast<NSMenuItem*>(item) setTitle:menuTitle]; | 1045 [static_cast<NSMenuItem*>(item) setTitle:menuTitle]; |
1056 } | 1046 } |
1057 break; | 1047 break; |
1058 } | 1048 } |
1059 case IDC_SHOW_SYNC_SETUP: { | 1049 case IDC_SHOW_SYNC_SETUP: { |
1060 Profile* original_profile = | 1050 Profile* original_profile = |
(...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1943 // On Lion, this method is called by either the Lion fullscreen button or the | 1933 // On Lion, this method is called by either the Lion fullscreen button or the |
1944 // "Enter Full Screen" menu item. On Snow Leopard, this function is never | 1934 // "Enter Full Screen" menu item. On Snow Leopard, this function is never |
1945 // called by the UI directly, but it provides the implementation for | 1935 // called by the UI directly, but it provides the implementation for |
1946 // |-setPresentationMode:|. | 1936 // |-setPresentationMode:|. |
1947 - (void)setFullscreen:(BOOL)fullscreen | 1937 - (void)setFullscreen:(BOOL)fullscreen |
1948 url:(const GURL&)url | 1938 url:(const GURL&)url |
1949 bubbleType:(FullscreenExitBubbleType)bubbleType { | 1939 bubbleType:(FullscreenExitBubbleType)bubbleType { |
1950 if (fullscreen == [self isFullscreen]) | 1940 if (fullscreen == [self isFullscreen]) |
1951 return; | 1941 return; |
1952 | 1942 |
1953 if (![self supportsFullscreen]) | 1943 if (!chrome::IsCommandEnabled(browser_.get(), IDC_FULLSCREEN)) |
1954 return; | 1944 return; |
1955 | 1945 |
1956 if (base::mac::IsOSLionOrLater()) { | 1946 if (base::mac::IsOSLionOrLater()) { |
1957 enteredPresentationModeFromFullscreen_ = YES; | 1947 enteredPresentationModeFromFullscreen_ = YES; |
1958 if ([[self window] isKindOfClass:[FramedBrowserWindow class]]) | 1948 if ([[self window] isKindOfClass:[FramedBrowserWindow class]]) |
1959 [static_cast<FramedBrowserWindow*>([self window]) toggleSystemFullScreen]; | 1949 [static_cast<FramedBrowserWindow*>([self window]) toggleSystemFullScreen]; |
1960 } else { | 1950 } else { |
1961 if (fullscreen) | 1951 if (fullscreen) |
1962 [self enterFullscreenForSnowLeopard]; | 1952 [self enterFullscreenForSnowLeopard]; |
1963 else | 1953 else |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2179 | 2169 |
2180 - (BOOL)supportsBookmarkBar { | 2170 - (BOOL)supportsBookmarkBar { |
2181 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; | 2171 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; |
2182 } | 2172 } |
2183 | 2173 |
2184 - (BOOL)isTabbedWindow { | 2174 - (BOOL)isTabbedWindow { |
2185 return browser_->is_type_tabbed(); | 2175 return browser_->is_type_tabbed(); |
2186 } | 2176 } |
2187 | 2177 |
2188 @end // @implementation BrowserWindowController(WindowType) | 2178 @end // @implementation BrowserWindowController(WindowType) |
OLD | NEW |