From 7abb512a86e909df602e45e55f9395b758233bf3 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 27 Sep 2022 18:12:54 +0200 Subject: [PATCH] LibWeb: Make PercentageOr::contains_percentage() handle more cases --- Userland/Libraries/LibWeb/CSS/Percentage.h | 19 ++++++++++++++----- Userland/Libraries/LibWeb/CSS/StyleValue.cpp | 5 +++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/Percentage.h b/Userland/Libraries/LibWeb/CSS/Percentage.h index 3ee0a60ef9..3a686f0ee5 100644 --- a/Userland/Libraries/LibWeb/CSS/Percentage.h +++ b/Userland/Libraries/LibWeb/CSS/Percentage.h @@ -43,6 +43,8 @@ private: float m_value; }; +bool calculated_style_value_contains_percentage(CalculatedStyleValue const&); + template class PercentageOr { public: @@ -80,11 +82,18 @@ public: bool contains_percentage() const { - if (is_percentage()) - return true; - if (is_calculated()) - return calculated()->contains_percentage(); - return false; + return m_value.visit( + [&](T const& t) { + if (t.is_calculated()) + return calculated_style_value_contains_percentage(*t.calculated_style_value()); + return false; + }, + [&](Percentage const&) { + return true; + }, + [&](NonnullRefPtr const& calculated) { + return calculated_style_value_contains_percentage(*calculated); + }); } Percentage const& percentage() const diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp index 31330f3987..6d37f1d3fb 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp @@ -2272,4 +2272,9 @@ bool CalculatedStyleValue::CalcValue::contains_percentage() const [](auto const&) { return false; }); } +bool calculated_style_value_contains_percentage(CalculatedStyleValue const& value) +{ + return value.contains_percentage(); +} + }