From 800d503e67b86dc523c65d99b7c0cd229a8e02d9 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Tue, 28 May 2019 10:27:23 -0700 Subject: [PATCH] fix: respect minimizable/closable for customButtonsOnHover --- atom/browser/native_window_mac.h | 2 +- atom/browser/native_window_mac.mm | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index f948c7a3acec6..e8fbf84e76c2b 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -164,7 +164,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 ShowWindowButton(NSWindowButton button); diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index f9b6d9a7e05d2..541c90fff4235 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -73,9 +73,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; @@ -466,7 +468,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]; @@ -857,9 +859,9 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) { if (newLevel >= minWindowLevel && newLevel <= maxWindowLevel) { [window_ setLevel:newLevel]; } else { - *error = std::string([ - [NSString stringWithFormat:@"relativeLevel must be between %d and %d", - minWindowLevel, maxWindowLevel] UTF8String]); + *error = std::string([[NSString + stringWithFormat:@"relativeLevel must be between %d and %d", + minWindowLevel, maxWindowLevel] UTF8String]); } } @@ -1080,7 +1082,7 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) { if (browser_view()) { [browser_view()->GetInspectableWebContentsView()->GetNativeView() - removeFromSuperview]; + removeFromSuperview]; set_browser_view(nullptr); } @@ -1379,7 +1381,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. But do not enable it on OS X 10.9 for transparent // window, otherwise a semi-transparent frame would show. @@ -1420,6 +1422,12 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) { [[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_ != NORMAL) { @@ -1484,7 +1492,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) {