fix: incorrect view ordering for customButtonsOnHover (#15564) (#16002)

This commit is contained in:
trop[bot] 2018-12-10 13:44:59 -08:00 committed by Michelle Tilley
parent 6de26d3b4a
commit 2046d8052a
4 changed files with 21 additions and 18 deletions

View file

@ -63,7 +63,12 @@ void BrowserWindow::OverrideNSWindowContentView(
NSView* webView = iwc->GetView()->GetNativeView(); NSView* webView = iwc->GetView()->GetNativeView();
NSView* contentView = [window()->GetNativeWindow() contentView]; NSView* contentView = [window()->GetNativeWindow() contentView];
[webView setFrame:[contentView bounds]]; [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]; [contentView viewDidMoveToWindow];
} }

View file

@ -74,9 +74,7 @@
forStyleMask:NSTitledWindowMask]; forStyleMask:NSTitledWindowMask];
NSButton* miniaturize_button = NSButton* miniaturize_button =
[NSWindow standardWindowButton:NSWindowMiniaturizeButton [NSWindow standardWindowButton:NSWindowMiniaturizeButton
forStyleMask:NSTitledWindowMask]; forStyleMask:NSWindowStyleMaskTitled];
NSButton* zoom_button = [NSWindow standardWindowButton:NSWindowZoomButton
forStyleMask:NSTitledWindowMask];
CGFloat x = 0; CGFloat x = 0;
const CGFloat space_between = 20; const CGFloat space_between = 20;
@ -89,11 +87,7 @@
x += space_between; x += space_between;
[self addSubview:miniaturize_button]; [self addSubview:miniaturize_button];
[zoom_button setFrameOrigin:NSMakePoint(x, 0)]; const auto last_button_frame = miniaturize_button.frame;
x += space_between;
[self addSubview:zoom_button];
const auto last_button_frame = zoom_button.frame;
[self setFrameSize:NSMakeSize(last_button_frame.origin.x + [self setFrameSize:NSMakeSize(last_button_frame.origin.x +
last_button_frame.size.width, last_button_frame.size.width,
last_button_frame.size.height)]; last_button_frame.size.height)];
@ -1356,6 +1350,8 @@ void NativeWindowMac::AddContentViewLayers() {
if (title_bar_style_ == CUSTOM_BUTTONS_ON_HOVER) { if (title_bar_style_ == CUSTOM_BUTTONS_ON_HOVER) {
buttons_view_.reset( buttons_view_.reset(
[[CustomWindowButtonView alloc] initWithFrame:NSZeroRect]); [[CustomWindowButtonView alloc] initWithFrame:NSZeroRect]);
// NSWindowStyleMaskFullSizeContentView does not work with zoom button
SetFullScreenable(false);
[[window_ contentView] addSubview:buttons_view_]; [[window_ contentView] addSubview:buttons_view_];
} else { } else {
if (title_bar_style_ != NORMAL) { if (title_bar_style_ != NORMAL) {

View file

@ -222,11 +222,11 @@ It creates a new `BrowserWindow` with native properties as set by the `options`.
the top left. the top left.
* `hiddenInset` - Results in a hidden title bar with an alternative look * `hiddenInset` - Results in a hidden title bar with an alternative look
where the traffic light buttons are slightly more inset from the window edge. where the traffic light buttons are slightly more inset from the window edge.
* `customButtonsOnHover` Boolean (optional) - Draw custom close, minimize, * `customButtonsOnHover` Boolean (optional) - Draw custom close,
and full screen buttons on macOS frameless windows. These buttons will not and minimize buttons on macOS frameless windows. These buttons will not display
display unless hovered over in the top left of the window. These custom unless hovered over in the top left of the window. These custom buttons prevent
buttons prevent issues with mouse events that occur with the standard issues with mouse events that occur with the standard window toolbar buttons.
window toolbar buttons. **Note:** This option is currently experimental. **Note:** This option is currently experimental.
* `fullscreenWindowTitle` Boolean (optional) - Shows the title in the * `fullscreenWindowTitle` Boolean (optional) - Shows the title in the
title bar in full screen mode on macOS for all `titleBarStyle` options. title bar in full screen mode on macOS for all `titleBarStyle` options.
Default is `false`. Default is `false`.

View file

@ -50,10 +50,12 @@ win.show()
#### `customButtonsOnHover` #### `customButtonsOnHover`
Uses custom drawn close, miniaturize, and fullscreen buttons that display Uses custom drawn close, and miniaturize buttons that display
when hovering in the top left of the window. These custom buttons prevent issues when hovering in the top left of the window. The fullscreen button
with mouse events that occur with the standard window toolbar buttons. This is not available due to restrictions of frameless windows as they
option is only applicable for frameless windows. 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 ```javascript
const {BrowserWindow} = require('electron') const {BrowserWindow} = require('electron')