| Index: chrome/browser/ui/cocoa/browser_window_controller.mm
|
| diff --git a/chrome/browser/ui/cocoa/browser_window_controller.mm b/chrome/browser/ui/cocoa/browser_window_controller.mm
|
| index b2103789057b29653bce2c19ec402e8a00953ace..c4205301f799e87d52ba2ceacf4e8451191d9afc 100644
|
| --- a/chrome/browser/ui/cocoa/browser_window_controller.mm
|
| +++ b/chrome/browser/ui/cocoa/browser_window_controller.mm
|
| @@ -15,7 +15,6 @@
|
| #include "base/strings/sys_string_conversions.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "chrome/app/chrome_command_ids.h" // IDC_*
|
| -#import "chrome/browser/app_controller_mac.h"
|
| #include "chrome/browser/bookmarks/bookmark_model_factory.h"
|
| #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h"
|
| #include "chrome/browser/browser_process.h"
|
| @@ -31,7 +30,6 @@
|
| #include "chrome/browser/themes/theme_service_factory.h"
|
| #include "chrome/browser/translate/chrome_translate_client.h"
|
| #include "chrome/browser/ui/bookmarks/bookmark_editor.h"
|
| -#include "chrome/browser/ui/bookmarks/bookmark_utils.h"
|
| #include "chrome/browser/ui/browser.h"
|
| #include "chrome/browser/ui/browser_command_controller.h"
|
| #include "chrome/browser/ui/browser_commands.h"
|
| @@ -44,6 +42,7 @@
|
| #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_observer_cocoa.h"
|
| #import "chrome/browser/ui/cocoa/bookmarks/bookmark_editor_controller.h"
|
| #import "chrome/browser/ui/cocoa/browser_window_cocoa.h"
|
| +#import "chrome/browser/ui/cocoa/browser_window_command_handler.h"
|
| #import "chrome/browser/ui/cocoa/browser_window_controller_private.h"
|
| #import "chrome/browser/ui/cocoa/browser_window_layout.h"
|
| #import "chrome/browser/ui/cocoa/browser_window_utils.h"
|
| @@ -75,7 +74,6 @@
|
| #include "chrome/browser/ui/location_bar/location_bar.h"
|
| #include "chrome/browser/ui/tabs/tab_strip_model.h"
|
| #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h"
|
| -#include "chrome/browser/ui/toolbar/encoding_menu_controller.h"
|
| #include "chrome/browser/ui/translate/translate_bubble_model_impl.h"
|
| #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
|
| #include "chrome/browser/ui/window_sizer/window_sizer.h"
|
| @@ -228,6 +226,11 @@ using content::WebContents;
|
| browser_.reset(browser);
|
| ownsBrowser_ = ownIt;
|
| NSWindow* window = [self window];
|
| + // Make the window handle browser window commands.
|
| + [base::mac::ObjCCastStrict<ChromeEventProcessingWindow>(window)
|
| + setCommandHandler:[[[BrowserWindowCommandHandler alloc] init]
|
| + autorelease]];
|
| +
|
| // Make the content view for the window have a layer. This will make all
|
| // sub-views have layers. This is necessary to ensure correct layer
|
| // ordering of all child views and their layers.
|
| @@ -1063,211 +1066,6 @@ using content::WebContents;
|
| }
|
| }
|
|
|
| -// Update a toggle state for an NSMenuItem if modified.
|
| -// Take care to ensure |item| looks like a NSMenuItem.
|
| -// Called by validateUserInterfaceItem:.
|
| -- (void)updateToggleStateWithTag:(NSInteger)tag forItem:(id)item {
|
| - if (![item respondsToSelector:@selector(state)] ||
|
| - ![item respondsToSelector:@selector(setState:)])
|
| - return;
|
| -
|
| - // On Windows this logic happens in bookmark_bar_view.cc. On the
|
| - // Mac we're a lot more MVC happy so we've moved it into a
|
| - // controller. To be clear, this simply updates the menu item; it
|
| - // does not display the bookmark bar itself.
|
| - if (tag == IDC_SHOW_BOOKMARK_BAR) {
|
| - bool toggled = windowShim_->IsBookmarkBarVisible();
|
| - NSInteger oldState = [(NSMenuItem*)item state];
|
| - NSInteger newState = toggled ? NSOnState : NSOffState;
|
| - if (oldState != newState)
|
| - [item setState:newState];
|
| - }
|
| -
|
| - // Update the checked/Unchecked state of items in the encoding menu.
|
| - // On Windows, this logic is part of |EncodingMenuModel| in
|
| - // browser/ui/views/toolbar_view.h.
|
| - EncodingMenuController encoding_controller;
|
| - if (encoding_controller.DoesCommandBelongToEncodingMenu(tag)) {
|
| - DCHECK(browser_.get());
|
| - Profile* profile = browser_->profile();
|
| - DCHECK(profile);
|
| - WebContents* current_tab =
|
| - browser_->tab_strip_model()->GetActiveWebContents();
|
| - if (!current_tab)
|
| - return;
|
| -
|
| - const std::string encoding = current_tab->GetEncoding();
|
| -
|
| - bool toggled = encoding_controller.IsItemChecked(profile, encoding, tag);
|
| - NSInteger oldState = [(NSMenuItem*)item state];
|
| - NSInteger newState = toggled ? NSOnState : NSOffState;
|
| - if (oldState != newState)
|
| - [item setState:newState];
|
| - }
|
| -}
|
| -
|
| -// Called to validate menu and toolbar items when this window is key. All the
|
| -// items we care about have been set with the |-commandDispatch:| or
|
| -// |-commandDispatchUsingKeyModifiers:| actions and a target of FirstResponder
|
| -// in IB. If it's not one of those, let it continue up the responder chain to be
|
| -// handled elsewhere. We pull out the tag as the cross-platform constant to
|
| -// differentiate and dispatch the various commands.
|
| -// NOTE: we might have to handle state for app-wide menu items,
|
| -// although we could cheat and directly ask the app controller if our
|
| -// command_updater doesn't support the command. This may or may not be an issue,
|
| -// too early to tell.
|
| -- (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item {
|
| - SEL action = [item action];
|
| - BOOL enable = NO;
|
| - if (action == @selector(commandDispatch:) ||
|
| - action == @selector(commandDispatchUsingKeyModifiers:)) {
|
| - NSInteger tag = [item tag];
|
| - if (chrome::SupportsCommand(browser_.get(), tag)) {
|
| - // Generate return value (enabled state)
|
| - enable = chrome::IsCommandEnabled(browser_.get(), tag);
|
| - switch (tag) {
|
| - case IDC_CLOSE_TAB:
|
| - // Disable "close tab" if the receiving window is not tabbed.
|
| - // We simply check whether the item has a keyboard shortcut set here;
|
| - // app_controller_mac.mm actually determines whether the item should
|
| - // be enabled.
|
| - if (NSMenuItem* menuItem = base::mac::ObjCCast<NSMenuItem>(item))
|
| - enable &= !![[menuItem keyEquivalent] length];
|
| - break;
|
| - case IDC_FULLSCREEN: {
|
| - if (NSMenuItem* menuItem = base::mac::ObjCCast<NSMenuItem>(item)) {
|
| - if (chrome::mac::SupportsSystemFullscreen()) {
|
| - [menuItem setTitle:[self titleForFullscreenMenuItem]];
|
| - } else {
|
| - [menuItem setHidden:YES];
|
| - }
|
| - }
|
| - break;
|
| - }
|
| - case IDC_PRESENTATION_MODE: {
|
| - if (NSMenuItem* menuItem = base::mac::ObjCCast<NSMenuItem>(item)) {
|
| - [menuItem setTitle:[self titleForFullscreenMenuItem]];
|
| -
|
| - if (chrome::mac::SupportsSystemFullscreen())
|
| - [menuItem setAlternate:YES];
|
| - }
|
| - break;
|
| - }
|
| - case IDC_SHOW_SIGNIN: {
|
| - Profile* original_profile =
|
| - browser_->profile()->GetOriginalProfile();
|
| - [AppController updateSigninItem:item
|
| - shouldShow:enable
|
| - currentProfile:original_profile];
|
| - break;
|
| - }
|
| - case IDC_BOOKMARK_PAGE: {
|
| - // Extensions have the ability to hide the bookmark page menu item.
|
| - // This only affects the bookmark page menu item under the main menu.
|
| - // The bookmark page menu item under the wrench menu has its
|
| - // visibility controlled by WrenchMenuModel.
|
| - bool shouldHide =
|
| - chrome::ShouldRemoveBookmarkThisPageUI(browser_->profile());
|
| - NSMenuItem* menuItem = base::mac::ObjCCast<NSMenuItem>(item);
|
| - [menuItem setHidden:shouldHide];
|
| - break;
|
| - }
|
| - case IDC_BOOKMARK_ALL_TABS: {
|
| - // Extensions have the ability to hide the bookmark all tabs menu
|
| - // item. This only affects the bookmark page menu item under the main
|
| - // menu. The bookmark page menu item under the wrench menu has its
|
| - // visibility controlled by WrenchMenuModel.
|
| - bool shouldHide =
|
| - chrome::ShouldRemoveBookmarkOpenPagesUI(browser_->profile());
|
| - NSMenuItem* menuItem = base::mac::ObjCCast<NSMenuItem>(item);
|
| - [menuItem setHidden:shouldHide];
|
| - break;
|
| - }
|
| - default:
|
| - // Special handling for the contents of the Text Encoding submenu. On
|
| - // Mac OS, instead of enabling/disabling the top-level menu item, we
|
| - // enable/disable the submenu's contents (per Apple's HIG).
|
| - EncodingMenuController encoding_controller;
|
| - if (encoding_controller.DoesCommandBelongToEncodingMenu(tag)) {
|
| - enable &= chrome::IsCommandEnabled(browser_.get(),
|
| - IDC_ENCODING_MENU) ? YES : NO;
|
| - }
|
| - }
|
| -
|
| - // If the item is toggleable, find its toggle state and
|
| - // try to update it. This is a little awkward, but the alternative is
|
| - // to check after a commandDispatch, which seems worse.
|
| - [self updateToggleStateWithTag:tag forItem:item];
|
| - }
|
| - }
|
| - return enable;
|
| -}
|
| -
|
| -// Called when the user picks a menu or toolbar item when this window is key.
|
| -// Calls through to the browser object to execute the command. This assumes that
|
| -// the command is supported and doesn't check, otherwise it would have been
|
| -// disabled in the UI in validateUserInterfaceItem:.
|
| -- (void)commandDispatch:(id)sender {
|
| - DCHECK(sender);
|
| - // Identify the actual BWC to which the command should be dispatched. It might
|
| - // belong to a background window, yet this controller gets it because it is
|
| - // the foreground window's controller and thus in the responder chain. Some
|
| - // senders don't have this problem (for example, menus only operate on the
|
| - // foreground window), so this is only an issue for senders that are part of
|
| - // windows.
|
| - BrowserWindowController* targetController = self;
|
| - if ([sender respondsToSelector:@selector(window)])
|
| - targetController = [[sender window] windowController];
|
| - DCHECK([targetController isKindOfClass:[BrowserWindowController class]]);
|
| - DCHECK(targetController->browser_.get());
|
| -
|
| - // When system fullscreen is available, it supercedes presentation mode.
|
| - int tag = [sender tag];
|
| - if (tag == IDC_PRESENTATION_MODE && chrome::mac::SupportsSystemFullscreen())
|
| - tag = IDC_FULLSCREEN;
|
| -
|
| - chrome::ExecuteCommand(targetController->browser_.get(), tag);
|
| -}
|
| -
|
| -// Same as |-commandDispatch:|, but executes commands using a disposition
|
| -// determined by the key flags. If the window is in the background and the
|
| -// command key is down, ignore the command key, but process any other modifiers.
|
| -- (void)commandDispatchUsingKeyModifiers:(id)sender {
|
| - DCHECK(sender);
|
| -
|
| - if (![sender isEnabled]) {
|
| - // This code is reachable e.g. if the user mashes the back button, queuing
|
| - // up a bunch of events before the button's enabled state is updated:
|
| - // http://crbug.com/63254
|
| - return;
|
| - }
|
| -
|
| - // See comment above for why we do this.
|
| - BrowserWindowController* targetController = self;
|
| - if ([sender respondsToSelector:@selector(window)])
|
| - targetController = [[sender window] windowController];
|
| - DCHECK([targetController isKindOfClass:[BrowserWindowController class]]);
|
| - DCHECK(targetController->browser_.get());
|
| -
|
| - NSInteger command = [sender tag];
|
| - NSUInteger modifierFlags = [[NSApp currentEvent] modifierFlags];
|
| - if ((command == IDC_RELOAD) &&
|
| - (modifierFlags & (NSShiftKeyMask | NSControlKeyMask))) {
|
| - command = IDC_RELOAD_IGNORING_CACHE;
|
| - // Mask off Shift and Control so they don't affect the disposition below.
|
| - modifierFlags &= ~(NSShiftKeyMask | NSControlKeyMask);
|
| - }
|
| - if (![[sender window] isMainWindow]) {
|
| - // Remove the command key from the flags, it means "keep the window in
|
| - // the background" in this case.
|
| - modifierFlags &= ~NSCommandKeyMask;
|
| - }
|
| - chrome::ExecuteCommandWithDisposition(
|
| - targetController->browser_.get(), command,
|
| - ui::WindowOpenDispositionFromNSEventWithFlags(
|
| - [NSApp currentEvent], modifierFlags));
|
| -}
|
| -
|
| - (BOOL)handledByExtensionCommand:(NSEvent*)event
|
| priority:(ui::AcceleratorManager::HandlerPriority)priority {
|
| return extension_keybinding_registry_->ProcessKeyEvent(
|
| @@ -2107,18 +1905,6 @@ willAnimateFromState:(BookmarkBar::State)oldState
|
| chrome::ExecuteCommand(browser_.get(), IDC_FULLSCREEN);
|
| }
|
|
|
| -- (NSString*)titleForFullscreenMenuItem {
|
| - if (!chrome::mac::SupportsSystemFullscreen()) {
|
| - return l10n_util::GetNSString([self inPresentationMode]
|
| - ? IDS_EXIT_PRESENTATION_MAC
|
| - : IDS_ENTER_PRESENTATION_MAC);
|
| - }
|
| -
|
| - return l10n_util::GetNSString([self isInAppKitFullscreen]
|
| - ? IDS_EXIT_FULLSCREEN_MAC
|
| - : IDS_ENTER_FULLSCREEN_MAC);
|
| -}
|
| -
|
| - (void)enterBrowserFullscreenWithToolbar:(BOOL)withToolbar {
|
| if (!chrome::mac::SupportsSystemFullscreen()) {
|
| if (![self isInImmersiveFullscreen])
|
|
|