HTMLLegendElement.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/HTMLLegendElementPrototype.h>
  7. #include <LibWeb/Bindings/Intrinsics.h>
  8. #include <LibWeb/HTML/HTMLFieldSetElement.h>
  9. #include <LibWeb/HTML/HTMLLegendElement.h>
  10. #include <LibWeb/Layout/LegendBox.h>
  11. namespace Web::HTML {
  12. GC_DEFINE_ALLOCATOR(HTMLLegendElement);
  13. HTMLLegendElement::HTMLLegendElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  14. : HTMLElement(document, move(qualified_name))
  15. {
  16. }
  17. HTMLLegendElement::~HTMLLegendElement() = default;
  18. void HTMLLegendElement::initialize(JS::Realm& realm)
  19. {
  20. Base::initialize(realm);
  21. WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLLegendElement);
  22. }
  23. // https://html.spec.whatwg.org/multipage/form-elements.html#dom-legend-form
  24. HTMLFormElement* HTMLLegendElement::form()
  25. {
  26. // The form IDL attribute's behavior depends on whether the legend element is in a fieldset element or not.
  27. // If the legend has a fieldset element as its parent, then the form IDL attribute must return the same value as the form IDL attribute on that fieldset element.
  28. if (is<HTML::HTMLFieldSetElement>(parent_element())) {
  29. return verify_cast<HTML::HTMLFieldSetElement>(parent_element())->form();
  30. }
  31. // Otherwise, it must return null.
  32. return nullptr;
  33. }
  34. GC::Ptr<Layout::Node> HTMLLegendElement::create_layout_node(CSS::StyleProperties style)
  35. {
  36. return heap().allocate<Layout::LegendBox>(document(), *this, move(style));
  37. }
  38. Layout::LegendBox* HTMLLegendElement::layout_node()
  39. {
  40. return static_cast<Layout::LegendBox*>(Node::layout_node());
  41. }
  42. Layout::LegendBox const* HTMLLegendElement::layout_node() const
  43. {
  44. return static_cast<Layout::LegendBox const*>(Node::layout_node());
  45. }
  46. }