mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
Previously, the LibWeb bindings generator would output multiple per interface files like Prototype/Constructor/Namespace/GlobalMixin depending on the contents of that IDL file. This complicates the build system as it means that it does not know what files will be generated without knowledge of the contents of that IDL file. Instead, for each IDL file only generate a single Bindings/<IDLFile>.h and Bindings/<IDLFile>.cpp.
101 lines
4.6 KiB
C++
101 lines
4.6 KiB
C++
/*
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibWeb/Bindings/HTMLLIElement.h>
|
|
#include <LibWeb/CSS/CascadedProperties.h>
|
|
#include <LibWeb/CSS/PropertyID.h>
|
|
#include <LibWeb/CSS/StyleValues/CounterStyleStyleValue.h>
|
|
#include <LibWeb/CSS/StyleValues/KeywordStyleValue.h>
|
|
#include <LibWeb/HTML/HTMLLIElement.h>
|
|
#include <LibWeb/HTML/Numbers.h>
|
|
#include <LibWeb/HTML/Window.h>
|
|
|
|
namespace Web::HTML {
|
|
|
|
GC_DEFINE_ALLOCATOR(HTMLLIElement);
|
|
|
|
HTMLLIElement::HTMLLIElement(DOM::Document& document, DOM::QualifiedName qualified_name)
|
|
: HTMLElement(document, move(qualified_name))
|
|
{
|
|
}
|
|
|
|
HTMLLIElement::~HTMLLIElement() = default;
|
|
|
|
void HTMLLIElement::initialize(JS::Realm& realm)
|
|
{
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLLIElement);
|
|
Base::initialize(realm);
|
|
}
|
|
|
|
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);
|
|
maybe_invalidate_ordinals_for_list_owner();
|
|
}
|
|
}
|
|
}
|
|
|
|
// 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;
|
|
}
|
|
|
|
void HTMLLIElement::set_value(WebIDL::Long value)
|
|
{
|
|
set_attribute_value(AttributeNames::value, String::number(value));
|
|
}
|
|
|
|
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
|
|
{
|
|
Base::apply_presentational_hints(cascaded_properties);
|
|
|
|
// 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::CounterStyleStyleValue::create("decimal"_fly_string));
|
|
} else if (value == "a"sv) {
|
|
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::ListStyleType, CSS::CounterStyleStyleValue::create("lower-alpha"_fly_string));
|
|
} else if (value == "A"sv) {
|
|
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::ListStyleType, CSS::CounterStyleStyleValue::create("upper-alpha"_fly_string));
|
|
} else if (value == "i"sv) {
|
|
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::ListStyleType, CSS::CounterStyleStyleValue::create("lower-roman"_fly_string));
|
|
} else if (value == "I"sv) {
|
|
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::ListStyleType, CSS::CounterStyleStyleValue::create("upper-roman"_fly_string));
|
|
} else if (value.equals_ignoring_ascii_case("none"sv)) {
|
|
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::ListStyleType, CSS::KeywordStyleValue::create(CSS::Keyword::None));
|
|
} else if (value.equals_ignoring_ascii_case("disc"sv)) {
|
|
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::ListStyleType, CSS::CounterStyleStyleValue::create("disc"_fly_string));
|
|
} else if (value.equals_ignoring_ascii_case("circle"sv)) {
|
|
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::ListStyleType, CSS::CounterStyleStyleValue::create("circle"_fly_string));
|
|
} else if (value.equals_ignoring_ascii_case("square"sv)) {
|
|
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::ListStyleType, CSS::CounterStyleStyleValue::create("square"_fly_string));
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
}
|