LibWeb: Store BackgroundSizeStyleValue sub-values directly

Storing these within LengthPercentage is unnecessary
This commit is contained in:
Callum Law 2025-10-02 16:50:43 +13:00 committed by Sam Atkins
commit 2ebf446cbf
Notes: github-actions[bot] 2025-10-07 09:51:23 +00:00
5 changed files with 21 additions and 52 deletions

View file

@ -11,7 +11,7 @@
namespace Web::CSS {
BackgroundSizeStyleValue::BackgroundSizeStyleValue(LengthPercentageOrAuto size_x, LengthPercentageOrAuto size_y)
BackgroundSizeStyleValue::BackgroundSizeStyleValue(ValueComparingNonnullRefPtr<StyleValue const> size_x, ValueComparingNonnullRefPtr<StyleValue const> size_y)
: StyleValueWithDefaultOperators(Type::BackgroundSize)
, m_properties { .size_x = move(size_x), .size_y = move(size_y) }
{
@ -21,21 +21,15 @@ BackgroundSizeStyleValue::~BackgroundSizeStyleValue() = default;
String BackgroundSizeStyleValue::to_string(SerializationMode mode) const
{
if (m_properties.size_x.is_auto() && m_properties.size_y.is_auto())
if (m_properties.size_x->has_auto() && m_properties.size_y->has_auto())
return "auto"_string;
return MUST(String::formatted("{} {}", m_properties.size_x.to_string(mode), m_properties.size_y.to_string(mode)));
return MUST(String::formatted("{} {}", m_properties.size_x->to_string(mode), m_properties.size_y->to_string(mode)));
}
ValueComparingNonnullRefPtr<StyleValue const> BackgroundSizeStyleValue::absolutized(ComputationContext const& computation_context) const
{
auto absolutize = [&](auto& size) -> LengthPercentageOrAuto {
if (size.is_auto())
return size;
return size.length_percentage().absolutized(computation_context);
};
auto absolutized_size_x = absolutize(m_properties.size_x);
auto absolutized_size_y = absolutize(m_properties.size_y);
auto absolutized_size_x = m_properties.size_x->absolutized(computation_context);
auto absolutized_size_y = m_properties.size_y->absolutized(computation_context);
if (absolutized_size_x == m_properties.size_x && absolutized_size_y == m_properties.size_y)
return *this;