LibWeb/CSS: Remove the "Auto" type from Length

This has always been a bit of a hack. Initially it made sense as a lot
of properties that accept a length also accept `auto`, but while
convenient, that leads to problems: It's easy to forget to check if a
length is `auto`, and places that don't accept it end up with an
invalid state lurking in the type system, which makes things unclear.
This commit is contained in:
Sam Atkins 2025-09-01 14:03:25 +01:00
commit 930ee495e7
Notes: github-actions[bot] 2025-09-04 12:32:29 +00:00
10 changed files with 8 additions and 66 deletions

View file

@ -38,11 +38,6 @@ Length::Length(double value, Type type)
}
Length::~Length() = default;
Length Length::make_auto()
{
return Length(0, Type::Auto);
}
Length Length::make_px(double value)
{
return Length(value, Type::Px);
@ -55,11 +50,6 @@ Length Length::make_px(CSSPixels value)
Length Length::percentage_of(Percentage const& percentage) const
{
if (is_auto()) {
dbgln("Attempting to get percentage of an auto length, this seems wrong? But for now we just return the original length.");
return *this;
}
return Length { percentage.as_fraction() * raw_value(), m_type };
}
@ -191,11 +181,6 @@ CSSPixels Length::to_px(ResolutionContext const& context) const
CSSPixels Length::to_px_slow_case(Layout::Node const& layout_node) const
{
if (is_auto()) {
// FIXME: We really, really shouldn't end up here, but we do, and so frequently that
// adding a dbgln() here outputs a couple hundred lines loading `welcome.html`.
return 0;
}
if (!layout_node.document().browsing_context())
return 0;
@ -223,9 +208,6 @@ CSSPixels Length::to_px_slow_case(Layout::Node const& layout_node) const
String Length::to_string(SerializationMode serialization_mode) const
{
if (is_auto())
return "auto"_string;
// https://drafts.csswg.org/cssom/#serialize-a-css-value
// -> <length>
// The <number> component serialized as per <number> followed by the unit in its canonical form as defined in its
@ -334,8 +316,6 @@ StringView Length::unit_name() const
return "pc"sv;
case Type::Px:
return "px"sv;
case Type::Auto:
return "auto"sv;
}
VERIFY_NOT_REACHED();
}