Repository navigation
Commit 13cbbd2
committed
[css-sizing-4] Add support for fit-content(<length-percentage>) in the sizing properties
https://bugs.webkit.org/show_bug.cgi?id=330787
<rdar://problem/192283145>
Reviewed by NOBODY (OOPS!).
https://drafts.csswg.org/css-sizing-4/#funcdef-width-fit-content
"Use the fit-content formula with the available space replaced by stretch() into the specified
argument, i.e. min(max-content, max(min-content, stretch(<length-percentage>)))", where stretch()
fits the margin box to the argument, treating auto margins as zero (resolved by the CSSWG on
October 7, 2026 in w3c/csswg-drafts#5715).
fit-content() parses and answers to the fit-content keyword since the style patch, so layout sized it
as the keyword. Resolving the size now clamps stretch() into the argument between the min-content and
max-content sizes, and the stretch() goes through the same box-sizing conversions as a stretch() size
does (https://bugs.webkit.org/show_bug.cgi?id=330814): its margins come off the argument, resolved
against the containing block's inline size. Where layout has no available space to replace, the value
needs its own rule:
- A fixed argument gives a size that doesn't depend on the available space, so it is also the
box's min-content and max-content contribution, with its margins resolved against zero as the
contributions resolve them.
- A percentage argument is cyclic in the contributions, and "For fit-content(), if the
<length-percentage> expression on its own would resolve to the property's initial value, then
instead: For a maximum size property, treat it as max-content. For a minimum size property,
treat it as min-content. For a preferred size property, treat it as fit-content."
- An out-of-flow box resolves the argument against its containing block, not the space the insets
leave.
In the block axis min-content and max-content are both the content size, so fit-content() resolves
as the keyword does there. A fit-content() flex basis needs nothing more: with the main axis in the
item's inline axis, step A of https://drafts.csswg.org/css-flexbox/#algo-main-item resolves it against
the flex container's main size, and in the block axis the item's content size is its fit-content size.
Tests: imported/w3c/web-platform-tests/css/css-flexbox/flex-basis-fit-content-function-001.html
imported/w3c/web-platform-tests/css/css-sizing/fit-content-length-percentage-abspos-001.html
imported/w3c/web-platform-tests/css/css-sizing/fit-content-length-percentage-box-sizing-001.html
imported/w3c/web-platform-tests/css/css-sizing/fit-content-length-percentage-contribution-margins-001.html
imported/w3c/web-platform-tests/css/css-sizing/fit-content-length-percentage-margins-001.html
* LayoutTests/TestExpectations: The rest of the fit-content-length-percentage-0* tests pass now.
* LayoutTests/imported/w3c/web-platform-tests/css/css-flexbox/flex-basis-fit-content-function-001-expected.xht: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/css-flexbox/flex-basis-fit-content-function-001.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/css-sizing/fit-content-length-percentage-abspos-001-expected.xht: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/css-sizing/fit-content-length-percentage-abspos-001.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/css-sizing/fit-content-length-percentage-box-sizing-001-expected.xht: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/css-sizing/fit-content-length-percentage-box-sizing-001.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/css-sizing/fit-content-length-percentage-contribution-margins-001-expected.xht: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/css-sizing/fit-content-length-percentage-contribution-margins-001.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/css-sizing/fit-content-length-percentage-margins-001-expected.xht: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/css-sizing/fit-content-length-percentage-margins-001.html: Added.
* Source/WebCore/rendering/RenderBlock.cpp:
(WebCore::RenderBlock::logicalWidthContributionsForSize const):
* Source/WebCore/rendering/RenderBox.cpp:
(WebCore::RenderBox::computeFitContentFunctionLogicalWidthUsing const):
(WebCore::RenderBox::fitContentFunctionContentLogicalWidthContribution const):
(WebCore::RenderBox::computeSizingKeywordLogicalWidthUsingGeneric const):
(WebCore::RenderBox::constrainIntrinsicLogicalWidthContributionsByMinMax const):
(WebCore::RenderBox::computeOutOfFlowPositionedLogicalWidthUsing const):
* Source/WebCore/rendering/RenderBox.h:
* Source/WebCore/rendering/RenderReplaced.cpp:
(WebCore::RenderReplaced::computeReplacedLogicalWidthUsing const):1 parent 029ebd1 commit 13cbbd2
15 files changed
Lines changed: 346 additions & 18 deletions
File tree
- LayoutTests
- imported/w3c/web-platform-tests/css
- css-flexbox
- css-sizing
- Source/WebCore/rendering
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4664 | 4664 | | |
4665 | 4665 | | |
4666 | 4666 | | |
4667 | | - | |
4668 | | - | |
4669 | | - | |
4670 | | - | |
4671 | | - | |
4672 | | - | |
4673 | | - | |
4674 | | - | |
4675 | | - | |
4676 | | - | |
4677 | | - | |
4678 | | - | |
4679 | | - | |
4680 | | - | |
4681 | 4667 | | |
4682 | 4668 | | |
4683 | 4669 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
0 commit comments