HTMLDivElement.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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/ComputedProperties.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. bool HTMLDivElement::is_presentational_hint(FlyString const& name) const
  19. {
  20. if (Base::is_presentational_hint(name))
  21. return true;
  22. return name == HTML::AttributeNames::align;
  23. }
  24. // https://html.spec.whatwg.org/multipage/rendering.html#flow-content-3
  25. void HTMLDivElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
  26. {
  27. for_each_attribute([&](auto& name, auto& value) {
  28. if (name.equals_ignoring_ascii_case("align"sv)) {
  29. if (value.equals_ignoring_ascii_case("left"sv))
  30. cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::LibwebLeft));
  31. else if (value.equals_ignoring_ascii_case("right"sv))
  32. cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::LibwebRight));
  33. else if (value.equals_ignoring_ascii_case("center"sv))
  34. cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::LibwebCenter));
  35. else if (value.equals_ignoring_ascii_case("justify"sv))
  36. cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Justify));
  37. }
  38. });
  39. }
  40. void HTMLDivElement::initialize(JS::Realm& realm)
  41. {
  42. Base::initialize(realm);
  43. WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLDivElement);
  44. }
  45. }