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
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2024-12-09 17:01:54 +09:00
|
|
|
#include <AK/GenericShorthands.h>
|
2020-08-01 03:05:43 +01:00
|
|
|
#include <LibWeb/HTML/HTMLElement.h>
|
2024-12-09 17:01:54 +09:00
|
|
|
#include <LibWeb/HTML/HTMLOListElement.h>
|
|
|
|
#include <LibWeb/HTML/HTMLUListElement.h>
|
2024-11-26 15:36:18 +00:00
|
|
|
#include <LibWeb/WebIDL/Types.h>
|
2020-08-01 03:05:43 +01:00
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
|
|
|
class HTMLLIElement final : public HTMLElement {
|
2022-08-28 13:42:07 +02:00
|
|
|
WEB_PLATFORM_OBJECT(HTMLLIElement, HTMLElement);
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DECLARE_ALLOCATOR(HTMLLIElement);
|
2022-08-28 13:42:07 +02:00
|
|
|
|
2020-08-01 03:05:43 +01:00
|
|
|
public:
|
2022-08-28 13:42:07 +02:00
|
|
|
virtual ~HTMLLIElement() override;
|
2020-08-01 03:05:43 +01:00
|
|
|
|
2022-11-28 17:58:13 -06:00
|
|
|
// https://www.w3.org/TR/html-aria/#el-li
|
2024-12-09 17:01:54 +09:00
|
|
|
virtual Optional<ARIA::Role> default_role() const override
|
|
|
|
{
|
2025-04-18 14:19:19 +12:00
|
|
|
for (auto ancestor = parent_element(); ancestor; ancestor = ancestor->parent_element()) {
|
2024-12-09 17:01:54 +09:00
|
|
|
if (ancestor->role_or_default() == ARIA::Role::list)
|
|
|
|
return ARIA::Role::listitem;
|
|
|
|
}
|
|
|
|
// https://w3c.github.io/core-aam/#roleMappingComputedRole
|
|
|
|
// When an element has a role but is not contained in the required context (for example, an orphaned listitem
|
|
|
|
// without the required accessible parent of role list), User Agents MUST ignore the role token, and return the
|
|
|
|
// computedrole as if the ignored role token had not been included.
|
|
|
|
return ARIA::Role::none;
|
|
|
|
}
|
2022-11-28 17:58:13 -06:00
|
|
|
|
2024-11-26 15:36:18 +00:00
|
|
|
WebIDL::Long value();
|
|
|
|
void set_value(WebIDL::Long value)
|
2023-10-11 18:42:09 +02:00
|
|
|
{
|
2025-01-14 19:42:12 -05:00
|
|
|
MUST(set_attribute(AttributeNames::value, String::number(value)));
|
2023-10-11 18:42:09 +02:00
|
|
|
}
|
|
|
|
|
2025-04-23 07:06:11 -07:00
|
|
|
virtual bool is_html_li_element() const override { return true; }
|
|
|
|
|
2022-08-28 13:42:07 +02:00
|
|
|
private:
|
2022-02-18 21:00:52 +01:00
|
|
|
HTMLLIElement(DOM::Document&, DOM::QualifiedName);
|
2023-01-10 06:28:20 -05:00
|
|
|
|
2023-08-07 08:41:28 +02:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2025-05-10 19:08:25 +02:00
|
|
|
virtual void attribute_changed(FlyString const& local_name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_) override;
|
2025-02-18 15:09:42 +00:00
|
|
|
|
|
|
|
virtual bool is_presentational_hint(FlyString const&) const override;
|
|
|
|
virtual void apply_presentational_hints(GC::Ref<CSS::CascadedProperties>) const override;
|
2020-08-01 03:05:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2025-04-23 07:06:11 -07:00
|
|
|
|
|
|
|
namespace Web::DOM {
|
|
|
|
|
|
|
|
template<>
|
|
|
|
inline bool Node::fast_is<Web::HTML::HTMLLIElement>() const { return is_html_li_element(); }
|
|
|
|
|
|
|
|
}
|