chore: clean up NativeWindowMac::UpdateVibrancyRadii (#47665)
chore: clean up NativeWindowMac::UpdateVibrancyRadii
This commit is contained in:
parent
31b18c9830
commit
4601aeccde
2 changed files with 18 additions and 36 deletions
|
|
@ -67,10 +67,6 @@ template("mac_xib_bundle_data") {
|
||||||
ibtool_flags = [
|
ibtool_flags = [
|
||||||
"--minimum-deployment-target",
|
"--minimum-deployment-target",
|
||||||
mac_deployment_target,
|
mac_deployment_target,
|
||||||
|
|
||||||
# TODO(rsesek): Enable this once all the bots are on Xcode 7+.
|
|
||||||
# "--target-device",
|
|
||||||
# "mac",
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1308,44 +1308,30 @@ void NativeWindowMac::UpdateVibrancyRadii(bool fullscreen) {
|
||||||
|
|
||||||
if (vibrantView != nil && !vibrancy_type_.empty()) {
|
if (vibrantView != nil && !vibrancy_type_.empty()) {
|
||||||
const bool no_rounded_corner = !HasStyleMask(NSWindowStyleMaskTitled);
|
const bool no_rounded_corner = !HasStyleMask(NSWindowStyleMaskTitled);
|
||||||
const int macos_version = base::mac::MacOSMajorVersion();
|
|
||||||
const bool modal = is_modal();
|
|
||||||
|
|
||||||
// If the window is modal, its corners are rounded on macOS >= 11 or higher
|
// If the window is modal, its corners are rounded unless
|
||||||
// unless the user has explicitly passed noRoundedCorners.
|
// the user has explicitly passed |roundedCorners: false|.
|
||||||
bool should_round_modal =
|
bool should_round_modal = !no_rounded_corner && is_modal();
|
||||||
!no_rounded_corner && macos_version >= 11 && modal;
|
|
||||||
// If the window is nonmodal, its corners are rounded if it is frameless and
|
// If the window is nonmodal, its corners are rounded if it is frameless and
|
||||||
// the user hasn't passed noRoundedCorners.
|
// the user hasn't passed |roundedCorners: false|.
|
||||||
bool should_round_nonmodal = !no_rounded_corner && !modal && !has_frame();
|
bool should_round_nonmodal =
|
||||||
|
!no_rounded_corner && !is_modal() && !has_frame();
|
||||||
|
|
||||||
if (should_round_nonmodal || should_round_modal) {
|
if (should_round_nonmodal || should_round_modal) {
|
||||||
CGFloat radius;
|
CGFloat radius = fullscreen ? 0.0f : 9.0f;
|
||||||
if (fullscreen) {
|
|
||||||
radius = 0.0f;
|
|
||||||
} else if (macos_version >= 11) {
|
|
||||||
radius = 9.0f;
|
|
||||||
} else {
|
|
||||||
// Smaller corner radius on versions prior to Big Sur.
|
|
||||||
radius = 5.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
CGFloat dimension = 2 * radius + 1;
|
CGFloat dimension = 2 * radius + 1;
|
||||||
NSSize size = NSMakeSize(dimension, dimension);
|
NSImage* maskImage =
|
||||||
NSImage* maskImage = [NSImage imageWithSize:size
|
[NSImage imageWithSize:NSMakeSize(dimension, dimension)
|
||||||
flipped:NO
|
flipped:NO
|
||||||
drawingHandler:^BOOL(NSRect rect) {
|
drawingHandler:^BOOL(NSRect rect) {
|
||||||
NSBezierPath* bezierPath = [NSBezierPath
|
[[NSBezierPath bezierPathWithRoundedRect:rect
|
||||||
bezierPathWithRoundedRect:rect
|
|
||||||
xRadius:radius
|
xRadius:radius
|
||||||
yRadius:radius];
|
yRadius:radius] fill];
|
||||||
[[NSColor blackColor] set];
|
|
||||||
[bezierPath fill];
|
|
||||||
return YES;
|
return YES;
|
||||||
}];
|
}];
|
||||||
|
|
||||||
[maskImage setCapInsets:NSEdgeInsetsMake(radius, radius, radius, radius)];
|
maskImage.capInsets = NSEdgeInsetsMake(radius, radius, radius, radius);
|
||||||
[maskImage setResizingMode:NSImageResizingModeStretch];
|
maskImage.resizingMode = NSImageResizingModeStretch;
|
||||||
[vibrantView setMaskImage:maskImage];
|
[vibrantView setMaskImage:maskImage];
|
||||||
[window_ setCornerMask:maskImage];
|
[window_ setCornerMask:maskImage];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue