HTMLHeadingElement.cpp 1.7 KB

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