mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-28 18:47:15 +02:00
LibWeb: Implement CSS Grid dense packing and fix span placement
Implement the `dense` keyword for `grid-auto-flow` so auto-placed items backfill earlier gaps in the grid. The sparse/dense cursor logic is now centralized in `place_grid_items()` step 4: dense resets the cursor to the grid start before each search, while sparse keeps advancing forward. Also fix a pre-existing bug where `find_unoccupied_place()` and several placement helpers only checked if a single cell was unoccupied, ignoring multi-cell spans. Add `OccupationGrid::is_area_occupied()` and use it throughout to correctly verify the entire rectangular area is available.
This commit is contained in:
committed by
Alexander Kalenik
parent
aa2a95c775
commit
3c73457b26
Notes:
github-actions[bot]
2026-02-16 19:01:21 +00:00
Author: https://github.com/kalenikaliaksandr Commit: https://github.com/LadybirdBrowser/ladybird/commit/3c73457b26d Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/7990
@@ -0,0 +1,84 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<title>CSS Grid: Change named grid lines.</title>
|
||||
<link rel="author" title="Julien Chaffraix" href="mailto:jchaffraix@chromium.org"/>
|
||||
<link rel="help" href="https://drafts.csswg.org/css-grid/#placement"/>
|
||||
<meta name="assert" content="Checks that updating the named grid lines definitions in grid-template-{rows|columns} recomputes the positions of automatically placed grid items."/>
|
||||
<link rel="issue" href="https://crbug.com/248151"/>
|
||||
<link href="../../../css/support/grid.css" rel="stylesheet"/>
|
||||
<link href="../../../css/support/alignment.css" rel="stylesheet">
|
||||
<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css"/>
|
||||
<style>
|
||||
.grid {
|
||||
grid-auto-flow: row dense;
|
||||
}
|
||||
#firstGridItem {
|
||||
grid-row: auto;
|
||||
grid-column: column;
|
||||
}
|
||||
|
||||
#secondGridItem {
|
||||
grid-row: row;
|
||||
grid-column: auto;
|
||||
}
|
||||
|
||||
#thirdGridItem {
|
||||
grid-row: auto;
|
||||
grid-column: auto;
|
||||
}
|
||||
</style>
|
||||
<script src="../../../resources/testharness.js"></script>
|
||||
<script src="../../../resources/testharnessreport.js"></script>
|
||||
<script src="../../../resources/check-layout-th.js"></script>
|
||||
<script>
|
||||
function testGridDefinitions(gridTemplateRows, gridTemplateColumns, firstGridItemData, secondGridItemData, thirdGridItemData)
|
||||
{
|
||||
var gridElement = document.getElementsByClassName("grid")[0];
|
||||
gridElement.style.gridTemplateRows = gridTemplateRows;
|
||||
gridElement.style.gridTemplateColumns = gridTemplateColumns;
|
||||
|
||||
var firstGridItem = document.getElementById("firstGridItem");
|
||||
firstGridItem.setAttribute("data-expected-width", firstGridItemData.width);
|
||||
firstGridItem.setAttribute("data-expected-height", firstGridItemData.height);
|
||||
firstGridItem.setAttribute("data-offset-x", firstGridItemData.x);
|
||||
firstGridItem.setAttribute("data-offset-y", firstGridItemData.y);
|
||||
|
||||
var secondGridItem = document.getElementById("secondGridItem");
|
||||
secondGridItem.setAttribute("data-expected-width", secondGridItemData.width);
|
||||
secondGridItem.setAttribute("data-expected-height", secondGridItemData.height);
|
||||
secondGridItem.setAttribute("data-offset-x", secondGridItemData.x);
|
||||
secondGridItem.setAttribute("data-offset-y", secondGridItemData.y);
|
||||
|
||||
var thirdGridItem = document.getElementById("thirdGridItem");
|
||||
thirdGridItem.setAttribute("data-expected-width", thirdGridItemData.width);
|
||||
thirdGridItem.setAttribute("data-expected-height", thirdGridItemData.height);
|
||||
thirdGridItem.setAttribute("data-offset-x", thirdGridItemData.x);
|
||||
thirdGridItem.setAttribute("data-offset-y", thirdGridItemData.y);
|
||||
|
||||
checkLayout(".grid", false);
|
||||
}
|
||||
|
||||
function testChangingGridDefinitions()
|
||||
{
|
||||
testGridDefinitions('10px [row] 20px', '30px [column]', { 'width': '0', 'height': '10', 'x': '30', 'y': '0' }, { 'width': '30', 'height': '20', 'x': '0', 'y': '10' }, { 'width': '30', 'height': '10', 'x': '0', 'y': '0' });
|
||||
testGridDefinitions('10px [row] 20px', '30px', { 'width': '0', 'height': '10', 'x': '30', 'y': '0' }, { 'width': '30', 'height': '20', 'x': '0', 'y': '10' }, { 'width': '30', 'height': '10', 'x': '0', 'y': '0' });
|
||||
testGridDefinitions('10px 20px [row]', '30px', { 'width': '0', 'height': '10', 'x': '30', 'y': '0' }, { 'width': '30', 'height': '0', 'x': '0', 'y': '30' }, { 'width': '30', 'height': '10', 'x': '0', 'y': '0' });
|
||||
testGridDefinitions('10px 20px [row]', '30px [column]', { 'width': '0', 'height': '10', 'x': '30', 'y': '0' }, { 'width': '30', 'height': '0', 'x': '0', 'y': '30' }, { 'width': '30', 'height': '10', 'x': '0', 'y': '0' });
|
||||
done();
|
||||
}
|
||||
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
setup({ explicit_done: true });
|
||||
</script>
|
||||
<body onload="document.fonts.ready.then(() => { testChangingGridDefinitions(); })">
|
||||
<div style="position: relative">
|
||||
<div class="grid justifyContentStart">
|
||||
<div class="sizedToGridArea" id="firstGridItem"></div>
|
||||
<div class="sizedToGridArea" id="secondGridItem"></div>
|
||||
<div class="sizedToGridArea" id="thirdGridItem"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user