feat: add roundedCorners option for BrowserWindow (#27572)

* feat: add roundedCorner option for BrowserWindow

* Make roundedCorner work with vibrancy views

* roundedCorner => roundedCorners
This commit is contained in:
Cheng Zhao 2021-02-10 01:38:35 +09:00 коммит произвёл GitHub
Родитель e51ad4fa45
Коммит af4a050a1b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 21 добавлений и 7 удалений

Просмотреть файл

@ -228,6 +228,8 @@ It creates a new `BrowserWindow` with native properties as set by the `options`.
experimental.
* `trafficLightPosition` [Point](structures/point.md) (optional) - Set a
custom position for the traffic light buttons in frameless windows.
* `roundedCorners` Boolean (optional) - Whether frameless window should have
rounded corners on macOS. Default is `true`.
* `fullscreenWindowTitle` Boolean (optional) _Deprecated_ - Shows the title in
the title bar in full screen mode on macOS for `hiddenInset` titleBarStyle.
Default is `false`.

Просмотреть файл

@ -305,17 +305,25 @@ NativeWindowMac::NativeWindowMac(const gin_helper::Dictionary& options,
useStandardWindow = false;
}
// The window without titlebar is treated the same with frameless window.
if (title_bar_style_ != TitleBarStyle::kNormal)
set_has_frame(false);
NSUInteger styleMask = NSWindowStyleMaskTitled;
// The NSWindowStyleMaskFullSizeContentView style removes rounded corners
// for framless window.
bool rounded_corner = true;
options.Get(options::kRoundedCorners, &rounded_corner);
if (!rounded_corner && !has_frame())
styleMask = NSWindowStyleMaskFullSizeContentView;
if (minimizable)
styleMask |= NSMiniaturizableWindowMask;
if (closable)
styleMask |= NSWindowStyleMaskClosable;
if (resizable_)
styleMask |= NSResizableWindowMask;
// The window without titlebar is treated the same with frameless window.
if (title_bar_style_ != TitleBarStyle::kNormal)
set_has_frame(false);
if (!useStandardWindow || transparent() || !has_frame())
styleMask |= NSTexturedBackgroundWindowMask;
@ -1234,8 +1242,11 @@ void NativeWindowMac::SetVibrancy(const std::string& type) {
[effect_view setState:NSVisualEffectStateFollowsWindowActiveState];
}
// Make frameless Vibrant windows have rounded corners.
if (!has_frame() && !is_modal()) {
// Make Vibrant view have rounded corners, so the frameless window can keep
// its rounded corners.
const bool no_rounded_corner =
[window_ styleMask] & NSWindowStyleMaskFullSizeContentView;
if (!has_frame() && !is_modal() && !no_rounded_corner) {
CGFloat radius = 5.0f; // default corner radius
CGFloat dimension = 2 * radius + 1;
NSSize size = NSMakeSize(dimension, dimension);
@ -1254,7 +1265,6 @@ void NativeWindowMac::SetVibrancy(const std::string& type) {
[maskImage setResizingMode:NSImageResizingModeStretch];
[effect_view setMaskImage:maskImage];
[window_ setCornerMask:maskImage];
}
[[window_ contentView] addSubview:effect_view

Просмотреть файл

@ -29,6 +29,7 @@ const char kFullScreenable[] = "fullscreenable";
const char kClosable[] = "closable";
const char kFullscreen[] = "fullscreen";
const char kTrafficLightPosition[] = "trafficLightPosition";
const char kRoundedCorners[] = "roundedCorners";
// Whether the window should show in taskbar.
const char kSkipTaskbar[] = "skipTaskbar";

Просмотреть файл

@ -56,6 +56,7 @@ extern const char kWebPreferences[];
extern const char kVibrancyType[];
extern const char kVisualEffectState[];
extern const char kTrafficLightPosition[];
extern const char kRoundedCorners[];
// WebPreferences.
extern const char kZoomFactor[];