2020-01-18 05:38:21 -03:00
|
|
|
/*
|
2024-10-04 08:19:50 -03:00
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
2025-12-11 11:38:17 -03:00
|
|
|
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
|
2020-01-18 05:38:21 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2019-09-29 07:24:58 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
2023-01-28 19:23:16 -03:00
|
|
|
#include <LibWeb/ARIA/Roles.h>
|
2020-07-26 10:08:16 -03:00
|
|
|
#include <LibWeb/HTML/HTMLElement.h>
|
2019-09-29 07:24:58 -03:00
|
|
|
|
2020-07-28 13:20:36 -03:00
|
|
|
namespace Web::HTML {
|
2020-03-07 06:27:02 -03:00
|
|
|
|
2020-07-27 22:54:19 -03:00
|
|
|
class HTMLHeadingElement final : public HTMLElement {
|
2022-08-28 08:42:07 -03:00
|
|
|
WEB_PLATFORM_OBJECT(HTMLHeadingElement, HTMLElement);
|
2024-11-14 12:01:23 -03:00
|
|
|
GC_DECLARE_ALLOCATOR(HTMLHeadingElement);
|
2022-08-28 08:42:07 -03:00
|
|
|
|
2019-09-29 07:24:58 -03:00
|
|
|
public:
|
2022-08-28 08:42:07 -03:00
|
|
|
virtual ~HTMLHeadingElement() override;
|
2020-07-27 01:04:26 -03:00
|
|
|
|
2024-12-23 13:51:10 -03:00
|
|
|
virtual bool is_presentational_hint(FlyString const&) const override;
|
2026-04-30 06:44:26 -03:00
|
|
|
virtual void apply_presentational_hints(Vector<CSS::StyleProperty>&) const override;
|
2022-12-21 07:05:03 -03:00
|
|
|
|
2022-11-28 20:58:13 -03:00
|
|
|
// https://www.w3.org/TR/html-aria/#el-h1-h6
|
2023-01-28 19:23:16 -03:00
|
|
|
virtual Optional<ARIA::Role> default_role() const override { return ARIA::Role::heading; }
|
2023-01-29 15:12:00 -03:00
|
|
|
|
2025-12-11 11:38:17 -03:00
|
|
|
WebIDL::UnsignedLong heading_level() const;
|
|
|
|
|
|
2023-10-05 15:43:52 -03:00
|
|
|
virtual Optional<String> aria_level() const override
|
2022-11-28 20:58:13 -03:00
|
|
|
{
|
2025-10-10 12:25:49 -03:00
|
|
|
if (auto const attr = get_attribute(ARIA::AttributeNames::aria_level); attr.has_value())
|
|
|
|
|
return attr;
|
|
|
|
|
|
|
|
|
|
// Implicit defaults to the number in the element's tag name.
|
|
|
|
|
return MUST(local_name().to_string().substring_from_byte_offset(1));
|
2022-11-28 20:58:13 -03:00
|
|
|
}
|
|
|
|
|
|
2022-08-28 08:42:07 -03:00
|
|
|
private:
|
2022-02-18 17:00:52 -03:00
|
|
|
HTMLHeadingElement(DOM::Document&, DOM::QualifiedName);
|
2023-01-10 08:28:20 -03:00
|
|
|
|
2025-12-15 20:30:06 -03:00
|
|
|
virtual bool is_html_heading_element() const final { return true; }
|
|
|
|
|
|
2023-08-07 03:41:28 -03:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2025-12-11 11:38:17 -03:00
|
|
|
|
|
|
|
|
mutable WebIDL::UnsignedLong m_cached_heading_level { 0 };
|
|
|
|
|
mutable u64 m_dom_tree_version_for_cached_heading_level { 0 };
|
2019-09-29 07:24:58 -03:00
|
|
|
};
|
2020-03-07 06:27:02 -03:00
|
|
|
|
|
|
|
|
}
|
2025-12-15 20:30:06 -03:00
|
|
|
|
|
|
|
|
namespace Web::DOM {
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
|
inline bool Node::fast_is<HTML::HTMLHeadingElement>() const { return is_html_heading_element(); }
|
|
|
|
|
|
|
|
|
|
}
|