|
@@ -29,9 +29,56 @@
|
|
|
#include "ui/gfx/skia_util.h"
|
|
|
#include "ui/gl/gpu_switching_manager.h"
|
|
|
#include "ui/views/background.h"
|
|
|
+#include "ui/views/cocoa/bridged_content_view.h"
|
|
|
#include "ui/views/cocoa/bridged_native_widget.h"
|
|
|
#include "ui/views/widget/widget.h"
|
|
|
|
|
|
+// This view would inform Chromium to resize the hosted views::View.
|
|
|
+//
|
|
|
+// The overrided methods should behave the same with BridgedContentView.
|
|
|
+@interface ElectronAdapatedContentView : NSView {
|
|
|
+ @private
|
|
|
+ views::BridgedNativeWidget* bridged_widget_;
|
|
|
+}
|
|
|
+@end
|
|
|
+
|
|
|
+@implementation ElectronAdapatedContentView
|
|
|
+
|
|
|
+- (id)initWithShell:(atom::NativeWindowMac*)shell {
|
|
|
+ if ((self = [self init])) {
|
|
|
+ bridged_widget_ = views::NativeWidgetMac::GetBridgeForNativeWindow(
|
|
|
+ shell->GetNativeWindow());
|
|
|
+ }
|
|
|
+ return self;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)viewDidMoveToWindow {
|
|
|
+ // When this view is added to a window, AppKit calls setFrameSize before it is
|
|
|
+ // added to the window, so the behavior in setFrameSize is not triggered.
|
|
|
+ NSWindow* window = [self window];
|
|
|
+ if (window)
|
|
|
+ [self setFrameSize:NSZeroSize];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)setFrameSize:(NSSize)newSize {
|
|
|
+ // The size passed in here does not always use
|
|
|
+ // -[NSWindow contentRectForFrameRect]. The following ensures that the
|
|
|
+ // contentView for a frameless window can extend over the titlebar of the new
|
|
|
+ // window containing it, since AppKit requires a titlebar to give frameless
|
|
|
+ // windows correct shadows and rounded corners.
|
|
|
+ NSWindow* window = [self window];
|
|
|
+ if (window && [window contentView] == self)
|
|
|
+ newSize = [window contentRectForFrameRect:[window frame]].size;
|
|
|
+
|
|
|
+ [super setFrameSize:newSize];
|
|
|
+
|
|
|
+ views::View* hostedView = [bridged_widget_->ns_view() hostedView];
|
|
|
+ if (hostedView)
|
|
|
+ hostedView->SetSize(gfx::Size(newSize.width, newSize.height));
|
|
|
+}
|
|
|
+
|
|
|
+@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.
|
|
@@ -1493,10 +1540,15 @@ void NativeWindowMac::OverrideNSWindowContentView() {
|
|
|
// `BridgedContentView` as content view, which does not support draggable
|
|
|
// regions. In order to make draggable regions work, we have to replace the
|
|
|
// content view with a simple NSView.
|
|
|
- container_view_.reset([[FullSizeContentView alloc] init]);
|
|
|
+ if (has_frame()) {
|
|
|
+ container_view_.reset(
|
|
|
+ [[ElectronAdapatedContentView alloc] initWithShell:this]);
|
|
|
+ } else {
|
|
|
+ container_view_.reset([[FullSizeContentView alloc] init]);
|
|
|
+ [container_view_ setFrame:[[[window_ contentView] superview] bounds]];
|
|
|
+ }
|
|
|
[container_view_
|
|
|
setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
|
|
|
- [container_view_ setFrame:[[[window_ contentView] superview] bounds]];
|
|
|
[window_ setContentView:container_view_];
|
|
|
AddContentViewLayers(IsMinimizable(), IsClosable());
|
|
|
}
|