]> khamidou — GitHub mirrors - electron.git/commitdiff
mac: Fix installing view on frameless window
authorCheng Zhao <zcbenz@gmail.com>
Thu, 11 Dec 2014 22:25:51 +0000 (14:25 -0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 11 Dec 2014 22:25:51 +0000 (14:25 -0800)
Closes #601.

atom/browser/native_window_mac.h
atom/browser/native_window_mac.mm

index 3170239ed866190f43495b7bc8efa0a6ffaef899..2a34fe415154c25e497b7b8f64d08245371a370c 100644 (file)
@@ -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<NSWindow> window_;
 
+  // The view that will fill the whole frameless window.
+  base::scoped_nsobject<FullSizeContentView> content_view_;
+
   bool is_kiosk_;
 
   NSInteger attention_request_id_;  // identifier from requestUserAttention
index 131e2096d42d8f97779a4edfcc0accd95e547528..17e361f7892525467b2daad99dbe3098767c1e26 100644 (file)
@@ -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<NSWindowDelegate> {
  @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();