LibWeb/CSS: Stop allowing auto in ComputedProperties::length_percentage

We only had one user of this which allows `auto`, which is length_box().
So, inline the code there, remove the `auto` branch from
length_percentage(), and then remove length_percentage_or_fallback()
entirely as nobody uses it any more.
This commit is contained in:
Sam Atkins 2025-08-27 15:42:33 +01:00
commit 1a3246b560
Notes: github-actions[bot] 2025-09-04 12:33:56 +00:00
2 changed files with 40 additions and 15 deletions

View file

@ -222,11 +222,6 @@ Size ComputedProperties::size_value(PropertyID id) const
return Size::make_auto();
}
LengthPercentage ComputedProperties::length_percentage_or_fallback(PropertyID id, Layout::NodeWithStyle const& layout_node, ClampNegativeLengths disallow_negative_lengths, LengthPercentage const& fallback) const
{
return length_percentage(id, layout_node, disallow_negative_lengths).value_or(fallback);
}
Optional<LengthPercentage> ComputedProperties::length_percentage(PropertyID id, Layout::NodeWithStyle const& layout_node, ClampNegativeLengths disallow_negative_lengths) const
{
auto const& value = property(id);
@ -256,9 +251,6 @@ Optional<LengthPercentage> ComputedProperties::length_percentage(PropertyID id,
return length;
}
if (value.has_auto())
return LengthPercentage { Length::make_auto() };
return {};
}
@ -269,12 +261,46 @@ Length ComputedProperties::length(PropertyID property_id) const
LengthBox ComputedProperties::length_box(PropertyID left_id, PropertyID top_id, PropertyID right_id, PropertyID bottom_id, Layout::NodeWithStyle const& layout_node, ClampNegativeLengths disallow_negative_lengths, Length const& default_value) const
{
LengthBox box;
box.left() = length_percentage_or_fallback(left_id, layout_node, disallow_negative_lengths, default_value);
box.top() = length_percentage_or_fallback(top_id, layout_node, disallow_negative_lengths, default_value);
box.right() = length_percentage_or_fallback(right_id, layout_node, disallow_negative_lengths, default_value);
box.bottom() = length_percentage_or_fallback(bottom_id, layout_node, disallow_negative_lengths, default_value);
return box;
auto length_box_side = [&](PropertyID id) -> LengthPercentage {
auto const& value = property(id);
if (value.is_calculated())
return LengthPercentage { value.as_calculated() };
if (value.is_percentage()) {
auto percentage = value.as_percentage().percentage();
// FIXME: This value can be negative as interpolation does not yet clamp values to allowed ranges - remove this
// once we do that.
if (disallow_negative_lengths == ClampNegativeLengths::Yes && percentage.as_fraction() < 0)
return default_value;
return percentage;
}
if (value.is_length()) {
auto length = value.as_length().length();
// FIXME: This value can be negative as interpolation does not yet clamp values to allowed ranges - remove this
// once we do that.
if (disallow_negative_lengths == ClampNegativeLengths::Yes && length.to_px(layout_node) < 0)
return default_value;
return value.as_length().length();
}
if (value.has_auto())
return LengthPercentage { Length::make_auto() };
return default_value;
};
return LengthBox {
length_box_side(top_id),
length_box_side(right_id),
length_box_side(bottom_id),
length_box_side(left_id)
};
}
Color ComputedProperties::color_or_fallback(PropertyID id, ColorResolutionContext color_resolution_context, Color fallback) const

View file

@ -82,7 +82,6 @@ public:
No,
Yes,
};
LengthPercentage length_percentage_or_fallback(PropertyID, Layout::NodeWithStyle const&, ClampNegativeLengths, LengthPercentage const& fallback) const;
Optional<LengthPercentage> length_percentage(PropertyID, Layout::NodeWithStyle const&, ClampNegativeLengths) const;
LengthBox length_box(PropertyID left_id, PropertyID top_id, PropertyID right_id, PropertyID bottom_id, Layout::NodeWithStyle const&, ClampNegativeLengths, Length const& default_value) const;
Color color_or_fallback(PropertyID, ColorResolutionContext, Color fallback) const;