Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e58bee2

Browse files
committed
[Mac] Update frameless window implementation to upstream.
1 parent c36c8ae commit e58bee2

2 files changed

Lines changed: 69 additions & 5 deletions

File tree

nw.gypi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
'<(DEPTH)/chrome/browser/status_icons/status_icon_observer.h',
6161
'<(DEPTH)/chrome/browser/status_icons/status_tray.cc',
6262
'<(DEPTH)/chrome/browser/status_icons/status_tray.h',
63+
'<(DEPTH)/chrome/browser/ui/cocoa/custom_frame_view.h',
64+
'<(DEPTH)/chrome/browser/ui/cocoa/custom_frame_view.mm',
6365
'<(DEPTH)/chrome/browser/ui/base_window.h',
6466
'<(DEPTH)/chrome/browser/ui/gtk/gtk_window_util.cc',
6567
'<(DEPTH)/chrome/browser/ui/gtk/gtk_window_util.h',

src/browser/native_window_mac.mm

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "base/mac/mac_util.h"
2424
#include "base/sys_string_conversions.h"
2525
#include "base/values.h"
26+
#import "chrome/browser/ui/cocoa/custom_frame_view.h"
2627
#include "chrome/common/extensions/draggable_region.h"
2728
#include "content/nw/src/api/menu/menu.h"
2829
#include "content/nw/src/api/app/app.h"
@@ -172,6 +173,12 @@ - (void)mouseDragged:(NSEvent*)event {
172173

173174
@end
174175

176+
// This is really a method on NSGrayFrame, so it should only be called on the
177+
// view passed into -[NSWindow drawCustomFrameRect:forView:].
178+
@interface NSView (PrivateMethods)
179+
- (CGFloat)roundedCornerRadius;
180+
@end
181+
175182
@interface ShellNSWindow : UnderlayOpenGLHostingWindow {
176183
@private
177184
content::Shell* shell_;
@@ -197,6 +204,52 @@ - (void)closeAllWindows:(id)sender {
197204

198205
@end
199206

207+
@interface ShellFramelessNSWindow : ShellNSWindow
208+
209+
- (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view;
210+
211+
@end
212+
213+
@implementation ShellFramelessNSWindow
214+
215+
- (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view {
216+
[super drawCustomFrameRect:rect forView:view];
217+
218+
[[NSBezierPath bezierPathWithRect:rect] addClip];
219+
[[NSColor clearColor] set];
220+
NSRectFill(rect);
221+
222+
// Set up our clip.
223+
CGFloat cornerRadius = 4.0;
224+
if ([view respondsToSelector:@selector(roundedCornerRadius)])
225+
cornerRadius = [view roundedCornerRadius];
226+
[[NSBezierPath bezierPathWithRoundedRect:[view bounds]
227+
xRadius:cornerRadius
228+
yRadius:cornerRadius] addClip];
229+
[[NSColor whiteColor] set];
230+
NSRectFill(rect);
231+
}
232+
233+
+ (NSRect)frameRectForContentRect:(NSRect)contentRect
234+
styleMask:(NSUInteger)mask {
235+
return contentRect;
236+
}
237+
238+
+ (NSRect)contentRectForFrameRect:(NSRect)frameRect
239+
styleMask:(NSUInteger)mask {
240+
return frameRect;
241+
}
242+
243+
- (NSRect)frameRectForContentRect:(NSRect)contentRect {
244+
return contentRect;
245+
}
246+
247+
- (NSRect)contentRectForFrameRect:(NSRect)frameRect {
248+
return frameRect;
249+
}
250+
251+
@end
252+
200253
namespace nw {
201254

202255
NativeWindowCocoa::NativeWindowCocoa(
@@ -219,11 +272,20 @@ - (void)closeAllWindows:(id)sender {
219272
NSUInteger style_mask = NSTitledWindowMask | NSClosableWindowMask |
220273
NSMiniaturizableWindowMask | NSResizableWindowMask |
221274
NSTexturedBackgroundWindowMask;
222-
ShellNSWindow* shell_window = [[ShellNSWindow alloc]
223-
initWithContentRect:cocoa_bounds
224-
styleMask:style_mask
225-
backing:NSBackingStoreBuffered
226-
defer:NO];
275+
ShellNSWindow* shell_window;
276+
if (has_frame_) {
277+
shell_window = [[ShellNSWindow alloc]
278+
initWithContentRect:cocoa_bounds
279+
styleMask:style_mask
280+
backing:NSBackingStoreBuffered
281+
defer:NO];
282+
} else {
283+
shell_window = [[ShellFramelessNSWindow alloc]
284+
initWithContentRect:cocoa_bounds
285+
styleMask:style_mask
286+
backing:NSBackingStoreBuffered
287+
defer:NO];
288+
}
227289
window_ = shell_window;
228290
[shell_window setShell:shell];
229291
[window() setDelegate:[[NativeWindowDelegate alloc] initWithShell:shell]];

0 commit comments

Comments
 (0)