summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
diff options
context:
space:
mode:
authorLuke Wilde <lukew@serenityos.org>2022-03-01 20:59:46 +0000
committerAndreas Kling <kling@serenityos.org>2022-03-01 23:19:41 +0100
commitd2e18175eff3dea89375e9ce12998c5e820213a5 (patch)
tree04bfea8dcdc1ebeeb0c093b46e855382cd8a95e6 /Userland/Libraries/LibWeb
parent99f52e52d2f299de5ec9e80f9af9a0dbf3913159 (diff)
downloadserenity-d2e18175eff3dea89375e9ce12998c5e820213a5.zip
LibWeb: Move enabled() to FormAssociatedElement and follow the spec
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r--Userland/Libraries/LibWeb/HTML/FormAssociatedElement.cpp27
-rw-r--r--Userland/Libraries/LibWeb/HTML/FormAssociatedElement.h2
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp5
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLInputElement.h2
4 files changed, 29 insertions, 7 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/FormAssociatedElement.cpp b/Userland/Libraries/LibWeb/HTML/FormAssociatedElement.cpp
index 93e8213ff9..4e624cd0a3 100644
--- a/Userland/Libraries/LibWeb/HTML/FormAssociatedElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/FormAssociatedElement.cpp
@@ -5,7 +5,13 @@
*/
#include <LibWeb/HTML/FormAssociatedElement.h>
+#include <LibWeb/HTML/HTMLButtonElement.h>
+#include <LibWeb/HTML/HTMLFieldSetElement.h>
#include <LibWeb/HTML/HTMLFormElement.h>
+#include <LibWeb/HTML/HTMLInputElement.h>
+#include <LibWeb/HTML/HTMLLegendElement.h>
+#include <LibWeb/HTML/HTMLSelectElement.h>
+#include <LibWeb/HTML/HTMLTextAreaElement.h>
namespace Web::HTML {
@@ -18,4 +24,25 @@ void FormAssociatedElement::set_form(HTMLFormElement* 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<HTMLButtonElement>(this) || is<HTMLInputElement>(this) || is<HTMLSelectElement>(this) || is<HTMLTextAreaElement>(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<HTMLFieldSetElement>();
+ if (fieldset_ancestor && fieldset_ancestor->has_attribute(HTML::AttributeNames::disabled)) {
+ auto* first_legend_element_child = fieldset_ancestor->first_child_of_type<HTMLLegendElement>();
+ if (!first_legend_element_child || !is_descendant_of(*first_legend_element_child))
+ return false;
+ }
+
+ return true;
+}
+
}
diff --git a/Userland/Libraries/LibWeb/HTML/FormAssociatedElement.h b/Userland/Libraries/LibWeb/HTML/FormAssociatedElement.h
index 4571f3008b..cf373f98d7 100644
--- a/Userland/Libraries/LibWeb/HTML/FormAssociatedElement.h
+++ b/Userland/Libraries/LibWeb/HTML/FormAssociatedElement.h
@@ -19,6 +19,8 @@ public:
void set_form(HTMLFormElement*);
+ bool enabled() const;
+
protected:
FormAssociatedElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp
index c62788ae25..9605eaf1df 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp
@@ -138,11 +138,6 @@ void HTMLInputElement::did_edit_text_node(Badge<BrowsingContext>)
});
}
-bool HTMLInputElement::enabled() const
-{
- return !has_attribute(HTML::AttributeNames::disabled);
-}
-
String HTMLInputElement::value() const
{
if (m_text_node)
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h
index b708551570..45ad02cba0 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h
+++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h
@@ -73,8 +73,6 @@ public:
};
void set_checked(bool, ChangeSource = ChangeSource::Programmatic, ShouldRunActivationBehavior = ShouldRunActivationBehavior::Yes);
- bool enabled() const;
-
void did_click_button(Badge<Layout::ButtonBox>);
void did_click_checkbox(Badge<Layout::CheckBox>);