fix: don't allow window to go behind menu bar on mac (#22770)
This commit is contained in:
parent
07cd70a37e
commit
bdef77bad8
2 changed files with 10 additions and 4 deletions
|
@ -89,11 +89,11 @@ bool ScopedDisableResize::disable_resize_ = false;
|
||||||
if (electron::ScopedDisableResize::IsResizeDisabled())
|
if (electron::ScopedDisableResize::IsResizeDisabled())
|
||||||
return [self frame];
|
return [self frame];
|
||||||
|
|
||||||
|
NSRect result = [super constrainFrameRect:frameRect toScreen:screen];
|
||||||
// Enable the window to be larger than screen.
|
// Enable the window to be larger than screen.
|
||||||
if ([self enableLargerThanScreen])
|
if ([self enableLargerThanScreen])
|
||||||
return frameRect;
|
result.size = frameRect.size;
|
||||||
else
|
return result;
|
||||||
return [super constrainFrameRect:frameRect toScreen:screen];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setFrame:(NSRect)windowFrame display:(BOOL)displayViews {
|
- (void)setFrame:(NSRect)windowFrame display:(BOOL)displayViews {
|
||||||
|
|
|
@ -1597,10 +1597,16 @@ describe('BrowserWindow module', () => {
|
||||||
ifdescribe(process.platform === 'darwin')('"enableLargerThanScreen" option', () => {
|
ifdescribe(process.platform === 'darwin')('"enableLargerThanScreen" option', () => {
|
||||||
afterEach(closeAllWindows);
|
afterEach(closeAllWindows);
|
||||||
it('can move the window out of screen', () => {
|
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 });
|
const w = new BrowserWindow({ show: true, enableLargerThanScreen: true });
|
||||||
w.setPosition(-10, -10);
|
w.setPosition(-10, -10);
|
||||||
const after = w.getPosition();
|
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', () => {
|
it('without it, cannot move the window out of screen', () => {
|
||||||
const w = new BrowserWindow({ show: true, enableLargerThanScreen: false });
|
const w = new BrowserWindow({ show: true, enableLargerThanScreen: false });
|
||||||
|
|
Loading…
Reference in a new issue