LibWeb: Apply type presentational hint for HTMLOListElement

This commit is contained in:
Tim Ledbetter 2025-02-18 14:51:18 +00:00 committed by Tim Ledbetter
commit 7612f2161c
Notes: github-actions[bot] 2025-02-21 01:26:37 +00:00
4 changed files with 66 additions and 0 deletions

View file

@ -6,6 +6,7 @@
#include <LibWeb/Bindings/HTMLOListElementPrototype.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/CSS/StyleValues/CSSKeywordValue.h>
#include <LibWeb/HTML/HTMLOListElement.h>
#include <LibWeb/HTML/Numbers.h>
@ -36,4 +37,32 @@ WebIDL::Long HTMLOListElement::start()
return 1;
}
bool HTMLOListElement::is_presentational_hint(FlyString const& name) const
{
if (Base::is_presentational_hint(name))
return true;
return name == HTML::AttributeNames::type;
}
void HTMLOListElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
{
// https://html.spec.whatwg.org/multipage/rendering.html#lists
for_each_attribute([&](auto& name, auto& value) {
if (name == HTML::AttributeNames::type) {
if (value == "1"sv) {
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::ListStyleType, CSS::CSSKeywordValue::create(CSS::Keyword::Decimal));
} else if (value == "a"sv) {
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::ListStyleType, CSS::CSSKeywordValue::create(CSS::Keyword::LowerAlpha));
} else if (value == "A"sv) {
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::ListStyleType, CSS::CSSKeywordValue::create(CSS::Keyword::UpperAlpha));
} else if (value == "i"sv) {
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::ListStyleType, CSS::CSSKeywordValue::create(CSS::Keyword::LowerRoman));
} else if (value == "I"sv) {
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::ListStyleType, CSS::CSSKeywordValue::create(CSS::Keyword::UpperRoman));
}
}
});
}
}

View file

@ -32,6 +32,9 @@ private:
HTMLOListElement(DOM::Document&, DOM::QualifiedName);
virtual void initialize(JS::Realm&) override;
virtual bool is_presentational_hint(FlyString const&) const override;
virtual void apply_presentational_hints(GC::Ref<CSS::CascadedProperties>) const override;
};
}