Skip to content

fix: adjust client size constraints for frame insets before clamping - #51622

Merged
jkleinsc merged 1 commit into
electron:42-x-yfrom
gdavidkov:gdavidkov/42-x-y-cherry-pick-crbug-506480944
Jul 13, 2026
Merged

jkleinsc merged 1 commit into
electron:42-x-yfrom
gdavidkov:gdavidkov/42-x-y-cherry-pick-crbug-506480944

Conversation

@gdavidkov

@gdavidkov gdavidkov commented May 14, 2026 •

Copy link
Copy Markdown
Contributor

Description of Change

Note to maintainers: this is a Chromium CL cherry-pick to the 42-x-y release line only. Electron main is pinned to Chromium 150.0.7834.0, which already contains CL 7795073 natively (ui/views/win/hwnd_util.cc already exports InflateClientSizeConstraintsInPixels), so there is no electron/electron main PR to reference as Backport of #…. Please apply the backport-check-skip label so trop's required-check passes.

  • Backport of Chromium CL 7795073 (crbug.com/506480944) — original author Mitchell Cohen.
  • On Windows, BrowserWindow with useContentSize: true and a maxWidth / maxHeight configured was clamping the content area smaller than the configured maximum by the frame-inset amount. Fix corrects AdjustedContentBounds, OnGetMinMaxInfo, and SizeWindowToAspectRatio to inflate client-area constraints by frame insets before clamping the HWND.
  • Extracts the duplicated inset arithmetic into a new helper InflateClientSizeConstraintsInPixels() in ui/views/win/hwnd_util.{h,cc} to match the upstream merged state.
  • fix_aspect_ratio_with_max_size.patch is preserved; its inline inset block is refactored to call the new helper, so the aspect-ratio + maxWidth/maxHeight path keeps working.

Related

Test plan

  • frame: true + useContentSize: true at 125% scale — content clamps to exactly maxWidth × maxHeight (Δ = +0 × +0)
  • frame: true + useContentSize: true at 138% scale — Δ = +0 × +1 (sub-pixel rounding at non-integer scale)
  • frame: false + useContentSize: true at 138% scale — Δ = +0 × +1 (no regression on the frameless path)
  • frame: true + useContentSize: false at 138% scale — Δ ≈ −inset (documented window-coords-max behaviour preserved, matches stock 42.0.1 baseline)
  • e test — full spec suite (run separately)

Checklist

Release Notes

Notes: Fixed an issue on Windows where BrowserWindow with useContentSize: true would clamp the content area smaller than the configured maxWidth / maxHeight when programmatically resizing beyond those constraints via setBounds, setSize, or setContentSize.

@gdavidkov
gdavidkov requested a review from a team as a code owner May 14, 2026 15:48
@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label May 14, 2026
@gdavidkov

Copy link
Copy Markdown
Contributor Author

/request-review @mitchchn

@VerteDinde VerteDinde added semver/patch backwards-compatible bug fixes backport-check-skip Skip trop's backport validity checking 42-x-y labels Jun 5, 2026
@jkleinsc

jkleinsc commented Jun 8, 2026

Copy link
Copy Markdown
Member

@gdavidkov can you rebase this PR?

@gdavidkov
gdavidkov force-pushed the gdavidkov/42-x-y-cherry-pick-crbug-506480944 branch from b4c89bd to a3e5f43 Compare June 9, 2026 03:14
@gdavidkov

Copy link
Copy Markdown
Contributor Author

@gdavidkov can you rebase this PR?

Done — rebased onto the latest 42-x-y and force-pushed

@gdavidkov
gdavidkov force-pushed the gdavidkov/42-x-y-cherry-pick-crbug-506480944 branch 2 times, most recently from 9c800d7 to 0065cac Compare June 10, 2026 09:58
@gdavidkov
gdavidkov force-pushed the gdavidkov/42-x-y-cherry-pick-crbug-506480944 branch from 0065cac to 6ac203d Compare June 16, 2026 06:52
nikwen
nikwen previously requested changes Jun 16, 2026
Comment thread patches/chromium/.patches Resolved
@jkleinsc

Copy link
Copy Markdown
Member

@gdavidkov can you rebase on the latest from 42-x-y and update the patch by running e sync --3 and then e patches all?

@electron-datadog

This comment has been minimized.

@mitchchn

Copy link
Copy Markdown
Member

@gdavidkov please see if you can rebase and verify no issues with the apply patch, workflow, I'd like to get this in so we can backport #51562 to 42.x.

@gdavidkov
gdavidkov force-pushed the gdavidkov/42-x-y-cherry-pick-crbug-506480944 branch from 5d9cb68 to aba89b2 Compare June 24, 2026 17:58
Backport of https://chromium-review.googlesource.com/c/chromium/src/+/7795073
(Chromium bug 506480944, commit 22167afbecda05072355e5d8b324e00643b36bf4).

On Windows, when a widget reports its size as the client area
(WidgetSizeIsClientSize() is true), size constraints arrive in
client-area coordinates and must be inflated by the frame insets
before clamping the HWND. Without this, BrowserWindow.setBounds()
(and aspect-ratio-locked resize) constrain the window to a smaller
size than the configured maximum.

This is the full upstream CL: extracts the duplicated inset-inflation
arithmetic into a new helper InflateClientSizeConstraintsInPixels()
in ui/views/win/hwnd_util.{h,cc}, refactors OnGetMinMaxInfo and
SizeWindowToAspectRatio to use it, and adds the helper call to
AdjustedContentBounds (with a DIP<->screen-px roundtrip because
constraints arrive in DIPs at that call site).

Includes the helper extraction so the follow-up patch
fix_use_adjustwindowrectexfordpi_for_dpi-consistent_frame_insets.patch
can layer on top to address the cross-DPI bug.

The existing patch fix_aspect_ratio_with_max_size.patch is kept in
place: its inline inset block in SizeWindowToAspectRatio is now
refactored away by this patch, but its other change (switching from
SizeRectToAspectRatioWithExcludedMargin to SizeRectToAspectRatio) is
preserved.

The upstream CL's unit test (DesktopWidgetTest.SetBoundsRespectsMaximumSize)
is omitted: Electron does not run views_unittests.

Notes: Fixed an issue where BrowserWindow.setBounds() on Windows could
clamp the window to a size smaller than the configured maximumSize by
the frame inset amount when useContentSize was true.
@gdavidkov
gdavidkov force-pushed the gdavidkov/42-x-y-cherry-pick-crbug-506480944 branch from aba89b2 to 5db8e3a Compare June 24, 2026 19:23
@gdavidkov

Copy link
Copy Markdown
Contributor Author

@jkleinsc @mitchchn Rebased.

@jkleinsc
jkleinsc merged commit 9e14b4b into electron:42-x-y Jul 13, 2026
226 of 232 checks passed
@release-clerk

release-clerk Bot commented Jul 13, 2026

Copy link
Copy Markdown

Release Notes Persisted

Fixed an issue on Windows where BrowserWindow with useContentSize: true would clamp the content area smaller than the configured maxWidth / maxHeight when programmatically resizing beyond those constraints via setBounds, setSize, or setContentSize.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

42-x-y backport-check-skip Skip trop's backport validity checking semver/patch backwards-compatible bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants