HTMLLegendElement.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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/HTML/HTMLFieldSetElement.h>
  8. #include <LibWeb/HTML/HTMLLegendElement.h>
  9. namespace Web::HTML {
  10. JS_DEFINE_ALLOCATOR(HTMLLegendElement);
  11. HTMLLegendElement::HTMLLegendElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  12. : HTMLElement(document, move(qualified_name))
  13. {
  14. }
  15. HTMLLegendElement::~HTMLLegendElement() = default;
  16. void HTMLLegendElement::initialize(JS::Realm& realm)
  17. {
  18. Base::initialize(realm);
  19. WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLLegendElement);
  20. }
  21. // https://html.spec.whatwg.org/multipage/form-elements.html#dom-legend-form
  22. HTMLFormElement* HTMLLegendElement::form()
  23. {
  24. // The form IDL attribute's behavior depends on whether the legend element is in a fieldset element or not.
  25. // 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.
  26. if (is<HTML::HTMLFieldSetElement>(parent_element())) {
  27. return verify_cast<HTML::HTMLFieldSetElement>(parent_element())->form();
  28. }
  29. // Otherwise, it must return null.
  30. return nullptr;
  31. }
  32. }