Skip to content

Truly independent web browser

LibWeb: Leave the trailing gutter out of a grid area

Andreas Kling9d0a06ad0ecd
diff --git a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
index 0dfd8504742..fbf5d2d5435 100644
--- a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
@@ -3456,8 +3456,9 @@ impl<'pass> GridFormattingContext<'pass> {
return (self.track_sum(axis), padding_end);
}
+ // The area runs from the start of its first track to the end of its last, without the gutter after it.
let start = position.saturating_mul(2);
- let end = start.saturating_add(span.saturating_mul(2) as i32);
+ let end = start.saturating_add((span.saturating_mul(2) as i32).saturating_sub(1));
let container = self.grid_container_alignment_size(axis);
let alignment = self.content_alignment(axis);
let initial_offset = content_start_offset(alignment, container, self.track_sum(axis));
@@ -3507,7 +3508,9 @@ impl<'pass> GridFormattingContext<'pass> {
// Instead of auto-placement, an auto value for a grid-placement property contributes a special line to the placement whose position
// is that of the corresponding padding edge of the grid container (the padding edge of the scrollable area, if the grid container
// overflows). These lines become the first and last lines (0th and -0th) of the augmented grid used for positioning absolutely-positioned items.
- let explicit_line_position = |line: i32| {
+ // NB: A line between two tracks has a gutter in it. An area's start edge comes after the gutter, and its end edge
+ // before it, as in axis_grid_area().
+ let explicit_line_position = |line: i32, is_end: bool| {
let tracks = self.interleaved_tracks(axis);
let alignment = self.content_alignment(axis);
let mut offset = content_start_offset(
@@ -3515,7 +3518,12 @@ impl<'pass> GridFormattingContext<'pass> {
self.axis_available(axis).to_px_or_zero(),
self.track_sum(axis),
);
- for track in tracks.iter().take(line.saturating_mul(2).max(0) as usize) {
+ let entries = if is_end {
+ line.saturating_mul(2).saturating_sub(1)
+ } else {
+ line.saturating_mul(2)
+ };
+ for track in tracks.iter().take(entries.max(0) as usize) {
offset += track.base_size;
}
offset
@@ -3535,12 +3543,12 @@ impl<'pass> GridFormattingContext<'pass> {
let start_offset = if start_is_augmented {
augmented_edge(true)
} else {
- explicit_line_position(resolved.start)
+ explicit_line_position(resolved.start, false)
};
let end_offset = if end_is_augmented {
augmented_edge(false)
} else {
- explicit_line_position(resolved.end)
+ explicit_line_position(resolved.end, true)
};
rect = (start_offset, end_offset - start_offset);
rect
diff --git a/Tests/LibWeb/Layout/expected/grid/relative-position-grid-item-with-percentage-insets.txt b/Tests/LibWeb/Layout/expected/grid/relative-position-grid-item-with-percentage-insets.txt
index 3a5794c2dd0..975f7ae4c06 100644
--- a/Tests/LibWeb/Layout/expected/grid/relative-position-grid-item-with-percentage-insets.txt
+++ b/Tests/LibWeb/Layout/expected/grid/relative-position-grid-item-with-percentage-insets.txt
@@ -11,9 +11,9 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children
TextNode <#text> (not painted)
BlockContainer <(anonymous)> (not painted) [BFC] children: inline
TextNode <#text> (not painted)
- Box <div.grid-item.relative-item> at [247.5,97.5] positioned flex-container(row) [0+1+10 123 10+1+0] [0+1+10 123 10+1+0] [FFC] children: not-inline
- BlockContainer <(anonymous)> at [284.40625,151] flex-item [0+0+0 49.1875 0+0+0] [0+0+0 16 0+0+0] [BFC] children: inline
- frag 0 from TextNode start: 0, length: 6, rect: [284.40625,151 49.1875x16] baseline: 12.796875
+ Box <div.grid-item.relative-item> at [247.5,92.5] positioned flex-container(row) [0+1+10 123 10+1+0] [0+1+10 123 10+1+0] [FFC] children: not-inline
+ BlockContainer <(anonymous)> at [284.40625,146] flex-item [0+0+0 49.1875 0+0+0] [0+0+0 16 0+0+0] [BFC] children: inline
+ frag 0 from TextNode start: 0, length: 6, rect: [284.40625,146 49.1875x16] baseline: 12.796875
"Item 2"
TextNode <#text> (not painted)
BlockContainer <(anonymous)> (not painted) [BFC] children: inline
diff --git a/Tests/LibWeb/Text/expected/grid/abspos-augmented-line-excludes-trailing-gutter.txt b/Tests/LibWeb/Text/expected/grid/abspos-augmented-line-excludes-trailing-gutter.txt
new file mode 100644
index 00000000000..ac3a3cc1d70
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/grid/abspos-augmented-line-excludes-trailing-gutter.txt
@@ -0,0 +1,4 @@
+auto / 2: 0 100
+1 / 2: 0 100
+2: 120 280
+auto / 3: 0 220
diff --git a/Tests/LibWeb/Text/input/grid/abspos-augmented-line-excludes-trailing-gutter.html b/Tests/LibWeb/Text/input/grid/abspos-augmented-line-excludes-trailing-gutter.html
new file mode 100644
index 00000000000..a2304f05958
--- /dev/null
+++ b/Tests/LibWeb/Text/input/grid/abspos-augmented-line-excludes-trailing-gutter.html
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<style>
+ body { margin: 0; }
+ .grid {
+ display: grid;
+ position: relative;
+ grid-template-columns: 100px 100px;
+ column-gap: 20px;
+ width: 400px;
+ height: 50px;
+ }
+ .grid > div {
+ position: absolute;
+ left: 0;
+ right: 0;
+ top: 0;
+ height: 10px;
+ }
+</style>
+<!-- An area's end edge comes before the gutter that follows its last track, also when the other edge is
+ the augmented auto line. -->
+<div class="grid">
+ <div style="grid-column: auto / 2"></div>
+ <div style="grid-column: 1 / 2"></div>
+ <div style="grid-column: 2 / auto"></div>
+ <div style="grid-column: auto / 3"></div>
+</div>
+<script>
+ test(() => {
+ for (const item of document.querySelectorAll(".grid > div")) {
+ const rect = item.getBoundingClientRect();
+ println(`${item.style.gridColumn}: ${rect.left} ${rect.width}`);
+ }
+ });
+</script>