HTMLHeadingElement.cpp 1.7 KB

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