Skip to content

Commit

Permalink
fix: respect minimizable/closable for customButtonsOnHover (#18425)
Browse files Browse the repository at this point in the history
This PR ameliorates an issue whereby minimizable and closable weren't respected in customButtonsOnHover mode. maximizable isn't addressable here, since it's been blanket disabled in newer versions of macOS owing to an issue with the NSWindowStyleMaskFullSizeContentView style mask.
  • Loading branch information
codebytere committed May 28, 2019
1 parent 01cd6e7 commit 1688ebd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion atom/browser/native_window_mac.h
Expand Up @@ -167,7 +167,7 @@ class NativeWindowMac : public NativeWindow {

private:
// Add custom layers to the content view.
void AddContentViewLayers();
void AddContentViewLayers(bool minimizable, bool closable);

void InternalSetParentWindow(NativeWindow* parent, bool attach);
void SetForwardMouseMessages(bool forward);
Expand Down
42 changes: 24 additions & 18 deletions atom/browser/native_window_mac.mm
Expand Up @@ -74,9 +74,11 @@ - (id)initWithFrame:(NSRect)frame {
NSButton* close_button =
[NSWindow standardWindowButton:NSWindowCloseButton
forStyleMask:NSWindowStyleMaskTitled];
[close_button setTag:1];
NSButton* miniaturize_button =
[NSWindow standardWindowButton:NSWindowMiniaturizeButton
forStyleMask:NSWindowStyleMaskTitled];
[miniaturize_button setTag:2];

CGFloat x = 0;
const CGFloat space_between = 20;
Expand Down Expand Up @@ -320,26 +322,23 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
}

NSUInteger styleMask = NSWindowStyleMaskTitled;
if (title_bar_style_ == TitleBarStyle::CUSTOM_BUTTONS_ON_HOVER &&
(!useStandardWindow || transparent() || !has_frame())) {
bool customOnHover =
title_bar_style_ == TitleBarStyle::CUSTOM_BUTTONS_ON_HOVER;
if (customOnHover && (!useStandardWindow || transparent() || !has_frame()))
styleMask = NSWindowStyleMaskFullSizeContentView;
}
if (minimizable) {

if (minimizable)
styleMask |= NSMiniaturizableWindowMask;
}
if (closable) {
if (closable)
styleMask |= NSWindowStyleMaskClosable;
}
if (title_bar_style_ != TitleBarStyle::NORMAL) {
// The window without titlebar is treated the same with frameless window.
if (resizable_)
styleMask |= NSResizableWindowMask;

// The window without titlebar is treated the same with frameless window.
if (title_bar_style_ != TitleBarStyle::NORMAL)
set_has_frame(false);
}
if (!useStandardWindow || transparent() || !has_frame()) {
if (!useStandardWindow || transparent() || !has_frame())
styleMask |= NSTexturedBackgroundWindowMask;
}
if (resizable_) {
styleMask |= NSResizableWindowMask;
}

// Create views::Widget and assign window_ with it.
// TODO(zcbenz): Get rid of the window_ in future.
Expand Down Expand Up @@ -461,7 +460,7 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {

// Default content view.
SetContentView(new views::View());
AddContentViewLayers();
AddContentViewLayers(minimizable, closable);

original_frame_ = [window_ frame];
original_level_ = [window_ level];
Expand Down Expand Up @@ -1386,7 +1385,7 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
return root_view_.get();
}

void NativeWindowMac::AddContentViewLayers() {
void NativeWindowMac::AddContentViewLayers(bool minimizable, bool closable) {
// Make sure the bottom corner is rounded for non-modal windows:
// http://crbug.com/396264.
if (!is_modal()) {
Expand Down Expand Up @@ -1424,8 +1423,15 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
if (title_bar_style_ == TitleBarStyle::CUSTOM_BUTTONS_ON_HOVER) {
buttons_view_.reset(
[[CustomWindowButtonView alloc] initWithFrame:NSZeroRect]);

// NSWindowStyleMaskFullSizeContentView does not work with zoom button
SetFullScreenable(false);

if (!minimizable)
[[buttons_view_ viewWithTag:2] removeFromSuperview];
if (!closable)
[[buttons_view_ viewWithTag:1] removeFromSuperview];

[[window_ contentView] addSubview:buttons_view_];
} else {
if (title_bar_style_ != TitleBarStyle::NORMAL)
Expand Down Expand Up @@ -1482,7 +1488,7 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[container_view_ setFrame:[[[window_ contentView] superview] bounds]];
[window_ setContentView:container_view_];
AddContentViewLayers();
AddContentViewLayers(IsMinimizable(), IsClosable());
}

void NativeWindowMac::SetStyleMask(bool on, NSUInteger flag) {
Expand Down

0 comments on commit 1688ebd

Please sign in to comment.