diff --git a/layout/generic/nsGridContainerFrame.cpp b/layout/generic/nsGridContainerFrame.cpp index f2cc3f1a6afb..8fa1c93f1b19 100644 --- a/layout/generic/nsGridContainerFrame.cpp +++ b/layout/generic/nsGridContainerFrame.cpp @@ -449,7 +449,9 @@ TrackSize::StateBits nsGridContainerFrame::TrackSize::Initialize( if (aSize.IsFitContent()) { // In layout, fit-content(size) behaves as minmax(auto, max-content), with // 'size' as an additional upper-bound. - mState = eFitContent; + if (!::IsPercentOfIndefiniteSize(aSize.AsFitContent(), aPercentageBasis)) { + mState = eFitContent; + } minSizeTag = Tag::Auto; maxSizeTag = Tag::MaxContent; } diff --git a/testing/web-platform/tests/css/css-grid/layout-algorithm/grid-fit-content-percentage.html b/testing/web-platform/tests/css/css-grid/layout-algorithm/grid-fit-content-percentage.html index 892dbe40b468..22683fef14f0 100644 --- a/testing/web-platform/tests/css/css-grid/layout-algorithm/grid-fit-content-percentage.html +++ b/testing/web-platform/tests/css/css-grid/layout-algorithm/grid-fit-content-percentage.html @@ -36,30 +36,34 @@ function clamp(value, min, max) { } const minContent = 50; const maxContent = 100; -for (const use_calc of [false, true]) { - for (const percentage of [0, 50, 75, 100, 150]) { - const value = use_calc ? `fit-content(calc(0px + ${percentage}%))` - : `fit-content(${percentage}%)`; - const container = document.createElement("div"); - container.className = "container"; - document.body.appendChild(container); - const grid = document.createElement("div"); - grid.className = "grid"; - grid.style.gridTemplateColumns = value; - container.appendChild(grid); - const item = document.createElement("div"); - item.className = "item"; - grid.appendChild(item); - test(function() { - const colSize = clamp(percentage * maxContent / 100, minContent, maxContent); - const height = colSize < maxContent ? maxContent : minContent; - assert_equals(item.offsetWidth, colSize, "Grid item width"); - assert_equals(item.offsetHeight, height, "Grid item height"); - assert_equals(grid.offsetWidth, maxContent, "Grid container width"); - assert_equals(grid.offsetHeight, height, "Grid container height"); - assert_equals(getComputedStyle(grid).gridTemplateColumns, colSize + "px", - "Grid column size"); - }, value); +for (const use_min_width of [false, true]) { + for (const use_calc of [false, true]) { + for (const percentage of [0, 50, 75, 100, 150]) { + const value = use_calc ? `fit-content(calc(0px + ${percentage}%))` + : `fit-content(${percentage}%)`; + const container = document.createElement("div"); + container.className = "container"; + document.body.appendChild(container); + const grid = document.createElement("div"); + grid.className = "grid"; + grid.style.gridTemplateColumns = value; + container.appendChild(grid); + const item = document.createElement("div"); + item.className = "item"; + item.style.minWidth = use_min_width ? "auto" : "0px"; + grid.appendChild(item); + test(function() { + const minWidth = use_min_width ? minContent : 0; + const colSize = clamp(percentage * maxContent / 100, minWidth, maxContent); + const height = colSize < maxContent ? maxContent : minContent; + assert_equals(item.offsetWidth, colSize, "Grid item width"); + assert_equals(item.offsetHeight, height, "Grid item height"); + assert_equals(grid.offsetWidth, maxContent, "Grid container width"); + assert_equals(grid.offsetHeight, height, "Grid container height"); + assert_equals(getComputedStyle(grid).gridTemplateColumns, colSize + "px", + "Grid column size"); + }, value + "; min-width: " + item.style.minWidth); + } } }