HTMLParagraphElement.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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/CSS/StyleProperties.h>
  8. #include <LibWeb/CSS/StyleValues/IdentifierStyleValue.h>
  9. #include <LibWeb/HTML/HTMLParagraphElement.h>
  10. namespace Web::HTML {
  11. HTMLParagraphElement::HTMLParagraphElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  12. : HTMLElement(document, move(qualified_name))
  13. {
  14. }
  15. HTMLParagraphElement::~HTMLParagraphElement() = default;
  16. JS::ThrowCompletionOr<void> HTMLParagraphElement::initialize(JS::Realm& realm)
  17. {
  18. MUST_OR_THROW_OOM(Base::initialize(realm));
  19. set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLParagraphElementPrototype>(realm, "HTMLParagraphElement"));
  20. return {};
  21. }
  22. // https://html.spec.whatwg.org/multipage/rendering.html#tables-2
  23. void HTMLParagraphElement::apply_presentational_hints(CSS::StyleProperties& style) const
  24. {
  25. HTMLElement::apply_presentational_hints(style);
  26. for_each_attribute([&](auto& name, auto& value) {
  27. if (name.equals_ignoring_ascii_case("align"sv)) {
  28. if (value == "left"sv)
  29. style.set_property(CSS::PropertyID::TextAlign, CSS::IdentifierStyleValue::create(CSS::ValueID::Left).release_value_but_fixme_should_propagate_errors());
  30. else if (value == "right"sv)
  31. style.set_property(CSS::PropertyID::TextAlign, CSS::IdentifierStyleValue::create(CSS::ValueID::Right).release_value_but_fixme_should_propagate_errors());
  32. else if (value == "center"sv)
  33. style.set_property(CSS::PropertyID::TextAlign, CSS::IdentifierStyleValue::create(CSS::ValueID::Center).release_value_but_fixme_should_propagate_errors());
  34. else if (value == "justify"sv)
  35. style.set_property(CSS::PropertyID::TextAlign, CSS::IdentifierStyleValue::create(CSS::ValueID::Justify).release_value_but_fixme_should_propagate_errors());
  36. }
  37. });
  38. }
  39. }