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

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

Issue 2254273003: Remove text encoding UI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 3 months 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/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/bookmarks/bookmark_utils.h" 12 #include "chrome/browser/ui/bookmarks/bookmark_utils.h"
13 #include "chrome/browser/ui/browser_commands.h" 13 #include "chrome/browser/ui/browser_commands.h"
14 #include "chrome/browser/ui/browser_finder.h" 14 #include "chrome/browser/ui/browser_finder.h"
15 #include "chrome/browser/ui/browser_window.h" 15 #include "chrome/browser/ui/browser_window.h"
16 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h" 16 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h"
17 #include "chrome/browser/ui/toolbar/encoding_menu_controller.h"
18 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
19 #include "chrome/grit/generated_resources.h" 18 #include "chrome/grit/generated_resources.h"
20 #include "content/public/browser/user_metrics.h" 19 #include "content/public/browser/user_metrics.h"
21 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
22 #import "ui/base/cocoa/cocoa_base_utils.h" 21 #import "ui/base/cocoa/cocoa_base_utils.h"
23 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/base/l10n/l10n_util_mac.h" 23 #include "ui/base/l10n/l10n_util_mac.h"
25 24
26 namespace { 25 namespace {
27 26
(...skipping 22 matching lines...) Expand all
50 if (tag == IDC_SHOW_BOOKMARK_BAR) { 49 if (tag == IDC_SHOW_BOOKMARK_BAR) {
51 SetToggleState(browser->window()->IsBookmarkBarVisible(), item); 50 SetToggleState(browser->window()->IsBookmarkBarVisible(), item);
52 return; 51 return;
53 } 52 }
54 53
55 if (tag == IDC_TOGGLE_FULLSCREEN_TOOLBAR) { 54 if (tag == IDC_TOGGLE_FULLSCREEN_TOOLBAR) {
56 PrefService* prefs = browser->profile()->GetPrefs(); 55 PrefService* prefs = browser->profile()->GetPrefs();
57 SetToggleState(prefs->GetBoolean(prefs::kShowFullscreenToolbar), item); 56 SetToggleState(prefs->GetBoolean(prefs::kShowFullscreenToolbar), item);
58 return; 57 return;
59 } 58 }
60
61 // Update the checked/unchecked state of items in the encoding menu.
62 // On Windows, this logic is part of |EncodingMenuModel| in
63 // browser/ui/views/toolbar_view.h.
64 EncodingMenuController encoding_controller;
65 if (!encoding_controller.DoesCommandBelongToEncodingMenu(tag))
66 return;
67
68 Profile* profile = browser->profile();
69 DCHECK(profile);
70 content::WebContents* current_tab =
71 browser->tab_strip_model()->GetActiveWebContents();
72 if (!current_tab)
73 return;
74
75 const std::string encoding = current_tab->GetEncoding();
76
77 SetToggleState(encoding_controller.IsItemChecked(profile, encoding, tag),
78 item);
79 } 59 }
80 60
81 NSString* GetTitleForViewsFullscreenMenuItem(Browser* browser) { 61 NSString* GetTitleForViewsFullscreenMenuItem(Browser* browser) {
82 return l10n_util::GetNSString(browser->window()->IsFullscreen() 62 return l10n_util::GetNSString(browser->window()->IsFullscreen()
83 ? IDS_EXIT_FULLSCREEN_MAC 63 ? IDS_EXIT_FULLSCREEN_MAC
84 : IDS_ENTER_FULLSCREEN_MAC); 64 : IDS_ENTER_FULLSCREEN_MAC);
85 } 65 }
86 66
87 // Get the text for the "Enter/Exit Fullscreen" menu item. 67 // Get the text for the "Enter/Exit Fullscreen" menu item.
88 // TODO(jackhou): Remove the dependency on BrowserWindowController(Private). 68 // TODO(jackhou): Remove the dependency on BrowserWindowController(Private).
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 break; 165 break;
186 } 166 }
187 case IDC_SHOW_AS_TAB: { 167 case IDC_SHOW_AS_TAB: {
188 // Hide this menu option if the window is tabbed or is the devtools 168 // Hide this menu option if the window is tabbed or is the devtools
189 // window. 169 // window.
190 NSMenuItem* menuItem = base::mac::ObjCCast<NSMenuItem>(item); 170 NSMenuItem* menuItem = base::mac::ObjCCast<NSMenuItem>(item);
191 [menuItem setHidden:browser->is_type_tabbed() || browser->is_devtools()]; 171 [menuItem setHidden:browser->is_type_tabbed() || browser->is_devtools()];
192 break; 172 break;
193 } 173 }
194 default: 174 default:
195 // Special handling for the contents of the Text Encoding submenu. On 175 break;
196 // Mac OS, instead of enabling/disabling the top-level menu item, we
197 // enable/disable the submenu's contents (per Apple's HIG).
198 EncodingMenuController encoding_controller;
199 if (encoding_controller.DoesCommandBelongToEncodingMenu(tag))
200 enable &= chrome::IsCommandEnabled(browser, IDC_ENCODING_MENU);
201 } 176 }
202 177
203 // If the item is toggleable, find its toggle state and 178 // If the item is toggleable, find its toggle state and
204 // try to update it. This is a little awkward, but the alternative is 179 // try to update it. This is a little awkward, but the alternative is
205 // to check after a commandDispatch, which seems worse. 180 // to check after a commandDispatch, which seems worse.
206 UpdateToggleStateWithTag(tag, item, window); 181 UpdateToggleStateWithTag(tag, item, window);
207 182
208 return enable; 183 return enable;
209 } 184 }
210 185
(...skipping 26 matching lines...) Expand all
237 // the background" in this case. 212 // the background" in this case.
238 modifierFlags &= ~NSCommandKeyMask; 213 modifierFlags &= ~NSCommandKeyMask;
239 } 214 }
240 chrome::ExecuteCommandWithDisposition( 215 chrome::ExecuteCommandWithDisposition(
241 FindBrowserForSender(sender, window), command, 216 FindBrowserForSender(sender, window), command,
242 ui::WindowOpenDispositionFromNSEventWithFlags([NSApp currentEvent], 217 ui::WindowOpenDispositionFromNSEventWithFlags([NSApp currentEvent],
243 modifierFlags)); 218 modifierFlags));
244 } 219 }
245 220
246 @end 221 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698