/* * Copyright (c) 2021, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include #include #include #include #include #include namespace Web::HTML { void FormAssociatedElement::set_form(HTMLFormElement* form) { if (m_form) m_form->remove_associated_element({}, *this); m_form = form; if (m_form) m_form->add_associated_element({}, *this); } bool FormAssociatedElement::enabled() const { // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-fe-disabled // A form control is disabled if any of the following conditions are met: // 1. The element is a button, input, select, textarea, or form-associated custom element, and the disabled attribute is specified on this element (regardless of its value). // FIXME: This doesn't check for form-associated custom elements. if ((is(this) || is(this) || is(this) || is(this)) && has_attribute(HTML::AttributeNames::disabled)) return false; // 2. The element is a descendant of a fieldset element whose disabled attribute is specified, and is not a descendant of that fieldset element's first legend element child, if any. auto* fieldset_ancestor = first_ancestor_of_type(); if (fieldset_ancestor && fieldset_ancestor->has_attribute(HTML::AttributeNames::disabled)) { auto* first_legend_element_child = fieldset_ancestor->first_child_of_type(); if (!first_legend_element_child || !is_descendant_of(*first_legend_element_child)) return false; } return true; } }