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:
parent
e51ad4fa45
commit
af4a050a1b
4 changed files with 21 additions and 7 deletions
|
@ -228,6 +228,8 @@ It creates a new `BrowserWindow` with native properties as set by the `options`.
|
||||||
experimental.
|
experimental.
|
||||||
* `trafficLightPosition` [Point](structures/point.md) (optional) - Set a
|
* `trafficLightPosition` [Point](structures/point.md) (optional) - Set a
|
||||||
custom position for the traffic light buttons in frameless windows.
|
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
|
* `fullscreenWindowTitle` Boolean (optional) _Deprecated_ - Shows the title in
|
||||||
the title bar in full screen mode on macOS for `hiddenInset` titleBarStyle.
|
the title bar in full screen mode on macOS for `hiddenInset` titleBarStyle.
|
||||||
Default is `false`.
|
Default is `false`.
|
||||||
|
|
|
@ -305,17 +305,25 @@ NativeWindowMac::NativeWindowMac(const gin_helper::Dictionary& options,
|
||||||
useStandardWindow = false;
|
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;
|
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)
|
if (minimizable)
|
||||||
styleMask |= NSMiniaturizableWindowMask;
|
styleMask |= NSMiniaturizableWindowMask;
|
||||||
if (closable)
|
if (closable)
|
||||||
styleMask |= NSWindowStyleMaskClosable;
|
styleMask |= NSWindowStyleMaskClosable;
|
||||||
if (resizable_)
|
if (resizable_)
|
||||||
styleMask |= NSResizableWindowMask;
|
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())
|
if (!useStandardWindow || transparent() || !has_frame())
|
||||||
styleMask |= NSTexturedBackgroundWindowMask;
|
styleMask |= NSTexturedBackgroundWindowMask;
|
||||||
|
|
||||||
|
@ -1234,8 +1242,11 @@ void NativeWindowMac::SetVibrancy(const std::string& type) {
|
||||||
[effect_view setState:NSVisualEffectStateFollowsWindowActiveState];
|
[effect_view setState:NSVisualEffectStateFollowsWindowActiveState];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make frameless Vibrant windows have rounded corners.
|
// Make Vibrant view have rounded corners, so the frameless window can keep
|
||||||
if (!has_frame() && !is_modal()) {
|
// 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 radius = 5.0f; // default corner radius
|
||||||
CGFloat dimension = 2 * radius + 1;
|
CGFloat dimension = 2 * radius + 1;
|
||||||
NSSize size = NSMakeSize(dimension, dimension);
|
NSSize size = NSMakeSize(dimension, dimension);
|
||||||
|
@ -1254,7 +1265,6 @@ void NativeWindowMac::SetVibrancy(const std::string& type) {
|
||||||
[maskImage setResizingMode:NSImageResizingModeStretch];
|
[maskImage setResizingMode:NSImageResizingModeStretch];
|
||||||
|
|
||||||
[effect_view setMaskImage:maskImage];
|
[effect_view setMaskImage:maskImage];
|
||||||
[window_ setCornerMask:maskImage];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[[window_ contentView] addSubview:effect_view
|
[[window_ contentView] addSubview:effect_view
|
||||||
|
|
|
@ -29,6 +29,7 @@ const char kFullScreenable[] = "fullscreenable";
|
||||||
const char kClosable[] = "closable";
|
const char kClosable[] = "closable";
|
||||||
const char kFullscreen[] = "fullscreen";
|
const char kFullscreen[] = "fullscreen";
|
||||||
const char kTrafficLightPosition[] = "trafficLightPosition";
|
const char kTrafficLightPosition[] = "trafficLightPosition";
|
||||||
|
const char kRoundedCorners[] = "roundedCorners";
|
||||||
|
|
||||||
// Whether the window should show in taskbar.
|
// Whether the window should show in taskbar.
|
||||||
const char kSkipTaskbar[] = "skipTaskbar";
|
const char kSkipTaskbar[] = "skipTaskbar";
|
||||||
|
|
|
@ -56,6 +56,7 @@ extern const char kWebPreferences[];
|
||||||
extern const char kVibrancyType[];
|
extern const char kVibrancyType[];
|
||||||
extern const char kVisualEffectState[];
|
extern const char kVisualEffectState[];
|
||||||
extern const char kTrafficLightPosition[];
|
extern const char kTrafficLightPosition[];
|
||||||
|
extern const char kRoundedCorners[];
|
||||||
|
|
||||||
// WebPreferences.
|
// WebPreferences.
|
||||||
extern const char kZoomFactor[];
|
extern const char kZoomFactor[];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue