Phase 9: Advanced Layout#
Implement proper resolution of viewport-relative units (vw, vh, vmin, vmax) and percentage values against containing blocks.
Current State#
- CSS value types already include viewport units:
vw,vh,vmin,vmax(parsed incss/values.rs) Percentageis a parsed CSS value type- Length resolution in
style/computed.rsconverts px, pt, cm, mm, em, rem to px but does NOT resolve viewport units or percentages - Layout does not pass viewport dimensions to style resolution
- Percentage widths/heights/margins/paddings are not resolved
Requirements#
-
Viewport unit resolution: Thread viewport width/height through style resolution so
vw,vh,vmin,vmaxresolve to px:1vw= 1% of viewport width1vh= 1% of viewport height1vmin= min(1vw, 1vh)1vmax= max(1vw, 1vh)
-
Percentage resolution for layout properties:
widthpercentage: resolves against containing block widthheightpercentage: resolves against containing block height (if definite), else automarginpercentage (all sides): resolves against containing block WIDTH (per spec, even for top/bottom)paddingpercentage (all sides): resolves against containing block WIDTH (per spec, even for top/bottom)top/bottompercentage: containing block heightleft/rightpercentage: containing block width
-
Containing block: For normal flow elements, the containing block is the content area of the nearest block-level ancestor
Files to Modify#
crates/style/src/computed.rs— Accept viewport dimensions in resolution, handlevw/vh/vmin/vmaxcrates/layout/src/lib.rs— Pass viewport dimensions to style resolution; resolve percentages against containing block during layout
Tests#
width: 50%resolves to half the containing block widthmargin: 10%resolves against containing block width (not height)width: 50vwresolves to half viewport widthheight: 100vhresolves to full viewport heightfont-size: 5vminresolves to 5% of the smaller viewport dimension- Nested percentage widths compound correctly
Acceptance Criteria#
- Viewport units (vw, vh, vmin, vmax) resolve correctly
- Percentage values for width, height, margin, padding resolve against correct containing block dimension
- All tests pass, clippy clean, fmt clean