Commit a9900086 authored by erikchen's avatar erikchen Committed by Commit bot

mac: Add traffic lights to fullscreen mode in Yosemite.

No fancy animations, this just adds basic functionality. In fullscreen mode,
the tabs are shifted over, and traffic light buttons are manually added in.

BUG=405564

Review URL: https://codereview.chromium.org/508313002

Cr-Commit-Position: refs/heads/master@{#293357}
parent b83f02af
......@@ -333,9 +333,21 @@ willPositionSheet:(NSWindow*)sheet
maxY -= tabStripHeight;
[tabStripView setFrame:NSMakeRect(0, maxY, width, tabStripHeight)];
// In Yosemite fullscreen, manually add the fullscreen controls to the tab
// strip.
BOOL addControlsInFullscreen =
[self isInAppKitFullscreen] && base::mac::IsOSYosemiteOrLater();
// Set left indentation based on fullscreen mode status.
[tabStripController_ setLeftIndentForControls:(fullscreen ? 0 :
[[tabStripController_ class] defaultLeftIndentForControls])];
CGFloat leftIndent = 0;
if (!fullscreen || addControlsInFullscreen)
leftIndent = [[tabStripController_ class] defaultLeftIndentForControls];
[tabStripController_ setLeftIndentForControls:leftIndent];
if (addControlsInFullscreen)
[tabStripController_ addWindowControls];
else
[tabStripController_ removeWindowControls];
// Lay out the icognito/avatar badge because calculating the indentation on
// the right depends on it.
......
......@@ -139,6 +139,10 @@ class WebContents;
// Helper for performing tab selection as a result of dragging over a tab.
scoped_ptr<HoverTabSelector> hoverTabSelector_;
// A container view for the window controls, which must be manually added in
// fullscreen in 10.10+.
base::scoped_nsobject<NSView> fullscreenWindowControls_;
}
@property(nonatomic) CGFloat leftIndentForControls;
......@@ -248,6 +252,12 @@ class WebContents;
// Returns the currently active TabContentsController.
- (TabContentsController*)activeTabContentsController;
// Adds traffic lights to the tab strip. Idempotent.
- (void)addWindowControls;
// Removes traffic lights from the tab strip. Idempotent.
- (void)removeWindowControls;
@end
@interface TabStripController(TestingAPI)
......
......@@ -2172,6 +2172,56 @@ NSImage* Overlay(NSImage* ground, NSImage* overlay, CGFloat alpha) {
return [tabContentsArray_ objectAtIndex:index];
}
- (void)addWindowControls {
if (!fullscreenWindowControls_) {
// Make the container view.
CGFloat height = NSHeight([tabStripView_ frame]);
NSRect frame = NSMakeRect(0, 0, [self leftIndentForControls], height);
fullscreenWindowControls_.reset([[NSView alloc] initWithFrame:frame]);
[fullscreenWindowControls_
setAutoresizingMask:NSViewMaxXMargin | NSViewHeightSizable];
// Add the traffic light buttons. The horizontal layout was determined by
// manual inspection on Yosemite.
CGFloat closeButtonX = 11;
CGFloat miniButtonX = 31;
CGFloat zoomButtonX = 51;
NSUInteger styleMask = [[tabStripView_ window] styleMask];
NSButton* closeButton = [NSWindow standardWindowButton:NSWindowCloseButton
forStyleMask:styleMask];
// Vertically center the buttons in the tab strip.
CGFloat buttonY = floor((height - NSHeight([closeButton bounds])) / 2);
[closeButton setFrameOrigin:NSMakePoint(closeButtonX, buttonY)];
[fullscreenWindowControls_ addSubview:closeButton];
NSButton* miniaturizeButton =
[NSWindow standardWindowButton:NSWindowMiniaturizeButton
forStyleMask:styleMask];
[miniaturizeButton setFrameOrigin:NSMakePoint(miniButtonX, buttonY)];
[miniaturizeButton setEnabled:NO];
[fullscreenWindowControls_ addSubview:miniaturizeButton];
NSButton* zoomButton =
[NSWindow standardWindowButton:NSWindowZoomButton
forStyleMask:styleMask];
[fullscreenWindowControls_ addSubview:zoomButton];
[zoomButton setFrameOrigin:NSMakePoint(zoomButtonX, buttonY)];
}
if (![permanentSubviews_ containsObject:fullscreenWindowControls_]) {
[self addSubviewToPermanentList:fullscreenWindowControls_];
[self regenerateSubviewList];
}
}
- (void)removeWindowControls {
if (fullscreenWindowControls_)
[permanentSubviews_ removeObject:fullscreenWindowControls_];
[self regenerateSubviewList];
}
- (void)themeDidChangeNotification:(NSNotification*)notification {
[self setNewTabImages];
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment