Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fire show event when BrowserWindow shown via maximize() #33212

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions shell/browser/native_window_views.cc
Expand Up @@ -568,11 +568,13 @@ void NativeWindowViews::SetEnabledInternal(bool enable) {

#if defined(OS_LINUX)
void NativeWindowViews::Maximize() {
if (IsVisible())
if (IsVisible()) {
widget()->Maximize();
else
} else {
widget()->native_widget_private()->Show(ui::SHOW_STATE_MAXIMIZED,
gfx::Rect());
NotifyWindowShow();
}
}
#endif

Expand Down
7 changes: 4 additions & 3 deletions shell/browser/native_window_views_win.cc
Expand Up @@ -176,12 +176,13 @@ HHOOK NativeWindowViews::mouse_hook_ = NULL;
void NativeWindowViews::Maximize() {
// Only use Maximize() when window is NOT transparent style
if (!transparent()) {
if (IsVisible())
if (IsVisible()) {
widget()->Maximize();
else
} else {
widget()->native_widget_private()->Show(ui::SHOW_STATE_MAXIMIZED,
gfx::Rect());
return;
NotifyWindowShow();
}
} else {
restore_bounds_ = GetBounds();
auto display = display::Screen::GetScreen()->GetDisplayNearestWindow(
Expand Down
23 changes: 23 additions & 0 deletions spec-main/api-browser-window-spec.ts
Expand Up @@ -3550,6 +3550,29 @@ describe('BrowserWindow module', () => {
});
});

// TODO(dsanders11): Enable once maximize event works on Linux again on CI
ifdescribe(process.platform !== 'linux')('BrowserWindow.maximize()', () => {
afterEach(closeAllWindows);
// TODO(dsanders11): Disabled on macOS, see https://github.com/electron/electron/issues/32947
ifit(process.platform !== 'darwin')('should show the window if it is not currently shown', async () => {
const w = new BrowserWindow({ show: false });
const hidden = emittedOnce(w, 'hide');
const shown = emittedOnce(w, 'show');
const maximize = emittedOnce(w, 'maximize');
expect(w.isVisible()).to.be.false('visible');
w.maximize();
await maximize;
expect(w.isVisible()).to.be.true('visible');
// Even if the window is already maximized
w.hide();
await hidden;
expect(w.isVisible()).to.be.false('visible');
w.maximize();
await shown; // Ensure a 'show' event happens when it becomes visible
expect(w.isVisible()).to.be.true('visible');
});
});

describe('BrowserWindow.unmaximize()', () => {
afterEach(closeAllWindows);
it('should restore the previous window position', () => {
Expand Down