From 7457f8128345d5ff16c582bf4d141574809f90fc Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 11 Dec 2014 14:25:51 -0800 Subject: [PATCH] mac: Fix installing view on frameless window Closes #601. --- atom/browser/native_window_mac.h | 4 +++ atom/browser/native_window_mac.mm | 46 +++++++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index 3170239ed866..2a34fe415154 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -11,6 +11,7 @@ #include "base/memory/scoped_ptr.h" #include "atom/browser/native_window.h" +@class FullSizeContentView; class SkRegion; namespace atom { @@ -98,6 +99,9 @@ class NativeWindowMac : public NativeWindow { base::scoped_nsobject window_; + // The view that will fill the whole frameless window. + base::scoped_nsobject content_view_; + bool is_kiosk_; NSInteger attention_request_id_; // identifier from requestUserAttention diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index 131e2096d42d..17e361f78925 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -25,6 +25,31 @@ static const CGFloat kAtomWindowCornerRadius = 4.0; - (CGFloat)roundedCornerRadius; @end +// This view always takes the size of its superview. It is intended to be used +// as a NSWindow's contentView. It is needed because NSWindow's implementation +// explicitly resizes the contentView at inopportune times. +@interface FullSizeContentView : NSView +@end + +@implementation FullSizeContentView + +// This method is directly called by NSWindow during a window resize on OSX +// 10.10.0, beta 2. We must override it to prevent the content view from +// shrinking. +- (void)setFrameSize:(NSSize)size { + if ([self superview]) + size = [[self superview] bounds].size; + [super setFrameSize:size]; +} + +// The contentView gets moved around during certain full-screen operations. +// This is less than ideal, and should eventually be removed. +- (void)viewDidMoveToSuperview { + [self setFrame:[[self superview] bounds]]; +} + +@end + @interface AtomNSWindowDelegate : NSObject { @private atom::NativeWindowMac* shell_; @@ -690,9 +715,24 @@ void NativeWindowMac::InstallView() { [view setFrame:[[window_ contentView] bounds]]; [[window_ contentView] addSubview:view]; } else { - NSView* frameView = [[window_ contentView] superview]; - [view setFrame:[frameView bounds]]; - [frameView addSubview:view]; + if (base::mac::IsOSYosemiteOrLater()) { + // In OSX 10.10, adding subviews to the root view for the NSView hierarchy + // produces warnings. To eliminate the warnings, we resize the contentView + // to fill the window, and add subviews to that. + // http://crbug.com/380412 + content_view_.reset([[FullSizeContentView alloc] init]); + [content_view_ + setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; + [content_view_ setFrame:[[[window_ contentView] superview] bounds]]; + [window_ setContentView:content_view_]; + + [view setFrame:[content_view_ bounds]]; + [content_view_ addSubview:view]; + } else { + NSView* frameView = [[window_ contentView] superview]; + [view setFrame:[frameView bounds]]; + [frameView addSubview:view]; + } ClipWebView();