HTMLDivElement.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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/HTMLDivElement.h>
  10. namespace Web::HTML {
  11. JS_DEFINE_ALLOCATOR(HTMLDivElement);
  12. HTMLDivElement::HTMLDivElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  13. : HTMLElement(document, move(qualified_name))
  14. {
  15. }
  16. HTMLDivElement::~HTMLDivElement() = default;
  17. // https://html.spec.whatwg.org/multipage/rendering.html#flow-content-3
  18. void HTMLDivElement::apply_presentational_hints(CSS::StyleProperties& style) const
  19. {
  20. for_each_attribute([&](auto& name, auto& value) {
  21. if (name.equals_ignoring_ascii_case("align"sv)) {
  22. if (value.equals_ignoring_ascii_case("left"sv))
  23. style.set_property(CSS::PropertyID::TextAlign, CSS::IdentifierStyleValue::create(CSS::ValueID::LibwebLeft));
  24. else if (value.equals_ignoring_ascii_case("right"sv))
  25. style.set_property(CSS::PropertyID::TextAlign, CSS::IdentifierStyleValue::create(CSS::ValueID::LibwebRight));
  26. else if (value.equals_ignoring_ascii_case("center"sv))
  27. style.set_property(CSS::PropertyID::TextAlign, CSS::IdentifierStyleValue::create(CSS::ValueID::LibwebCenter));
  28. else if (value.equals_ignoring_ascii_case("justify"sv))
  29. style.set_property(CSS::PropertyID::TextAlign, CSS::IdentifierStyleValue::create(CSS::ValueID::Justify));
  30. }
  31. });
  32. }
  33. void HTMLDivElement::initialize(JS::Realm& realm)
  34. {
  35. Base::initialize(realm);
  36. WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLDivElement);
  37. }
  38. }