Chromium Code Reviews| 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" |
| 11 #include "chrome/browser/fullscreen.h" | 11 #include "chrome/browser/fullscreen.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/bookmarks/bookmark_utils.h" | 13 #include "chrome/browser/ui/bookmarks/bookmark_utils.h" |
| 14 #include "chrome/browser/ui/browser_commands.h" | 14 #include "chrome/browser/ui/browser_commands.h" |
| 15 #include "chrome/browser/ui/browser_finder.h" | 15 #include "chrome/browser/ui/browser_finder.h" |
| 16 #include "chrome/browser/ui/browser_window.h" | 16 #include "chrome/browser/ui/browser_window.h" |
| 17 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h" | 17 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h" |
| 18 #include "chrome/browser/ui/toolbar/encoding_menu_controller.h" | 18 #include "chrome/browser/ui/toolbar/encoding_menu_controller.h" |
| 19 #include "chrome/grit/generated_resources.h" | 19 #include "chrome/grit/generated_resources.h" |
| 20 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 21 #import "ui/base/cocoa/cocoa_base_utils.h" | 21 #import "ui/base/cocoa/cocoa_base_utils.h" |
| 22 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
| 23 #include "ui/base/l10n/l10n_util_mac.h" | 23 #include "ui/base/l10n/l10n_util_mac.h" |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 void SetToggleState(bool toggled, id item) { | |
| 28 DCHECK([item respondsToSelector:@selector(state)] && | |
| 29 [item respondsToSelector:@selector(setState:)]); | |
| 30 | |
| 31 NSInteger oldState = [item state]; | |
| 32 NSInteger newState = toggled ? NSOnState : NSOffState; | |
| 33 if (oldState != newState) | |
| 34 [item setState:newState]; | |
| 35 } | |
| 36 | |
| 27 // Update a toggle state for an item if modified. The item may be an NSMenuItem | 37 // Update a toggle state for an item if modified. The item may be an NSMenuItem |
| 28 // or NSButton. Called by -validateUserInterfaceItem:. | 38 // or NSButton. Called by -validateUserInterfaceItem:. |
| 29 void UpdateToggleStateWithTag(NSInteger tag, id item, NSWindow* window) { | 39 void UpdateToggleStateWithTag(NSInteger tag, id item, NSWindow* window) { |
| 30 if (![item respondsToSelector:@selector(state)] || | 40 if (![item respondsToSelector:@selector(state)] || |
| 31 ![item respondsToSelector:@selector(setState:)]) | 41 ![item respondsToSelector:@selector(setState:)]) |
| 32 return; | 42 return; |
| 33 | 43 |
| 34 Browser* browser = chrome::FindBrowserWithWindow(window); | 44 Browser* browser = chrome::FindBrowserWithWindow(window); |
| 35 DCHECK(browser); | 45 DCHECK(browser); |
| 36 | 46 |
| 37 // On Windows this logic happens in bookmark_bar_view.cc. This simply updates | 47 // On Windows this logic happens in bookmark_bar_view.cc. This simply updates |
| 38 // the menu item; it does not display the bookmark bar itself. | 48 // the menu item; it does not display the bookmark bar itself. |
| 39 if (tag == IDC_SHOW_BOOKMARK_BAR) { | 49 if (tag == IDC_SHOW_BOOKMARK_BAR) { |
| 40 bool toggled = browser->window()->IsBookmarkBarVisible(); | 50 SetToggleState(browser->window()->IsBookmarkBarVisible(), item); |
| 41 NSInteger oldState = [item state]; | |
| 42 NSInteger newState = toggled ? NSOnState : NSOffState; | |
| 43 if (oldState != newState) | |
| 44 [item setState:newState]; | |
| 45 return; | 51 return; |
| 46 } | 52 } |
| 47 | 53 |
| 54 if (tag == IDC_TOGGLE_FULLSCREEN_TOOLBAR) { | |
| 55 SetToggleState(browser->window()->ShouldHideFullscreenToolbar(), item); | |
| 56 return; | |
| 57 } | |
| 58 | |
| 48 // Update the checked/unchecked state of items in the encoding menu. | 59 // Update the checked/unchecked state of items in the encoding menu. |
| 49 // On Windows, this logic is part of |EncodingMenuModel| in | 60 // On Windows, this logic is part of |EncodingMenuModel| in |
| 50 // browser/ui/views/toolbar_view.h. | 61 // browser/ui/views/toolbar_view.h. |
| 51 EncodingMenuController encoding_controller; | 62 EncodingMenuController encoding_controller; |
| 52 if (!encoding_controller.DoesCommandBelongToEncodingMenu(tag)) | 63 if (!encoding_controller.DoesCommandBelongToEncodingMenu(tag)) |
| 53 return; | 64 return; |
| 54 | 65 |
| 55 Profile* profile = browser->profile(); | 66 Profile* profile = browser->profile(); |
| 56 DCHECK(profile); | 67 DCHECK(profile); |
| 57 content::WebContents* current_tab = | 68 content::WebContents* current_tab = |
| 58 browser->tab_strip_model()->GetActiveWebContents(); | 69 browser->tab_strip_model()->GetActiveWebContents(); |
| 59 if (!current_tab) | 70 if (!current_tab) |
| 60 return; | 71 return; |
| 61 | 72 |
| 62 const std::string encoding = current_tab->GetEncoding(); | 73 const std::string encoding = current_tab->GetEncoding(); |
| 63 | 74 |
| 64 bool toggled = encoding_controller.IsItemChecked(profile, encoding, tag); | 75 SetToggleState(encoding_controller.IsItemChecked(profile, encoding, tag), |
| 65 NSInteger oldState = [item state]; | 76 item); |
| 66 NSInteger newState = toggled ? NSOnState : NSOffState; | |
| 67 if (oldState != newState) | |
| 68 [item setState:newState]; | |
| 69 } | 77 } |
| 70 | 78 |
| 71 NSString* GetTitleForViewsFullscreenMenuItem(Browser* browser) { | 79 NSString* GetTitleForViewsFullscreenMenuItem(Browser* browser) { |
| 72 return l10n_util::GetNSString(browser->window()->IsFullscreen() | 80 return l10n_util::GetNSString(browser->window()->IsFullscreen() |
| 73 ? IDS_EXIT_FULLSCREEN_MAC | 81 ? IDS_EXIT_FULLSCREEN_MAC |
| 74 : IDS_ENTER_FULLSCREEN_MAC); | 82 : IDS_ENTER_FULLSCREEN_MAC); |
| 75 } | 83 } |
| 76 | 84 |
| 77 // Get the text for the "Enter/Exit Fullscreen" menu item. | 85 // Get the text for the "Enter/Exit Fullscreen" menu item. |
| 78 // TODO(jackhou): Remove the dependency on BrowserWindowController(Private). | 86 // TODO(jackhou): Remove the dependency on BrowserWindowController(Private). |
| 79 NSString* GetTitleForFullscreenMenuItem(Browser* browser) { | 87 NSString* GetTitleForFullscreenMenuItem(Browser* browser) { |
| 80 NSWindow* ns_window = browser->window()->GetNativeWindow(); | 88 NSWindow* ns_window = browser->window()->GetNativeWindow(); |
| 81 if (BrowserWindowController* controller = [ns_window windowController]) { | 89 if (BrowserWindowController* controller = [ns_window windowController]) { |
| 82 DCHECK(chrome::mac::SupportsSystemFullscreen()); | 90 DCHECK(chrome::mac::SupportsSystemFullscreen()); |
| 83 return l10n_util::GetNSString([controller isInAppKitFullscreen] | 91 return l10n_util::GetNSString([controller isInAppKitFullscreen] |
| 84 ? IDS_EXIT_FULLSCREEN_MAC | 92 ? IDS_EXIT_FULLSCREEN_MAC |
| 85 : IDS_ENTER_FULLSCREEN_MAC); | 93 : IDS_ENTER_FULLSCREEN_MAC); |
| 86 } | 94 } |
| 87 | 95 |
| 88 return GetTitleForViewsFullscreenMenuItem(browser); | 96 return GetTitleForViewsFullscreenMenuItem(browser); |
| 89 } | 97 } |
| 90 | 98 |
| 91 // Get the text for the "Enter/Exit Presentation Mode" menu item. | |
| 92 // TODO(jackhou): Remove the dependency on BrowserWindowController(Private). | |
| 93 NSString* GetTitleForPresentationModeMenuItem(Browser* browser) { | 99 NSString* GetTitleForPresentationModeMenuItem(Browser* browser) { |
| 94 NSWindow* ns_window = browser->window()->GetNativeWindow(); | 100 NSWindow* ns_window = browser->window()->GetNativeWindow(); |
| 95 if (BrowserWindowController* controller = [ns_window windowController]) { | 101 if (BrowserWindowController* controller = [ns_window windowController]) { |
| 96 return l10n_util::GetNSString([controller inPresentationMode] | 102 return l10n_util::GetNSString([controller inPresentationMode] |
| 97 ? IDS_EXIT_PRESENTATION_MAC | 103 ? IDS_EXIT_PRESENTATION_MAC |
| 98 : IDS_ENTER_PRESENTATION_MAC); | 104 : IDS_ENTER_PRESENTATION_MAC); |
| 99 } | 105 } |
| 100 | 106 return GetTitleForFullscreenMenuItem(browser); |
| 101 return GetTitleForViewsFullscreenMenuItem(browser); | |
| 102 } | 107 } |
| 103 | 108 |
| 104 // Identify the actual Browser to which the command should be dispatched. It | 109 // Identify the actual Browser to which the command should be dispatched. It |
| 105 // might belong to a background window, yet another dispatcher gets it because | 110 // might belong to a background window, yet another dispatcher gets it because |
| 106 // it is the foreground window's dispatcher and thus in the responder chain. | 111 // it is the foreground window's dispatcher and thus in the responder chain. |
| 107 // Some senders don't have this problem (for example, menus only operate on the | 112 // Some senders don't have this problem (for example, menus only operate on the |
| 108 // foreground window), so this is only an issue for senders that are part of | 113 // foreground window), so this is only an issue for senders that are part of |
| 109 // windows. | 114 // windows. |
| 110 Browser* FindBrowserForSender(id sender, NSWindow* window) { | 115 Browser* FindBrowserForSender(id sender, NSWindow* window) { |
| 111 NSWindow* targetWindow = window; | 116 NSWindow* targetWindow = window; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 if (NSMenuItem* menuItem = base::mac::ObjCCast<NSMenuItem>(item)) { | 161 if (NSMenuItem* menuItem = base::mac::ObjCCast<NSMenuItem>(item)) { |
| 157 if (chrome::mac::SupportsSystemFullscreen()) | 162 if (chrome::mac::SupportsSystemFullscreen()) |
| 158 [menuItem setTitle:GetTitleForFullscreenMenuItem(browser)]; | 163 [menuItem setTitle:GetTitleForFullscreenMenuItem(browser)]; |
| 159 else | 164 else |
| 160 [menuItem setHidden:YES]; | 165 [menuItem setHidden:YES]; |
| 161 } | 166 } |
| 162 break; | 167 break; |
| 163 } | 168 } |
| 164 case IDC_PRESENTATION_MODE: { | 169 case IDC_PRESENTATION_MODE: { |
| 165 if (NSMenuItem* menuItem = base::mac::ObjCCast<NSMenuItem>(item)) { | 170 if (NSMenuItem* menuItem = base::mac::ObjCCast<NSMenuItem>(item)) { |
| 166 [menuItem setTitle:GetTitleForPresentationModeMenuItem(browser)]; | 171 if (chrome::mac::SupportsSystemFullscreen()) { |
| 172 [menuItem setHidden:YES]; | |
| 173 enable = NO; | |
| 174 } else { | |
| 175 [menuItem setTitle:GetTitleForPresentationModeMenuItem(browser)]; | |
| 176 } | |
| 167 } | 177 } |
| 168 break; | 178 break; |
| 169 } | 179 } |
| 170 case IDC_SHOW_SIGNIN: { | 180 case IDC_SHOW_SIGNIN: { |
| 171 Profile* original_profile = browser->profile()->GetOriginalProfile(); | 181 Profile* original_profile = browser->profile()->GetOriginalProfile(); |
| 172 [AppController updateSigninItem:item | 182 [AppController updateSigninItem:item |
| 173 shouldShow:enable | 183 shouldShow:enable |
| 174 currentProfile:original_profile]; | 184 currentProfile:original_profile]; |
| 175 break; | 185 break; |
| 176 } | 186 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 189 // Extensions have the ability to hide the bookmark all tabs menu | 199 // Extensions have the ability to hide the bookmark all tabs menu |
| 190 // item. This only affects the bookmark page menu item under the main | 200 // item. This only affects the bookmark page menu item under the main |
| 191 // menu. The bookmark page menu item under the wrench menu has its | 201 // menu. The bookmark page menu item under the wrench menu has its |
| 192 // visibility controlled by WrenchMenuModel. | 202 // visibility controlled by WrenchMenuModel. |
| 193 bool shouldHide = | 203 bool shouldHide = |
| 194 chrome::ShouldRemoveBookmarkOpenPagesUI(browser->profile()); | 204 chrome::ShouldRemoveBookmarkOpenPagesUI(browser->profile()); |
| 195 NSMenuItem* menuItem = base::mac::ObjCCast<NSMenuItem>(item); | 205 NSMenuItem* menuItem = base::mac::ObjCCast<NSMenuItem>(item); |
| 196 [menuItem setHidden:shouldHide]; | 206 [menuItem setHidden:shouldHide]; |
| 197 break; | 207 break; |
| 198 } | 208 } |
| 209 case IDC_TOGGLE_FULLSCREEN_TOOLBAR: { | |
|
Robert Sesek
2015/11/04 21:57:16
Maybe make this item unconditionally disabled or h
spqchan
2015/11/04 23:59:21
Done.
| |
| 210 NSMenuItem* menuItem = base::mac::ObjCCast<NSMenuItem>(item); | |
| 211 if (chrome::mac::SupportsSystemFullscreen()) { | |
| 212 BOOL isFullscreenToolbarHidden = NO; | |
|
Robert Sesek
2015/11/04 21:57:16
Should there be a TODO for this?
spqchan
2015/11/04 23:59:21
Done.
| |
| 213 [menuItem setState:isFullscreenToolbarHidden]; | |
| 214 } else { | |
| 215 [menuItem setHidden:YES]; | |
| 216 } | |
| 217 break; | |
| 218 } | |
| 199 default: | 219 default: |
| 200 // Special handling for the contents of the Text Encoding submenu. On | 220 // Special handling for the contents of the Text Encoding submenu. On |
| 201 // Mac OS, instead of enabling/disabling the top-level menu item, we | 221 // Mac OS, instead of enabling/disabling the top-level menu item, we |
| 202 // enable/disable the submenu's contents (per Apple's HIG). | 222 // enable/disable the submenu's contents (per Apple's HIG). |
| 203 EncodingMenuController encoding_controller; | 223 EncodingMenuController encoding_controller; |
| 204 if (encoding_controller.DoesCommandBelongToEncodingMenu(tag)) | 224 if (encoding_controller.DoesCommandBelongToEncodingMenu(tag)) |
| 205 enable &= chrome::IsCommandEnabled(browser, IDC_ENCODING_MENU); | 225 enable &= chrome::IsCommandEnabled(browser, IDC_ENCODING_MENU); |
| 206 } | 226 } |
| 207 | 227 |
| 208 // If the item is toggleable, find its toggle state and | 228 // If the item is toggleable, find its toggle state and |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 // the background" in this case. | 262 // the background" in this case. |
| 243 modifierFlags &= ~NSCommandKeyMask; | 263 modifierFlags &= ~NSCommandKeyMask; |
| 244 } | 264 } |
| 245 chrome::ExecuteCommandWithDisposition( | 265 chrome::ExecuteCommandWithDisposition( |
| 246 FindBrowserForSender(sender, window), command, | 266 FindBrowserForSender(sender, window), command, |
| 247 ui::WindowOpenDispositionFromNSEventWithFlags([NSApp currentEvent], | 267 ui::WindowOpenDispositionFromNSEventWithFlags([NSApp currentEvent], |
| 248 modifierFlags)); | 268 modifierFlags)); |
| 249 } | 269 } |
| 250 | 270 |
| 251 @end | 271 @end |
| OLD | NEW |