Merge pull request #2287 from atom/fix-mac-content-size

mac: Always call SetSize for frameless window
This commit is contained in:
Cheng Zhao 2015-07-21 10:53:17 +08:00
commit 8df8b5731e
2 changed files with 28 additions and 1 deletions

View file

@ -357,7 +357,7 @@ NativeWindowMac::NativeWindowMac(
// On OS X the initial window size doesn't include window frame.
bool use_content_size = false;
options.Get(switches::kUseContentSize, &use_content_size);
if (has_frame_ && !use_content_size)
if (!has_frame_ || !use_content_size)
SetSize(gfx::Size(width, height));
// Enable the NSView to accept first mouse event.
@ -494,6 +494,11 @@ gfx::Rect NativeWindowMac::GetBounds() {
}
void NativeWindowMac::SetContentSize(const gfx::Size& size) {
if (!has_frame_) {
SetSize(size);
return;
}
NSRect frame_nsrect = [window_ frame];
NSSize frame = frame_nsrect.size;
NSSize content = [window_ contentRectForFrameRect:frame_nsrect].size;
@ -507,6 +512,9 @@ void NativeWindowMac::SetContentSize(const gfx::Size& size) {
}
gfx::Size NativeWindowMac::GetContentSize() {
if (!has_frame_)
return GetSize();
NSRect bounds = [[window_ contentView] bounds];
return gfx::Size(bounds.size.width, bounds.size.height);
}

View file

@ -117,6 +117,15 @@ describe 'browser-window module', ->
assert.equal after[0], size[0]
assert.equal after[1], size[1]
it 'works for framless window', ->
w.destroy()
w = new BrowserWindow(show: false, frame: false, width: 400, height: 400)
size = [400, 400]
w.setContentSize size[0], size[1]
after = w.getContentSize()
assert.equal after[0], size[0]
assert.equal after[1], size[1]
describe 'BrowserWindow.fromId(id)', ->
it 'returns the window with id', ->
assert.equal w.id, BrowserWindow.fromId(w.id).id
@ -134,6 +143,16 @@ describe 'browser-window module', ->
assert.equal size[0], 400
assert.equal size[1], 400
it 'works for framless window', ->
w.destroy()
w = new BrowserWindow(show: false, frame: false, width: 400, height: 400, 'use-content-size': true)
contentSize = w.getContentSize()
assert.equal contentSize[0], 400
assert.equal contentSize[1], 400
size = w.getSize()
assert.equal size[0], 400
assert.equal size[1], 400
describe '"enable-larger-than-screen" option', ->
return if process.platform is 'linux'