fix: broken transparent window styles on resizable change (#48501)

* fix: wrong api call

Co-authored-by: zoy <zoy-l@outlook.com>

* fix: consistency of the resize state

Co-authored-by: zoy <zoy-l@outlook.com>

* fix: edge cases

Co-authored-by: zoy <zoy-l@outlook.com>

* chore: add detailed comments

Co-authored-by: zoy <zoy-l@outlook.com>

* fix: lint

Co-authored-by: zoy <zoy-l@outlook.com>

* chore: only windows

Co-authored-by: zoy <zoy-l@outlook.com>

* chore: use transparent

Co-authored-by: zoy <zoy-l@outlook.com>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: zoy <zoy-l@outlook.com>
This commit is contained in:
trop[bot] 2025-10-10 11:36:22 -04:00 committed by GitHub
commit db72ce78f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 20 additions and 16 deletions

View file

@ -267,7 +267,7 @@ NativeWindowViews::NativeWindowViews(const gin_helper::Dictionary& options,
params.remove_standard_frame = !has_frame() || has_client_frame();
// If a client frame, we need to draw our own shadows.
if (IsTranslucent() || has_client_frame())
if (transparent() || has_client_frame())
params.opacity = InitParams::WindowOpacity::kTranslucent;
// The given window is most likely not rectangular since it is translucent and
@ -301,7 +301,7 @@ NativeWindowViews::NativeWindowViews(const gin_helper::Dictionary& options,
widget()->Init(std::move(params));
widget()->SetNativeWindowProperty(kNativeWindowKey.c_str(), this);
SetCanResize(resizable_);
widget()->OnSizeConstraintsChanged();
const bool fullscreen = options.ValueOrDefault(options::kFullscreen, false);
@ -355,11 +355,11 @@ NativeWindowViews::NativeWindowViews(const gin_helper::Dictionary& options,
// frameless.
DWORD frame_style = WS_CAPTION | WS_OVERLAPPED;
if (resizable_)
if (CanResize())
frame_style |= WS_THICKFRAME;
if (minimizable_)
frame_style |= WS_MINIMIZEBOX;
if (maximizable_)
if (maximizable_ && CanResize())
frame_style |= WS_MAXIMIZEBOX;
// We should not show a frame for transparent window.
@ -867,7 +867,7 @@ void NativeWindowViews::SetBounds(const gfx::Rect& bounds, bool animate) {
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX)
// On Linux and Windows the minimum and maximum size should be updated with
// window size when window is not resizable.
if (!resizable_) {
if (!CanResize()) {
SetMaximumSize(bounds.size());
SetMinimumSize(bounds.size());
}
@ -948,26 +948,21 @@ extensions::SizeConstraints NativeWindowViews::GetContentSizeConstraints()
void NativeWindowViews::SetResizable(bool resizable) {
if (resizable != resizable_) {
resizable_ = resizable;
// On Linux there is no "resizable" property of a window, we have to set
// both the minimum and maximum size to the window size to achieve it.
if (resizable) {
SetContentSizeConstraints(old_size_constraints_);
SetMaximizable(maximizable_);
} else {
old_size_constraints_ = GetContentSizeConstraints();
resizable_ = false;
gfx::Size content_size = GetContentSize();
SetContentSizeConstraints(
extensions::SizeConstraints(content_size, content_size));
}
}
resizable_ = resizable;
SetCanResize(resizable_);
#if BUILDFLAG(IS_WIN)
UpdateThickFrame();
UpdateThickFrame();
#endif
}
}
bool NativeWindowViews::MoveAbove(const std::string& sourceId) {
@ -1012,12 +1007,20 @@ void NativeWindowViews::MoveTop() {
#endif
}
bool NativeWindowViews::CanResize() const {
#if BUILDFLAG(IS_WIN)
return resizable_ && thick_frame_;
#else
return resizable_;
#endif
}
bool NativeWindowViews::IsResizable() const {
#if BUILDFLAG(IS_WIN)
if (has_frame())
return ::GetWindowLong(GetAcceleratedWidget(), GWL_STYLE) & WS_THICKFRAME;
#endif
return resizable_;
return CanResize();
}
void NativeWindowViews::SetAspectRatio(double aspect_ratio,
@ -1818,7 +1821,7 @@ views::View* NativeWindowViews::GetInitiallyFocusedView() {
}
bool NativeWindowViews::CanMaximize() const {
return resizable_ && maximizable_;
return CanResize() && maximizable_;
}
bool NativeWindowViews::CanMinimize() const {

View file

@ -89,6 +89,7 @@ class NativeWindowViews : public NativeWindow,
bool IsResizable() const override;
void SetAspectRatio(double aspect_ratio,
const gfx::Size& extra_size) override;
bool CanResize() const override;
void SetMovable(bool movable) override;
bool IsMovable() const override;
void SetMinimizable(bool minimizable) override;

View file

@ -5455,7 +5455,7 @@ describe('BrowserWindow module', () => {
thickFrame: true,
transparent: true
});
expect(w.isResizable()).to.be.true('resizable');
expect(w.isResizable()).to.be.false('resizable');
w.maximize();
expect(w.isMaximized()).to.be.true('maximized');
const bounds = w.getBounds();