fix: update NSView radii on fullscreen transition (#29084)
This commit is contained in:
parent
dca3b41ee6
commit
821c81f5ee
2 changed files with 48 additions and 31 deletions
|
@ -161,6 +161,8 @@ class NativeWindowMac : public NativeWindow,
|
||||||
// Use a custom content view instead of Chromium's BridgedContentView.
|
// Use a custom content view instead of Chromium's BridgedContentView.
|
||||||
void OverrideNSWindowContentView();
|
void OverrideNSWindowContentView();
|
||||||
|
|
||||||
|
void UpdateVibrancyRadii(bool fullscreen);
|
||||||
|
|
||||||
// Set the attribute of NSWindow while work around a bug of zoom button.
|
// Set the attribute of NSWindow while work around a bug of zoom button.
|
||||||
void SetStyleMask(bool on, NSUInteger flag);
|
void SetStyleMask(bool on, NSUInteger flag);
|
||||||
void SetCollectionBehavior(bool on, NSUInteger flag);
|
void SetCollectionBehavior(bool on, NSUInteger flag);
|
||||||
|
@ -271,6 +273,7 @@ class NativeWindowMac : public NativeWindow,
|
||||||
|
|
||||||
base::scoped_nsobject<NSColor> background_color_before_vibrancy_;
|
base::scoped_nsobject<NSColor> background_color_before_vibrancy_;
|
||||||
bool transparency_before_vibrancy_ = false;
|
bool transparency_before_vibrancy_ = false;
|
||||||
|
std::string vibrancy_type_;
|
||||||
|
|
||||||
// The presentation options before entering simple fullscreen mode.
|
// The presentation options before entering simple fullscreen mode.
|
||||||
NSApplicationPresentationOptions simple_fullscreen_options_;
|
NSApplicationPresentationOptions simple_fullscreen_options_;
|
||||||
|
|
|
@ -1303,6 +1303,45 @@ void NativeWindowMac::SetAutoHideCursor(bool auto_hide) {
|
||||||
[window_ setDisableAutoHideCursor:!auto_hide];
|
[window_ setDisableAutoHideCursor:!auto_hide];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NativeWindowMac::UpdateVibrancyRadii(bool fullscreen) {
|
||||||
|
NSView* vibrant_view = [window_ vibrantView];
|
||||||
|
NSVisualEffectView* effect_view = (NSVisualEffectView*)vibrant_view;
|
||||||
|
|
||||||
|
if (effect_view != nil && !vibrancy_type_.empty()) {
|
||||||
|
const bool no_rounded_corner =
|
||||||
|
[window_ styleMask] & NSWindowStyleMaskFullSizeContentView;
|
||||||
|
if (!has_frame() && !is_modal() && !no_rounded_corner) {
|
||||||
|
CGFloat radius;
|
||||||
|
if (fullscreen) {
|
||||||
|
radius = 0.0f;
|
||||||
|
} else if (@available(macOS 11.0, *)) {
|
||||||
|
radius = 9.0f;
|
||||||
|
} else {
|
||||||
|
// Smaller corner radius on versions prior to Big Sur.
|
||||||
|
radius = 5.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
CGFloat dimension = 2 * radius + 1;
|
||||||
|
NSSize size = NSMakeSize(dimension, dimension);
|
||||||
|
NSImage* maskImage = [NSImage imageWithSize:size
|
||||||
|
flipped:NO
|
||||||
|
drawingHandler:^BOOL(NSRect rect) {
|
||||||
|
NSBezierPath* bezierPath = [NSBezierPath
|
||||||
|
bezierPathWithRoundedRect:rect
|
||||||
|
xRadius:radius
|
||||||
|
yRadius:radius];
|
||||||
|
[[NSColor blackColor] set];
|
||||||
|
[bezierPath fill];
|
||||||
|
return YES;
|
||||||
|
}];
|
||||||
|
|
||||||
|
[maskImage setCapInsets:NSEdgeInsetsMake(radius, radius, radius, radius)];
|
||||||
|
[maskImage setResizingMode:NSImageResizingModeStretch];
|
||||||
|
[effect_view setMaskImage:maskImage];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void NativeWindowMac::SetVibrancy(const std::string& type) {
|
void NativeWindowMac::SetVibrancy(const std::string& type) {
|
||||||
NSView* vibrant_view = [window_ vibrantView];
|
NSView* vibrant_view = [window_ vibrantView];
|
||||||
|
|
||||||
|
@ -1320,6 +1359,7 @@ void NativeWindowMac::SetVibrancy(const std::string& type) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vibrancy_type_ = type;
|
||||||
background_color_before_vibrancy_.reset([[window_ backgroundColor] retain]);
|
background_color_before_vibrancy_.reset([[window_ backgroundColor] retain]);
|
||||||
transparency_before_vibrancy_ = [window_ titlebarAppearsTransparent];
|
transparency_before_vibrancy_ = [window_ titlebarAppearsTransparent];
|
||||||
|
|
||||||
|
@ -1345,39 +1385,11 @@ void NativeWindowMac::SetVibrancy(const std::string& type) {
|
||||||
[effect_view setState:NSVisualEffectStateFollowsWindowActiveState];
|
[effect_view setState:NSVisualEffectStateFollowsWindowActiveState];
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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;
|
|
||||||
if (@available(macOS 11.0, *)) {
|
|
||||||
radius = 9.0f;
|
|
||||||
} else {
|
|
||||||
radius = 5.0f; // smaller corner radius on older versions
|
|
||||||
}
|
|
||||||
CGFloat dimension = 2 * radius + 1;
|
|
||||||
NSSize size = NSMakeSize(dimension, dimension);
|
|
||||||
NSImage* maskImage = [NSImage imageWithSize:size
|
|
||||||
flipped:NO
|
|
||||||
drawingHandler:^BOOL(NSRect rect) {
|
|
||||||
NSBezierPath* bezierPath = [NSBezierPath
|
|
||||||
bezierPathWithRoundedRect:rect
|
|
||||||
xRadius:radius
|
|
||||||
yRadius:radius];
|
|
||||||
[[NSColor blackColor] set];
|
|
||||||
[bezierPath fill];
|
|
||||||
return YES;
|
|
||||||
}];
|
|
||||||
[maskImage setCapInsets:NSEdgeInsetsMake(radius, radius, radius, radius)];
|
|
||||||
[maskImage setResizingMode:NSImageResizingModeStretch];
|
|
||||||
|
|
||||||
[effect_view setMaskImage:maskImage];
|
|
||||||
}
|
|
||||||
|
|
||||||
[[window_ contentView] addSubview:effect_view
|
[[window_ contentView] addSubview:effect_view
|
||||||
positioned:NSWindowBelow
|
positioned:NSWindowBelow
|
||||||
relativeTo:nil];
|
relativeTo:nil];
|
||||||
|
|
||||||
|
UpdateVibrancyRadii(IsFullscreen());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string dep_warn = " has been deprecated and removed as of macOS 10.15.";
|
std::string dep_warn = " has been deprecated and removed as of macOS 10.15.";
|
||||||
|
@ -1385,7 +1397,6 @@ void NativeWindowMac::SetVibrancy(const std::string& type) {
|
||||||
node::Environment::GetCurrent(JavascriptEnvironment::GetIsolate());
|
node::Environment::GetCurrent(JavascriptEnvironment::GetIsolate());
|
||||||
|
|
||||||
NSVisualEffectMaterial vibrancyType;
|
NSVisualEffectMaterial vibrancyType;
|
||||||
|
|
||||||
if (type == "appearance-based") {
|
if (type == "appearance-based") {
|
||||||
EmitWarning(env, "NSVisualEffectMaterialAppearanceBased" + dep_warn,
|
EmitWarning(env, "NSVisualEffectMaterialAppearanceBased" + dep_warn,
|
||||||
"electron");
|
"electron");
|
||||||
|
@ -1623,6 +1634,8 @@ void NativeWindowMac::NotifyWindowWillEnterFullScreen() {
|
||||||
[buttons_view_ removeFromSuperview];
|
[buttons_view_ removeFromSuperview];
|
||||||
InternalSetStandardButtonsVisibility(true);
|
InternalSetStandardButtonsVisibility(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateVibrancyRadii(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowMac::NotifyWindowWillLeaveFullScreen() {
|
void NativeWindowMac::NotifyWindowWillLeaveFullScreen() {
|
||||||
|
@ -1634,6 +1647,7 @@ void NativeWindowMac::NotifyWindowWillLeaveFullScreen() {
|
||||||
}
|
}
|
||||||
|
|
||||||
RedrawTrafficLights();
|
RedrawTrafficLights();
|
||||||
|
UpdateVibrancyRadii(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowMac::Cleanup() {
|
void NativeWindowMac::Cleanup() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue