Truly independent web browser
LibWeb: Include the grid in a grid scroll container's overflow
Andreas Kling006848a6559b
diff --git a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rsindex 0c3efd22b95..0dfd8504742 100644--- a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs@@ -372,6 +372,8 @@ impl OwnedUsedGridTrackList {pub(crate) struct OwnedUsedGridTracks {pub(crate) columns: OwnedUsedGridTrackList,pub(crate) rows: OwnedUsedGridTrackList,+ /// The area the grid's tracks and gutters cover, relative to the container's content box.+ pub(crate) grid_area: CssPixelRect,}// https://drafts.csswg.org/css-grid/#overlarge-grids@@ -3713,9 +3715,22 @@ impl<'pass> GridFormattingContext<'pass> {fn save_used_tracks(&self, grid_style: &GridValues) {// getComputedStyle() needs to return the resolved values of grid-template-columns and grid-template-rows// so they need to be saved in the state, and then assigned to paintables by the Rust commit walk.+ let start = |axis: Axis| {+ content_start_offset(+ self.content_alignment(axis),+ self.grid_container_alignment_size(axis),+ self.track_sum(axis),+ )+ };let tracks = OwnedUsedGridTracks {columns: self.used_track_list_data(Axis::Column, self.is_subgridded(Axis::Column, grid_style)),rows: self.used_track_list_data(Axis::Row, self.is_subgridded(Axis::Row, grid_style)),+ grid_area: CssPixelRect::new(+ start(Axis::Column),+ start(Axis::Row),+ self.track_sum(Axis::Column),+ self.track_sum(Axis::Row),+ ),};self.container_used().rare_data_mut().used_grid_tracks = Some(std::sync::Arc::new(tracks));}diff --git a/Libraries/LibWeb/Rust/src/painting/scrollable_overflow.rs b/Libraries/LibWeb/Rust/src/painting/scrollable_overflow.rsindex 5442d51d38e..a9ebb30eb32 100644--- a/Libraries/LibWeb/Rust/src/painting/scrollable_overflow.rs+++ b/Libraries/LibWeb/Rust/src/painting/scrollable_overflow.rs@@ -356,6 +356,27 @@ fn measure_scrollable_overflow_impl(}}+ // https://drafts.csswg.org/css-grid-2/#overflow+ // The grid is also included in a grid container's scrollable overflow region.+ // INTEROP: Blink only does this when the grid container is a scroll container, so the grid does not reach the+ // scrollable overflow of its ancestors.+ if style_queries::is_scroll_container(layout_arena, box_node)+ && let Some(tracks) = paintable_geometry::committed_used_grid_tracks(layout_arena, box_paintable)+ {+ let grid_area = tracks+ .grid_area+ .translated_by(paintable_absolute_content_box.location());+ // NB: A grid with tracks in one axis only, e.g. columns but no rows, still reaches the overflow in that axis.+ if grid_area.width > CssPixels::default() {+ scrollable_overflow_rect.unite_horizontally(grid_area);+ in_flow_and_floated_content_bounds.unite_horizontally(grid_area);+ }+ if grid_area.height > CssPixels::default() {+ scrollable_overflow_rect.unite_vertically(grid_area);+ in_flow_and_floated_content_bounds.unite_vertically(grid_area);+ }+ }+// - The border boxes of all boxes for which it is the containing block and whose border boxes are positioned not// wholly in the negative scrollable overflow region,// FIXME: accounting for 3D transforms by projecting each box onto the plane of the element that establishesdiff --git a/Tests/LibWeb/Text/expected/grid/grid-scroll-container-overflow-includes-grid.txt b/Tests/LibWeb/Text/expected/grid/grid-scroll-container-overflow-includes-grid.txtnew file mode 100644index 00000000000..5b6331c3b46--- /dev/null+++ b/Tests/LibWeb/Text/expected/grid/grid-scroll-container-overflow-includes-grid.txt@@ -0,0 +1,3 @@+grid scroll container: 320x650+grid with columns but no rows: 300x50+grid inside a scroll container: 120x120diff --git a/Tests/LibWeb/Text/input/grid/grid-scroll-container-overflow-includes-grid.html b/Tests/LibWeb/Text/input/grid/grid-scroll-container-overflow-includes-grid.htmlnew file mode 100644index 00000000000..2604c1f7b8c--- /dev/null+++ b/Tests/LibWeb/Text/input/grid/grid-scroll-container-overflow-includes-grid.html@@ -0,0 +1,24 @@+<!DOCTYPE html>+<style>+ .grid {+ display: grid;+ gap: 10px;+ grid-template-columns: repeat(3, 100px);+ grid-template-rows: repeat(6, 100px);+ width: 120px;+ height: 120px;+ }+</style>+<div class="grid" id="scroller" style="overflow: auto"></div>+<div style="display: grid; grid-template-columns: 300px; width: 100px; height: 50px; overflow: auto" id="columns-only"></div>+<div style="width: 120px; height: 120px; overflow: auto" id="outer">+ <div class="grid"></div>+</div>+<script src="../include.js"></script>+<script>+ test(() => {+ println(`grid scroll container: ${scroller.scrollWidth}x${scroller.scrollHeight}`);+ println(`grid with columns but no rows: ${document.getElementById("columns-only").scrollWidth}x${document.getElementById("columns-only").scrollHeight}`);+ println(`grid inside a scroll container: ${outer.scrollWidth}x${outer.scrollHeight}`);+ });+</script>