Add support for the CSS aspect-ratio property#67
Draft
maitredede wants to merge 4 commits into
Draft
Conversation
Register the `aspect-ratio` longhand, parse the `auto || <ratio>`
grammar into an ident/pair/list value, and expose it on BoxStyle via
an AspectRatio { isAuto, value } accessor. No layout effect yet.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Blend the CSS aspect-ratio into ReplacedBox::computeAspectRatioInformation: a specified ratio overrides the natural one, unless `auto` was given and the element has a natural ratio of its own (per CSS Sizing 4). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Derive the automatic axis from the definite one in BlockBox::computeWidth /computeHeight. The ratio applies to the content box, except for a bare `<ratio>` where it applies to the box designated by `box-sizing`. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the CSS
aspect-ratioproperty. Closes #46.What
Parses
aspect-ratio: auto || <ratio>(with<ratio> = <number [0,∞]> [ / <number [0,∞]> ]?) and applies the preferred aspect ratio during layout, following CSS Sizing Level 4 §4.AspectRatiolonghand, aconsumeAspectRatioconsumer, and aBoxStyle::aspectRatio()accessor returning{ isAuto, value }. The value is stored in the generic property map (not inherited), likewidth/height.ReplacedBox::computeAspectRatioInformation: a specified ratio overrides the natural one, unlessautowas given and the element has a natural ratio of its own.BlockBox::computeWidth/computeHeight, reusing the existingconstrain*and box-sizing (adjust*) helpers.Box-sizing
Per the spec, the reference box depends on the value:
auto && <ratio>→ content box;<ratio>→ the box designated bybox-sizing(border box whenbox-sizing: border-box).A degenerate ratio (a
0side) behaves asauto.Not covered (yet)
constrain*functions.Testing
Built with meson/ninja (no new warnings) and verified end-to-end by rendering to PNG and measuring the resulting box dimensions:
width:200px; aspect-ratio:2/1height:100px; width:auto; aspect-ratio:3/1width:150px; aspect-ratio:1/1; box-sizing:border-box; border:10pxwidth:100px; aspect-ratio:16/9<img>(40×20) noaspect-ratio<img> width:80px; aspect-ratio:1/1<img> aspect-ratio:auto 1/1