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
|
|
|
|
*/
|
|
|
|
|
|
|
2026-04-18 05:54:06 -03:00
|
|
|
|
#include <LibWeb/Bindings/HTMLHeadingElement.h>
|
2022-09-30 20:16:16 -03:00
|
|
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
2024-12-20 07:32:17 -03:00
|
|
|
|
#include <LibWeb/CSS/ComputedProperties.h>
|
2025-08-08 06:28:41 -03:00
|
|
|
|
#include <LibWeb/CSS/StyleValues/KeywordStyleValue.h>
|
2025-12-11 11:38:17 -03:00
|
|
|
|
#include <LibWeb/DOM/Document.h>
|
2020-07-26 10:08:16 -03:00
|
|
|
|
#include <LibWeb/HTML/HTMLHeadingElement.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
|
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
|
GC_DEFINE_ALLOCATOR(HTMLHeadingElement);
|
2023-11-19 15:47:52 -03:00
|
|
|
|
|
2022-02-18 17:00:52 -03:00
|
|
|
|
HTMLHeadingElement::HTMLHeadingElement(DOM::Document& document, DOM::QualifiedName qualified_name)
|
2021-02-07 07:20:15 -03:00
|
|
|
|
: HTMLElement(document, move(qualified_name))
|
2019-09-29 07:24:58 -03:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-14 16:21:51 -03:00
|
|
|
|
HTMLHeadingElement::~HTMLHeadingElement() = default;
|
2022-12-21 07:05:03 -03:00
|
|
|
|
|
2023-08-07 03:41:28 -03:00
|
|
|
|
void HTMLHeadingElement::initialize(JS::Realm& realm)
|
2023-01-10 08:28:20 -03:00
|
|
|
|
{
|
2024-03-16 09:13:08 -03:00
|
|
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLHeadingElement);
|
2025-04-20 11:22:57 -03:00
|
|
|
|
Base::initialize(realm);
|
2023-01-10 08:28:20 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-12-23 13:51:10 -03: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 07:05:03 -03:00
|
|
|
|
// https://html.spec.whatwg.org/multipage/rendering.html#tables-2
|
2026-04-30 06:44:26 -03:00
|
|
|
|
void HTMLHeadingElement::apply_presentational_hints(Vector<CSS::StyleProperty>& properties) const
|
2022-12-21 07:05:03 -03:00
|
|
|
|
{
|
2026-04-30 06:44:26 -03:00
|
|
|
|
HTMLElement::apply_presentational_hints(properties);
|
2022-12-21 07:05:03 -03:00
|
|
|
|
for_each_attribute([&](auto& name, auto& value) {
|
2025-06-04 10:34:04 -03:00
|
|
|
|
if (name == HTML::AttributeNames::align) {
|
2022-12-21 07:05:03 -03:00
|
|
|
|
if (value == "left"sv)
|
2026-04-30 06:44:26 -03:00
|
|
|
|
properties.append({ .property_id = CSS::PropertyID::TextAlign, .value = CSS::KeywordStyleValue::create(CSS::Keyword::Left) });
|
2022-12-21 07:05:03 -03:00
|
|
|
|
else if (value == "right"sv)
|
2026-04-30 06:44:26 -03:00
|
|
|
|
properties.append({ .property_id = CSS::PropertyID::TextAlign, .value = CSS::KeywordStyleValue::create(CSS::Keyword::Right) });
|
2022-12-21 07:05:03 -03:00
|
|
|
|
else if (value == "center"sv)
|
2026-04-30 06:44:26 -03:00
|
|
|
|
properties.append({ .property_id = CSS::PropertyID::TextAlign, .value = CSS::KeywordStyleValue::create(CSS::Keyword::Center) });
|
2022-12-21 07:05:03 -03:00
|
|
|
|
else if (value == "justify"sv)
|
2026-04-30 06:44:26 -03:00
|
|
|
|
properties.append({ .property_id = CSS::PropertyID::TextAlign, .value = CSS::KeywordStyleValue::create(CSS::Keyword::Justify) });
|
2022-12-21 07:05:03 -03:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-11 11:38:17 -03: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 06:27:02 -03:00
|
|
|
|
}
|