Repository navigation
fix: clamp zoom to minimum 1.0 on Windows and macOS - #5205
Conversation
When SetZoom is called with a value less than 1.0, the rendered web content shrinks but the window's hit-testing area is not adjusted. This causes the invisible region outside the content to still be draggable and resizable. Linux already clamps to 1.0 minimum. Apply the same guard on Windows and macOS for consistency and to prevent the drag/resize area mismatch bug. Fixes #4590
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
WalkthroughThis PR prevents zoom levels below 1.0 from being applied to webview windows on macOS and Windows, addressing UI scaling and window edge dragging issues. The implementation adds zoom value clamping in both platform-specific ChangesZoom Level Clamping
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies" Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Tested on Windows 11 Pro 24H2 (Build 26100) — verdict: ✓ pass
Test results (
The three-line guard in PR test pass on Windows (go1.26.2 / WebView2 147.0.3912.98 / amd64) |
|
Simple but important fix! Zoom values below 1.0 causing invisible draggable/resizable regions is a UX issue that should be caught early. The clamp brings Windows and macOS in line with Linux. I've dispatched cross-platform test sub-issues:
Once all platforms report back with successful test results, I'll apply the CC @leaanthony |
|
Investigating on Windows 11 Pro (24H2, Build 26100). Test environment: Go 1.26.2 · WebView2 147.0.3912.86 Unit tests ( All 7 clamp-logic subtests pass on Windows. The 3-line guard in CC @leaanthony |
Every backend raised a factor below 1.0 to 1.0 in setZoom, so Window.SetZoom(0.8) silently applied 100%. The floor came from wailsapp#5205, which closed wailsapp#4590 (SetZoom(0.5) leaves drag and resize regions where the content used to be) by clamping the input instead of adjusting those regions, citing the Linux clamp as precedent. None of the backends needs it: WebView2 only rejects factors <= 0 and normalises values outside its own range itself; WKWebView's magnification and WebKitGTK's zoom level accept any positive value. The window option WebviewWindowOptions.Zoom never had the floor either: on Windows it is passed straight to PutZoomFactor at creation, so a window could start at 80% but never be set to 80% afterwards. setZoom now goes through zoomFactor, which - rejects non-positive, NaN and Inf factors (WebView2 returns an error for them, WKWebView raises NSInvalidArgumentException, fatal from cgo) instead of raising them to 1.0, - keeps the 1.0 floor for frameless windows only, whose drag and resize regions are what wailsapp#4590 is about; framed windows leave resizing to the OS and get the requested factor. TestZoomClamp reimplemented the clamp inside the test body and never called production code; TestZoomFactor exercises the helper instead. ZoomIn, ZoomOut and ZoomReset are untouched.
Every backend raised a factor below 1.0 to 1.0 in setZoom, so Window.SetZoom(0.8) silently applied 100%. The floor came from wailsapp#5205, which closed wailsapp#4590 (SetZoom(0.5) leaves drag and resize regions where the content used to be) by clamping the input instead of adjusting those regions, citing the Linux clamp as precedent. None of the backends needs it: WebView2 only rejects factors <= 0 and normalises values outside its own range itself; WKWebView's magnification and WebKitGTK's zoom level accept any positive value. The window option WebviewWindowOptions.Zoom never had the floor either: on Windows it is passed straight to PutZoomFactor at creation, so a window could start at 80% but never be set to 80% afterwards. setZoom now goes through zoomFactor, which - rejects non-positive, NaN and Inf factors (WebView2 returns an error for them, WKWebView raises NSInvalidArgumentException, fatal from cgo) instead of raising them to 1.0, - keeps the 1.0 floor for frameless windows only, whose drag and resize regions are what wailsapp#4590 is about; framed windows leave resizing to the OS and get the requested factor. TestZoomClamp reimplemented the clamp inside the test body and never called production code; TestZoomFactor exercises the helper instead. ZoomIn, ZoomOut and ZoomReset are untouched.
fix(v3): let Window.SetZoom go below 1.0 on framed windows Every backend raised a factor below 1.0 to 1.0 in setZoom, so Window.SetZoom(0.8) silently applied 100%. The floor came from #5205, which closed #4590 (SetZoom(0.5) leaves drag and resize regions where the content used to be) by clamping the input instead of adjusting those regions, citing the Linux clamp as precedent. None of the backends needs it: WebView2 only rejects factors <= 0 and normalises values outside its own range itself; WKWebView's magnification and WebKitGTK's zoom level accept any positive value. The window option WebviewWindowOptions.Zoom never had the floor either: on Windows it is passed straight to PutZoomFactor at creation, so a window could start at 80% but never be set to 80% afterwards. setZoom now goes through zoomFactor, which - rejects non-positive, NaN and Inf factors (WebView2 returns an error for them, WKWebView raises NSInvalidArgumentException, fatal from cgo) instead of raising them to 1.0, - keeps the 1.0 floor for frameless windows only, whose drag and resize regions are what #4590 is about; framed windows leave resizing to the OS and get the requested factor. TestZoomClamp reimplemented the clamp inside the test body and never called production code; TestZoomFactor exercises the helper instead. ZoomIn, ZoomOut and ZoomReset are untouched. Co-authored-by: Lea Anthony <[email protected]>
Summary
SetZoom(0.5)causes the rendered content to shrink but the window's hit-testing area is not adjusted, making invisible regions draggable/resizableTest plan
TestZoomClampverifies the clamping logic for values below, at, and above 1.0window.SetZoom(0.5)and verify the call is clamped to 1.0Fixes #4590
Summary by CodeRabbit