LibWeb: Apply type presentational hint for HTMLUListElement

This commit is contained in:
Tim Ledbetter 2025-02-18 14:58:48 +00:00 committed by Tim Ledbetter
parent 7612f2161c
commit 74bf7bc28e
Notes: github-actions[bot] 2025-02-21 01:26:31 +00:00
4 changed files with 59 additions and 0 deletions

View file

@ -6,6 +6,7 @@
#include <LibWeb/Bindings/HTMLUListElementPrototype.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/CSS/StyleValues/CSSKeywordValue.h>
#include <LibWeb/HTML/HTMLUListElement.h>
namespace Web::HTML {
@ -25,4 +26,30 @@ void HTMLUListElement::initialize(JS::Realm& realm)
WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLUListElement);
}
bool HTMLUListElement::is_presentational_hint(FlyString const& name) const
{
if (Base::is_presentational_hint(name))
return true;
return name == HTML::AttributeNames::type;
}
void HTMLUListElement::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.equals_ignoring_ascii_case("none"sv)) {
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::ListStyleType, CSS::CSSKeywordValue::create(CSS::Keyword::None));
} else if (value.equals_ignoring_ascii_case("disc"sv)) {
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::ListStyleType, CSS::CSSKeywordValue::create(CSS::Keyword::Disc));
} else if (value.equals_ignoring_ascii_case("circle"sv)) {
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::ListStyleType, CSS::CSSKeywordValue::create(CSS::Keyword::Circle));
} else if (value.equals_ignoring_ascii_case("square"sv)) {
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::ListStyleType, CSS::CSSKeywordValue::create(CSS::Keyword::Square));
}
}
});
}
}

View file

@ -25,6 +25,9 @@ private:
HTMLUListElement(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;
};
}

View file

@ -0,0 +1,21 @@
<!doctype html>
<meta charset=utf-8>
<title>ul@type: supported types</title>
<style>
.disc {
list-style-type: disc;
}
.circle {
list-style-type: circle;
}
.square {
list-style-type: square;
}
.none {
list-style-type: none;
}
</style>
<ul class="disc"><li>first disc</li><li>second disc</li></ul>
<ul class="circle"><li>first circle</li><li>second circle</li></ul>
<ul class="square"><li>first square</li><li>second square</li></ul>
<ul class="none"><li>first none</li><li>second none</li></ul>

View file

@ -0,0 +1,8 @@
<!doctype html>
<meta charset=utf-8>
<title>ul@type: supported types</title>
<link rel=match href=../../../../../../expected/wpt-import/html/rendering/non-replaced-elements/lists/ul-type-supported-ref.html>
<ul type=disc><li>first disc</li><li>second disc</li></ul>
<ul type=circle><li>first circle</li><li>second circle</li></ul>
<ul type=square><li>first square</li><li>second square</li></ul>
<ul type=none><li>first none</li><li>second none</li></ul>