| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_command_handler.h" | 5 #import "chrome/browser/ui/cocoa/browser_window_command_handler.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #import "base/mac/foundation_util.h" | 8 #import "base/mac/foundation_util.h" |
| 9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
| 10 #import "chrome/browser/app_controller_mac.h" | 10 #import "chrome/browser/app_controller_mac.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 if (BrowserWindowController* controller = [ns_window windowController]) { | 92 if (BrowserWindowController* controller = [ns_window windowController]) { |
| 93 DCHECK(chrome::mac::SupportsSystemFullscreen()); | 93 DCHECK(chrome::mac::SupportsSystemFullscreen()); |
| 94 return l10n_util::GetNSString([controller isInAppKitFullscreen] | 94 return l10n_util::GetNSString([controller isInAppKitFullscreen] |
| 95 ? IDS_EXIT_FULLSCREEN_MAC | 95 ? IDS_EXIT_FULLSCREEN_MAC |
| 96 : IDS_ENTER_FULLSCREEN_MAC); | 96 : IDS_ENTER_FULLSCREEN_MAC); |
| 97 } | 97 } |
| 98 | 98 |
| 99 return GetTitleForViewsFullscreenMenuItem(browser); | 99 return GetTitleForViewsFullscreenMenuItem(browser); |
| 100 } | 100 } |
| 101 | 101 |
| 102 // Get the text for the "Enter/Exit Presentation Mode" menu item. | |
| 103 // TODO(jackhou): Remove the dependency on BrowserWindowController(Private). | |
| 104 NSString* GetTitleForPresentationModeMenuItem(Browser* browser) { | |
| 105 NSWindow* ns_window = browser->window()->GetNativeWindow(); | |
| 106 if (BrowserWindowController* controller = [ns_window windowController]) { | |
| 107 return l10n_util::GetNSString([controller inPresentationMode] | |
| 108 ? IDS_EXIT_PRESENTATION_MAC | |
| 109 : IDS_ENTER_PRESENTATION_MAC); | |
| 110 } | |
| 111 return GetTitleForFullscreenMenuItem(browser); | |
| 112 } | |
| 113 | |
| 114 // Identify the actual Browser to which the command should be dispatched. It | 102 // Identify the actual Browser to which the command should be dispatched. It |
| 115 // might belong to a background window, yet another dispatcher gets it because | 103 // might belong to a background window, yet another dispatcher gets it because |
| 116 // it is the foreground window's dispatcher and thus in the responder chain. | 104 // it is the foreground window's dispatcher and thus in the responder chain. |
| 117 // Some senders don't have this problem (for example, menus only operate on the | 105 // Some senders don't have this problem (for example, menus only operate on the |
| 118 // foreground window), so this is only an issue for senders that are part of | 106 // foreground window), so this is only an issue for senders that are part of |
| 119 // windows. | 107 // windows. |
| 120 Browser* FindBrowserForSender(id sender, NSWindow* window) { | 108 Browser* FindBrowserForSender(id sender, NSWindow* window) { |
| 121 NSWindow* targetWindow = window; | 109 NSWindow* targetWindow = window; |
| 122 if ([sender respondsToSelector:@selector(window)]) | 110 if ([sender respondsToSelector:@selector(window)]) |
| 123 targetWindow = [sender window]; | 111 targetWindow = [sender window]; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 switch (tag) { | 144 switch (tag) { |
| 157 case IDC_CLOSE_TAB: | 145 case IDC_CLOSE_TAB: |
| 158 // Disable "close tab" if the receiving window is not tabbed. | 146 // Disable "close tab" if the receiving window is not tabbed. |
| 159 // We simply check whether the item has a keyboard shortcut set here; | 147 // We simply check whether the item has a keyboard shortcut set here; |
| 160 // app_controller_mac.mm actually determines whether the item should | 148 // app_controller_mac.mm actually determines whether the item should |
| 161 // be enabled. | 149 // be enabled. |
| 162 if (NSMenuItem* menuItem = base::mac::ObjCCast<NSMenuItem>(item)) | 150 if (NSMenuItem* menuItem = base::mac::ObjCCast<NSMenuItem>(item)) |
| 163 enable &= !![[menuItem keyEquivalent] length]; | 151 enable &= !![[menuItem keyEquivalent] length]; |
| 164 break; | 152 break; |
| 165 case IDC_FULLSCREEN: { | 153 case IDC_FULLSCREEN: { |
| 166 if (NSMenuItem* menuItem = base::mac::ObjCCast<NSMenuItem>(item)) { | 154 if (NSMenuItem* menuItem = base::mac::ObjCCast<NSMenuItem>(item)) |
| 167 if (chrome::mac::SupportsSystemFullscreen()) | 155 [menuItem setTitle:GetTitleForFullscreenMenuItem(browser)]; |
| 168 [menuItem setTitle:GetTitleForFullscreenMenuItem(browser)]; | |
| 169 else | |
| 170 [menuItem setHidden:YES]; | |
| 171 } | |
| 172 break; | |
| 173 } | |
| 174 case IDC_PRESENTATION_MODE: { | |
| 175 if (NSMenuItem* menuItem = base::mac::ObjCCast<NSMenuItem>(item)) { | |
| 176 if (chrome::mac::SupportsSystemFullscreen()) { | |
| 177 [menuItem setHidden:YES]; | |
| 178 enable = NO; | |
| 179 } else { | |
| 180 [menuItem setTitle:GetTitleForPresentationModeMenuItem(browser)]; | |
| 181 } | |
| 182 } | |
| 183 break; | 156 break; |
| 184 } | 157 } |
| 185 case IDC_SHOW_SIGNIN: { | 158 case IDC_SHOW_SIGNIN: { |
| 186 Profile* original_profile = browser->profile()->GetOriginalProfile(); | 159 Profile* original_profile = browser->profile()->GetOriginalProfile(); |
| 187 [AppController updateSigninItem:item | 160 [AppController updateSigninItem:item |
| 188 shouldShow:enable | 161 shouldShow:enable |
| 189 currentProfile:original_profile]; | 162 currentProfile:original_profile]; |
| 190 content::RecordAction( | 163 content::RecordAction( |
| 191 base::UserMetricsAction("Signin_Impression_FromMenu")); | 164 base::UserMetricsAction("Signin_Impression_FromMenu")); |
| 192 break; | 165 break; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 206 // Extensions have the ability to hide the bookmark all tabs menu | 179 // Extensions have the ability to hide the bookmark all tabs menu |
| 207 // item. This only affects the bookmark page menu item under the main | 180 // item. This only affects the bookmark page menu item under the main |
| 208 // menu. The bookmark page menu item under the app menu has its | 181 // menu. The bookmark page menu item under the app menu has its |
| 209 // visibility controlled by AppMenuModel. | 182 // visibility controlled by AppMenuModel. |
| 210 bool shouldHide = | 183 bool shouldHide = |
| 211 chrome::ShouldRemoveBookmarkOpenPagesUI(browser->profile()); | 184 chrome::ShouldRemoveBookmarkOpenPagesUI(browser->profile()); |
| 212 NSMenuItem* menuItem = base::mac::ObjCCast<NSMenuItem>(item); | 185 NSMenuItem* menuItem = base::mac::ObjCCast<NSMenuItem>(item); |
| 213 [menuItem setHidden:shouldHide]; | 186 [menuItem setHidden:shouldHide]; |
| 214 break; | 187 break; |
| 215 } | 188 } |
| 216 case IDC_TOGGLE_FULLSCREEN_TOOLBAR: { | |
| 217 if (!chrome::mac::SupportsSystemFullscreen()) { | |
| 218 NSMenuItem* menuItem = base::mac::ObjCCast<NSMenuItem>(item); | |
| 219 [menuItem setHidden:YES]; | |
| 220 enable = NO; | |
| 221 } | |
| 222 break; | |
| 223 } | |
| 224 case IDC_SHOW_AS_TAB: { | 189 case IDC_SHOW_AS_TAB: { |
| 225 // Hide this menu option if the window is tabbed or is the devtools | 190 // Hide this menu option if the window is tabbed or is the devtools |
| 226 // window. | 191 // window. |
| 227 NSMenuItem* menuItem = base::mac::ObjCCast<NSMenuItem>(item); | 192 NSMenuItem* menuItem = base::mac::ObjCCast<NSMenuItem>(item); |
| 228 [menuItem setHidden:browser->is_type_tabbed() || browser->is_devtools()]; | 193 [menuItem setHidden:browser->is_type_tabbed() || browser->is_devtools()]; |
| 229 break; | 194 break; |
| 230 } | 195 } |
| 231 default: | 196 default: |
| 232 // Special handling for the contents of the Text Encoding submenu. On | 197 // Special handling for the contents of the Text Encoding submenu. On |
| 233 // Mac OS, instead of enabling/disabling the top-level menu item, we | 198 // Mac OS, instead of enabling/disabling the top-level menu item, we |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 // the background" in this case. | 239 // the background" in this case. |
| 275 modifierFlags &= ~NSCommandKeyMask; | 240 modifierFlags &= ~NSCommandKeyMask; |
| 276 } | 241 } |
| 277 chrome::ExecuteCommandWithDisposition( | 242 chrome::ExecuteCommandWithDisposition( |
| 278 FindBrowserForSender(sender, window), command, | 243 FindBrowserForSender(sender, window), command, |
| 279 ui::WindowOpenDispositionFromNSEventWithFlags([NSApp currentEvent], | 244 ui::WindowOpenDispositionFromNSEventWithFlags([NSApp currentEvent], |
| 280 modifierFlags)); | 245 modifierFlags)); |
| 281 } | 246 } |
| 282 | 247 |
| 283 @end | 248 @end |
| OLD | NEW |