From 2046d8052a529b7f20798e8d8e6c78496664a094 Mon Sep 17 00:00:00 2001 From: "trop[bot]" Date: Mon, 10 Dec 2018 13:44:59 -0800 Subject: [PATCH] fix: incorrect view ordering for customButtonsOnHover (#15564) (#16002) --- atom/browser/api/atom_api_browser_window_mac.mm | 7 ++++++- atom/browser/native_window_mac.mm | 12 ++++-------- docs/api/browser-window.md | 10 +++++----- docs/api/frameless-window.md | 10 ++++++---- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/atom/browser/api/atom_api_browser_window_mac.mm b/atom/browser/api/atom_api_browser_window_mac.mm index f6238ee8167e..7c3c3be4b25f 100644 --- a/atom/browser/api/atom_api_browser_window_mac.mm +++ b/atom/browser/api/atom_api_browser_window_mac.mm @@ -63,7 +63,12 @@ void BrowserWindow::OverrideNSWindowContentView( NSView* webView = iwc->GetView()->GetNativeView(); NSView* contentView = [window()->GetNativeWindow() contentView]; [webView setFrame:[contentView bounds]]; - [contentView addSubview:webView]; + + // ensure that buttons view is floated to top of view hierarchy + NSArray* subviews = [contentView subviews]; + NSView* last = subviews.lastObject; + [contentView addSubview:webView positioned:NSWindowBelow relativeTo:last]; + [contentView viewDidMoveToWindow]; } diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index b3515b9e547e..8cb2635307d4 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -74,9 +74,7 @@ forStyleMask:NSTitledWindowMask]; NSButton* miniaturize_button = [NSWindow standardWindowButton:NSWindowMiniaturizeButton - forStyleMask:NSTitledWindowMask]; - NSButton* zoom_button = [NSWindow standardWindowButton:NSWindowZoomButton - forStyleMask:NSTitledWindowMask]; + forStyleMask:NSWindowStyleMaskTitled]; CGFloat x = 0; const CGFloat space_between = 20; @@ -89,11 +87,7 @@ x += space_between; [self addSubview:miniaturize_button]; - [zoom_button setFrameOrigin:NSMakePoint(x, 0)]; - x += space_between; - [self addSubview:zoom_button]; - - const auto last_button_frame = zoom_button.frame; + const auto last_button_frame = miniaturize_button.frame; [self setFrameSize:NSMakeSize(last_button_frame.origin.x + last_button_frame.size.width, last_button_frame.size.height)]; @@ -1356,6 +1350,8 @@ void NativeWindowMac::AddContentViewLayers() { if (title_bar_style_ == CUSTOM_BUTTONS_ON_HOVER) { buttons_view_.reset( [[CustomWindowButtonView alloc] initWithFrame:NSZeroRect]); + // NSWindowStyleMaskFullSizeContentView does not work with zoom button + SetFullScreenable(false); [[window_ contentView] addSubview:buttons_view_]; } else { if (title_bar_style_ != NORMAL) { diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index cdc99ce9e7c2..d7897d4201e8 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -222,11 +222,11 @@ It creates a new `BrowserWindow` with native properties as set by the `options`. the top left. * `hiddenInset` - Results in a hidden title bar with an alternative look where the traffic light buttons are slightly more inset from the window edge. - * `customButtonsOnHover` Boolean (optional) - Draw custom close, minimize, - and full screen buttons on macOS frameless windows. These buttons will not - display unless hovered over in the top left of the window. These custom - buttons prevent issues with mouse events that occur with the standard - window toolbar buttons. **Note:** This option is currently experimental. + * `customButtonsOnHover` Boolean (optional) - Draw custom close, + and minimize buttons on macOS frameless windows. These buttons will not display + unless hovered over in the top left of the window. These custom buttons prevent + issues with mouse events that occur with the standard window toolbar buttons. + **Note:** This option is currently experimental. * `fullscreenWindowTitle` Boolean (optional) - Shows the title in the title bar in full screen mode on macOS for all `titleBarStyle` options. Default is `false`. diff --git a/docs/api/frameless-window.md b/docs/api/frameless-window.md index 46e496407a8d..543120ef97b0 100644 --- a/docs/api/frameless-window.md +++ b/docs/api/frameless-window.md @@ -50,10 +50,12 @@ win.show() #### `customButtonsOnHover` -Uses custom drawn close, miniaturize, and fullscreen buttons that display -when hovering in the top left of the window. These custom buttons prevent issues -with mouse events that occur with the standard window toolbar buttons. This -option is only applicable for frameless windows. +Uses custom drawn close, and miniaturize buttons that display +when hovering in the top left of the window. The fullscreen button +is not available due to restrictions of frameless windows as they +interface with Apple's MacOS window masks. These custom buttons prevent +issues with mouse events that occur with the standard window toolbar buttons. +This option is only applicable for frameless windows. ```javascript const {BrowserWindow} = require('electron')