From 450c0df9386aae2dcf88bdb999d8afa442dfd8d8 Mon Sep 17 00:00:00 2001 From: Simon Wanner Date: Sun, 3 Apr 2022 22:05:03 +0200 Subject: [PATCH] LibWeb: Make resolved styles handle calculated length-percentages This could lead to a crash when inspecting for example the on holidaycss.js.org, because it has `width: calc(100% - 1em)` --- Userland/Libraries/LibWeb/CSS/Percentage.h | 6 ++++++ .../Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/CSS/Percentage.h b/Userland/Libraries/LibWeb/CSS/Percentage.h index c9479b514a..f5493c6abb 100644 --- a/Userland/Libraries/LibWeb/CSS/Percentage.h +++ b/Userland/Libraries/LibWeb/CSS/Percentage.h @@ -83,6 +83,12 @@ public: return m_value.template get(); } + NonnullRefPtr const& calculated() const + { + VERIFY(is_calculated()); + return m_value.template get>(); + } + virtual T resolve_calculated(NonnullRefPtr const&, [[maybe_unused]] Layout::Node const&, [[maybe_unused]] T const& reference_value) const { VERIFY_NOT_REACHED(); diff --git a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp index 7f61cf1136..b02f500b29 100644 --- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp @@ -497,7 +497,9 @@ static NonnullRefPtr style_value_for_length_percentage(LengthPercent { if (length_percentage.is_percentage()) return PercentageStyleValue::create(length_percentage.percentage()); - return LengthStyleValue::create(length_percentage.length()); + if (length_percentage.is_length()) + return LengthStyleValue::create(length_percentage.length()); + return length_percentage.calculated(); } RefPtr ResolvedCSSStyleDeclaration::style_value_for_property(Layout::NodeWithStyle const& layout_node, PropertyID property_id) const