From 2ade229f272aaa49826b3b94c418cd1e532cf91d Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Fri, 2 Jun 2023 18:31:39 +0300 Subject: [PATCH] LibWeb: Fix crashing when grid track size is calc() with percentage Use contains_percentage() that works for calc() values instead of is_percentage(). This fixes issue when tracks with calc() that has percentages where considered as "fixed" tracks with resolvable size which led to incorrectly resolved infinite final track sizes. --- .../grid/track-size-calc-with-percentage.txt | 13 +++++++++++++ .../input/grid/track-size-calc-with-percentage.html | 10 ++++++++++ Userland/Libraries/LibWeb/CSS/GridTrackSize.cpp | 4 ++-- 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 Tests/LibWeb/Layout/expected/grid/track-size-calc-with-percentage.txt create mode 100644 Tests/LibWeb/Layout/input/grid/track-size-calc-with-percentage.html diff --git a/Tests/LibWeb/Layout/expected/grid/track-size-calc-with-percentage.txt b/Tests/LibWeb/Layout/expected/grid/track-size-calc-with-percentage.txt new file mode 100644 index 00000000000..4d5df47f76c --- /dev/null +++ b/Tests/LibWeb/Layout/expected/grid/track-size-calc-with-percentage.txt @@ -0,0 +1,13 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x600 [BFC] children: not-inline + BlockContainer at (8,8) content-size 784x35.40625 children: not-inline + Box at (8,8) content-size 784x35.40625 flex-container(row) [FFC] children: not-inline + Box at (8,8) content-size 401.28125x35.40625 flex-item [GFC] children: not-inline + BlockContainer <(anonymous)> at (8,8) content-size 401.281x35.40625 [BFC] children: inline + line 0 width: 356.96875, height: 17.46875, bottom: 17.46875, baseline: 13.53125 + frag 0 from TextNode start: 0, length: 40, rect: [8,8 356.96875x17.46875] + "The 10 Most Anticipated Summer Movies of" + line 1 width: 36.3125, height: 17.9375, bottom: 35.40625, baseline: 13.53125 + frag 0 from TextNode start: 41, length: 4, rect: [8,25 36.3125x17.46875] + "2023" + TextNode <#text> diff --git a/Tests/LibWeb/Layout/input/grid/track-size-calc-with-percentage.html b/Tests/LibWeb/Layout/input/grid/track-size-calc-with-percentage.html new file mode 100644 index 00000000000..b1d28309167 --- /dev/null +++ b/Tests/LibWeb/Layout/input/grid/track-size-calc-with-percentage.html @@ -0,0 +1,10 @@ + +
The 10 Most Anticipated Summer Movies of 2023
\ No newline at end of file diff --git a/Userland/Libraries/LibWeb/CSS/GridTrackSize.cpp b/Userland/Libraries/LibWeb/CSS/GridTrackSize.cpp index 939d476b95d..304fcdbe61e 100644 --- a/Userland/Libraries/LibWeb/CSS/GridTrackSize.cpp +++ b/Userland/Libraries/LibWeb/CSS/GridTrackSize.cpp @@ -39,7 +39,7 @@ GridSize::~GridSize() = default; bool GridSize::is_auto(Layout::AvailableSize const& available_size) const { if (m_type == Type::LengthPercentage) { - if (m_length_percentage.is_percentage()) + if (m_length_percentage.contains_percentage()) return !available_size.is_definite(); return m_length_percentage.is_auto(); } @@ -50,7 +50,7 @@ bool GridSize::is_auto(Layout::AvailableSize const& available_size) const bool GridSize::is_fixed(Layout::AvailableSize const& available_size) const { if (m_type == Type::LengthPercentage) { - if (m_length_percentage.is_percentage()) + if (m_length_percentage.contains_percentage()) return available_size.is_definite(); return !m_length_percentage.is_auto(); }