HTMLFieldSetElement.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/HTML/HTMLFieldSetElement.h>
  7. #include <LibWeb/HTML/HTMLLegendElement.h>
  8. #include <LibWeb/HTML/Window.h>
  9. namespace Web::HTML {
  10. HTMLFieldSetElement::HTMLFieldSetElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  11. : HTMLElement(document, move(qualified_name))
  12. {
  13. set_prototype(&window().cached_web_prototype("HTMLFieldSetElement"));
  14. }
  15. HTMLFieldSetElement::~HTMLFieldSetElement() = default;
  16. // https://html.spec.whatwg.org/multipage/form-elements.html#concept-fieldset-disabled
  17. bool HTMLFieldSetElement::is_disabled() const
  18. {
  19. // A fieldset element is a disabled fieldset if it matches any of the following conditions:
  20. // - Its disabled attribute is specified
  21. if (has_attribute(AttributeNames::disabled))
  22. return true;
  23. // - 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.
  24. for (auto* fieldset_ancestor = first_ancestor_of_type<HTMLFieldSetElement>(); fieldset_ancestor; fieldset_ancestor = fieldset_ancestor->first_ancestor_of_type<HTMLFieldSetElement>()) {
  25. if (fieldset_ancestor->has_attribute(HTML::AttributeNames::disabled)) {
  26. auto* first_legend_element_child = fieldset_ancestor->first_child_of_type<HTMLLegendElement>();
  27. if (!first_legend_element_child || !is_descendant_of(*first_legend_element_child))
  28. return true;
  29. }
  30. }
  31. return false;
  32. }
  33. }