fix: don't allow window to go behind menu bar on mac (#22770)

This commit is contained in:
CezaryKulakowski 2020-03-25 03:13:43 +01:00 committed by GitHub
parent 07cd70a37e
commit bdef77bad8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View file

@ -89,11 +89,11 @@ bool ScopedDisableResize::disable_resize_ = false;
if (electron::ScopedDisableResize::IsResizeDisabled())
return [self frame];
NSRect result = [super constrainFrameRect:frameRect toScreen:screen];
// Enable the window to be larger than screen.
if ([self enableLargerThanScreen])
return frameRect;
else
return [super constrainFrameRect:frameRect toScreen:screen];
result.size = frameRect.size;
return result;
}
- (void)setFrame:(NSRect)windowFrame display:(BOOL)displayViews {

View file

@ -1597,10 +1597,16 @@ describe('BrowserWindow module', () => {
ifdescribe(process.platform === 'darwin')('"enableLargerThanScreen" option', () => {
afterEach(closeAllWindows);
it('can move the window out of screen', () => {
const w = new BrowserWindow({ show: true, enableLargerThanScreen: true });
w.setPosition(-10, 50);
const after = w.getPosition();
expect(after).to.deep.equal([-10, 50]);
});
it('cannot move the window behind menu bar', () => {
const w = new BrowserWindow({ show: true, enableLargerThanScreen: true });
w.setPosition(-10, -10);
const after = w.getPosition();
expect(after).to.deep.equal([-10, -10]);
expect(after[1]).to.be.at.least(0);
});
it('without it, cannot move the window out of screen', () => {
const w = new BrowserWindow({ show: true, enableLargerThanScreen: false });