Merge pull request #91 from atom/rounded-corner
Round whole frame in Frameless mode
This commit is contained in:
commit
a2c3690592
4 changed files with 36 additions and 68 deletions
|
@ -63,6 +63,9 @@ class NativeWindowMac : public NativeWindow {
|
||||||
// Called to handle a mouse event.
|
// Called to handle a mouse event.
|
||||||
void HandleMouseEvent(NSEvent* event);
|
void HandleMouseEvent(NSEvent* event);
|
||||||
|
|
||||||
|
// Clip web view to rounded corner.
|
||||||
|
void ClipWebView();
|
||||||
|
|
||||||
NSWindow*& window() { return window_; }
|
NSWindow*& window() { return window_; }
|
||||||
SkRegion* draggable_region() const { return draggable_region_.get(); }
|
SkRegion* draggable_region() const { return draggable_region_.get(); }
|
||||||
|
|
||||||
|
|
|
@ -24,13 +24,7 @@
|
||||||
#include "content/public/browser/web_contents_view.h"
|
#include "content/public/browser/web_contents_view.h"
|
||||||
#include "content/public/browser/render_view_host.h"
|
#include "content/public/browser/render_view_host.h"
|
||||||
|
|
||||||
@interface NSWindow (NSPrivateApis)
|
static const CGFloat kAtomWindowCornerRadius = 4.0;
|
||||||
- (void)setBottomCornerRounded:(BOOL)rounded;
|
|
||||||
@end
|
|
||||||
|
|
||||||
@interface NSView (WebContentsView)
|
|
||||||
- (void)setMouseDownCanMoveWindow:(BOOL)can_move;
|
|
||||||
@end
|
|
||||||
|
|
||||||
@interface NSView (PrivateMethods)
|
@interface NSView (PrivateMethods)
|
||||||
- (CGFloat)roundedCornerRadius;
|
- (CGFloat)roundedCornerRadius;
|
||||||
|
@ -55,6 +49,11 @@
|
||||||
shell_->NotifyWindowBlur();
|
shell_->NotifyWindowBlur();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)windowDidResize:(NSNotification*)otification {
|
||||||
|
if (!shell_->has_frame())
|
||||||
|
shell_->ClipWebView();
|
||||||
|
}
|
||||||
|
|
||||||
- (void)windowWillClose:(NSNotification*)notification {
|
- (void)windowWillClose:(NSNotification*)notification {
|
||||||
shell_->window() = nil;
|
shell_->window() = nil;
|
||||||
[self autorelease];
|
[self autorelease];
|
||||||
|
@ -78,7 +77,7 @@
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface AtomNSWindow : AtomEventProcessingWindow {
|
@interface AtomNSWindow : AtomEventProcessingWindow {
|
||||||
@private
|
@protected
|
||||||
atom::NativeWindowMac* shell_;
|
atom::NativeWindowMac* shell_;
|
||||||
}
|
}
|
||||||
- (void)setShell:(atom::NativeWindowMac*)shell;
|
- (void)setShell:(atom::NativeWindowMac*)shell;
|
||||||
|
@ -101,48 +100,6 @@
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface AtomFramelessNSWindow : AtomNSWindow
|
|
||||||
- (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view;
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation AtomFramelessNSWindow
|
|
||||||
|
|
||||||
- (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view {
|
|
||||||
[[NSBezierPath bezierPathWithRect:rect] addClip];
|
|
||||||
[[NSColor clearColor] set];
|
|
||||||
NSRectFill(rect);
|
|
||||||
|
|
||||||
// Set up our clip.
|
|
||||||
CGFloat cornerRadius = 4.0;
|
|
||||||
if ([view respondsToSelector:@selector(roundedCornerRadius)])
|
|
||||||
cornerRadius = [view roundedCornerRadius];
|
|
||||||
[[NSBezierPath bezierPathWithRoundedRect:[view bounds]
|
|
||||||
xRadius:cornerRadius
|
|
||||||
yRadius:cornerRadius] addClip];
|
|
||||||
[[NSColor whiteColor] set];
|
|
||||||
NSRectFill(rect);
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (NSRect)frameRectForContentRect:(NSRect)contentRect
|
|
||||||
styleMask:(NSUInteger)mask {
|
|
||||||
return contentRect;
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (NSRect)contentRectForFrameRect:(NSRect)frameRect
|
|
||||||
styleMask:(NSUInteger)mask {
|
|
||||||
return frameRect;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSRect)frameRectForContentRect:(NSRect)contentRect {
|
|
||||||
return contentRect;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSRect)contentRectForFrameRect:(NSRect)frameRect {
|
|
||||||
return frameRect;
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
@interface ControlRegionView : NSView {
|
@interface ControlRegionView : NSView {
|
||||||
@private
|
@private
|
||||||
atom::NativeWindowMac* shellWindow_; // Weak; owns self.
|
atom::NativeWindowMac* shellWindow_; // Weak; owns self.
|
||||||
|
@ -191,27 +148,24 @@ NativeWindowMac::NativeWindowMac(content::WebContents* web_contents,
|
||||||
|
|
||||||
NSRect main_screen_rect = [[[NSScreen screens] objectAtIndex:0] frame];
|
NSRect main_screen_rect = [[[NSScreen screens] objectAtIndex:0] frame];
|
||||||
NSRect cocoa_bounds = NSMakeRect(
|
NSRect cocoa_bounds = NSMakeRect(
|
||||||
(NSWidth(main_screen_rect) - width) / 2,
|
round((NSWidth(main_screen_rect) - width) / 2) ,
|
||||||
(NSHeight(main_screen_rect) - height) / 2,
|
round((NSHeight(main_screen_rect) - height) / 2),
|
||||||
width,
|
width,
|
||||||
height);
|
height);
|
||||||
NSUInteger style_mask = NSTitledWindowMask | NSClosableWindowMask |
|
|
||||||
|
AtomNSWindow* atomWindow;
|
||||||
|
|
||||||
|
atomWindow = [[AtomNSWindow alloc]
|
||||||
|
initWithContentRect:cocoa_bounds
|
||||||
|
styleMask:NSTitledWindowMask | NSClosableWindowMask |
|
||||||
NSMiniaturizableWindowMask | NSResizableWindowMask |
|
NSMiniaturizableWindowMask | NSResizableWindowMask |
|
||||||
NSTexturedBackgroundWindowMask;
|
NSTexturedBackgroundWindowMask
|
||||||
AtomNSWindow* atom_window = has_frame_ ?
|
|
||||||
[[AtomNSWindow alloc]
|
|
||||||
initWithContentRect:cocoa_bounds
|
|
||||||
styleMask:style_mask
|
|
||||||
backing:NSBackingStoreBuffered
|
|
||||||
defer:YES] :
|
|
||||||
[[AtomFramelessNSWindow alloc]
|
|
||||||
initWithContentRect:cocoa_bounds
|
|
||||||
styleMask:style_mask
|
|
||||||
backing:NSBackingStoreBuffered
|
backing:NSBackingStoreBuffered
|
||||||
defer:YES];
|
defer:YES];
|
||||||
[atom_window setShell:this];
|
|
||||||
|
|
||||||
window_ = atom_window;
|
[atomWindow setShell:this];
|
||||||
|
window_ = atomWindow;
|
||||||
|
|
||||||
[window() setDelegate:[[AtomNSWindowDelegate alloc] initWithShell:this]];
|
[window() setDelegate:[[AtomNSWindowDelegate alloc] initWithShell:this]];
|
||||||
|
|
||||||
// Disable fullscreen button when 'fullscreen' is specified to false.
|
// Disable fullscreen button when 'fullscreen' is specified to false.
|
||||||
|
@ -434,7 +388,7 @@ gfx::NativeWindow NativeWindowMac::GetNativeWindow() {
|
||||||
bool NativeWindowMac::IsWithinDraggableRegion(NSPoint point) const {
|
bool NativeWindowMac::IsWithinDraggableRegion(NSPoint point) const {
|
||||||
if (!draggable_region_)
|
if (!draggable_region_)
|
||||||
return false;
|
return false;
|
||||||
NSView* webView = web_contents()->GetView()->GetNativeView();
|
NSView* webView = GetWebContents()->GetView()->GetNativeView();
|
||||||
NSInteger webViewHeight = NSHeight([webView bounds]);
|
NSInteger webViewHeight = NSHeight([webView bounds]);
|
||||||
// |draggable_region_| is stored in local platform-indepdent coordiate system
|
// |draggable_region_| is stored in local platform-indepdent coordiate system
|
||||||
// while |point| is in local Cocoa coordinate system. Do the conversion
|
// while |point| is in local Cocoa coordinate system. Do the conversion
|
||||||
|
@ -491,6 +445,8 @@ void NativeWindowMac::InstallView() {
|
||||||
[view setFrame:[frameView bounds]];
|
[view setFrame:[frameView bounds]];
|
||||||
[frameView addSubview:view];
|
[frameView addSubview:view];
|
||||||
|
|
||||||
|
ClipWebView();
|
||||||
|
|
||||||
[[window() standardWindowButton:NSWindowZoomButton] setHidden:YES];
|
[[window() standardWindowButton:NSWindowZoomButton] setHidden:YES];
|
||||||
[[window() standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES];
|
[[window() standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES];
|
||||||
[[window() standardWindowButton:NSWindowCloseButton] setHidden:YES];
|
[[window() standardWindowButton:NSWindowCloseButton] setHidden:YES];
|
||||||
|
@ -503,6 +459,14 @@ void NativeWindowMac::UninstallView() {
|
||||||
[view removeFromSuperview];
|
[view removeFromSuperview];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NativeWindowMac::ClipWebView() {
|
||||||
|
NSView* view = GetWebContents()->GetView()->GetNativeView();
|
||||||
|
|
||||||
|
view.wantsLayer = YES;
|
||||||
|
view.layer.masksToBounds = YES;
|
||||||
|
view.layer.cornerRadius = kAtomWindowCornerRadius;
|
||||||
|
}
|
||||||
|
|
||||||
void NativeWindowMac::InstallDraggableRegionViews() {
|
void NativeWindowMac::InstallDraggableRegionViews() {
|
||||||
DCHECK(!has_frame_);
|
DCHECK(!has_frame_);
|
||||||
|
|
||||||
|
|
1
script/cpplint.py
vendored
1
script/cpplint.py
vendored
|
@ -12,6 +12,7 @@ IGNORE_FILES = [
|
||||||
'browser/atom_application_delegate_mac.h',
|
'browser/atom_application_delegate_mac.h',
|
||||||
'browser/native_window_mac.h',
|
'browser/native_window_mac.h',
|
||||||
'browser/ui/atom_menu_controller_mac.h',
|
'browser/ui/atom_menu_controller_mac.h',
|
||||||
|
'browser/ui/cocoa/custom_frame_view.h',
|
||||||
'browser/ui/nsalert_synchronous_sheet_mac.h',
|
'browser/ui/nsalert_synchronous_sheet_mac.h',
|
||||||
'common/api/api_messages.cc',
|
'common/api/api_messages.cc',
|
||||||
'common/api/api_messages.h',
|
'common/api/api_messages.h',
|
||||||
|
|
Loading…
Reference in a new issue