add border radius to frameless window (#20360)
This commit is contained in:
parent
20c910f98e
commit
425d2a2e1b
3 changed files with 31 additions and 0 deletions
|
@ -1372,6 +1372,28 @@ void NativeWindowMac::SetVibrancy(const std::string& type) {
|
||||||
[effect_view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
|
[effect_view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
|
||||||
[effect_view setBlendingMode:NSVisualEffectBlendingModeBehindWindow];
|
[effect_view setBlendingMode:NSVisualEffectBlendingModeBehindWindow];
|
||||||
[effect_view setState:NSVisualEffectStateActive];
|
[effect_view setState:NSVisualEffectStateActive];
|
||||||
|
|
||||||
|
// The default corner radius of a macOS window.
|
||||||
|
CGFloat 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;
|
||||||
|
}] autorelease];
|
||||||
|
[maskImage setCapInsets:NSEdgeInsetsMake(radius, radius, radius, radius)];
|
||||||
|
[maskImage setResizingMode:NSImageResizingModeStretch];
|
||||||
|
|
||||||
|
[effect_view setMaskImage:maskImage];
|
||||||
|
[window_ setCornerMask:maskImage];
|
||||||
|
|
||||||
[[window_ contentView] addSubview:effect_view
|
[[window_ contentView] addSubview:effect_view
|
||||||
positioned:NSWindowBelow
|
positioned:NSWindowBelow
|
||||||
relativeTo:nil];
|
relativeTo:nil];
|
||||||
|
|
|
@ -36,12 +36,14 @@ class ScopedDisableResize {
|
||||||
@property BOOL disableAutoHideCursor;
|
@property BOOL disableAutoHideCursor;
|
||||||
@property BOOL disableKeyOrMainWindow;
|
@property BOOL disableKeyOrMainWindow;
|
||||||
@property(nonatomic, retain) NSView* vibrantView;
|
@property(nonatomic, retain) NSView* vibrantView;
|
||||||
|
@property(nonatomic, retain) NSImage* cornerMask;
|
||||||
- (id)initWithShell:(electron::NativeWindowMac*)shell
|
- (id)initWithShell:(electron::NativeWindowMac*)shell
|
||||||
styleMask:(NSUInteger)styleMask;
|
styleMask:(NSUInteger)styleMask;
|
||||||
- (electron::NativeWindowMac*)shell;
|
- (electron::NativeWindowMac*)shell;
|
||||||
- (id)accessibilityFocusedUIElement;
|
- (id)accessibilityFocusedUIElement;
|
||||||
- (NSRect)originalContentRectForFrameRect:(NSRect)frameRect;
|
- (NSRect)originalContentRectForFrameRect:(NSRect)frameRect;
|
||||||
- (void)toggleFullScreenMode:(id)sender;
|
- (void)toggleFullScreenMode:(id)sender;
|
||||||
|
- (NSImage*)_cornerMask;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
#endif // SHELL_BROWSER_UI_COCOA_ATOM_NS_WINDOW_H_
|
#endif // SHELL_BROWSER_UI_COCOA_ATOM_NS_WINDOW_H_
|
||||||
|
|
|
@ -24,6 +24,7 @@ bool ScopedDisableResize::disable_resize_ = false;
|
||||||
@synthesize disableAutoHideCursor;
|
@synthesize disableAutoHideCursor;
|
||||||
@synthesize disableKeyOrMainWindow;
|
@synthesize disableKeyOrMainWindow;
|
||||||
@synthesize vibrantView;
|
@synthesize vibrantView;
|
||||||
|
@synthesize cornerMask;
|
||||||
|
|
||||||
- (id)initWithShell:(electron::NativeWindowMac*)shell
|
- (id)initWithShell:(electron::NativeWindowMac*)shell
|
||||||
styleMask:(NSUInteger)styleMask {
|
styleMask:(NSUInteger)styleMask {
|
||||||
|
@ -139,6 +140,12 @@ bool ScopedDisableResize::disable_resize_ = false;
|
||||||
return [[self contentView] superview];
|
return [[self contentView] superview];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// By overriding this built-in method the corners of the vibrant view (if set)
|
||||||
|
// will be smooth.
|
||||||
|
- (NSImage*)_cornerMask {
|
||||||
|
return [self cornerMask];
|
||||||
|
}
|
||||||
|
|
||||||
// Quicklook methods
|
// Quicklook methods
|
||||||
|
|
||||||
- (BOOL)acceptsPreviewPanelControl:(QLPreviewPanel*)panel {
|
- (BOOL)acceptsPreviewPanelControl:(QLPreviewPanel*)panel {
|
||||||
|
|
Loading…
Reference in a new issue