From ab8fd49c72e275fe8fb9697f466546c4bfb156aa Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Mon, 15 Aug 2016 21:36:57 +0200 Subject: [PATCH] Add support for titleBarStyle: 'hidden' on OS X 10.9 (hidden-inset falls back to hidden) --- atom/browser/native_window_mac.h | 2 ++ atom/browser/native_window_mac.mm | 24 +++++++++++++++++++----- docs/api/browser-window.md | 3 ++- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index 1a04ff9a494cd..1e51ee8e7979f 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -127,6 +127,8 @@ class NativeWindowMac : public NativeWindow, void UpdateDraggableRegions( const std::vector& regions) override; + void ShowWindowButton(NSWindowButton button); + void InstallView(); void UninstallView(); diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index 8e8f988ee99c1..0085ac8634a0f 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -416,7 +416,11 @@ static bool FromV8(v8::Isolate* isolate, v8::Handle val, *out = atom::NativeWindowMac::HIDDEN; } else if (title_bar_style == "hidden-inset" || // Deprecate this after 2.0 title_bar_style == "hiddenInset") { - *out = atom::NativeWindowMac::HIDDEN_INSET; + if (base::mac::IsOSYosemiteOrLater()) { + *out = atom::NativeWindowMac::HIDDEN_INSET; + } else { + *out = atom::NativeWindowMac::HIDDEN; + } } else { return false; } @@ -460,9 +464,7 @@ static bool FromV8(v8::Isolate* isolate, v8::Handle val, bool closable = true; options.Get(options::kClosable, &closable); - // New title bar styles are available in Yosemite or newer - if (base::mac::IsOSYosemiteOrLater()) - options.Get(options::kTitleBarStyle, &title_bar_style_); + options.Get(options::kTitleBarStyle, &title_bar_style_); std::string windowType; options.Get(options::kType, &windowType); @@ -1099,6 +1101,11 @@ static bool FromV8(v8::Isolate* isolate, v8::Handle val, UpdateDraggableRegionViews(regions); } +void NativeWindowMac::ShowWindowButton(NSWindowButton button) { + auto view = [window_ standardWindowButton:button]; + [view.superview addSubview:view positioned:NSWindowAbove relativeTo:nil]; +} + void NativeWindowMac::InstallView() { // Make sure the bottom corner is rounded: http://crbug.com/396264. // But do not enable it on OS X 10.9 for transparent window, otherwise a @@ -1127,8 +1134,15 @@ static bool FromV8(v8::Isolate* isolate, v8::Handle val, // The fullscreen button should always be hidden for frameless window. [[window_ standardWindowButton:NSWindowFullScreenButton] setHidden:YES]; - if (title_bar_style_ != NORMAL) + if (title_bar_style_ != NORMAL) { + if (base::mac::IsOSMavericks()) { + ShowWindowButton(NSWindowZoomButton); + ShowWindowButton(NSWindowMiniaturizeButton); + ShowWindowButton(NSWindowCloseButton); + } + return; + } // Hide the window buttons. [[window_ standardWindowButton:NSWindowZoomButton] setHidden:YES]; diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index d0c21ecd491eb..abec157fd3c28 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -208,7 +208,7 @@ Possible values are: input sparingly. * On Windows, possible type is `toolbar`. -The `titleBarStyle` option is only supported on macOS 10.10 Yosemite and newer. +The `titleBarStyle` option. Possible values are: * `default` or not specified, results in the standard gray opaque Mac title @@ -218,6 +218,7 @@ Possible values are: the top left. * `hidden-inset` results in a hidden title bar with an alternative look where the traffic light buttons are slightly more inset from the window edge. + It is not supported on macOS 10.9 Mavericks, where it falls back to `hidden`. The `webPreferences` option is an object that can have the following properties: