| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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_controller.h" | 5 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <numeric> | 8 #include <numeric> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/mac/bundle_locations.h" | 11 #include "base/mac/bundle_locations.h" |
| 12 #import "base/mac/foundation_util.h" |
| 12 #include "base/mac/mac_util.h" | 13 #include "base/mac/mac_util.h" |
| 13 #import "base/mac/sdk_forward_declarations.h" | 14 #import "base/mac/sdk_forward_declarations.h" |
| 14 #include "base/strings/sys_string_conversions.h" | 15 #include "base/strings/sys_string_conversions.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 16 #include "chrome/app/chrome_command_ids.h" // IDC_* | 17 #include "chrome/app/chrome_command_ids.h" // IDC_* |
| 17 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 18 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 18 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/browser/devtools/devtools_window.h" | 20 #include "chrome/browser/devtools/devtools_window.h" |
| 20 #include "chrome/browser/fullscreen.h" | 21 #include "chrome/browser/fullscreen.h" |
| 21 #include "chrome/browser/profiles/avatar_menu.h" | 22 #include "chrome/browser/profiles/avatar_menu.h" |
| (...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1089 NSInteger tag = [item tag]; | 1090 NSInteger tag = [item tag]; |
| 1090 if (chrome::SupportsCommand(browser_.get(), tag)) { | 1091 if (chrome::SupportsCommand(browser_.get(), tag)) { |
| 1091 // Generate return value (enabled state) | 1092 // Generate return value (enabled state) |
| 1092 enable = chrome::IsCommandEnabled(browser_.get(), tag); | 1093 enable = chrome::IsCommandEnabled(browser_.get(), tag); |
| 1093 switch (tag) { | 1094 switch (tag) { |
| 1094 case IDC_CLOSE_TAB: | 1095 case IDC_CLOSE_TAB: |
| 1095 // Disable "close tab" if the receiving window is not tabbed. | 1096 // Disable "close tab" if the receiving window is not tabbed. |
| 1096 // We simply check whether the item has a keyboard shortcut set here; | 1097 // We simply check whether the item has a keyboard shortcut set here; |
| 1097 // app_controller_mac.mm actually determines whether the item should | 1098 // app_controller_mac.mm actually determines whether the item should |
| 1098 // be enabled. | 1099 // be enabled. |
| 1099 if ([static_cast<NSObject*>(item) isKindOfClass:[NSMenuItem class]]) | 1100 if (NSMenuItem* menuItem = base::mac::ObjCCast<NSMenuItem>(item)) |
| 1100 enable &= !![[static_cast<NSMenuItem*>(item) keyEquivalent] length]; | 1101 enable &= !![[menuItem keyEquivalent] length]; |
| 1101 break; | 1102 break; |
| 1102 case IDC_FULLSCREEN: { | 1103 case IDC_FULLSCREEN: { |
| 1103 if ([static_cast<NSObject*>(item) isKindOfClass:[NSMenuItem class]]) { | 1104 if (NSMenuItem* menuItem = base::mac::ObjCCast<NSMenuItem>(item)) { |
| 1104 NSString* menuTitle = l10n_util::GetNSString( | 1105 NSString* menuTitle = l10n_util::GetNSString( |
| 1105 [self isFullscreen] && ![self inPresentationMode] ? | 1106 [self isFullscreen] && ![self inPresentationMode] ? |
| 1106 IDS_EXIT_FULLSCREEN_MAC : | 1107 IDS_EXIT_FULLSCREEN_MAC : |
| 1107 IDS_ENTER_FULLSCREEN_MAC); | 1108 IDS_ENTER_FULLSCREEN_MAC); |
| 1108 [static_cast<NSMenuItem*>(item) setTitle:menuTitle]; | 1109 [menuItem setTitle:menuTitle]; |
| 1109 | 1110 |
| 1110 if (!chrome::mac::SupportsSystemFullscreen()) | 1111 if (!chrome::mac::SupportsSystemFullscreen()) |
| 1111 [static_cast<NSMenuItem*>(item) setHidden:YES]; | 1112 [menuItem setHidden:YES]; |
| 1112 } | 1113 } |
| 1113 break; | 1114 break; |
| 1114 } | 1115 } |
| 1115 case IDC_PRESENTATION_MODE: { | 1116 case IDC_PRESENTATION_MODE: { |
| 1116 if ([static_cast<NSObject*>(item) isKindOfClass:[NSMenuItem class]]) { | 1117 if (NSMenuItem* menuItem = base::mac::ObjCCast<NSMenuItem>(item)) { |
| 1117 NSString* menuTitle = l10n_util::GetNSString( | 1118 NSString* menuTitle = l10n_util::GetNSString( |
| 1118 [self inPresentationMode] ? IDS_EXIT_PRESENTATION_MAC : | 1119 [self inPresentationMode] ? IDS_EXIT_PRESENTATION_MAC : |
| 1119 IDS_ENTER_PRESENTATION_MAC); | 1120 IDS_ENTER_PRESENTATION_MAC); |
| 1120 [static_cast<NSMenuItem*>(item) setTitle:menuTitle]; | 1121 [menuItem setTitle:menuTitle]; |
| 1121 } | 1122 } |
| 1122 break; | 1123 break; |
| 1123 } | 1124 } |
| 1124 case IDC_SHOW_SIGNIN: { | 1125 case IDC_SHOW_SIGNIN: { |
| 1125 Profile* original_profile = | 1126 Profile* original_profile = |
| 1126 browser_->profile()->GetOriginalProfile(); | 1127 browser_->profile()->GetOriginalProfile(); |
| 1127 [BrowserWindowController updateSigninItem:item | 1128 [BrowserWindowController updateSigninItem:item |
| 1128 shouldShow:enable | 1129 shouldShow:enable |
| 1129 currentProfile:original_profile]; | 1130 currentProfile:original_profile]; |
| 1130 break; | 1131 break; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1262 // to tab content area coordinates and flip the coordinate system. | 1263 // to tab content area coordinates and flip the coordinate system. |
| 1263 NSRect growBoxRect = | 1264 NSRect growBoxRect = |
| 1264 [[self tabContentArea] convertRect:[window _growBoxRect] fromView:nil]; | 1265 [[self tabContentArea] convertRect:[window _growBoxRect] fromView:nil]; |
| 1265 growBoxRect.origin.y = | 1266 growBoxRect.origin.y = |
| 1266 NSHeight([[self tabContentArea] frame]) - NSMaxY(growBoxRect); | 1267 NSHeight([[self tabContentArea] frame]) - NSMaxY(growBoxRect); |
| 1267 return growBoxRect; | 1268 return growBoxRect; |
| 1268 } | 1269 } |
| 1269 | 1270 |
| 1270 // Accept tabs from a BrowserWindowController with the same Profile. | 1271 // Accept tabs from a BrowserWindowController with the same Profile. |
| 1271 - (BOOL)canReceiveFrom:(TabWindowController*)source { | 1272 - (BOOL)canReceiveFrom:(TabWindowController*)source { |
| 1272 if (![source isKindOfClass:[BrowserWindowController class]]) { | 1273 BrowserWindowController* realSource = |
| 1274 base::mac::ObjCCast<BrowserWindowController>(source); |
| 1275 if (!realSource || browser_->profile() != realSource->browser_->profile()) { |
| 1273 return NO; | 1276 return NO; |
| 1274 } | 1277 } |
| 1275 | 1278 |
| 1276 BrowserWindowController* realSource = | |
| 1277 static_cast<BrowserWindowController*>(source); | |
| 1278 if (browser_->profile() != realSource->browser_->profile()) { | |
| 1279 return NO; | |
| 1280 } | |
| 1281 | |
| 1282 // Can't drag a tab from a normal browser to a pop-up | 1279 // Can't drag a tab from a normal browser to a pop-up |
| 1283 if (browser_->type() != realSource->browser_->type()) { | 1280 if (browser_->type() != realSource->browser_->type()) { |
| 1284 return NO; | 1281 return NO; |
| 1285 } | 1282 } |
| 1286 | 1283 |
| 1287 return YES; | 1284 return YES; |
| 1288 } | 1285 } |
| 1289 | 1286 |
| 1290 // Move a given tab view to the location of the current placeholder. If there is | 1287 // Move a given tab view to the location of the current placeholder. If there is |
| 1291 // no placeholder, it will go at the end. |controller| is the window controller | 1288 // no placeholder, it will go at the end. |controller| is the window controller |
| 1292 // of a tab being dropped from a different window. It will be nil if the drag is | 1289 // of a tab being dropped from a different window. It will be nil if the drag is |
| 1293 // within the window, otherwise the tab is removed from that window before being | 1290 // within the window, otherwise the tab is removed from that window before being |
| 1294 // placed into this one. The implementation will call |-removePlaceholder| since | 1291 // placed into this one. The implementation will call |-removePlaceholder| since |
| 1295 // the drag is now complete. This also calls |-layoutTabs| internally so | 1292 // the drag is now complete. This also calls |-layoutTabs| internally so |
| 1296 // clients do not need to call it again. | 1293 // clients do not need to call it again. |
| 1297 - (void)moveTabView:(NSView*)view | 1294 - (void)moveTabView:(NSView*)view |
| 1298 fromController:(TabWindowController*)dragController { | 1295 fromController:(TabWindowController*)dragController { |
| 1299 if (dragController) { | 1296 if (dragController) { |
| 1300 // Moving between windows. Figure out the WebContents to drop into our tab | 1297 // Moving between windows. Figure out the WebContents to drop into our tab |
| 1301 // model from the source window's model. | 1298 // model from the source window's model. |
| 1302 BOOL isBrowser = | 1299 BrowserWindowController* dragBWC = |
| 1303 [dragController isKindOfClass:[BrowserWindowController class]]; | 1300 base::mac::ObjCCastStrict<BrowserWindowController>(dragController); |
| 1304 DCHECK(isBrowser); | |
| 1305 if (!isBrowser) return; | |
| 1306 BrowserWindowController* dragBWC = (BrowserWindowController*)dragController; | |
| 1307 int index = [dragBWC->tabStripController_ modelIndexForTabView:view]; | 1301 int index = [dragBWC->tabStripController_ modelIndexForTabView:view]; |
| 1308 WebContents* contents = | 1302 WebContents* contents = |
| 1309 dragBWC->browser_->tab_strip_model()->GetWebContentsAt(index); | 1303 dragBWC->browser_->tab_strip_model()->GetWebContentsAt(index); |
| 1310 // The tab contents may have gone away if given a window.close() while it | 1304 // The tab contents may have gone away if given a window.close() while it |
| 1311 // is being dragged. If so, bail, we've got nothing to drop. | 1305 // is being dragged. If so, bail, we've got nothing to drop. |
| 1312 if (!contents) | 1306 if (!contents) |
| 1313 return; | 1307 return; |
| 1314 | 1308 |
| 1315 // Convert |view|'s frame (which starts in the source tab strip's coordinate | 1309 // Convert |view|'s frame (which starts in the source tab strip's coordinate |
| 1316 // system) to the coordinate system of the destination tab strip. This needs | 1310 // system) to the coordinate system of the destination tab strip. This needs |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1819 // TODO: calling |layoutSubviews| here is a waste, find a better way to | 1813 // TODO: calling |layoutSubviews| here is a waste, find a better way to |
| 1820 // do this. | 1814 // do this. |
| 1821 if ([findBarCocoaController_ isFindBarVisible]) | 1815 if ([findBarCocoaController_ isFindBarVisible]) |
| 1822 [self layoutSubviews]; | 1816 [self layoutSubviews]; |
| 1823 } | 1817 } |
| 1824 | 1818 |
| 1825 // Handle the openLearnMoreAboutCrashLink: action from SadTabController when | 1819 // Handle the openLearnMoreAboutCrashLink: action from SadTabController when |
| 1826 // "Learn more" link in "Aw snap" page (i.e. crash page or sad tab) is | 1820 // "Learn more" link in "Aw snap" page (i.e. crash page or sad tab) is |
| 1827 // clicked. Decoupling the action from its target makes unit testing possible. | 1821 // clicked. Decoupling the action from its target makes unit testing possible. |
| 1828 - (void)openLearnMoreAboutCrashLink:(id)sender { | 1822 - (void)openLearnMoreAboutCrashLink:(id)sender { |
| 1829 if ([sender isKindOfClass:[SadTabController class]]) { | 1823 if (SadTabController* sadTab = |
| 1830 SadTabController* sad_tab = static_cast<SadTabController*>(sender); | 1824 base::mac::ObjCCast<SadTabController>(sender)) { |
| 1831 WebContents* web_contents = [sad_tab webContents]; | 1825 WebContents* webContents = [sadTab webContents]; |
| 1832 if (web_contents) { | 1826 if (webContents) { |
| 1833 OpenURLParams params( | 1827 OpenURLParams params( |
| 1834 GURL(chrome::kCrashReasonURL), Referrer(), CURRENT_TAB, | 1828 GURL(chrome::kCrashReasonURL), Referrer(), CURRENT_TAB, |
| 1835 content::PAGE_TRANSITION_LINK, false); | 1829 content::PAGE_TRANSITION_LINK, false); |
| 1836 web_contents->OpenURL(params); | 1830 webContents->OpenURL(params); |
| 1837 } | 1831 } |
| 1838 } | 1832 } |
| 1839 } | 1833 } |
| 1840 | 1834 |
| 1841 // Delegate method called when window did move. (See below for why we don't use | 1835 // Delegate method called when window did move. (See below for why we don't use |
| 1842 // |-windowWillMove:|, which is called less frequently than |-windowDidMove| | 1836 // |-windowWillMove:|, which is called less frequently than |-windowDidMove| |
| 1843 // instead.) | 1837 // instead.) |
| 1844 - (void)windowDidMove:(NSNotification*)notification { | 1838 - (void)windowDidMove:(NSNotification*)notification { |
| 1845 [self saveWindowPositionIfNeeded]; | 1839 [self saveWindowPositionIfNeeded]; |
| 1846 | 1840 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1988 // |-setPresentationMode:|. | 1982 // |-setPresentationMode:|. |
| 1989 - (void)setFullscreen:(BOOL)fullscreen { | 1983 - (void)setFullscreen:(BOOL)fullscreen { |
| 1990 if (fullscreen == [self isFullscreen]) | 1984 if (fullscreen == [self isFullscreen]) |
| 1991 return; | 1985 return; |
| 1992 | 1986 |
| 1993 if (!chrome::IsCommandEnabled(browser_.get(), IDC_FULLSCREEN)) | 1987 if (!chrome::IsCommandEnabled(browser_.get(), IDC_FULLSCREEN)) |
| 1994 return; | 1988 return; |
| 1995 | 1989 |
| 1996 if (chrome::mac::SupportsSystemFullscreen() && !fullscreenWindow_) { | 1990 if (chrome::mac::SupportsSystemFullscreen() && !fullscreenWindow_) { |
| 1997 enteredPresentationModeFromFullscreen_ = YES; | 1991 enteredPresentationModeFromFullscreen_ = YES; |
| 1998 if ([[self window] isKindOfClass:[FramedBrowserWindow class]]) | 1992 if (FramedBrowserWindow* framedBrowserWindow = |
| 1999 [static_cast<FramedBrowserWindow*>([self window]) toggleSystemFullScreen]; | 1993 base::mac::ObjCCast<FramedBrowserWindow>([self window])) { |
| 1994 [framedBrowserWindow toggleSystemFullScreen]; |
| 1995 } |
| 2000 } else { | 1996 } else { |
| 2001 if (fullscreen) | 1997 if (fullscreen) |
| 2002 [self enterFullscreenForSnowLeopard]; | 1998 [self enterFullscreenForSnowLeopard]; |
| 2003 else | 1999 else |
| 2004 [self exitFullscreenForSnowLeopard]; | 2000 [self exitFullscreenForSnowLeopard]; |
| 2005 } | 2001 } |
| 2006 } | 2002 } |
| 2007 | 2003 |
| 2008 - (void)enterFullscreen { | 2004 - (void)enterFullscreen { |
| 2009 [self setFullscreen:YES]; | 2005 [self setFullscreen:YES]; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2064 [self releaseBarVisibilityForOwner:self withAnimation:YES delay:YES]; | 2060 [self releaseBarVisibilityForOwner:self withAnimation:YES delay:YES]; |
| 2065 // Since -windowDidEnterFullScreen: won't be called in the | 2061 // Since -windowDidEnterFullScreen: won't be called in the |
| 2066 // fullscreen --> presentation mode case, manually show the exit bubble | 2062 // fullscreen --> presentation mode case, manually show the exit bubble |
| 2067 // and notify the change happened with WindowFullscreenStateChanged(). | 2063 // and notify the change happened with WindowFullscreenStateChanged(). |
| 2068 [self showFullscreenExitBubbleIfNecessary]; | 2064 [self showFullscreenExitBubbleIfNecessary]; |
| 2069 browser_->WindowFullscreenStateChanged(); | 2065 browser_->WindowFullscreenStateChanged(); |
| 2070 } else { | 2066 } else { |
| 2071 // If not in fullscreen mode, trigger the Lion fullscreen mode machinery. | 2067 // If not in fullscreen mode, trigger the Lion fullscreen mode machinery. |
| 2072 // Presentation mode will automatically be enabled in | 2068 // Presentation mode will automatically be enabled in |
| 2073 // |-windowWillEnterFullScreen:|. | 2069 // |-windowWillEnterFullScreen:|. |
| 2074 NSWindow* window = [self window]; | 2070 if (FramedBrowserWindow* window = |
| 2075 if ([window isKindOfClass:[FramedBrowserWindow class]]) | 2071 base::mac::ObjCCast<FramedBrowserWindow>([self window])) { |
| 2076 [static_cast<FramedBrowserWindow*>(window) toggleSystemFullScreen]; | 2072 [window toggleSystemFullScreen]; |
| 2073 } |
| 2077 } | 2074 } |
| 2078 } else { | 2075 } else { |
| 2079 // Exiting presentation mode does not exit system fullscreen; it merely | 2076 // Exiting presentation mode does not exit system fullscreen; it merely |
| 2080 // switches from presentation mode to normal fullscreen. | 2077 // switches from presentation mode to normal fullscreen. |
| 2081 [self setPresentationModeInternal:NO forceDropdown:NO]; | 2078 [self setPresentationModeInternal:NO forceDropdown:NO]; |
| 2082 | 2079 |
| 2083 // Since -windowDidExitFullScreen: won't be called in the | 2080 // Since -windowDidExitFullScreen: won't be called in the |
| 2084 // presentation mode --> normal fullscreen case, manually show the exit | 2081 // presentation mode --> normal fullscreen case, manually show the exit |
| 2085 // bubble and notify the change happened with | 2082 // bubble and notify the change happened with |
| 2086 // WindowFullscreenStateChanged(). | 2083 // WindowFullscreenStateChanged(). |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2238 | 2235 |
| 2239 - (BOOL)supportsBookmarkBar { | 2236 - (BOOL)supportsBookmarkBar { |
| 2240 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; | 2237 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; |
| 2241 } | 2238 } |
| 2242 | 2239 |
| 2243 - (BOOL)isTabbedWindow { | 2240 - (BOOL)isTabbedWindow { |
| 2244 return browser_->is_type_tabbed(); | 2241 return browser_->is_type_tabbed(); |
| 2245 } | 2242 } |
| 2246 | 2243 |
| 2247 @end // @implementation BrowserWindowController(WindowType) | 2244 @end // @implementation BrowserWindowController(WindowType) |
| OLD | NEW |