From 741c7aef21cba526c09608560cb6ad4d2ea7c8ff Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 12 Jun 2023 14:25:46 +0200 Subject: [PATCH] LibWeb: Support more CSS functions in grid track size lists Instead of hard-coding a check for "calc", we now call out to parse_dynamic_value() which allows use of other functions like min(), max(), clamp(), etc. --- .../grid-template-columns-with-min-css-function.txt | 8 ++++++++ .../grid-template-columns-with-min-css-function.html | 11 +++++++++++ Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp | 7 ++----- 3 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 Tests/LibWeb/Layout/expected/grid/grid-template-columns-with-min-css-function.txt create mode 100644 Tests/LibWeb/Layout/input/grid/grid-template-columns-with-min-css-function.html diff --git a/Tests/LibWeb/Layout/expected/grid/grid-template-columns-with-min-css-function.txt b/Tests/LibWeb/Layout/expected/grid/grid-template-columns-with-min-css-function.txt new file mode 100644 index 00000000000..e5d4d3d6fbf --- /dev/null +++ b/Tests/LibWeb/Layout/expected/grid/grid-template-columns-with-min-css-function.txt @@ -0,0 +1,8 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (1,1) content-size 798x54.9375 [BFC] children: not-inline + Box at (10,10) content-size 780x36.9375 [GFC] children: not-inline + BlockContainer

at (55.5,11) content-size 689x34.9375 [BFC] children: inline + line 0 width: 200.40625, height: 34.9375, bottom: 34.9375, baseline: 27.0625 + frag 0 from TextNode start: 0, length: 13, rect: [55.5,11 200.40625x34.9375] + "hello friends" + TextNode <#text> diff --git a/Tests/LibWeb/Layout/input/grid/grid-template-columns-with-min-css-function.html b/Tests/LibWeb/Layout/input/grid/grid-template-columns-with-min-css-function.html new file mode 100644 index 00000000000..c390478f5bb --- /dev/null +++ b/Tests/LibWeb/Layout/input/grid/grid-template-columns-with-min-css-function.html @@ -0,0 +1,11 @@ +

hello friends

\ No newline at end of file diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index e169f133966..eb783c9e7fb 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -6900,11 +6900,8 @@ Optional Parser::parse_track_sizing_function(ComponentVa return CSS::ExplicitGridTrack(maybe_min_max_value.value()); else return {}; - } else if (function_token.name().equals_ignoring_ascii_case("calc"sv)) { - auto grid_size = parse_grid_size(token); - if (!grid_size.has_value()) - return {}; - return CSS::ExplicitGridTrack(grid_size.value()); + } else if (auto maybe_dynamic = parse_dynamic_value(token); !maybe_dynamic.is_error() && maybe_dynamic.value()) { + return CSS::ExplicitGridTrack(GridSize(LengthPercentage(maybe_dynamic.release_value()->as_calculated()))); } return {}; } else if (token.is(Token::Type::Ident) && token.token().ident().equals_ignoring_ascii_case("auto"sv)) {