Switch to titleBarStyle for custom window buttons on hover

This commit is contained in:
Kevin Sawicki 2017-06-05 13:30:08 -07:00
parent 566e04f1c0
commit 7d10bf229d
3 changed files with 16 additions and 19 deletions

View file

@ -127,13 +127,12 @@ class NativeWindowMac : public NativeWindow,
NORMAL, NORMAL,
HIDDEN, HIDDEN,
HIDDEN_INSET, HIDDEN_INSET,
CUSTOM_BUTTONS_ON_HOVER,
}; };
TitleBarStyle title_bar_style() const { return title_bar_style_; } TitleBarStyle title_bar_style() const { return title_bar_style_; }
bool zoom_to_page_width() const { return zoom_to_page_width_; } bool zoom_to_page_width() const { return zoom_to_page_width_; }
bool custom_window_buttons() const { return custom_window_buttons_; }
protected: protected:
// Return a vector of non-draggable regions that fill a window of size // Return a vector of non-draggable regions that fill a window of size
// |width| by |height|, but leave gaps where the window should be draggable. // |width| by |height|, but leave gaps where the window should be draggable.
@ -178,8 +177,6 @@ class NativeWindowMac : public NativeWindow,
bool zoom_to_page_width_; bool zoom_to_page_width_;
bool custom_window_buttons_;
NSInteger attention_request_id_; // identifier from requestUserAttention NSInteger attention_request_id_; // identifier from requestUserAttention
// The presentation options before entering kiosk mode. // The presentation options before entering kiosk mode.

View file

@ -701,14 +701,14 @@ enum {
// Custom window button methods // Custom window button methods
- (void)performClose:(id)sender { - (void)performClose:(id)sender {
if (shell_->custom_window_buttons()) if (shell_->title_bar_style() == atom::NativeWindowMac::CUSTOM_BUTTONS_ON_HOVER)
[[self delegate] windowShouldClose:self]; [[self delegate] windowShouldClose:self];
else else
[super performClose:sender]; [super performClose:sender];
} }
- (void)performMiniaturize:(id)sender { - (void)performMiniaturize:(id)sender {
if (shell_->custom_window_buttons()) if (shell_->title_bar_style() == atom::NativeWindowMac::CUSTOM_BUTTONS_ON_HOVER)
[self miniaturize:self]; [self miniaturize:self];
else else
[super performMiniaturize:sender]; [super performMiniaturize:sender];
@ -782,6 +782,8 @@ struct Converter<atom::NativeWindowMac::TitleBarStyle> {
} else if (title_bar_style == "hidden-inset" || // Deprecate this after 2.0 } else if (title_bar_style == "hidden-inset" || // Deprecate this after 2.0
title_bar_style == "hiddenInset") { title_bar_style == "hiddenInset") {
*out = atom::NativeWindowMac::HIDDEN_INSET; *out = atom::NativeWindowMac::HIDDEN_INSET;
} else if (title_bar_style == "customButtonsOnHover") {
*out = atom::NativeWindowMac::CUSTOM_BUTTONS_ON_HOVER;
} else { } else {
return false; return false;
} }
@ -802,7 +804,6 @@ NativeWindowMac::NativeWindowMac(
is_kiosk_(false), is_kiosk_(false),
was_fullscreen_(false), was_fullscreen_(false),
zoom_to_page_width_(false), zoom_to_page_width_(false),
custom_window_buttons_(false),
attention_request_id_(0), attention_request_id_(0),
title_bar_style_(NORMAL) { title_bar_style_(NORMAL) {
int width = 800, height = 600; int width = 800, height = 600;
@ -844,10 +845,8 @@ NativeWindowMac::NativeWindowMac(
useStandardWindow = false; useStandardWindow = false;
} }
options.Get(options::kCustomWindowButtons, &custom_window_buttons_);
NSUInteger styleMask = NSTitledWindowMask; NSUInteger styleMask = NSTitledWindowMask;
if (custom_window_buttons_ && if (title_bar_style_ == CUSTOM_BUTTONS_ON_HOVER &&
base::mac::IsAtLeastOS10_10() && base::mac::IsAtLeastOS10_10() &&
(!useStandardWindow || transparent() || !has_frame())) { (!useStandardWindow || transparent() || !has_frame())) {
styleMask = NSFullSizeContentViewWindowMask; styleMask = NSFullSizeContentViewWindowMask;
@ -906,7 +905,7 @@ NativeWindowMac::NativeWindowMac(
if (transparent() || !has_frame()) { if (transparent() || !has_frame()) {
if (base::mac::IsAtLeastOS10_10()) { if (base::mac::IsAtLeastOS10_10()) {
// Don't show title bar. // Don't show title bar.
if (custom_window_buttons_) { if (title_bar_style_ == CUSTOM_BUTTONS_ON_HOVER) {
[window_ setTitlebarAppearsTransparent:YES]; [window_ setTitlebarAppearsTransparent:YES];
} }
[window_ setTitleVisibility:NSWindowTitleHidden]; [window_ setTitleVisibility:NSWindowTitleHidden];
@ -1692,7 +1691,7 @@ void NativeWindowMac::InstallView() {
// The fullscreen button should always be hidden for frameless window. // The fullscreen button should always be hidden for frameless window.
[[window_ standardWindowButton:NSWindowFullScreenButton] setHidden:YES]; [[window_ standardWindowButton:NSWindowFullScreenButton] setHidden:YES];
if (custom_window_buttons_) { if (title_bar_style_ == CUSTOM_BUTTONS_ON_HOVER) {
NSView* buttons = [[SemaphoreView alloc] initWithFrame:NSZeroRect]; NSView* buttons = [[SemaphoreView alloc] initWithFrame:NSZeroRect];
buttons.frame = CGRectMake(0, buttons.frame = CGRectMake(0,
[content_view_ bounds].size.height - buttons.frame.size.height, [content_view_ bounds].size.height - buttons.frame.size.height,

View file

@ -191,14 +191,20 @@ It creates a new `BrowserWindow` with native properties as set by the `options`.
Default is `false`. Default is `false`.
* `type` String (optional) - The type of window, default is normal window. See more about * `type` String (optional) - The type of window, default is normal window. See more about
this below. this below.
* `titleBarStyle` String (optional) - The style of window title bar. Default is `default`. Possible values are: * `titleBarStyle` String (optional) - The style of window title bar.
Default is `default`. Possible values are:
* `default` - Results in the standard gray opaque Mac title * `default` - Results in the standard gray opaque Mac title
bar. bar.
* `hidden` - Results in a hidden title bar and a full size content window, yet * `hidden` - Results in a hidden title bar and a full size content window, yet
the title bar still has the standard window controls ("traffic lights") in the title bar still has the standard window controls ("traffic lights") in
the top left. the top left.
* `hidden-inset` - 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,
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.
* `thickFrame` Boolean (optional) - Use `WS_THICKFRAME` style for frameless windows on * `thickFrame` Boolean (optional) - Use `WS_THICKFRAME` style for frameless windows on
Windows, which adds standard window frame. Setting it to `false` will remove Windows, which adds standard window frame. Setting it to `false` will remove
window shadow and window animations. Default is `true`. window shadow and window animations. Default is `true`.
@ -214,11 +220,6 @@ It creates a new `BrowserWindow` with native properties as set by the `options`.
* `tabbingIdentifier` String (optional) - Tab group name, allows opening the * `tabbingIdentifier` String (optional) - Tab group name, allows opening the
window as a native tab on macOS 10.12+. Windows with the same tabbing window as a native tab on macOS 10.12+. Windows with the same tabbing
identifier will be grouped together. identifier will be grouped together.
* `customWindowButtons` 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.
* `webPreferences` Object (optional) - Settings of web page's features. * `webPreferences` Object (optional) - Settings of web page's features.
* `devTools` Boolean (optional) - Whether to enable DevTools. If it is set to `false`, can not use `BrowserWindow.webContents.openDevTools()` to open DevTools. Default is `true`. * `devTools` Boolean (optional) - Whether to enable DevTools. If it is set to `false`, can not use `BrowserWindow.webContents.openDevTools()` to open DevTools. Default is `true`.
* `nodeIntegration` Boolean (optional) - Whether node integration is enabled. Default * `nodeIntegration` Boolean (optional) - Whether node integration is enabled. Default