HTMLFieldSetElement.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. HTMLFieldSetElement::HTMLFieldSetElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  11. : HTMLElement(document, move(qualified_name))
  12. {
  13. }
  14. HTMLFieldSetElement::~HTMLFieldSetElement() = default;
  15. void HTMLFieldSetElement::initialize(JS::Realm& realm)
  16. {
  17. Base::initialize(realm);
  18. set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLFieldSetElementPrototype>(realm, "HTMLFieldSetElement"));
  19. }
  20. // https://html.spec.whatwg.org/multipage/form-elements.html#concept-fieldset-disabled
  21. bool HTMLFieldSetElement::is_disabled() const
  22. {
  23. // A fieldset element is a disabled fieldset if it matches any of the following conditions:
  24. // - Its disabled attribute is specified
  25. if (has_attribute(AttributeNames::disabled))
  26. return true;
  27. // - It is a descendant of another fieldset element whose disabled attribute is specified, and is not a descendant of that fieldset element's first legend element child, if any.
  28. for (auto* fieldset_ancestor = first_ancestor_of_type<HTMLFieldSetElement>(); fieldset_ancestor; fieldset_ancestor = fieldset_ancestor->first_ancestor_of_type<HTMLFieldSetElement>()) {
  29. if (fieldset_ancestor->has_attribute(HTML::AttributeNames::disabled)) {
  30. auto* first_legend_element_child = fieldset_ancestor->first_child_of_type<HTMLLegendElement>();
  31. if (!first_legend_element_child || !is_descendant_of(*first_legend_element_child))
  32. return true;
  33. }
  34. }
  35. return false;
  36. }
  37. }