/src/serenity/Userland/Libraries/LibWeb/HTML/HTMLFieldSetElement.cpp
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2020, the SerenityOS developers. |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #include <LibWeb/Bindings/HTMLFieldSetElementPrototype.h> |
8 | | #include <LibWeb/Bindings/Intrinsics.h> |
9 | | #include <LibWeb/HTML/HTMLButtonElement.h> |
10 | | #include <LibWeb/HTML/HTMLFieldSetElement.h> |
11 | | #include <LibWeb/HTML/HTMLInputElement.h> |
12 | | #include <LibWeb/HTML/HTMLLegendElement.h> |
13 | | #include <LibWeb/HTML/HTMLObjectElement.h> |
14 | | #include <LibWeb/HTML/HTMLOutputElement.h> |
15 | | #include <LibWeb/HTML/HTMLSelectElement.h> |
16 | | #include <LibWeb/HTML/HTMLTextAreaElement.h> |
17 | | |
18 | | namespace Web::HTML { |
19 | | |
20 | | JS_DEFINE_ALLOCATOR(HTMLFieldSetElement); |
21 | | |
22 | | HTMLFieldSetElement::HTMLFieldSetElement(DOM::Document& document, DOM::QualifiedName qualified_name) |
23 | 0 | : HTMLElement(document, move(qualified_name)) |
24 | 0 | { |
25 | 0 | } |
26 | | |
27 | 0 | HTMLFieldSetElement::~HTMLFieldSetElement() = default; |
28 | | |
29 | | void HTMLFieldSetElement::initialize(JS::Realm& realm) |
30 | 0 | { |
31 | 0 | Base::initialize(realm); |
32 | 0 | WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLFieldSetElement); |
33 | 0 | } |
34 | | |
35 | | void HTMLFieldSetElement::visit_edges(Cell::Visitor& visitor) |
36 | 0 | { |
37 | 0 | Base::visit_edges(visitor); |
38 | 0 | visitor.visit(m_elements); |
39 | 0 | } |
40 | | |
41 | | // https://html.spec.whatwg.org/multipage/form-elements.html#concept-fieldset-disabled |
42 | | bool HTMLFieldSetElement::is_disabled() const |
43 | 0 | { |
44 | | // A fieldset element is a disabled fieldset if it matches any of the following conditions: |
45 | | // - Its disabled attribute is specified |
46 | 0 | if (has_attribute(AttributeNames::disabled)) |
47 | 0 | return true; |
48 | | |
49 | | // - 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. |
50 | 0 | for (auto* fieldset_ancestor = first_ancestor_of_type<HTMLFieldSetElement>(); fieldset_ancestor; fieldset_ancestor = fieldset_ancestor->first_ancestor_of_type<HTMLFieldSetElement>()) { |
51 | 0 | if (fieldset_ancestor->has_attribute(HTML::AttributeNames::disabled)) { |
52 | 0 | auto* first_legend_element_child = fieldset_ancestor->first_child_of_type<HTMLLegendElement>(); |
53 | 0 | if (!first_legend_element_child || !is_descendant_of(*first_legend_element_child)) |
54 | 0 | return true; |
55 | 0 | } |
56 | 0 | } |
57 | | |
58 | 0 | return false; |
59 | 0 | } |
60 | | |
61 | | // https://html.spec.whatwg.org/multipage/form-elements.html#dom-fieldset-elements |
62 | | JS::GCPtr<DOM::HTMLCollection> const& HTMLFieldSetElement::elements() |
63 | 0 | { |
64 | | // The elements IDL attribute must return an HTMLCollection rooted at the fieldset element, whose filter matches listed elements. |
65 | 0 | if (!m_elements) { |
66 | 0 | m_elements = DOM::HTMLCollection::create(*this, DOM::HTMLCollection::Scope::Descendants, [](DOM::Element const& element) { |
67 | | // FIXME: Form-associated custom elements return also true |
68 | 0 | return is<HTMLButtonElement>(element) |
69 | 0 | || is<HTMLFieldSetElement>(element) |
70 | 0 | || is<HTMLInputElement>(element) |
71 | 0 | || is<HTMLObjectElement>(element) |
72 | 0 | || is<HTMLOutputElement>(element) |
73 | 0 | || is<HTMLSelectElement>(element) |
74 | 0 | || is<HTMLTextAreaElement>(element); |
75 | 0 | }); |
76 | 0 | } |
77 | 0 | return m_elements; |
78 | 0 | } |
79 | | |
80 | | } |