diff --git a/Libraries/LibWeb/HTML/AttributeNames.h b/Libraries/LibWeb/HTML/AttributeNames.h
index 26ab6d49c19..209f68c2c9c 100644
--- a/Libraries/LibWeb/HTML/AttributeNames.h
+++ b/Libraries/LibWeb/HTML/AttributeNames.h
@@ -28,6 +28,7 @@ namespace AttributeNames {
__ENUMERATE_HTML_ATTRIBUTE(async, "async") \
__ENUMERATE_HTML_ATTRIBUTE(autocapitalize, "autocapitalize") \
__ENUMERATE_HTML_ATTRIBUTE(autocomplete, "autocomplete") \
+ __ENUMERATE_HTML_ATTRIBUTE(autocorrect, "autocorrect") \
__ENUMERATE_HTML_ATTRIBUTE(autofocus, "autofocus") \
__ENUMERATE_HTML_ATTRIBUTE(autoplay, "autoplay") \
__ENUMERATE_HTML_ATTRIBUTE(axis, "axis") \
diff --git a/Libraries/LibWeb/HTML/HTMLElement.cpp b/Libraries/LibWeb/HTML/HTMLElement.cpp
index 0988c5b7dfc..55df08802c2 100644
--- a/Libraries/LibWeb/HTML/HTMLElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLElement.cpp
@@ -31,6 +31,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -2325,4 +2326,64 @@ void HTMLElement::set_autocapitalize(String const& given_value)
MUST(set_attribute(HTML::AttributeNames::autocapitalize, given_value));
}
+// https://html.spec.whatwg.org/multipage/interaction.html#used-autocorrection-state
+HTMLElement::AutocorrectionState HTMLElement::used_autocorrection_state() const
+{
+ // The autocorrect attribute is an enumerated attribute with the following keywords and states:
+ // Keyword | State | Brief description
+ // on | on | The user agent is permitted to automatically correct spelling errors while the user
+ // (the empty string) | | types. Whether spelling is automatically corrected while typing left is for the user
+ // | | agent to decide, and may depend on the element as well as the user's preferences.
+ // off | off | The user agent is not allowed to automatically correct spelling while the user types.
+
+ // The attribute's invalid value default and missing value default are both the on state.
+
+ auto autocorrect_attribute_state = [](Optional attribute) {
+ if (attribute.has_value() && attribute.value().equals_ignoring_ascii_case("off"sv))
+ return AutocorrectionState::Off;
+
+ return AutocorrectionState::On;
+ };
+
+ // To compute the used autocorrection state of an element element, run these steps:
+ // 1. If element is an input element whose type attribute is in one of the URL, E-mail, or Password states, then return off.
+ if (auto const* input_element = as_if(this)) {
+ if (first_is_one_of(input_element->type_state(), HTMLInputElement::TypeAttributeState::URL, HTMLInputElement::TypeAttributeState::Email, HTMLInputElement::TypeAttributeState::Password))
+ return AutocorrectionState::Off;
+ }
+
+ // 2. If the autocorrect content attribute is present on element, then return the state of the attribute.
+ auto maybe_autocorrect_attribute = attribute(HTML::AttributeNames::autocorrect);
+
+ if (maybe_autocorrect_attribute.has_value())
+ return autocorrect_attribute_state(maybe_autocorrect_attribute);
+
+ // 3. If element is an autocapitalize-and-autocorrect inheriting element and has a non-null form owner, then return
+ // the state of element's form owner's autocorrect attribute.
+ if (auto const* form_associated_element = as_if(this)) {
+ if (form_associated_element->is_autocapitalize_and_autocorrect_inheriting() && form_associated_element->form())
+ return autocorrect_attribute_state(form_associated_element->form()->attribute(HTML::AttributeNames::autocorrect));
+ }
+
+ // 4. Return on.
+ return AutocorrectionState::On;
+}
+
+// https://html.spec.whatwg.org/multipage/interaction.html#dom-autocorrect
+bool HTMLElement::autocorrect() const
+{
+ // The autocorrect getter steps are: return true if the element's used autocorrection state is on and false if the element's used autocorrection state is off.
+ return used_autocorrection_state() == AutocorrectionState::On;
+}
+
+// https://html.spec.whatwg.org/multipage/interaction.html#dom-autocorrect
+void HTMLElement::set_autocorrect(bool given_value)
+{
+ // The setter steps are: if the given value is true, then the element's autocorrect attribute must be set to "on"; otherwise it must be set to "off".
+ if (given_value)
+ MUST(set_attribute(HTML::AttributeNames::autocorrect, "on"_string));
+ else
+ MUST(set_attribute(HTML::AttributeNames::autocorrect, "off"_string));
+}
+
}
diff --git a/Libraries/LibWeb/HTML/HTMLElement.h b/Libraries/LibWeb/HTML/HTMLElement.h
index 03aea314a70..8799bf30f6c 100644
--- a/Libraries/LibWeb/HTML/HTMLElement.h
+++ b/Libraries/LibWeb/HTML/HTMLElement.h
@@ -135,6 +135,15 @@ public:
String autocapitalize() const;
void set_autocapitalize(String const&);
+ enum class AutocorrectionState {
+ On,
+ Off
+ };
+
+ AutocorrectionState used_autocorrection_state() const;
+ bool autocorrect() const;
+ void set_autocorrect(bool);
+
bool fire_a_synthetic_pointer_event(FlyString const& type, DOM::Element& target, bool not_trusted);
// https://html.spec.whatwg.org/multipage/forms.html#category-label
diff --git a/Libraries/LibWeb/HTML/HTMLElement.idl b/Libraries/LibWeb/HTML/HTMLElement.idl
index ff0f1d44032..82a606f9291 100644
--- a/Libraries/LibWeb/HTML/HTMLElement.idl
+++ b/Libraries/LibWeb/HTML/HTMLElement.idl
@@ -27,7 +27,7 @@ interface HTMLElement : Element {
[CEReactions] attribute boolean spellcheck;
[CEReactions] attribute DOMString writingSuggestions;
[CEReactions] attribute DOMString autocapitalize;
- [FIXME, CEReactions] attribute boolean autocorrect;
+ [CEReactions] attribute boolean autocorrect;
[LegacyNullToEmptyString, CEReactions] attribute Utf16DOMString innerText;
[LegacyNullToEmptyString, CEReactions] attribute Utf16DOMString outerText;
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/editing/editing-0/autocorrection/autocorrection.txt b/Tests/LibWeb/Text/expected/wpt-import/html/editing/editing-0/autocorrection/autocorrection.txt
new file mode 100644
index 00000000000..7557066b845
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/editing/editing-0/autocorrection/autocorrection.txt
@@ -0,0 +1,14 @@
+Harness status: OK
+
+Found 9 tests
+
+9 Pass
+Pass Test that the autocorrect attribute is available on HTMLInputElement.
+Pass Test that the autocorrect attribute is available on HTMLTextAreaElement.
+Pass Test that the autocorrect attribute is available on div.
+Pass Test that the autocorrect attribute is available on form.
+Pass Test setting the autocorrect IDL attribute.
+Pass Test setting the autocorrect attribute using setAttribute.
+Pass Test inheriting autocorrection from a form.
+Pass Test autocorrection in an editing host.
+Pass Test autocorrection in password, URL, and email inputs.
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/wpt-import/html/editing/editing-0/autocorrection/autocorrection.html b/Tests/LibWeb/Text/input/wpt-import/html/editing/editing-0/autocorrection/autocorrection.html
new file mode 100644
index 00000000000..79d2e0a27d5
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/html/editing/editing-0/autocorrection/autocorrection.html
@@ -0,0 +1,342 @@
+
+
+
+
+
+
+
+
+