HTMLParagraphElement.cpp 1.6 KB

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