diff options
author | Simon Wanner <skyrising@pvpctutorials.de> | 2022-04-03 22:05:03 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-04-03 23:12:13 +0200 |
commit | 450c0df9386aae2dcf88bdb999d8afa442dfd8d8 (patch) | |
tree | 5bae5a4fc23d245d6896f5930a577d8b108db7a5 | |
parent | fe0f0b0acfad80bc89f66028b5767df124d9d7e5 (diff) | |
download | serenity-450c0df9386aae2dcf88bdb999d8afa442dfd8d8.zip |
LibWeb: Make resolved styles handle calculated length-percentages
This could lead to a crash when inspecting for example the <body>
on holidaycss.js.org, because it has `width: calc(100% - 1em)`
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Percentage.h | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp | 4 |
2 files changed, 9 insertions, 1 deletions
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<Percentage>(); } + NonnullRefPtr<CalculatedStyleValue> const& calculated() const + { + VERIFY(is_calculated()); + return m_value.template get<NonnullRefPtr<CalculatedStyleValue>>(); + } + virtual T resolve_calculated(NonnullRefPtr<CalculatedStyleValue> 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<StyleValue> 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<StyleValue> ResolvedCSSStyleDeclaration::style_value_for_property(Layout::NodeWithStyle const& layout_node, PropertyID property_id) const |