Skip to content

Lay web pages out at their own size, and let pages fill the player - #56

Merged
514sid merged 2 commits into
mainfrom
web-viewport
Nov 24, 2026
Merged

514sid merged 2 commits into
mainfrom
web-viewport

Conversation

@514sid

@514sid 514sid commented Nov 24, 2026

Copy link
Copy Markdown
Owner

A page lays out at the player's size in CSS pixels, which is the player's pixels divided by the screen density. On the test TVs (1280x720 UI, density 1.33) that is 961x541, so a dashboard designed for 1920x1080 wraps or shows its mobile layout.

A web asset's width and height, ignored for pages until now, are now the CSS pixel size the page lays out at. The library sets the page's viewport tag to that width at document start, in the top frame only, and keeps it there if the page changes it. With wide viewport and overview mode WebView zooms the page to the view, and the view is sized as the asset's fit says, with backgroundColor around it. Stretch lays the page out at the contained size and scales it, since a page can't be laid out distorted. The page still draws at the player's own resolution. On WebView older than 87 the width is set when the page first paints.

This also drops setInitialScale(100), left over from a viewport injection that no longer exists. It drew one CSS pixel per screen pixel, so on a screen with a density above 1 a responsive page filled only part of the player: three quarters of the width on the test TVs. Pages without a size now fill the player, which changes how every page looks on such screens.

The sample app gets web_viewport_check, a page that prints the viewport it was laid out at and draws a 1920x1080 frame, the same page as web_viewport_1920 with a size, and a viewport playlist.

Checked on both TVs: the 1920 page lays out at 1920x1080 (the visual viewport is 1920.00 x 1080.00; clientHeight rounds to 1079) with its frame on the screen edges. Two players side by side showed Contain, Cover, Stretch and Original correctly. A recording alternating the page and a video had no black frame at any cut, cold start time is unchanged, and Wikipedia and BBC News now fill the screen.

A web asset's width and height are now the CSS pixel size the page is laid
out at, whatever the player's size and the screen's density. The page's
viewport tag is set to that width at document start and the WebView is
fitted to the player as the asset's fit says, with its background colour
around it.

Drops setInitialScale(100), left over from a viewport injection that no
longer exists. It drew one CSS pixel per screen pixel, so on a screen with
a density above 1 a responsive page filled only part of the player.
@514sid

514sid commented Nov 24, 2026

Copy link
Copy Markdown
Owner Author

Tested in rotated players on the TV. At 90 degrees a page with no size lays out at 541x961 and fills the portrait player; the 1920x1080 page at 90 and 270 degrees is contained with bars above and below, and covers correctly. At 180 and 270 degrees Chromium reports visualViewport.height as 0, with or without this change (also with setInitialScale(100) restored), so that comes from the rotated container, not from this PR.

@514sid
514sid merged commit bbc5c55 into main Nov 24, 2026
1 check passed
@514sid
514sid deleted the web-viewport branch November 24, 2026 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant