fix: maximized window bounds when toggle setResizable (#40503)
This commit is contained in:
parent
2029224a84
commit
3340bc1bf9
5 changed files with 94 additions and 4 deletions
|
@ -682,11 +682,16 @@ void NativeWindowViews::Unmaximize() {
|
||||||
if (transparent()) {
|
if (transparent()) {
|
||||||
SetBounds(restore_bounds_, false);
|
SetBounds(restore_bounds_, false);
|
||||||
NotifyWindowUnmaximize();
|
NotifyWindowUnmaximize();
|
||||||
|
UpdateThickFrame();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
widget()->Restore();
|
widget()->Restore();
|
||||||
|
|
||||||
|
#if BUILDFLAG(IS_WIN)
|
||||||
|
UpdateThickFrame();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -719,6 +724,10 @@ void NativeWindowViews::Minimize() {
|
||||||
|
|
||||||
void NativeWindowViews::Restore() {
|
void NativeWindowViews::Restore() {
|
||||||
widget()->Restore();
|
widget()->Restore();
|
||||||
|
|
||||||
|
#if BUILDFLAG(IS_WIN)
|
||||||
|
UpdateThickFrame();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NativeWindowViews::IsMinimized() {
|
bool NativeWindowViews::IsMinimized() {
|
||||||
|
@ -892,12 +901,13 @@ void NativeWindowViews::SetResizable(bool resizable) {
|
||||||
extensions::SizeConstraints(content_size, content_size));
|
extensions::SizeConstraints(content_size, content_size));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if BUILDFLAG(IS_WIN)
|
|
||||||
if (has_frame() && thick_frame_)
|
|
||||||
FlipWindowStyle(GetAcceleratedWidget(), resizable, WS_THICKFRAME);
|
|
||||||
#endif
|
|
||||||
resizable_ = resizable;
|
resizable_ = resizable;
|
||||||
SetCanResize(resizable_);
|
SetCanResize(resizable_);
|
||||||
|
|
||||||
|
#if BUILDFLAG(IS_WIN)
|
||||||
|
UpdateThickFrame();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NativeWindowViews::MoveAbove(const std::string& sourceId) {
|
bool NativeWindowViews::MoveAbove(const std::string& sourceId) {
|
||||||
|
@ -1644,6 +1654,22 @@ void NativeWindowViews::SetIcon(const gfx::ImageSkia& icon) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if BUILDFLAG(IS_WIN)
|
||||||
|
void NativeWindowViews::UpdateThickFrame() {
|
||||||
|
if (!thick_frame_)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (IsMaximized() && !transparent()) {
|
||||||
|
// For maximized window add thick frame always, otherwise it will be removed
|
||||||
|
// in HWNDMessageHandler::SizeConstraintsChanged() which will result in
|
||||||
|
// maximized window bounds change.
|
||||||
|
FlipWindowStyle(GetAcceleratedWidget(), true, WS_THICKFRAME);
|
||||||
|
} else if (has_frame()) {
|
||||||
|
FlipWindowStyle(GetAcceleratedWidget(), resizable_, WS_THICKFRAME);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void NativeWindowViews::OnWidgetActivationChanged(views::Widget* changed_widget,
|
void NativeWindowViews::OnWidgetActivationChanged(views::Widget* changed_widget,
|
||||||
bool active) {
|
bool active) {
|
||||||
if (changed_widget != widget())
|
if (changed_widget != widget())
|
||||||
|
|
|
@ -190,6 +190,8 @@ class NativeWindowViews : public NativeWindow,
|
||||||
void set_overlay_symbol_color(SkColor color) {
|
void set_overlay_symbol_color(SkColor color) {
|
||||||
overlay_symbol_color_ = color;
|
overlay_symbol_color_ = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UpdateThickFrame();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -30,6 +30,16 @@ void ElectronDesktopNativeWidgetAura::InitNativeWidget(
|
||||||
views::DesktopNativeWidgetAura::InitNativeWidget(std::move(params));
|
views::DesktopNativeWidgetAura::InitNativeWidget(std::move(params));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if BUILDFLAG(IS_WIN)
|
||||||
|
void ElectronDesktopNativeWidgetAura::OnSizeConstraintsChanged() {
|
||||||
|
views::DesktopNativeWidgetAura::OnSizeConstraintsChanged();
|
||||||
|
|
||||||
|
// OnSizeConstraintsChanged can remove thick frame depending from
|
||||||
|
// resizable state, so add it if needed.
|
||||||
|
native_window_view_->UpdateThickFrame();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void ElectronDesktopNativeWidgetAura::Activate() {
|
void ElectronDesktopNativeWidgetAura::Activate() {
|
||||||
// Activate can cause the focused window to be blurred so only
|
// Activate can cause the focused window to be blurred so only
|
||||||
// call when the window being activated is visible. This prevents
|
// call when the window being activated is visible. This prevents
|
||||||
|
|
|
@ -27,6 +27,9 @@ class ElectronDesktopNativeWidgetAura : public views::DesktopNativeWidgetAura {
|
||||||
|
|
||||||
// views::DesktopNativeWidgetAura:
|
// views::DesktopNativeWidgetAura:
|
||||||
void InitNativeWidget(views::Widget::InitParams params) override;
|
void InitNativeWidget(views::Widget::InitParams params) override;
|
||||||
|
#if BUILDFLAG(IS_WIN)
|
||||||
|
void OnSizeConstraintsChanged() override;
|
||||||
|
#endif
|
||||||
|
|
||||||
// internal::NativeWidgetPrivate:
|
// internal::NativeWidgetPrivate:
|
||||||
void Activate() override;
|
void Activate() override;
|
||||||
|
|
|
@ -5091,6 +5091,55 @@ describe('BrowserWindow module', () => {
|
||||||
w.setContentSize(10, 10);
|
w.setContentSize(10, 10);
|
||||||
expectBoundsEqual(w.getContentSize(), [10, 10]);
|
expectBoundsEqual(w.getContentSize(), [10, 10]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ifit(process.platform === 'win32')('do not change window with frame bounds when maximized', () => {
|
||||||
|
const w = new BrowserWindow({
|
||||||
|
show: true,
|
||||||
|
frame: true,
|
||||||
|
thickFrame: true
|
||||||
|
});
|
||||||
|
expect(w.isResizable()).to.be.true('resizable');
|
||||||
|
w.maximize();
|
||||||
|
expect(w.isMaximized()).to.be.true('maximized');
|
||||||
|
const bounds = w.getBounds();
|
||||||
|
w.setResizable(false);
|
||||||
|
expectBoundsEqual(w.getBounds(), bounds);
|
||||||
|
w.setResizable(true);
|
||||||
|
expectBoundsEqual(w.getBounds(), bounds);
|
||||||
|
});
|
||||||
|
|
||||||
|
ifit(process.platform === 'win32')('do not change window without frame bounds when maximized', () => {
|
||||||
|
const w = new BrowserWindow({
|
||||||
|
show: true,
|
||||||
|
frame: false,
|
||||||
|
thickFrame: true
|
||||||
|
});
|
||||||
|
expect(w.isResizable()).to.be.true('resizable');
|
||||||
|
w.maximize();
|
||||||
|
expect(w.isMaximized()).to.be.true('maximized');
|
||||||
|
const bounds = w.getBounds();
|
||||||
|
w.setResizable(false);
|
||||||
|
expectBoundsEqual(w.getBounds(), bounds);
|
||||||
|
w.setResizable(true);
|
||||||
|
expectBoundsEqual(w.getBounds(), bounds);
|
||||||
|
});
|
||||||
|
|
||||||
|
ifit(process.platform === 'win32')('do not change window transparent without frame bounds when maximized', () => {
|
||||||
|
const w = new BrowserWindow({
|
||||||
|
show: true,
|
||||||
|
frame: false,
|
||||||
|
thickFrame: true,
|
||||||
|
transparent: true
|
||||||
|
});
|
||||||
|
expect(w.isResizable()).to.be.true('resizable');
|
||||||
|
w.maximize();
|
||||||
|
expect(w.isMaximized()).to.be.true('maximized');
|
||||||
|
const bounds = w.getBounds();
|
||||||
|
w.setResizable(false);
|
||||||
|
expectBoundsEqual(w.getBounds(), bounds);
|
||||||
|
w.setResizable(true);
|
||||||
|
expectBoundsEqual(w.getBounds(), bounds);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('loading main frame state', () => {
|
describe('loading main frame state', () => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue