HTMLTableCaptionElement.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/HTMLTableCaptionElementPrototype.h>
  7. #include <LibWeb/Bindings/Intrinsics.h>
  8. #include <LibWeb/CSS/ComputedProperties.h>
  9. #include <LibWeb/CSS/StyleValues/CSSKeywordValue.h>
  10. #include <LibWeb/HTML/HTMLTableCaptionElement.h>
  11. namespace Web::HTML {
  12. GC_DEFINE_ALLOCATOR(HTMLTableCaptionElement);
  13. HTMLTableCaptionElement::HTMLTableCaptionElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  14. : HTMLElement(document, move(qualified_name))
  15. {
  16. }
  17. HTMLTableCaptionElement::~HTMLTableCaptionElement() = default;
  18. void HTMLTableCaptionElement::initialize(JS::Realm& realm)
  19. {
  20. Base::initialize(realm);
  21. WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLTableCaptionElement);
  22. }
  23. bool HTMLTableCaptionElement::is_presentational_hint(FlyString const& name) const
  24. {
  25. if (Base::is_presentational_hint(name))
  26. return true;
  27. return name == HTML::AttributeNames::align;
  28. }
  29. // https://html.spec.whatwg.org/multipage/rendering.html#tables-2
  30. void HTMLTableCaptionElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
  31. {
  32. HTMLElement::apply_presentational_hints(cascaded_properties);
  33. for_each_attribute([&](auto& name, auto& value) {
  34. if (name.equals_ignoring_ascii_case("align"sv)) {
  35. if (value == "bottom"sv)
  36. cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::CaptionSide, CSS::CSSKeywordValue::create(CSS::Keyword::Bottom));
  37. }
  38. });
  39. }
  40. }