Skip to content

Truly independent web browser

LibWeb: Draw random base values nested in grid tracks and anchors

Andreas Kling5ed46d31f7e0
diff --git a/Libraries/LibWeb/Rust/src/css/style_compute.rs b/Libraries/LibWeb/Rust/src/css/style_compute.rs
index 4a415025c48..3fac1cde38a 100644
--- a/Libraries/LibWeb/Rust/src/css/style_compute.rs
+++ b/Libraries/LibWeb/Rust/src/css/style_compute.rs
@@ -2091,6 +2091,26 @@ pub(crate) fn collect_unfixed_random_sharings_in_value(
}
}
+ fn collect_grid_entries(
+ entries: &[crate::css::style_value::RetainedGridTrackEntry],
+ sharings: &mut Vec<*const StyleValueData>,
+ ) {
+ for entry in entries {
+ match entry.kind {
+ GridTrackEntryKind::LineNames => {}
+ GridTrackEntryKind::Size => collect_optional(&entry.size_value, sharings),
+ GridTrackEntryKind::MinMax => {
+ collect_optional(&entry.min_value, sharings);
+ collect_optional(&entry.max_value, sharings);
+ }
+ GridTrackEntryKind::Repeat => {
+ collect_grid_entries(entry.repeat_entries(), sharings);
+ collect_optional(&entry.repeat_count, sharings);
+ }
+ }
+ }
+ }
+
let collect_values = |values: &[&RetainedStyleValueData], sharings: &mut Vec<*const StyleValueData>| {
for value in values {
collect_optional(value, sharings);
@@ -2101,6 +2121,14 @@ pub(crate) fn collect_unfixed_random_sharings_in_value(
let CalculatedPayload { rust_calculation, .. } = &**calculated_payload;
crate::css::calc::collect_unfixed_random_sharings(rust_calculation.node(), sharings);
}
+ StyleValueData::GridTrackSizeList(grid_track_size_list_payload) => {
+ let GridTrackSizeListPayload { entries, .. } = &**grid_track_size_list_payload;
+ collect_grid_entries(entries.as_slice(), sharings);
+ }
+ StyleValueData::Anchor(_) | StyleValueData::AnchorSize(_) => {
+ let (_, _, fallback_value) = value.anchor_name_and_fallback().unwrap();
+ collect_optional(fallback_value, sharings);
+ }
StyleValueData::RandomValueSharing(random_value_sharing_payload) => {
let RandomValueSharingPayload { fixed_value, .. } = &**random_value_sharing_payload;
match fixed_value.optional_data() {
diff --git a/Tests/LibWeb/Text/expected/css/random-in-grid-tracks-and-anchor-fallbacks.txt b/Tests/LibWeb/Text/expected/css/random-in-grid-tracks-and-anchor-fallbacks.txt
new file mode 100644
index 00000000000..8c4744b841c
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/random-in-grid-tracks-and-anchor-fallbacks.txt
@@ -0,0 +1,6 @@
+grid-auto-columns: 1px
+grid-auto-rows: minmax(1px, 2px)
+grid-template-columns: 1px 1px
+grid-template-rows: 2px 2px
+left: 1px
+width: 1px
diff --git a/Tests/LibWeb/Text/input/css/random-in-grid-tracks-and-anchor-fallbacks.html b/Tests/LibWeb/Text/input/css/random-in-grid-tracks-and-anchor-fallbacks.html
new file mode 100644
index 00000000000..8ad16297e8f
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/random-in-grid-tracks-and-anchor-fallbacks.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<body>
+<script src="../include.js"></script>
+<script>
+ test(() => {
+ // A random function nested in grid tracks or an anchor fallback draws its base value like any other.
+ for (const [property, value] of [
+ ["grid-auto-columns", "random(1px, 1px)"],
+ ["grid-auto-rows", "minmax(random(1px, 1px), 2px)"],
+ ["grid-template-columns", "repeat(2, random(1px, 1px))"],
+ ["grid-template-rows", "repeat(2, minmax(random(1px, 1px), 2px))"],
+ ["left", "anchor(--nothing left, random(1px, 1px))"],
+ ["width", "anchor-size(--nothing width, random(1px, 1px))"],
+ ]) {
+ const element = document.createElement("div");
+ element.style.position = "absolute";
+ element.style.display = "grid";
+ element.style.setProperty(property, value);
+ document.body.append(element);
+ println(`${property}: ${getComputedStyle(element).getPropertyValue(property)}`);
+ element.remove();
+ }
+ });
+</script>