2020-01-18 09:38:21 +01:00
|
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
2025-12-11 14:38:17 +00:00
|
|
|
|
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
|
2020-01-18 09:38:21 +01:00
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
2026-04-18 10:54:06 +02:00
|
|
|
|
#include <LibWeb/Bindings/HTMLHeadingElement.h>
|
2022-09-30 17:16:16 -06:00
|
|
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
2024-12-20 11:32:17 +01:00
|
|
|
|
#include <LibWeb/CSS/ComputedProperties.h>
|
2025-08-08 10:28:41 +01:00
|
|
|
|
#include <LibWeb/CSS/StyleValues/KeywordStyleValue.h>
|
2025-12-11 14:38:17 +00:00
|
|
|
|
#include <LibWeb/DOM/Document.h>
|
2020-07-26 15:08:16 +02:00
|
|
|
|
#include <LibWeb/HTML/HTMLHeadingElement.h>
|
2019-09-29 12:24:58 +02:00
|
|
|
|
|
2020-07-28 18:20:36 +02:00
|
|
|
|
namespace Web::HTML {
|
2020-03-07 10:27:02 +01:00
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
|
GC_DEFINE_ALLOCATOR(HTMLHeadingElement);
|
2023-11-19 19:47:52 +01:00
|
|
|
|
|
2022-02-18 21:00:52 +01:00
|
|
|
|
HTMLHeadingElement::HTMLHeadingElement(DOM::Document& document, DOM::QualifiedName qualified_name)
|
2021-02-07 11:20:15 +01:00
|
|
|
|
: HTMLElement(document, move(qualified_name))
|
2019-09-29 12:24:58 +02:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-14 13:21:51 -06:00
|
|
|
|
HTMLHeadingElement::~HTMLHeadingElement() = default;
|
2022-12-21 12:05:03 +02:00
|
|
|
|
|
2023-08-07 08:41:28 +02:00
|
|
|
|
void HTMLHeadingElement::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(HTMLHeadingElement);
|
2025-04-20 16:22:57 +02:00
|
|
|
|
Base::initialize(realm);
|
2023-01-10 06:28:20 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-12-23 17:51:10 +01:00
|
|
|
|
bool HTMLHeadingElement::is_presentational_hint(FlyString const& name) const
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Base::is_presentational_hint(name))
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
return name == HTML::AttributeNames::align;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-21 12:05:03 +02:00
|
|
|
|
// https://html.spec.whatwg.org/multipage/rendering.html#tables-2
|
2026-04-30 10:44:26 +01:00
|
|
|
|
void HTMLHeadingElement::apply_presentational_hints(Vector<CSS::StyleProperty>& properties) const
|
2022-12-21 12:05:03 +02:00
|
|
|
|
{
|
2026-04-30 10:44:26 +01:00
|
|
|
|
HTMLElement::apply_presentational_hints(properties);
|
2022-12-21 12:05:03 +02:00
|
|
|
|
for_each_attribute([&](auto& name, auto& value) {
|
2025-06-04 14:34:04 +01:00
|
|
|
|
if (name == HTML::AttributeNames::align) {
|
2022-12-21 12:05:03 +02:00
|
|
|
|
if (value == "left"sv)
|
2026-04-30 10:44:26 +01:00
|
|
|
|
properties.append({ .property_id = CSS::PropertyID::TextAlign, .value = CSS::KeywordStyleValue::create(CSS::Keyword::Left) });
|
2022-12-21 12:05:03 +02:00
|
|
|
|
else if (value == "right"sv)
|
2026-04-30 10:44:26 +01:00
|
|
|
|
properties.append({ .property_id = CSS::PropertyID::TextAlign, .value = CSS::KeywordStyleValue::create(CSS::Keyword::Right) });
|
2022-12-21 12:05:03 +02:00
|
|
|
|
else if (value == "center"sv)
|
2026-04-30 10:44:26 +01:00
|
|
|
|
properties.append({ .property_id = CSS::PropertyID::TextAlign, .value = CSS::KeywordStyleValue::create(CSS::Keyword::Center) });
|
2022-12-21 12:05:03 +02:00
|
|
|
|
else if (value == "justify"sv)
|
2026-04-30 10:44:26 +01:00
|
|
|
|
properties.append({ .property_id = CSS::PropertyID::TextAlign, .value = CSS::KeywordStyleValue::create(CSS::Keyword::Justify) });
|
2022-12-21 12:05:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-11 14:38:17 +00:00
|
|
|
|
// https://html.spec.whatwg.org/multipage/sections.html#heading-level
|
|
|
|
|
|
WebIDL::UnsignedLong HTMLHeadingElement::heading_level() const
|
|
|
|
|
|
{
|
|
|
|
|
|
// h1–h6 elements have a heading level, which is given by getting the element's computed heading level.
|
|
|
|
|
|
if (m_dom_tree_version_for_cached_heading_level < document().dom_tree_version()) {
|
|
|
|
|
|
m_dom_tree_version_for_cached_heading_level = document().dom_tree_version();
|
|
|
|
|
|
m_cached_heading_level = computed_heading_level();
|
|
|
|
|
|
}
|
|
|
|
|
|
return m_cached_heading_level;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-07 10:27:02 +01:00
|
|
|
|
}
|