Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(644)

Side by Side Diff: chrome/browser/ui/cocoa/browser_window_command_handler.mm

Issue 1414033009: Implement a Menu Item to Hide the Toolbar in Fullscreen (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and merge code Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 old_state = [item state];
32 NSInteger new_state = toggled ? NSOnState : NSOffState;
33 if (old_state != new_state)
34 [item setState:new_state];
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. 99 // Get the text for the "Enter/Exit Presentation Mode" menu item.
92 // TODO(jackhou): Remove the dependency on BrowserWindowController(Private). 100 // TODO(jackhou): Remove the dependency on BrowserWindowController(Private).
93 NSString* GetTitleForPresentationModeMenuItem(Browser* browser) { 101 NSString* GetTitleForPresentationModeMenuItem(Browser* browser) {
94 NSWindow* ns_window = browser->window()->GetNativeWindow(); 102 NSWindow* ns_window = browser->window()->GetNativeWindow();
95 if (BrowserWindowController* controller = [ns_window windowController]) { 103 if (BrowserWindowController* controller = [ns_window windowController]) {
96 return l10n_util::GetNSString([controller inPresentationMode] 104 return l10n_util::GetNSString([controller inPresentationMode]
97 ? IDS_EXIT_PRESENTATION_MAC 105 ? IDS_EXIT_PRESENTATION_MAC
98 : IDS_ENTER_PRESENTATION_MAC); 106 : IDS_ENTER_PRESENTATION_MAC);
99 } 107 }
100 108 return GetTitleForFullscreenMenuItem(browser);
101 return GetTitleForViewsFullscreenMenuItem(browser);
102 } 109 }
103 110
104 // Identify the actual Browser to which the command should be dispatched. It 111 // 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 112 // 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. 113 // 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 114 // 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 115 // foreground window), so this is only an issue for senders that are part of
109 // windows. 116 // windows.
110 Browser* FindBrowserForSender(id sender, NSWindow* window) { 117 Browser* FindBrowserForSender(id sender, NSWindow* window) {
111 NSWindow* targetWindow = window; 118 NSWindow* targetWindow = window;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 // Extensions have the ability to hide the bookmark all tabs menu 196 // Extensions have the ability to hide the bookmark all tabs menu
190 // item. This only affects the bookmark page menu item under the main 197 // 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 198 // menu. The bookmark page menu item under the wrench menu has its
192 // visibility controlled by AppMenuModel. 199 // visibility controlled by AppMenuModel.
193 bool shouldHide = 200 bool shouldHide =
194 chrome::ShouldRemoveBookmarkOpenPagesUI(browser->profile()); 201 chrome::ShouldRemoveBookmarkOpenPagesUI(browser->profile());
195 NSMenuItem* menuItem = base::mac::ObjCCast<NSMenuItem>(item); 202 NSMenuItem* menuItem = base::mac::ObjCCast<NSMenuItem>(item);
196 [menuItem setHidden:shouldHide]; 203 [menuItem setHidden:shouldHide];
197 break; 204 break;
198 } 205 }
206 case IDC_TOGGLE_FULLSCREEN_TOOLBAR: {
207 // TODO(spqchan): Implement a preferences for this command and replace
208 // the Presentation Mode menu item with item.
209 if (NSMenuItem* menuItem = base::mac::ObjCCast<NSMenuItem>(item)) {
210 [menuItem setHidden:YES];
211 enable = false;
212 }
213 break;
214 }
199 default: 215 default:
200 // Special handling for the contents of the Text Encoding submenu. On 216 // Special handling for the contents of the Text Encoding submenu. On
201 // Mac OS, instead of enabling/disabling the top-level menu item, we 217 // Mac OS, instead of enabling/disabling the top-level menu item, we
202 // enable/disable the submenu's contents (per Apple's HIG). 218 // enable/disable the submenu's contents (per Apple's HIG).
203 EncodingMenuController encoding_controller; 219 EncodingMenuController encoding_controller;
204 if (encoding_controller.DoesCommandBelongToEncodingMenu(tag)) 220 if (encoding_controller.DoesCommandBelongToEncodingMenu(tag))
205 enable &= chrome::IsCommandEnabled(browser, IDC_ENCODING_MENU); 221 enable &= chrome::IsCommandEnabled(browser, IDC_ENCODING_MENU);
206 } 222 }
207 223
208 // If the item is toggleable, find its toggle state and 224 // If the item is toggleable, find its toggle state and
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 // the background" in this case. 258 // the background" in this case.
243 modifierFlags &= ~NSCommandKeyMask; 259 modifierFlags &= ~NSCommandKeyMask;
244 } 260 }
245 chrome::ExecuteCommandWithDisposition( 261 chrome::ExecuteCommandWithDisposition(
246 FindBrowserForSender(sender, window), command, 262 FindBrowserForSender(sender, window), command,
247 ui::WindowOpenDispositionFromNSEventWithFlags([NSApp currentEvent], 263 ui::WindowOpenDispositionFromNSEventWithFlags([NSApp currentEvent],
248 modifierFlags)); 264 modifierFlags));
249 } 265 }
250 266
251 @end 267 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/browser_window_cocoa.mm ('k') | chrome/browser/ui/cocoa/browser_window_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698