HTMLDivElement.cpp 1.7 KB

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