2020-08-01 03:05:43 +01:00
|
|
|
/*
|
2021-04-28 22:46:44 +02:00
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
2020-08-01 03:05:43 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-08-01 03:05:43 +01:00
|
|
|
*/
|
|
|
|
|
2024-04-27 12:09:58 +12:00
|
|
|
#include <LibWeb/Bindings/HTMLLIElementPrototype.h>
|
2025-08-08 10:28:41 +01:00
|
|
|
#include <LibWeb/CSS/StyleValues/KeywordStyleValue.h>
|
2020-08-01 03:05:43 +01:00
|
|
|
#include <LibWeb/HTML/HTMLLIElement.h>
|
2024-11-26 15:36:18 +00:00
|
|
|
#include <LibWeb/HTML/Numbers.h>
|
2022-08-28 13:42:07 +02:00
|
|
|
#include <LibWeb/HTML/Window.h>
|
2020-08-01 03:05:43 +01:00
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DEFINE_ALLOCATOR(HTMLLIElement);
|
2023-11-19 19:47:52 +01:00
|
|
|
|
2022-02-18 21:00:52 +01:00
|
|
|
HTMLLIElement::HTMLLIElement(DOM::Document& document, DOM::QualifiedName qualified_name)
|
2021-02-07 11:20:15 +01:00
|
|
|
: HTMLElement(document, move(qualified_name))
|
2020-08-01 03:05:43 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-03-14 13:21:51 -06:00
|
|
|
HTMLLIElement::~HTMLLIElement() = default;
|
2023-01-10 06:28:20 -05:00
|
|
|
|
2023-08-07 08:41:28 +02:00
|
|
|
void HTMLLIElement::initialize(JS::Realm& realm)
|
2023-01-10 06:28:20 -05:00
|
|
|
{
|
2024-03-16 13:13:08 +01:00
|
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLLIElement);
|
2025-04-20 16:22:57 +02:00
|
|
|
Base::initialize(realm);
|
2023-01-10 06:28:20 -05:00
|
|
|
}
|
|
|
|
|
2025-05-10 19:08:25 +02:00
|
|
|
void HTMLLIElement::attribute_changed(FlyString const& local_name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_)
|
|
|
|
{
|
|
|
|
Base::attribute_changed(local_name, old_value, value, namespace_);
|
|
|
|
|
|
|
|
if (local_name == HTML::AttributeNames::value) {
|
|
|
|
if (auto* owner = list_owner()) {
|
|
|
|
owner->set_needs_layout_tree_update(true, DOM::SetNeedsLayoutTreeUpdateReason::HTMLOListElementOrdinalValues);
|
2025-05-13 06:59:03 -07:00
|
|
|
maybe_invalidate_ordinals_for_list_owner();
|
2025-05-10 19:08:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-26 15:36:18 +00:00
|
|
|
// https://html.spec.whatwg.org/multipage/grouping-content.html#dom-li-value
|
|
|
|
WebIDL::Long HTMLLIElement::value()
|
|
|
|
{
|
|
|
|
// The value IDL attribute must reflect the value of the value content attribute.
|
|
|
|
// NOTE: This is equivalent to the code that would be generated by the IDL generator if we used [Reflect] on the value attribute.
|
|
|
|
// We don't do that in this case, since this method is used elsewhere.
|
|
|
|
auto content_attribute_value = get_attribute(AttributeNames::value).value_or("0"_string);
|
|
|
|
if (auto maybe_number = HTML::parse_integer(content_attribute_value); maybe_number.has_value())
|
|
|
|
return *maybe_number;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2025-02-18 15:09:42 +00:00
|
|
|
bool HTMLLIElement::is_presentational_hint(FlyString const& name) const
|
|
|
|
{
|
|
|
|
if (Base::is_presentational_hint(name))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return name == HTML::AttributeNames::type;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLLIElement::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) {
|
2025-08-08 10:28:41 +01:00
|
|
|
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::ListStyleType, CSS::KeywordStyleValue::create(CSS::Keyword::Decimal));
|
2025-02-18 15:09:42 +00:00
|
|
|
} else if (value == "a"sv) {
|
2025-08-08 10:28:41 +01:00
|
|
|
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::ListStyleType, CSS::KeywordStyleValue::create(CSS::Keyword::LowerAlpha));
|
2025-02-18 15:09:42 +00:00
|
|
|
} else if (value == "A"sv) {
|
2025-08-08 10:28:41 +01:00
|
|
|
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::ListStyleType, CSS::KeywordStyleValue::create(CSS::Keyword::UpperAlpha));
|
2025-02-18 15:09:42 +00:00
|
|
|
} else if (value == "i"sv) {
|
2025-08-08 10:28:41 +01:00
|
|
|
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::ListStyleType, CSS::KeywordStyleValue::create(CSS::Keyword::LowerRoman));
|
2025-02-18 15:09:42 +00:00
|
|
|
} else if (value == "I"sv) {
|
2025-08-08 10:28:41 +01:00
|
|
|
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::ListStyleType, CSS::KeywordStyleValue::create(CSS::Keyword::UpperRoman));
|
2025-02-18 15:09:42 +00:00
|
|
|
} else if (value.equals_ignoring_ascii_case("none"sv)) {
|
2025-08-08 10:28:41 +01:00
|
|
|
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::ListStyleType, CSS::KeywordStyleValue::create(CSS::Keyword::None));
|
2025-02-18 15:09:42 +00:00
|
|
|
} else if (value.equals_ignoring_ascii_case("disc"sv)) {
|
2025-08-08 10:28:41 +01:00
|
|
|
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::ListStyleType, CSS::KeywordStyleValue::create(CSS::Keyword::Disc));
|
2025-02-18 15:09:42 +00:00
|
|
|
} else if (value.equals_ignoring_ascii_case("circle"sv)) {
|
2025-08-08 10:28:41 +01:00
|
|
|
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::ListStyleType, CSS::KeywordStyleValue::create(CSS::Keyword::Circle));
|
2025-02-18 15:09:42 +00:00
|
|
|
} else if (value.equals_ignoring_ascii_case("square"sv)) {
|
2025-08-08 10:28:41 +01:00
|
|
|
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::ListStyleType, CSS::KeywordStyleValue::create(CSS::Keyword::Square));
|
2025-02-18 15:09:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-08-01 03:05:43 +01:00
|
|
|
}
|