← All issues

Implement calc-mix()

0f31efd

LayoutTests/imported/w3c/web-platform-tests/css/css-values/calc-mix-computed.tentative-expected.txt

+PASS calc-mix(1 75%, 3 75%) should be used-value-equivalent to 2
+PASS calc-mix(1 25%, 3 25%) should be used-value-equivalent to 1
+PASS calc-mix(1 25%, 3 25%, 5, 7) should be used-value-equivalent to 4
+PASS calc-mix(1px 0%) should be used-value-equivalent to 0px
+PASS calc-mix(1% 0%, 3px 0%) should be used-value-equivalent to 0%
+PASS calc-mix(1px 0%, 3% 0%) should be used-value-equivalent to 0px
+PASS calc-mix(1 * sibling-index() 50%, 3 50%) should be used-value-equivalent to 2
+PASS calc-mix(1 calc(50% * sibling-index()), 3 50%) should be used-value-equivalent to 2

WebKit's CSS calc system uses two parallel tree representations: CSSCalcTree (parsed/CSS-level form, used during parsing, validation, and serialization) and StyleCalculationTree (resolved/style-level form, used during cascade and computed-value resolution). Every new calc function must be threaded through all passes on both trees: copying, simplification, evaluation, serialization, and computed-style dependency tracking.

This commit implements the CSS calc-mix() function from CSS Values Level 5 — a weighted average across a list of calc terms — across the entire pipeline: parser, simplification, evaluation, serialization, type resolution, and style resolution. The implementation is gated behind a new CSSCalcMixEnabled preference flag. calc-mix() introduces a weighted-average node whose semantics require normalizing percentage weights that may not sum to 100%, may be omitted entirely, or may all be 0% — and resolving the result type across potentially heterogeneous operands. The commit explicitly links csswg-drafts issue #13839, acknowledging open spec questions that force the implementation to make judgment calls in undefined territory.

This adds substantial new attack surface across WebKit's most complex CSS subsystem, with the spec itself carrying open questions about simplification semantics. Weight normalization, heterogeneous type mixing, and tree-context functions inside weight arguments each create underspecified edge cases the implementation must handle unilaterally.

🔒

New weighted-average math function with open spec questions, type-mixing edge cases, and tree-context functions in weight arguments — several implementation paths worth security investigation.

Subscribe to read more