diff --git a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp index 900384f994..4b5b149582 100644 --- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp @@ -168,6 +168,8 @@ static NonnullRefPtr style_value_for_size(CSS::Size const& siz return LengthStyleValue::create(size.length()); if (size.is_auto()) return IdentifierStyleValue::create(ValueID::Auto); + if (size.is_calculated()) + return size.calculated(); if (size.is_min_content()) return IdentifierStyleValue::create(ValueID::MinContent); if (size.is_max_content()) diff --git a/Userland/Libraries/LibWeb/CSS/Size.cpp b/Userland/Libraries/LibWeb/CSS/Size.cpp index 9b6ea918eb..fa4e8f8fe9 100644 --- a/Userland/Libraries/LibWeb/CSS/Size.cpp +++ b/Userland/Libraries/LibWeb/CSS/Size.cpp @@ -41,6 +41,11 @@ Size Size::make_percentage(Percentage percentage) return Size { Type::Percentage, move(percentage) }; } +Size Size::make_calculated(NonnullRefPtr calculated) +{ + return Size { Type::Calculated, move(calculated) }; +} + Size Size::make_min_content() { return Size { Type::MinContent, Length::make_auto() }; @@ -79,6 +84,7 @@ ErrorOr Size::to_string() const switch (m_type) { case Type::Auto: return "auto"_string; + case Type::Calculated: case Type::Length: case Type::Percentage: return m_length_percentage.to_string(); diff --git a/Userland/Libraries/LibWeb/CSS/Size.h b/Userland/Libraries/LibWeb/CSS/Size.h index d8cad444a1..8e2a8ac952 100644 --- a/Userland/Libraries/LibWeb/CSS/Size.h +++ b/Userland/Libraries/LibWeb/CSS/Size.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2022, Andreas Kling + * Copyright (c) 2023, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ @@ -15,6 +16,7 @@ class Size { public: enum class Type { Auto, + Calculated, Length, Percentage, MinContent, @@ -27,12 +29,14 @@ public: static Size make_px(CSSPixels); static Size make_length(Length); static Size make_percentage(Percentage); + static Size make_calculated(NonnullRefPtr); static Size make_min_content(); static Size make_max_content(); static Size make_fit_content(Length available_space); static Size make_none(); bool is_auto() const { return m_type == Type::Auto; } + bool is_calculated() const { return m_type == Type::Calculated; } bool is_length() const { return m_type == Type::Length; } bool is_percentage() const { return m_type == Type::Percentage; } bool is_min_content() const { return m_type == Type::MinContent; } @@ -45,6 +49,12 @@ public: bool contains_percentage() const; + CalculatedStyleValue const& calculated() const + { + VERIFY(is_calculated()); + return m_length_percentage.calculated(); + } + CSS::Length const& length() const { VERIFY(is_length()); diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp index ded4425ebb..eadfa46b1a 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp @@ -79,7 +79,7 @@ CSS::Size StyleProperties::size_value(CSS::PropertyID id) const } if (value->is_calculated()) - return CSS::Size::make_length(CSS::Length::make_calculated(const_cast(value->as_calculated()))); + return CSS::Size::make_calculated(const_cast(value->as_calculated())); if (value->is_percentage()) return CSS::Size::make_percentage(value->as_percentage().percentage());