report correct content size in AtomNSWindow

The views framework relies on NSWindow to return content size of window,
since we don't use the borderless window, the original result would
include titlebar. We have to override the function to return correct
result for frameless window.
This commit is contained in:
Cheng Zhao 2018-05-02 21:28:28 +09:00
parent 28fc58067b
commit 5547df6073
5 changed files with 35 additions and 14 deletions

View file

@ -232,7 +232,6 @@ void SetFrameSize(NSView* self, SEL _cmd, NSSize size) {
// For frameless window, resize the view to cover full window.
if ([self superview])
size = [[self superview] bounds].size;
// [super setFrameSize:size];
auto super_impl = reinterpret_cast<decltype(&SetFrameSize)>(
[[self superclass] instanceMethodForSelector:_cmd]);
super_impl(self, _cmd, size);
@ -332,11 +331,10 @@ NativeWindowMac::NativeWindowMac(const mate::Dictionary& options,
params.bounds = bounds;
params.delegate = this;
params.type = views::Widget::InitParams::TYPE_WINDOW;
params.native_widget = new AtomNativeWidgetMac(styleMask, widget());
params.native_widget = new AtomNativeWidgetMac(this, styleMask, widget());
widget()->Init(params);
window_ = static_cast<AtomNSWindow*>(widget()->GetNativeWindow());
[window_ setShell:this];
[window_ setEnableLargerThanScreen:enable_larger_than_screen()];
window_delegate_.reset([[AtomNSWindowDelegate alloc] initWithShell:this]);
@ -714,7 +712,7 @@ void NativeWindowMac::SetContentSizeConstraints(
// will result in actual content size being larger.
if (!has_frame()) {
NSRect frame = NSMakeRect(0, 0, size.width(), size.height());
NSRect content = [window_ contentRectForFrameRect:frame];
NSRect content = [window_ originalContentRectForFrameRect:frame];
return content.size;
} else {
return NSMakeSize(size.width(), size.height());