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

Unified Diff: chrome/browser/ui/cocoa/browser_window_controller_private.mm

Issue 493143004: mac: Major fullscreen refactor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix 2 minor bugs, remove 2 unit tests that no longer test anything. Created 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/browser_window_controller_private.mm
diff --git a/chrome/browser/ui/cocoa/browser_window_controller_private.mm b/chrome/browser/ui/cocoa/browser_window_controller_private.mm
index 00bc9a2d7f6f39bcc704b66cfc704b58e0758ef1..9cff4d3304f650f1e7bb99fd543d5ca915ab33cc 100644
--- a/chrome/browser/ui/cocoa/browser_window_controller_private.mm
+++ b/chrome/browser/ui/cocoa/browser_window_controller_private.mm
@@ -23,7 +23,6 @@
#import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h"
#import "chrome/browser/ui/cocoa/floating_bar_backing_view.h"
#import "chrome/browser/ui/cocoa/framed_browser_window.h"
-#import "chrome/browser/ui/cocoa/fullscreen_mode_controller.h"
#import "chrome/browser/ui/cocoa/fullscreen_window.h"
#import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h"
#include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h"
@@ -90,7 +89,9 @@ const CGFloat kLocBarBottomInset = 1;
// If we're in fullscreen mode, save the position of the regular window
// instead.
- NSWindow* window = [self isFullscreen] ? savedRegularWindow_ : [self window];
+ NSWindow* window = [self isInOrEnteringAnyFullscreenMode]
+ ? savedRegularWindow_
+ : [self window];
// Window positions are stored relative to the origin of the primary monitor.
NSRect monitorFrame = [[[NSScreen screens] objectAtIndex:0] frame];
@@ -105,7 +106,7 @@ const CGFloat kLocBarBottomInset = 1;
ui::WindowShowState show_state = ui::SHOW_STATE_NORMAL;
if ([window isMiniaturized])
show_state = ui::SHOW_STATE_MINIMIZED;
- else if ([self isFullscreen])
+ else if ([self isInOrEnteringAnyFullscreenMode])
show_state = ui::SHOW_STATE_FULLSCREEN;
chrome::SaveWindowPlacement(browser_.get(), bounds, show_state);
@@ -188,23 +189,47 @@ willPositionSheet:(NSWindow*)sheet
CGFloat minY = NSMinY(contentBounds);
CGFloat width = NSWidth(contentBounds);
- BOOL useSimplifiedFullscreen = CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kEnableSimplifiedFullscreen);
-
// Suppress title drawing if necessary.
if ([window respondsToSelector:@selector(setShouldHideTitle:)])
[(id)window setShouldHideTitle:![self hasTitleBar]];
// Update z-order. The code below depends on this.
- [self updateSubviewZOrder:[self inPresentationMode]];
+ [self updateSubviewZOrder:[self isInFullscreenWithOmniboxSliding]];
- BOOL inPresentationMode = [self inPresentationMode];
CGFloat floatingBarHeight = [self floatingBarHeight];
- // In presentation mode, |yOffset| accounts for the sliding position of the
- // floating bar and the extra offset needed to dodge the menu bar.
- CGFloat yOffset = inPresentationMode && !useSimplifiedFullscreen ?
- (std::floor((1 - floatingBarShownFraction_) * floatingBarHeight) -
- [presentationModeController_ floatingBarVerticalOffset]) : 0;
+ CGFloat yOffset = 0;
+ if ([self isInFullscreenWithOmniboxSliding]) {
+ switch (fullscreenStyle_) {
+ case fullscreen_mac::OMNIBOX_TABS_PRESENT:
+ // In system fullscreen mode, |yOffset| accounts for the extra offset
+ // needed to dodge the menu bar.
+ yOffset = -std::floor(
+ (floatingBarShownFraction_) *
+ [presentationModeController_ floatingBarVerticalOffset]);
+ break;
+ case fullscreen_mac::OMNIBOX_PRESENT: {
+ // At rest: omnibox showing. yOffset should be tabstrip height
+ // When cursor is at top: everything shows. yOffset should be -menubar
+ // height.
+ CGFloat tabStripHeight = 0;
+ if ([self hasTabStrip])
+ tabStripHeight = NSHeight([[self tabStripView] frame]);
+ yOffset = std::floor(
+ (1 - floatingBarShownFraction_) * tabStripHeight -
+ floatingBarShownFraction_ *
+ [presentationModeController_ floatingBarVerticalOffset]);
+ break;
+ }
+ case fullscreen_mac::OMNIBOX_TABS_HIDDEN:
+ // In presentation mode, |yOffset| accounts for the sliding position of
+ // the floating bar and the extra offset needed to dodge the menu bar.
+ yOffset =
+ std::floor((1 - floatingBarShownFraction_) * floatingBarHeight) -
+ [presentationModeController_ floatingBarVerticalOffset];
+ break;
+ }
+ }
+
CGFloat maxY = NSMaxY(contentBounds) + yOffset;
if ([self hasTabStrip]) {
@@ -212,20 +237,9 @@ willPositionSheet:(NSWindow*)sheet
// value, and then lay out the tab strip.
NSRect windowFrame = [contentView convertRect:[window frame] fromView:nil];
maxY = NSHeight(windowFrame) + yOffset;
- if (useSimplifiedFullscreen && [self isFullscreen]) {
- CGFloat tabStripHeight = NSHeight([[self tabStripView] frame]);
- CGFloat revealAmount = (1 - floatingBarShownFraction_) * tabStripHeight;
- // In simplified fullscreen, only the toolbar is visible by default, and
- // the tabstrip and menu bar come down (each separately) when the user
- // mouses near the top of the window. Push the maxY of the toolbar up by
- // the amount of the tabstrip that is revealed, while removing the amount
- // of space needed by the menu bar.
- maxY += std::floor(
- revealAmount - [fullscreenModeController_ menuBarHeight]);
- }
maxY = [self layoutTabStripAtMaxY:maxY
width:width
- fullscreen:[self isFullscreen]];
+ fullscreen:[self isInOrEnteringAnyFullscreenMode]];
}
// Sanity-check |maxY|.
@@ -245,7 +259,7 @@ willPositionSheet:(NSWindow*)sheet
NSRect floatingBarBackingRect =
NSMakeRect(minX, maxY, width, floatingBarHeight);
[self layoutFloatingBarBackingView:floatingBarBackingRect
- presentationMode:inPresentationMode];
+ presentationMode:[self isInFullscreenWithOmniboxSliding]];
// Place the find bar immediately below the toolbar/attached bookmark bar. In
// presentation mode, it hangs off the top of the screen when the bar is
@@ -253,11 +267,20 @@ willPositionSheet:(NSWindow*)sheet
[findBarCocoaController_ positionFindBarViewAtMaxY:maxY maxWidth:width];
[fullscreenExitBubbleController_ positionInWindowAtTop:maxY width:width];
- // If in presentation mode, reset |maxY| to top of screen, so that the
- // floating bar slides over the things which appear to be in the content area.
- if (inPresentationMode ||
- (useSimplifiedFullscreen && !fullscreenUrl_.is_empty())) {
- maxY = NSMaxY(contentBounds);
+ if ([self isInFullscreenWithOmniboxSliding]) {
+ switch (fullscreenStyle_) {
+ case fullscreen_mac::OMNIBOX_TABS_PRESENT:
+ case fullscreen_mac::OMNIBOX_PRESENT:
+ // Do nothing in system fullscreen and simplified fullscreen. All
+ // content slides.
+ break;
+ case fullscreen_mac::OMNIBOX_TABS_HIDDEN:
+ // If in presentation mode, reset |maxY| to top of screen, so that the
+ // floating bar slides over the things which appear to be in the content
+ // area.
+ maxY = NSMaxY(contentBounds);
+ break;
+ }
}
// Also place the info bar container immediate below the toolbar, except in
@@ -281,10 +304,12 @@ willPositionSheet:(NSWindow*)sheet
}
- (CGFloat)floatingBarHeight {
- if (![self inPresentationMode])
+ if (![self isInFullscreenWithOmniboxSliding])
return 0;
- CGFloat totalHeight = [presentationModeController_ floatingBarVerticalOffset];
+ CGFloat totalHeight = 0;
+ if (presentationModeController_)
+ totalHeight = [presentationModeController_ floatingBarVerticalOffset];
if ([self hasTabStrip])
totalHeight += NSHeight([[self tabStripView] frame]);
@@ -328,7 +353,7 @@ willPositionSheet:(NSWindow*)sheet
if ([self shouldUseNewAvatarButton]) {
// The fullscreen icon is displayed to the right of the avatar button.
- if (![self isFullscreen])
+ if (![self isInOrEnteringAnyFullscreenMode])
badgeXOffset -= kFullscreenIconWidth;
// Center the button vertically on the tabstrip.
badgeYOffset = (tabStripHeight - buttonHeight) / 2;
@@ -364,7 +389,7 @@ willPositionSheet:(NSWindow*)sheet
// When the fullscreen icon is not displayed, return its width to the
// tabstrip.
- if ([self isFullscreen])
+ if ([self isInOrEnteringAnyFullscreenMode])
rightIndent -= kFullscreenIconWidth;
}
} else if ([self shouldShowAvatar]) {
@@ -515,7 +540,8 @@ willPositionSheet:(NSWindow*)sheet
}
- (void)updateRoundedBottomCorners {
- [[self tabContentArea] setRoundedBottomCorners:![self isFullscreen]];
+ [[self tabContentArea]
+ setRoundedBottomCorners:![self isInOrEnteringAnyFullscreenMode]];
}
- (void)adjustToolbarAndBookmarkBarForCompression:(CGFloat)compression {
@@ -643,22 +669,13 @@ willPositionSheet:(NSWindow*)sheet
delay:YES];
}
-- (void)setPresentationModeInternal:(BOOL)presentationMode
- forceDropdown:(BOOL)forceDropdown {
- if (presentationMode == [self inPresentationMode])
- return;
-
- if (presentationMode) {
+- (BOOL)commonAppKitFullscreenSetup {
Robert Sesek 2014/08/27 22:04:30 nit: method indention is off
erikchen 2014/08/28 00:50:28 You're right. Wonder why clang-format didn't catch
BOOL fullscreen_for_tab =
browser_->fullscreen_controller()->IsWindowFullscreenForTabOrPending();
BOOL kiosk_mode =
CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode);
- BOOL showDropdown = !fullscreen_for_tab &&
- !kiosk_mode &&
- (forceDropdown || [self floatingBarHasFocus]);
- presentationModeController_.reset(
- [[PresentationModeController alloc] initWithBrowserController:self]);
-
+ BOOL showDropdown =
+ !fullscreen_for_tab && !kiosk_mode && ([self floatingBarHasFocus]);
if (permissionBubbleCocoa_ && permissionBubbleCocoa_->IsVisible()) {
DCHECK(permissionBubbleCocoa_->window());
// A visible permission bubble will force the dropdown to remain visible.
@@ -686,20 +703,51 @@ willPositionSheet:(NSWindow*)sheet
windowViewWantsLayer_ = [[[self window] cr_windowView] wantsLayer];
[[[self window] cr_windowView] setWantsLayer:YES];
}
- NSView* contentView = [[self window] contentView];
- [presentationModeController_ enterPresentationModeForContentView:contentView
- showDropdown:showDropdown];
- } else {
+ return showDropdown;
+}
+
+- (void)adjustUIForExitingFullscreenAndStopOmniboxSliding {
+ [presentationModeController_ exitPresentationMode];
+ presentationModeController_.reset();
+
+ // Force the bookmark bar z-order to update.
+ [[bookmarkBarController_ view] removeFromSuperview];
+ [self layoutSubviews];
+}
+
+- (void)adjustUIForSlidingFullscreenStyle:(fullscreen_mac::SlidingStyle)style {
+ fullscreenStyle_ = style;
+
+ if (!presentationModeController_) {
+ // Kill the "fullscreen" controller if needed.
+ // TODO: consider not doing this?
[presentationModeController_ exitPresentationMode];
- presentationModeController_.reset();
+ presentationModeController_.reset(
+ [[PresentationModeController alloc] initWithBrowserController:self]);
+
+ BOOL showDropdown = [self commonAppKitFullscreenSetup];
+
+ NSView* contentView = [[self window] contentView];
+ [presentationModeController_
+ enterPresentationModeForContentView:contentView
+ showDropdown:showDropdown];
+ }
+
+ if (!floatingBarBackingView_.get() &&
+ ([self hasTabStrip] || [self hasToolbar] || [self hasLocationBar])) {
+ floatingBarBackingView_.reset(
+ [[FloatingBarBackingView alloc] initWithFrame:NSZeroRect]);
+ [floatingBarBackingView_
+ setAutoresizingMask:(NSViewWidthSizable | NSViewMinYMargin)];
}
- [self adjustUIForPresentationMode:presentationMode];
+ // Force the bookmark bar z-order to update.
+ [[bookmarkBarController_ view] removeFromSuperview];
[self layoutSubviews];
}
- (void)enterImmersiveFullscreen {
- // |-isFullscreen:| will return YES from here onwards.
+ // |-isInOrEnteringAnyFullscreenMode| will return YES from here onwards.
enteringFullscreen_ = YES; // Set to NO by |-windowDidEnterFullScreen:|.
// Fade to black.
@@ -724,12 +772,13 @@ willPositionSheet:(NSWindow*)sheet
// When simplified fullscreen is enabled, do not enter presentation mode.
const CommandLine* command_line = CommandLine::ForCurrentProcess();
+ fullscreen_mac::SlidingStyle style;
if (command_line->HasSwitch(switches::kEnableSimplifiedFullscreen)) {
- // TODO(rohitrao): Add code to manage the menubar here.
+ style = fullscreen_mac::OMNIBOX_PRESENT;
} else {
- [self adjustUIForPresentationMode:YES];
- [self setPresentationModeInternal:YES forceDropdown:NO];
+ style = fullscreen_mac::OMNIBOX_TABS_HIDDEN;
}
+ [self adjustUIForSlidingFullscreenStyle:style];
// AppKit is helpful and prevents NSWindows from having the same height as
// the screen while the menu bar is showing. This only applies to windows on
@@ -799,24 +848,6 @@ willPositionSheet:(NSWindow*)sheet
}
}
-// TODO(rohitrao): This function has shrunk into uselessness, and
-// |-setFullscreen:| has grown rather large. Find a good way to break up
-// |-setFullscreen:| into smaller pieces. http://crbug.com/36449
-- (void)adjustUIForPresentationMode:(BOOL)fullscreen {
- // Create the floating bar backing view if necessary.
- if (fullscreen && !floatingBarBackingView_.get() &&
- ([self hasTabStrip] || [self hasToolbar] || [self hasLocationBar])) {
- floatingBarBackingView_.reset(
- [[FloatingBarBackingView alloc] initWithFrame:NSZeroRect]);
- [floatingBarBackingView_ setAutoresizingMask:(NSViewWidthSizable |
- NSViewMinYMargin)];
- }
-
- // Force the bookmark bar z-order to update.
- [[bookmarkBarController_ view] removeFromSuperview];
- [self updateSubviewZOrder:fullscreen];
-}
-
- (void)showFullscreenExitBubbleIfNecessary {
// This method is called in response to
// |-updateFullscreenExitBubbleURL:bubbleType:|. If we're in the middle of the
@@ -890,7 +921,17 @@ willPositionSheet:(NSWindow*)sheet
BOOL mode = enteringPresentationMode_ ||
browser_->fullscreen_controller()->IsWindowFullscreenForTabOrPending();
enteringFullscreen_ = YES;
- [self setPresentationModeInternal:mode forceDropdown:NO];
+
+ fullscreen_mac::SlidingStyle style;
+ const CommandLine* command_line = CommandLine::ForCurrentProcess();
+ if (command_line->HasSwitch(switches::kEnableSimplifiedFullscreen))
+ style = fullscreen_mac::OMNIBOX_PRESENT;
+ else if (mode)
+ style = fullscreen_mac::OMNIBOX_TABS_HIDDEN;
+ else
+ style = fullscreen_mac::OMNIBOX_TABS_PRESENT;
+
+ [self adjustUIForSlidingFullscreenStyle:style];
}
- (void)windowDidEnterFullScreen:(NSNotification*)notification {
@@ -912,13 +953,6 @@ willPositionSheet:(NSWindow*)sheet
enteringFullscreen_ = NO;
enteringPresentationMode_ = NO;
- const CommandLine* command_line = CommandLine::ForCurrentProcess();
- if (command_line->HasSwitch(switches::kEnableSimplifiedFullscreen) &&
- fullscreenUrl_.is_empty()) {
- fullscreenModeController_.reset([[FullscreenModeController alloc]
- initWithBrowserWindowController:self]);
- }
-
[self showFullscreenExitBubbleIfNecessary];
browser_->WindowFullscreenStateChanged();
[[[self window] cr_windowView] setWantsLayer:windowViewWantsLayer_];
@@ -928,9 +962,8 @@ willPositionSheet:(NSWindow*)sheet
- (void)windowWillExitFullScreen:(NSNotification*)notification {
if (notification) // For System Fullscreen when non-nil.
[self registerForContentViewResizeNotifications];
- fullscreenModeController_.reset();
[self destroyFullscreenExitBubbleIfNecessary];
- [self setPresentationModeInternal:NO forceDropdown:NO];
+ [self adjustUIForExitingFullscreenAndStopOmniboxSliding];
}
- (void)windowDidExitFullScreen:(NSNotification*)notification {
@@ -943,10 +976,7 @@ willPositionSheet:(NSWindow*)sheet
- (void)windowDidFailToEnterFullScreen:(NSWindow*)window {
[self deregisterForContentViewResizeNotifications];
enteringFullscreen_ = NO;
- [self setPresentationModeInternal:NO forceDropdown:NO];
-
- // Force a relayout to try and get the window back into a reasonable state.
- [self layoutSubviews];
+ [self adjustUIForExitingFullscreenAndStopOmniboxSliding];
}
- (void)windowDidFailToExitFullScreen:(NSWindow*)window {
@@ -989,11 +1019,17 @@ willPositionSheet:(NSWindow*)sheet
return [bookmarkBarController_ toolbarDividerOpacity];
}
-- (void)updateSubviewZOrder:(BOOL)inPresentationMode {
+// TODO(erikchen): The implementation of this method is quite fragile. The
+// method cr_ensureSubview:... does not check that the subview is /directly/
+// above/below the given view. e.g. I have 3 subviews: A, B, C, in that order.
+// The method cr_ensureSubviuw:A isPositioned:NSWindowBelow relativeTo:C will
+// have no effect, even though the desired result may have been: B, A, C.
+// Consider changing it?
+- (void)updateSubviewZOrder:(BOOL)inAnyFullscreen {
NSView* contentView = [[self window] contentView];
NSView* toolbarView = [toolbarController_ view];
- if (inPresentationMode) {
+ if (inAnyFullscreen) {
// Toolbar is above tab contents so that it can slide down from top of
// screen.
[contentView cr_ensureSubview:toolbarView
@@ -1012,7 +1048,7 @@ willPositionSheet:(NSWindow*)sheet
isPositioned:NSWindowBelow
relativeTo:toolbarView];
- if (inPresentationMode) {
+ if (inAnyFullscreen) {
// In presentation mode the info bar is below all other views.
[contentView cr_ensureSubview:[infoBarContainerController_ view]
isPositioned:NSWindowBelow
@@ -1028,7 +1064,7 @@ willPositionSheet:(NSWindow*)sheet
// The find bar is above everything.
if (findBarCocoaController_) {
NSView* relativeView = nil;
- if (inPresentationMode)
+ if (inAnyFullscreen)
relativeView = toolbarView;
else
relativeView = [self tabContentArea];
@@ -1049,6 +1085,46 @@ willPositionSheet:(NSWindow*)sheet
isPositioned:NSWindowBelow
relativeTo:[bookmarkBarController_ view]];
}
+
+ // TODO(erikchen): This constraint is necessary. See comment at the
+ // beginning of the method.
+ [contentView cr_ensureSubview:floatingBarBackingView_
+ isPositioned:NSWindowAbove
+ relativeTo:[self tabContentArea]];
+ }
+
+ // TODO(erikchen): Remove and then add the tabStripView to the root NSView.
+ // This fixes a layer ordering problem that occurs between the contentView
+ // and the tabStripView. This is a hack required because NSThemeFrame is not
+ // layer backed, and because we add subviews directly to the NSThemeFrame.
+ // http://crbug.com/407921
+ if (enteringFullscreen_) {
+ // Disable implicit animations.
+ [CATransaction begin];
+ [CATransaction setDisableActions:YES];
+
+ // Get the current position of the tabStripView.
+ NSView* superview = [[self tabStripView] superview];
+ NSArray* subviews = [superview subviews];
+ NSInteger index = [subviews indexOfObject:[self tabStripView]];
+ NSView* siblingBelow = nil;
+ if (index > 0)
+ siblingBelow = [subviews objectAtIndex:index - 1];
+
+ // Remove the tabStripView.
+ [[self tabStripView] removeFromSuperview];
+
+ // Add it to the same position.
+ if (siblingBelow)
Robert Sesek 2014/08/27 22:04:30 nit: needs braces since body is multi-line
erikchen 2014/08/28 00:50:28 Done.
+ [superview addSubview:[self tabStripView]
+ positioned:NSWindowAbove
+ relativeTo:siblingBelow];
+ else
+ [superview addSubview:[self tabStripView]
+ positioned:NSWindowBelow
+ relativeTo:nil];
+
+ [CATransaction commit];
}
}
@@ -1058,4 +1134,18 @@ willPositionSheet:(NSWindow*)sheet
setShouldSuppressTopInfoBarTip:![self hasToolbar]];
}
+- (void)enterAppKitFullscreen {
+ if (FramedBrowserWindow* framedBrowserWindow =
+ base::mac::ObjCCast<FramedBrowserWindow>([self window])) {
+ [framedBrowserWindow toggleSystemFullScreen];
+ }
+}
+
+- (void)exitAppKitFullscreen {
+ if (FramedBrowserWindow* framedBrowserWindow =
+ base::mac::ObjCCast<FramedBrowserWindow>([self window])) {
+ [framedBrowserWindow toggleSystemFullScreen];
+ }
+}
+
@end // @implementation BrowserWindowController(Private)

Powered by Google App Engine
This is Rietveld 408576698