LibWeb: Support strings as list-style-types

We've long claimed to support this, but then silently ignored string
values, until 4cb2063577 which would
not-so-silently crash instead. (Oops)

So, actually pass the string value along and use it in the list marker.

As part of this, rename our `list-style-type` enum to
`counter-style-name-keyword`. This is an awkward name, attempting to be
spec-based. (The spec says `<counter-style>`, which is either a
`<counter-style-name>` or a function, and the `<counter-style-name>` is
a `<custom-ident>` that also has a few predefined values. So this is the
best I could come up with.)

Unfortunately only one WPT test for this passes - the others fail
because we produce a different layout when text is in `::before` than
when it's in `::marker`, and similar issues.
This commit is contained in:
Sam Atkins 2025-02-10 12:48:40 +00:00 committed by Andreas Kling
commit 0fd0596dbf
Notes: github-actions[bot] 2025-02-11 09:40:22 +00:00
10 changed files with 201 additions and 132 deletions

View file

@ -18,40 +18,43 @@ ListItemMarkerBox::ListItemMarkerBox(DOM::Document& document, CSS::ListStyleType
, m_list_style_position(style_position)
, m_index(index)
{
switch (m_list_style_type) {
case CSS::ListStyleType::Square:
case CSS::ListStyleType::Circle:
case CSS::ListStyleType::Disc:
case CSS::ListStyleType::DisclosureClosed:
case CSS::ListStyleType::DisclosureOpen:
break;
case CSS::ListStyleType::Decimal:
m_text = MUST(String::formatted("{}.", m_index));
break;
case CSS::ListStyleType::DecimalLeadingZero:
// This is weird, but in accordance to spec.
m_text = m_index < 10 ? MUST(String::formatted("0{}.", m_index)) : MUST(String::formatted("{}.", m_index));
break;
case CSS::ListStyleType::LowerAlpha:
case CSS::ListStyleType::LowerLatin:
m_text = String::bijective_base_from(m_index - 1, String::Case::Lower);
break;
case CSS::ListStyleType::UpperAlpha:
case CSS::ListStyleType::UpperLatin:
m_text = String::bijective_base_from(m_index - 1, String::Case::Upper);
break;
case CSS::ListStyleType::LowerRoman:
m_text = String::roman_number_from(m_index, String::Case::Lower);
break;
case CSS::ListStyleType::UpperRoman:
m_text = String::roman_number_from(m_index, String::Case::Upper);
break;
case CSS::ListStyleType::None:
break;
default:
VERIFY_NOT_REACHED();
}
m_list_style_type.visit(
[this](CSS::CounterStyleNameKeyword keyword) {
switch (keyword) {
case CSS::CounterStyleNameKeyword::Square:
case CSS::CounterStyleNameKeyword::Circle:
case CSS::CounterStyleNameKeyword::Disc:
case CSS::CounterStyleNameKeyword::DisclosureClosed:
case CSS::CounterStyleNameKeyword::DisclosureOpen:
break;
case CSS::CounterStyleNameKeyword::Decimal:
m_text = MUST(String::formatted("{}.", m_index));
break;
case CSS::CounterStyleNameKeyword::DecimalLeadingZero:
// This is weird, but in accordance to spec.
m_text = m_index < 10 ? MUST(String::formatted("0{}.", m_index)) : MUST(String::formatted("{}.", m_index));
break;
case CSS::CounterStyleNameKeyword::LowerAlpha:
case CSS::CounterStyleNameKeyword::LowerLatin:
m_text = String::bijective_base_from(m_index - 1, String::Case::Lower);
break;
case CSS::CounterStyleNameKeyword::UpperAlpha:
case CSS::CounterStyleNameKeyword::UpperLatin:
m_text = String::bijective_base_from(m_index - 1, String::Case::Upper);
break;
case CSS::CounterStyleNameKeyword::LowerRoman:
m_text = String::roman_number_from(m_index, String::Case::Lower);
break;
case CSS::CounterStyleNameKeyword::UpperRoman:
m_text = String::roman_number_from(m_index, String::Case::Upper);
break;
case CSS::CounterStyleNameKeyword::None:
break;
}
},
[this](String const& string) {
m_text = string;
});
}
ListItemMarkerBox::~ListItemMarkerBox() = default;