#54374: fix: clamp zoom levels to the displayable range and keep the page scale when visual zoom limits change
Description of Change
After this change zoom in/out responds immediately at the ends of the zoom range, getZoomLevel()/getZoomFactor() report what is on screen, and setVisualZoomLevelLimits() with a minimum below 1 no longer shrinks the page.
Two causes. setZoomLevel(), setZoomFactor() and the zoomIn/zoomOut roles stored any level in the HostZoomMap while the renderer only displays 25% to 500%, so after zooming past an end the stored value kept moving and the opposite command had to be repeated before anything changed. Separately, Blink resolves an unset initial page scale to the minimum limit, so a visual zoom minimum below 1 rescaled the whole page on the next layout.
WebContentsZoomController::SetZoomLevel now clamps to Blink's displayable range, and the renderer pins the initial page scale to 1 when visual zoom limits are set. Three specs fail on main (factor 100 stored as 100, zoomIn does not recover, visualViewport.scale reads 0.25 after a resize) and pass here; the other zoom specs are unchanged. Docs state the clamping range.
Checklist
- I have built and tested this change
- I have filled out the PR description
- I have reviewed and verified the changes
- tests are changed or added
- relevant API documentation, tutorials, and examples are updated and follow the documentation style guide
Release Notes
Notes:
- Fixed zoom in/out getting stuck after zooming past the 25%-500% range.
- Fixed
setVisualZoomLevelLimits()shrinking pages when the minimum is under 1.
Backports
Semver Impact
Semantic Versioning helps users understand the impact of updates:
- Major (X.y.z): Breaking changes that may require code modifications
- Minor (x.Y.z): New features that maintain backward compatibility
- Patch (x.y.Z): Bug fixes that don't change the API
- None: Changes that don't affect using facing parts of Electron