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

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

Issue 7566016: Fullscreen support for Lion. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <Carbon/Carbon.h> 7 #include <Carbon/Carbon.h>
8 8
9 #include <cmath> 9 #include <cmath>
10 #include <numeric> 10 #include <numeric>
(...skipping 21 matching lines...) Expand all
32 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_editor_controller.h" 32 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_editor_controller.h"
33 #import "chrome/browser/ui/cocoa/browser/avatar_button.h" 33 #import "chrome/browser/ui/cocoa/browser/avatar_button.h"
34 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" 34 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h"
35 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h" 35 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h"
36 #import "chrome/browser/ui/cocoa/dev_tools_controller.h" 36 #import "chrome/browser/ui/cocoa/dev_tools_controller.h"
37 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h" 37 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h"
38 #import "chrome/browser/ui/cocoa/event_utils.h" 38 #import "chrome/browser/ui/cocoa/event_utils.h"
39 #import "chrome/browser/ui/cocoa/fast_resize_view.h" 39 #import "chrome/browser/ui/cocoa/fast_resize_view.h"
40 #import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" 40 #import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h"
41 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h" 41 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h"
42 #import "chrome/browser/ui/cocoa/focus_tracker.h" 42 #import "chrome/browser/ui/cocoa/framed_browser_window.h"
43 #import "chrome/browser/ui/cocoa/fullscreen_controller.h"
44 #import "chrome/browser/ui/cocoa/fullscreen_window.h" 43 #import "chrome/browser/ui/cocoa/fullscreen_window.h"
45 #import "chrome/browser/ui/cocoa/gesture_utils.h" 44 #import "chrome/browser/ui/cocoa/gesture_utils.h"
46 #import "chrome/browser/ui/cocoa/image_utils.h" 45 #import "chrome/browser/ui/cocoa/image_utils.h"
47 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" 46 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h"
48 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" 47 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h"
48 #import "chrome/browser/ui/cocoa/presentation_mode_controller.h"
49 #import "chrome/browser/ui/cocoa/sidebar_controller.h" 49 #import "chrome/browser/ui/cocoa/sidebar_controller.h"
50 #import "chrome/browser/ui/cocoa/status_bubble_mac.h" 50 #import "chrome/browser/ui/cocoa/status_bubble_mac.h"
51 #import "chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h" 51 #import "chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h"
52 #import "chrome/browser/ui/cocoa/tab_contents/sad_tab_controller.h" 52 #import "chrome/browser/ui/cocoa/tab_contents/sad_tab_controller.h"
53 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" 53 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h"
54 #import "chrome/browser/ui/cocoa/tabpose_window.h" 54 #import "chrome/browser/ui/cocoa/tabpose_window.h"
55 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" 55 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h"
56 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" 56 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h"
57 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" 57 #import "chrome/browser/ui/cocoa/tabs/tab_view.h"
58 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" 58 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 189
190 enum { 190 enum {
191 NSWindowAnimationBehaviorDefault = 0, 191 NSWindowAnimationBehaviorDefault = 0,
192 NSWindowAnimationBehaviorNone = 2, 192 NSWindowAnimationBehaviorNone = 2,
193 NSWindowAnimationBehaviorDocumentWindow = 3, 193 NSWindowAnimationBehaviorDocumentWindow = 3,
194 NSWindowAnimationBehaviorUtilityWindow = 4, 194 NSWindowAnimationBehaviorUtilityWindow = 4,
195 NSWindowAnimationBehaviorAlertPanel = 5 195 NSWindowAnimationBehaviorAlertPanel = 5
196 }; 196 };
197 typedef NSInteger NSWindowAnimationBehavior; 197 typedef NSInteger NSWindowAnimationBehavior;
198 198
199 enum {
200 NSWindowCollectionBehaviorFullScreenPrimary = 1 << 7,
201 NSWindowCollectionBehaviorFullScreenAuxiliary = 1 << 8
202 };
203
204 enum {
205 NSFullScreenWindowMask = 1 << 14
206 };
207
199 @interface NSWindow (LionSDKDeclarations) 208 @interface NSWindow (LionSDKDeclarations)
200 - (void)setRestorable:(BOOL)flag; 209 - (void)setRestorable:(BOOL)flag;
201 - (void)setAnimationBehavior:(NSWindowAnimationBehavior)newAnimationBehavior; 210 - (void)setAnimationBehavior:(NSWindowAnimationBehavior)newAnimationBehavior;
202 @end 211 @end
203 212
204 #endif // MAC_OS_X_VERSION_10_7 213 #endif // MAC_OS_X_VERSION_10_7
205 214
206 @implementation BrowserWindowController 215 @implementation BrowserWindowController
207 216
208 + (BrowserWindowController*)browserWindowControllerForWindow:(NSWindow*)window { 217 + (BrowserWindowController*)browserWindowControllerForWindow:(NSWindow*)window {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 // functionality appears to be leaky (or at least interacts badly with our 264 // functionality appears to be leaky (or at least interacts badly with our
256 // architecture) and thus BrowserWindowController never gets released. This 265 // architecture) and thus BrowserWindowController never gets released. This
257 // prevents the browser from being able to quit <http://crbug.com/79113>. 266 // prevents the browser from being able to quit <http://crbug.com/79113>.
258 if ([window respondsToSelector:@selector(setRestorable:)]) 267 if ([window respondsToSelector:@selector(setRestorable:)])
259 [window setRestorable:NO]; 268 [window setRestorable:NO];
260 269
261 // Get the windows to swish in on Lion. 270 // Get the windows to swish in on Lion.
262 if ([window respondsToSelector:@selector(setAnimationBehavior:)]) 271 if ([window respondsToSelector:@selector(setAnimationBehavior:)])
263 [window setAnimationBehavior:NSWindowAnimationBehaviorDocumentWindow]; 272 [window setAnimationBehavior:NSWindowAnimationBehaviorDocumentWindow];
264 273
274 // Set the window to participate in Lion Fullscreen mode. Setting this flag
275 // has no effect on Snow Leopard or earlier.
276 NSUInteger collectionBehavior = [window collectionBehavior];
277 collectionBehavior |= NSWindowCollectionBehaviorFullScreenPrimary;
278 [window setCollectionBehavior:collectionBehavior];
279
265 // Get the most appropriate size for the window, then enforce the 280 // Get the most appropriate size for the window, then enforce the
266 // minimum width and height. The window shim will handle flipping 281 // minimum width and height. The window shim will handle flipping
267 // the coordinates for us so we can use it to save some code. 282 // the coordinates for us so we can use it to save some code.
268 // Note that this may leave a significant portion of the window 283 // Note that this may leave a significant portion of the window
269 // offscreen, but there will always be enough window onscreen to 284 // offscreen, but there will always be enough window onscreen to
270 // drag the whole window back into view. 285 // drag the whole window back into view.
271 gfx::Rect desiredContentRect = browser_->GetSavedWindowBounds(); 286 gfx::Rect desiredContentRect = browser_->GetSavedWindowBounds();
272 gfx::Rect windowRect = desiredContentRect; 287 gfx::Rect windowRect = desiredContentRect;
273 windowRect = [self enforceMinWindowSize:windowRect]; 288 windowRect = [self enforceMinWindowSize:windowRect];
274 289
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 addObserver:self 415 addObserver:self
401 selector:@selector(applicationDidUnhide:) 416 selector:@selector(applicationDidUnhide:)
402 name:NSApplicationDidUnhideNotification 417 name:NSApplicationDidUnhideNotification
403 object:nil]; 418 object:nil];
404 419
405 // This must be done after the view is added to the window since it relies 420 // This must be done after the view is added to the window since it relies
406 // on the window bounds to determine whether to show buttons or not. 421 // on the window bounds to determine whether to show buttons or not.
407 if ([self hasToolbar]) // Do not create the buttons in popups. 422 if ([self hasToolbar]) // Do not create the buttons in popups.
408 [toolbarController_ createBrowserActionButtons]; 423 [toolbarController_ createBrowserActionButtons];
409 424
410 [self setUpOSFullScreenButton];
411
412 // We are done initializing now. 425 // We are done initializing now.
413 initializing_ = NO; 426 initializing_ = NO;
414 } 427 }
415 return self; 428 return self;
416 } 429 }
417 430
418 - (void)awakeFromNib { 431 - (void)awakeFromNib {
419 // Set different minimum sizes on tabbed windows vs non-tabbed, e.g. popups. 432 // Set different minimum sizes on tabbed windows vs non-tabbed, e.g. popups.
420 NSSize minSize = [self isTabbedWindow] ? 433 NSSize minSize = [self isTabbedWindow] ?
421 NSMakeSize(400, 272) : NSMakeSize(100, 122); 434 NSMakeSize(400, 272) : NSMakeSize(100, 122);
422 [[self window] setMinSize:minSize]; 435 [[self window] setMinSize:minSize];
423 } 436 }
424 437
425 - (void)dealloc { 438 - (void)dealloc {
426 browser_->CloseAllTabs(); 439 browser_->CloseAllTabs();
427 [downloadShelfController_ exiting]; 440 [downloadShelfController_ exiting];
428 441
429 // Explicitly release |fullscreenController_| here, as it may call back to 442 // Explicitly release |presentationModeController_| here, as it may call back
430 // this BWC in |-dealloc|. We are required to call |-exitFullscreen| before 443 // to this BWC in |-dealloc|. We are required to call |-exitPresentationMode|
431 // releasing the controller. 444 // before releasing the controller.
432 [fullscreenController_ exitFullscreen]; 445 [presentationModeController_ exitPresentationMode];
433 fullscreenController_.reset(); 446 presentationModeController_.reset();
434 447
435 // Under certain testing configurations we may not actually own the browser. 448 // Under certain testing configurations we may not actually own the browser.
436 if (ownsBrowser_ == NO) 449 if (ownsBrowser_ == NO)
437 ignore_result(browser_.release()); 450 ignore_result(browser_.release());
438 451
439 [[NSNotificationCenter defaultCenter] removeObserver:self]; 452 [[NSNotificationCenter defaultCenter] removeObserver:self];
440 453
441 [super dealloc]; 454 [super dealloc];
442 } 455 }
443 456
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
1011 // one tab. 1024 // one tab.
1012 enable &= [[self window] isKeyWindow]; 1025 enable &= [[self window] isKeyWindow];
1013 break; 1026 break;
1014 case IDC_FULLSCREEN: { 1027 case IDC_FULLSCREEN: {
1015 enable &= [self supportsFullscreen]; 1028 enable &= [self supportsFullscreen];
1016 if ([static_cast<NSObject*>(item) isKindOfClass:[NSMenuItem class]]) { 1029 if ([static_cast<NSObject*>(item) isKindOfClass:[NSMenuItem class]]) {
1017 NSString* menuTitle = l10n_util::GetNSString( 1030 NSString* menuTitle = l10n_util::GetNSString(
1018 [self isFullscreen] ? IDS_EXIT_FULLSCREEN_MAC : 1031 [self isFullscreen] ? IDS_EXIT_FULLSCREEN_MAC :
1019 IDS_ENTER_FULLSCREEN_MAC); 1032 IDS_ENTER_FULLSCREEN_MAC);
1020 [static_cast<NSMenuItem*>(item) setTitle:menuTitle]; 1033 [static_cast<NSMenuItem*>(item) setTitle:menuTitle];
1034
1035 if (base::mac::IsOSSnowLeopardOrEarlier())
1036 [static_cast<NSMenuItem*>(item) setHidden:YES];
1037 }
1038 break;
1039 }
1040 case IDC_PRESENTATION_MODE: {
1041 enable &= [self supportsFullscreen];
1042 if ([static_cast<NSObject*>(item) isKindOfClass:[NSMenuItem class]]) {
1043 NSString* menuTitle = l10n_util::GetNSString(
1044 [self inPresentationMode] ? IDS_EXIT_PRESENTATION_MAC :
1045 IDS_ENTER_PRESENTATION_MAC);
1046 [static_cast<NSMenuItem*>(item) setTitle:menuTitle];
1021 } 1047 }
1022 break; 1048 break;
1023 } 1049 }
1024 case IDC_SYNC_BOOKMARKS: 1050 case IDC_SYNC_BOOKMARKS:
1025 enable &= browser_->profile()->IsSyncAccessible(); 1051 enable &= browser_->profile()->IsSyncAccessible();
1026 sync_ui_util::UpdateSyncItem(item, enable, browser_->profile()); 1052 sync_ui_util::UpdateSyncItem(item, enable, browser_->profile());
1027 break; 1053 break;
1028 default: 1054 default:
1029 // Special handling for the contents of the Text Encoding submenu. On 1055 // Special handling for the contents of the Text Encoding submenu. On
1030 // Mac OS, instead of enabling/disabling the top-level menu item, we 1056 // Mac OS, instead of enabling/disabling the top-level menu item, we
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
1392 DCHECK(!findBarCocoaController_.get()); 1418 DCHECK(!findBarCocoaController_.get());
1393 1419
1394 // Create a controller for the findbar. 1420 // Create a controller for the findbar.
1395 findBarCocoaController_.reset([findBarCocoaController retain]); 1421 findBarCocoaController_.reset([findBarCocoaController retain]);
1396 NSView *contentView = [[self window] contentView]; 1422 NSView *contentView = [[self window] contentView];
1397 [contentView addSubview:[findBarCocoaController_ view] 1423 [contentView addSubview:[findBarCocoaController_ view]
1398 positioned:NSWindowAbove 1424 positioned:NSWindowAbove
1399 relativeTo:[infoBarContainerController_ view]]; 1425 relativeTo:[infoBarContainerController_ view]];
1400 1426
1401 // Place the find bar immediately below the toolbar/attached bookmark bar. In 1427 // Place the find bar immediately below the toolbar/attached bookmark bar. In
1402 // fullscreen mode, it hangs off the top of the screen when the bar is hidden. 1428 // presentation mode, it hangs off the top of the screen when the bar is
1429 // hidden.
1403 CGFloat maxY = [self placeBookmarkBarBelowInfoBar] ? 1430 CGFloat maxY = [self placeBookmarkBarBelowInfoBar] ?
1404 NSMinY([[toolbarController_ view] frame]) : 1431 NSMinY([[toolbarController_ view] frame]) :
1405 NSMinY([[bookmarkBarController_ view] frame]); 1432 NSMinY([[bookmarkBarController_ view] frame]);
1406 CGFloat maxWidth = NSWidth([contentView frame]); 1433 CGFloat maxWidth = NSWidth([contentView frame]);
1407 [findBarCocoaController_ positionFindBarViewAtMaxY:maxY maxWidth:maxWidth]; 1434 [findBarCocoaController_ positionFindBarViewAtMaxY:maxY maxWidth:maxWidth];
1408 1435
1409 // This allows the FindBarCocoaController to call |layoutSubviews| and get 1436 // This allows the FindBarCocoaController to call |layoutSubviews| and get
1410 // its position adjusted. 1437 // its position adjusted.
1411 [findBarCocoaController_ setBrowserWindowController:self]; 1438 [findBarCocoaController_ setBrowserWindowController:self];
1412 } 1439 }
(...skipping 11 matching lines...) Expand all
1424 - (BOOL)hasLiveTabs { 1451 - (BOOL)hasLiveTabs {
1425 return !browser_->tabstrip_model()->empty(); 1452 return !browser_->tabstrip_model()->empty();
1426 } 1453 }
1427 1454
1428 - (NSString*)activeTabTitle { 1455 - (NSString*)activeTabTitle {
1429 TabContents* contents = browser_->GetSelectedTabContents(); 1456 TabContents* contents = browser_->GetSelectedTabContents();
1430 return base::SysUTF16ToNSString(contents->GetTitle()); 1457 return base::SysUTF16ToNSString(contents->GetTitle());
1431 } 1458 }
1432 1459
1433 - (NSRect)regularWindowFrame { 1460 - (NSRect)regularWindowFrame {
1434 return [self isFullscreen] ? [savedRegularWindow_ frame] : 1461 return [self isFullscreen] ? savedRegularWindowFrame_ :
1435 [[self window] frame]; 1462 [[self window] frame];
1436 } 1463 }
1437 1464
1438 // (Override of |TabWindowController| method.) 1465 // (Override of |TabWindowController| method.)
1439 - (BOOL)hasTabStrip { 1466 - (BOOL)hasTabStrip {
1440 return [self supportsWindowFeature:Browser::FEATURE_TABSTRIP]; 1467 return [self supportsWindowFeature:Browser::FEATURE_TABSTRIP];
1441 } 1468 }
1442 1469
1443 // TabContentsControllerDelegate protocol. 1470 // TabContentsControllerDelegate protocol.
1444 - (void)tabContentsViewFrameWillChange:(TabContentsController*)source 1471 - (void)tabContentsViewFrameWillChange:(TabContentsController*)source
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
2007 returnCode:(NSInteger)code 2034 returnCode:(NSInteger)code
2008 context:(void*)context { 2035 context:(void*)context {
2009 [sheet orderOut:self]; 2036 [sheet orderOut:self];
2010 } 2037 }
2011 2038
2012 @end // @implementation BrowserWindowController 2039 @end // @implementation BrowserWindowController
2013 2040
2014 2041
2015 @implementation BrowserWindowController(Fullscreen) 2042 @implementation BrowserWindowController(Fullscreen)
2016 2043
2017 - (IBAction)enterFullscreen:(id)sender { 2044 - (void)handleLionToggleFullscreen {
2045 DCHECK(base::mac::IsOSLionOrLater());
2018 browser_->ExecuteCommand(IDC_FULLSCREEN); 2046 browser_->ExecuteCommand(IDC_FULLSCREEN);
2019 } 2047 }
2020 2048
2049 // On Lion, this method is called by either the Lion fullscreen button or the
2050 // "Enter Full Screen" menu item. On Snow Leopard, this function is never
2051 // called by the UI directly, but it provides the implementation for
2052 // |-setPresentationMode:|.
2021 - (void)setFullscreen:(BOOL)fullscreen { 2053 - (void)setFullscreen:(BOOL)fullscreen {
2022 // The logic in this function is a bit complicated and very carefully
2023 // arranged. See the below comments for more details.
2024
2025 if (fullscreen == [self isFullscreen]) 2054 if (fullscreen == [self isFullscreen])
2026 return; 2055 return;
2027 2056
2028 if (![self supportsFullscreen]) 2057 if (![self supportsFullscreen])
2029 return; 2058 return;
2030 2059
2031 // Fade to black. 2060 if (base::mac::IsOSLionOrLater()) {
2032 const CGDisplayReservationInterval kFadeDurationSeconds = 0.6; 2061 enteredPresentationModeFromFullscreen_ = YES;
2033 Boolean didFadeOut = NO; 2062 if ([[self window] respondsToSelector:@selector(toggleSystemFullScreen)])
Mark Mentovai 2011/08/04 19:18:17 Can you do this as an isKindOfClass check with a c
rohitrao (ping after 24h) 2011/08/04 19:49:17 Done. Why is this better?
Mark Mentovai 2011/08/04 19:56:53 rohitrao wrote:
2034 CGDisplayFadeReservationToken token; 2063 [(id)[self window] toggleSystemFullScreen];
2035 if (CGAcquireDisplayFadeReservation(kFadeDurationSeconds, &token) 2064 return;
2036 == kCGErrorSuccess) {
2037 didFadeOut = YES;
2038 CGDisplayFade(token, kFadeDurationSeconds / 2, kCGDisplayBlendNormal,
2039 kCGDisplayBlendSolidColor, 0.0, 0.0, 0.0, /*synchronous=*/true);
2040 } 2065 }
2041 2066
2042 // Close the bookmark bubble, if it's open. We use |-ok:| instead of 2067 if (fullscreen)
2043 // |-cancel:| or |-close| because that matches the behavior when the bubble 2068 [self enterFullscreenForSnowLeopardOrEarlier];
2044 // loses key status. 2069 else
2045 [bookmarkBubbleController_ ok:self]; 2070 [self exitFullscreenForSnowLeopardOrEarlier];
2071 }
2046 2072
2047 // Save the current first responder so we can restore after views are moved. 2073 - (BOOL)isFullscreen {
2048 NSWindow* window = [self window]; 2074 return (fullscreenWindow_.get() != nil) ||
2049 scoped_nsobject<FocusTracker> focusTracker( 2075 ([[self window] styleMask] & NSFullScreenWindowMask);
2050 [[FocusTracker alloc] initWithWindow:window]); 2076 }
2051 BOOL showDropdown = [self floatingBarHasFocus];
2052 2077
2053 // While we move views (and focus) around, disable any bar visibility changes. 2078 - (void)togglePresentationMode:(id)sender {
2054 [self disableBarVisibilityUpdates]; 2079 // Called only by the presentation mode toggle button.
2080 DCHECK(base::mac::IsOSLionOrLater());
2081 enteredPresentationModeFromFullscreen_ = YES;
2082 browser_->ExecuteCommand(IDC_PRESENTATION_MODE);
2083 }
2055 2084
2056 // If we're entering fullscreen, create the fullscreen controller. If we're 2085 // On Lion, this function is called by either the presentation mode toggle
2057 // exiting fullscreen, kill the controller. 2086 // button or the "Enter Presentation Mode" menu item. In the latter case, this
2058 if (fullscreen) { 2087 // function also triggers the Lion machinery to enter fullscreen mode as well as
2059 fullscreenController_.reset([[FullscreenController alloc] 2088 // set presentation mode. On Snow Leopard, this function is called by the
2060 initWithBrowserController:self]); 2089 // "Enter Presentation Mode" menu item, and triggering presentation mode always
2061 } else { 2090 // moves the user into fullscreen mode.
2062 [fullscreenController_ exitFullscreen]; 2091 - (void)setPresentationMode:(BOOL)presentationMode {
2063 fullscreenController_.reset(); 2092 // Presentation mode on Leopard and Snow Leopard maps directly to fullscreen
2093 // mode.
2094 if (base::mac::IsOSSnowLeopardOrEarlier()) {
2095 [self setFullscreen:presentationMode];
2096 return;
2064 } 2097 }
2065 2098
2066 // Destroy the tab strip's sheet controller. We will recreate it in the new 2099 if (presentationMode) {
2067 // window when needed. 2100 BOOL fullscreen = [self isFullscreen];
2068 [tabStripController_ destroySheetController]; 2101 [self setShouldUsePresentationModeWhenEnteringFullscreen:YES];
2102 enteredPresentationModeFromFullscreen_ = fullscreen;
2069 2103
2070 // Retain the tab strip view while we remove it from its superview. 2104 if (fullscreen) {
2071 scoped_nsobject<NSView> tabStripView; 2105 // If already in fullscreen mode, just toggle the presentation mode
2072 if ([self hasTabStrip] && ![self useVerticalTabs]) { 2106 // setting. Go through an elaborate dance to force the overlay to show,
2073 tabStripView.reset([[self tabStripView] retain]); 2107 // then animate out once the mouse moves away. This helps draw attention
2074 [tabStripView removeFromSuperview]; 2108 // to the fact that the UI is in an overlay. Focus the tab contents
2075 } 2109 // because the omnibox is the most likely source of bar visibility locks,
2076 2110 // and taking focus away from the omnibox releases its lock.
2077 // Ditto for the content view. 2111 [self lockBarVisibilityForOwner:self withAnimation:NO delay:NO];
2078 scoped_nsobject<NSView> contentView([[window contentView] retain]); 2112 [self focusTabContents];
2079 // Disable autoresizing of subviews while we move views around. This prevents 2113 [self setPresentationModeInternal:YES forceDropdown:YES];
2080 // spurious renderer resizes. 2114 [self releaseBarVisibilityForOwner:self withAnimation:YES delay:YES];
2081 [contentView setAutoresizesSubviews:NO]; 2115 } else {
2082 [contentView removeFromSuperview]; 2116 // If not in fullscreen mode, trigger the Lion fullscreen mode machinery.
2083 2117 // Presentation mode will automatically be enabled in
2084 NSWindow* destWindow = nil; 2118 // |-windowWillEnterFullScreen:|.
2085 if (fullscreen) { 2119 if ([[self window] respondsToSelector:@selector(toggleSystemFullScreen)])
2086 DCHECK(!savedRegularWindow_); 2120 [(id)[self window] toggleSystemFullScreen];
2087 savedRegularWindow_ = [window retain]; 2121 }
2088 destWindow = [self createFullscreenWindow];
2089 } else { 2122 } else {
2090 DCHECK(savedRegularWindow_); 2123 if (enteredPresentationModeFromFullscreen_) {
2091 destWindow = [savedRegularWindow_ autorelease]; 2124 // The window is currently in fullscreen mode, but the user is choosing to
2092 savedRegularWindow_ = nil; 2125 // turn presentation mode off (choosing to always show the UI). Set the
2093 } 2126 // preference to ensure that presentation mode will stay off for the next
2094 DCHECK(destWindow); 2127 // window that goes fullscreen.
2095 2128 [self setShouldUsePresentationModeWhenEnteringFullscreen:NO];
2096 // Have to do this here, otherwise later calls can crash because the window 2129 [self setPresentationModeInternal:NO forceDropdown:NO];
2097 // has no delegate. 2130 } else {
2098 [window setDelegate:nil]; 2131 // The user entered presentation mode directly from non-fullscreen mode
2099 [destWindow setDelegate:self]; 2132 // using the "Enter Presentation Mode" menu item and is using that same
2100 2133 // menu item to exit presentation mode. In this case, exit fullscreen
2101 // With this call, valgrind complains that a "Conditional jump or move depends 2134 // mode as well (using the Lion machinery).
2102 // on uninitialised value(s)". The error happens in -[NSThemeFrame 2135 if ([[self window] respondsToSelector:@selector(toggleSystemFullScreen)])
2103 // drawOverlayRect:]. I'm pretty convinced this is an Apple bug, but there is 2136 [(id)[self window] toggleSystemFullScreen];
2104 // no visual impact. I have been unable to tickle it away with other window 2137 }
2105 // or view manipulation Cocoa calls. Stack added to suppressions_mac.txt.
2106 [contentView setAutoresizesSubviews:YES];
2107 [destWindow setContentView:contentView];
2108
2109 // Move the incognito badge if present.
2110 if (avatarButton_.get()) {
2111 [avatarButton_ removeFromSuperview];
2112 [avatarButton_ setHidden:YES]; // Will be shown in layout.
2113 [[[destWindow contentView] superview] addSubview:avatarButton_];
2114 }
2115
2116 // Add the tab strip after setting the content view and moving the incognito
2117 // badge (if any), so that the tab strip will be on top (in the z-order).
2118 if ([self hasTabStrip] && ![self useVerticalTabs])
2119 [[[destWindow contentView] superview] addSubview:tabStripView];
2120
2121 [window setWindowController:nil];
2122 [self setWindow:destWindow];
2123 [destWindow setWindowController:self];
2124 [self adjustUIForFullscreen:fullscreen];
2125
2126 // Adjust the infobar container. In fullscreen, it needs to be below all
2127 // top chrome elements so it only sits atop the web contents. When in normal
2128 // mode, it needs to draw over the bookmark bar and part of the toolbar.
2129 [[infoBarContainerController_ view] removeFromSuperview];
2130 NSView* infoBarDest = [[destWindow contentView] superview];
2131 [infoBarDest addSubview:[infoBarContainerController_ view]
2132 positioned:fullscreen ? NSWindowBelow : NSWindowAbove
2133 relativeTo:fullscreen ? floatingBarBackingView_
2134 : [bookmarkBarController_ view]];
2135
2136 // When entering fullscreen mode, the controller forces a layout for us. When
2137 // exiting, we need to call layoutSubviews manually.
2138 if (fullscreen) {
2139 [fullscreenController_ enterFullscreenForContentView:contentView
2140 showDropdown:showDropdown];
2141 } else {
2142 [self layoutSubviews];
2143 }
2144
2145 // Move the status bubble over, if we have one.
2146 if (statusBubble_)
2147 statusBubble_->SwitchParentWindow(destWindow);
2148
2149 // Move the title over.
2150 [destWindow setTitle:[window title]];
2151
2152 // The window needs to be onscreen before we can set its first responder.
2153 // Ordering the window to the front can change the active Space (either to
2154 // the window's old Space or to the application's assigned Space). To prevent
2155 // this by temporarily change the collectionBehavior.
2156 NSWindowCollectionBehavior behavior = [window collectionBehavior];
2157 [destWindow setCollectionBehavior:
2158 NSWindowCollectionBehaviorMoveToActiveSpace];
2159 [destWindow makeKeyAndOrderFront:self];
2160 [destWindow setCollectionBehavior:behavior];
2161
2162 [focusTracker restoreFocusInWindow:destWindow];
2163 [window orderOut:self];
2164
2165 // We're done moving focus, so re-enable bar visibility changes.
2166 [self enableBarVisibilityUpdates];
2167
2168 // This needs to be done when leaving full-screen mode to ensure that the
2169 // button's action is set properly.
2170 [self setUpOSFullScreenButton];
2171
2172 // Fade back in.
2173 if (didFadeOut) {
2174 CGDisplayFade(token, kFadeDurationSeconds / 2, kCGDisplayBlendSolidColor,
2175 kCGDisplayBlendNormal, 0.0, 0.0, 0.0, /*synchronous=*/false);
2176 CGReleaseDisplayFadeReservation(token);
2177 } 2138 }
2178 } 2139 }
2179 2140
2180 - (BOOL)isFullscreen { 2141 - (BOOL)inPresentationMode {
2181 return fullscreenController_.get() && [fullscreenController_ isFullscreen]; 2142 return presentationModeController_.get() &&
2143 [presentationModeController_ inPresentationMode];
2182 } 2144 }
2183 2145
2184 - (void)resizeFullscreenWindow { 2146 - (void)resizeFullscreenWindow {
2185 DCHECK([self isFullscreen]); 2147 DCHECK([self isFullscreen]);
2186 if (![self isFullscreen]) 2148 if (![self isFullscreen])
2187 return; 2149 return;
2188 2150
2189 NSWindow* window = [self window]; 2151 NSWindow* window = [self window];
2190 [window setFrame:[[window screen] frame] display:YES]; 2152 [window setFrame:[[window screen] frame] display:YES];
2191 [self layoutSubviews]; 2153 [self layoutSubviews];
(...skipping 13 matching lines...) Expand all
2205 DCHECK(barVisibilityLocks_); 2167 DCHECK(barVisibilityLocks_);
2206 return [barVisibilityLocks_ containsObject:owner]; 2168 return [barVisibilityLocks_ containsObject:owner];
2207 } 2169 }
2208 2170
2209 - (void)lockBarVisibilityForOwner:(id)owner 2171 - (void)lockBarVisibilityForOwner:(id)owner
2210 withAnimation:(BOOL)animate 2172 withAnimation:(BOOL)animate
2211 delay:(BOOL)delay { 2173 delay:(BOOL)delay {
2212 if (![self isBarVisibilityLockedForOwner:owner]) { 2174 if (![self isBarVisibilityLockedForOwner:owner]) {
2213 [barVisibilityLocks_ addObject:owner]; 2175 [barVisibilityLocks_ addObject:owner];
2214 2176
2215 // If enabled, show the overlay if necessary (and if in fullscreen mode). 2177 // If enabled, show the overlay if necessary (and if in presentation mode).
2216 if (barVisibilityUpdatesEnabled_) { 2178 if (barVisibilityUpdatesEnabled_) {
2217 [fullscreenController_ ensureOverlayShownWithAnimation:animate 2179 [presentationModeController_ ensureOverlayShownWithAnimation:animate
2218 delay:delay]; 2180 delay:delay];
2219 } 2181 }
2220 } 2182 }
2221 } 2183 }
2222 2184
2223 - (void)releaseBarVisibilityForOwner:(id)owner 2185 - (void)releaseBarVisibilityForOwner:(id)owner
2224 withAnimation:(BOOL)animate 2186 withAnimation:(BOOL)animate
2225 delay:(BOOL)delay { 2187 delay:(BOOL)delay {
2226 if ([self isBarVisibilityLockedForOwner:owner]) { 2188 if ([self isBarVisibilityLockedForOwner:owner]) {
2227 [barVisibilityLocks_ removeObject:owner]; 2189 [barVisibilityLocks_ removeObject:owner];
2228 2190
2229 // If enabled, hide the overlay if necessary (and if in fullscreen mode). 2191 // If enabled, hide the overlay if necessary (and if in presentation mode).
2230 if (barVisibilityUpdatesEnabled_ && 2192 if (barVisibilityUpdatesEnabled_ &&
2231 ![barVisibilityLocks_ count]) { 2193 ![barVisibilityLocks_ count]) {
2232 [fullscreenController_ ensureOverlayHiddenWithAnimation:animate 2194 [presentationModeController_ ensureOverlayHiddenWithAnimation:animate
2233 delay:delay]; 2195 delay:delay];
2234 } 2196 }
2235 } 2197 }
2236 } 2198 }
2237 2199
2238 - (BOOL)floatingBarHasFocus { 2200 - (BOOL)floatingBarHasFocus {
2239 NSResponder* focused = [[self window] firstResponder]; 2201 NSResponder* focused = [[self window] firstResponder];
2240 return [focused isKindOfClass:[AutocompleteTextFieldEditor class]]; 2202 return [focused isKindOfClass:[AutocompleteTextFieldEditor class]];
2241 } 2203 }
2242 2204
2243 - (void)tabposeWillClose:(NSNotification*)notif { 2205 - (void)tabposeWillClose:(NSNotification*)notif {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
2305 2267
2306 - (BOOL)supportsBookmarkBar { 2268 - (BOOL)supportsBookmarkBar {
2307 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; 2269 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR];
2308 } 2270 }
2309 2271
2310 - (BOOL)isTabbedWindow { 2272 - (BOOL)isTabbedWindow {
2311 return browser_->is_type_tabbed(); 2273 return browser_->is_type_tabbed();
2312 } 2274 }
2313 2275
2314 @end // @implementation BrowserWindowController(WindowType) 2276 @end // @implementation BrowserWindowController(WindowType)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698