LibWeb/CSS: Use generated FooUnit types instead of Foo::Type

I've also renamed the `m_type` and `type()` members to be `m_unit` and
`unit()` instead, to match what they actually are.
This commit is contained in:
Sam Atkins 2025-09-02 13:48:49 +01:00
commit b3e32445d3
Notes: github-actions[bot] 2025-09-11 16:08:15 +00:00
29 changed files with 232 additions and 669 deletions

View file

@ -11,20 +11,20 @@
namespace Web::CSS {
Frequency::Frequency(double value, Type type)
: m_type(type)
Frequency::Frequency(double value, FrequencyUnit unit)
: m_unit(unit)
, m_value(value)
{
}
Frequency Frequency::make_hertz(double value)
{
return { value, Type::Hz };
return { value, FrequencyUnit::Hz };
}
Frequency Frequency::percentage_of(Percentage const& percentage) const
{
return Frequency { percentage.as_fraction() * m_value, m_type };
return Frequency { percentage.as_fraction() * m_value, m_unit };
}
String Frequency::to_string(SerializationMode serialization_mode) const
@ -47,36 +47,15 @@ String Frequency::to_string(SerializationMode serialization_mode) const
double Frequency::to_hertz() const
{
switch (m_type) {
case Type::Hz:
switch (m_unit) {
case FrequencyUnit::Hz:
return m_value;
case Type::kHz:
case FrequencyUnit::KHz:
return m_value * 1000;
}
VERIFY_NOT_REACHED();
}
StringView Frequency::unit_name() const
{
switch (m_type) {
case Type::Hz:
return "hz"sv;
case Type::kHz:
return "khz"sv;
}
VERIFY_NOT_REACHED();
}
Optional<Frequency::Type> Frequency::unit_from_name(StringView name)
{
if (name.equals_ignoring_ascii_case("hz"sv)) {
return Type::Hz;
} else if (name.equals_ignoring_ascii_case("khz"sv)) {
return Type::kHz;
}
return {};
}
Frequency Frequency::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, Layout::Node const& layout_node, Frequency const& reference_value)
{
CalculationResolutionContext context {