HTMLDivElement.cpp 1.7 KB

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