HTMLFieldSetElement.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. JS::ThrowCompletionOr<void> HTMLFieldSetElement::initialize(JS::Realm& realm)
  16. {
  17. MUST_OR_THROW_OOM(Base::initialize(realm));
  18. set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLFieldSetElementPrototype>(realm, "HTMLFieldSetElement"));
  19. return {};
  20. }
  21. // https://html.spec.whatwg.org/multipage/form-elements.html#concept-fieldset-disabled
  22. bool HTMLFieldSetElement::is_disabled() const
  23. {
  24. // A fieldset element is a disabled fieldset if it matches any of the following conditions:
  25. // - Its disabled attribute is specified
  26. if (has_attribute(AttributeNames::disabled))
  27. return true;
  28. // - 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.
  29. for (auto* fieldset_ancestor = first_ancestor_of_type<HTMLFieldSetElement>(); fieldset_ancestor; fieldset_ancestor = fieldset_ancestor->first_ancestor_of_type<HTMLFieldSetElement>()) {
  30. if (fieldset_ancestor->has_attribute(HTML::AttributeNames::disabled)) {
  31. auto* first_legend_element_child = fieldset_ancestor->first_child_of_type<HTMLLegendElement>();
  32. if (!first_legend_element_child || !is_descendant_of(*first_legend_element_child))
  33. return true;
  34. }
  35. }
  36. return false;
  37. }
  38. }