HTMLLegendElement.cpp 1.3 KB

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