Serenity Operating System
1/*
2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#include <LibWeb/Bindings/Intrinsics.h>
8#include <LibWeb/HTML/HTMLHeadingElement.h>
9
10namespace Web::HTML {
11
12HTMLHeadingElement::HTMLHeadingElement(DOM::Document& document, DOM::QualifiedName qualified_name)
13 : HTMLElement(document, move(qualified_name))
14{
15}
16
17HTMLHeadingElement::~HTMLHeadingElement() = default;
18
19JS::ThrowCompletionOr<void> HTMLHeadingElement::initialize(JS::Realm& realm)
20{
21 MUST_OR_THROW_OOM(Base::initialize(realm));
22 set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLHeadingElementPrototype>(realm, "HTMLHeadingElement"));
23
24 return {};
25}
26
27// https://html.spec.whatwg.org/multipage/rendering.html#tables-2
28void HTMLHeadingElement::apply_presentational_hints(CSS::StyleProperties& style) const
29{
30 HTMLElement::apply_presentational_hints(style);
31 for_each_attribute([&](auto& name, auto& value) {
32 if (name.equals_ignoring_ascii_case("align"sv)) {
33 if (value == "left"sv)
34 style.set_property(CSS::PropertyID::TextAlign, CSS::IdentifierStyleValue::create(CSS::ValueID::Left));
35 else if (value == "right"sv)
36 style.set_property(CSS::PropertyID::TextAlign, CSS::IdentifierStyleValue::create(CSS::ValueID::Right));
37 else if (value == "center"sv)
38 style.set_property(CSS::PropertyID::TextAlign, CSS::IdentifierStyleValue::create(CSS::ValueID::Center));
39 else if (value == "justify"sv)
40 style.set_property(CSS::PropertyID::TextAlign, CSS::IdentifierStyleValue::create(CSS::ValueID::Justify));
41 }
42 });
43}
44
45}