Serenity Operating System
1/*
2 * Copyright (c) 2020, the SerenityOS developers.
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#include <LibWeb/Bindings/Intrinsics.h>
8#include <LibWeb/HTML/HTMLFieldSetElement.h>
9#include <LibWeb/HTML/HTMLLegendElement.h>
10
11namespace Web::HTML {
12
13HTMLFieldSetElement::HTMLFieldSetElement(DOM::Document& document, DOM::QualifiedName qualified_name)
14 : HTMLElement(document, move(qualified_name))
15{
16}
17
18HTMLFieldSetElement::~HTMLFieldSetElement() = default;
19
20JS::ThrowCompletionOr<void> HTMLFieldSetElement::initialize(JS::Realm& realm)
21{
22 MUST_OR_THROW_OOM(Base::initialize(realm));
23 set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLFieldSetElementPrototype>(realm, "HTMLFieldSetElement"));
24
25 return {};
26}
27
28// https://html.spec.whatwg.org/multipage/form-elements.html#concept-fieldset-disabled
29bool HTMLFieldSetElement::is_disabled() const
30{
31 // A fieldset element is a disabled fieldset if it matches any of the following conditions:
32 // - Its disabled attribute is specified
33 if (has_attribute(AttributeNames::disabled))
34 return true;
35
36 // - 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.
37 for (auto* fieldset_ancestor = first_ancestor_of_type<HTMLFieldSetElement>(); fieldset_ancestor; fieldset_ancestor = fieldset_ancestor->first_ancestor_of_type<HTMLFieldSetElement>()) {
38 if (fieldset_ancestor->has_attribute(HTML::AttributeNames::disabled)) {
39 auto* first_legend_element_child = fieldset_ancestor->first_child_of_type<HTMLLegendElement>();
40 if (!first_legend_element_child || !is_descendant_of(*first_legend_element_child))
41 return true;
42 }
43 }
44
45 return false;
46}
47
48}