LibWeb/HTML: Capitalize autocorrection and autocapitalization states

Only comment changes.

Corresponds to:
ea29ce1963
This commit is contained in:
Sam Atkins 2025-11-27 16:03:24 +00:00
parent c0b8f47a76
commit 2feff2b519
Notes: github-actions[bot] 2025-12-01 11:09:00 +00:00

View file

@ -2224,15 +2224,15 @@ HTMLElement::AutocapitalizationHint HTMLElement::own_autocapitalization_hint() c
{ {
// The autocapitalization processing model is based on selecting among five autocapitalization hints, defined as follows: // The autocapitalization processing model is based on selecting among five autocapitalization hints, defined as follows:
// //
// default // Default
// The user agent and input method should make their own determination of whether or not to enable autocapitalization. // The user agent and input method should make their own determination of whether or not to enable autocapitalization.
// none // none
// No autocapitalization should be applied (all letters should default to lowercase). // No autocapitalization should be applied (all letters should default to lowercase).
// sentences // Sentences
// The first letter of each sentence should default to a capital letter; all other letters should default to lowercase. // The first letter of each sentence should default to a capital letter; all other letters should default to lowercase.
// words // Words
// The first letter of each word should default to a capital letter; all other letters should default to lowercase. // The first letter of each word should default to a capital letter; all other letters should default to lowercase.
// characters // Characters
// All letters should default to uppercase. // All letters should default to uppercase.
// The autocapitalize attribute is an enumerated attribute whose states are the possible autocapitalization hints. // The autocapitalize attribute is an enumerated attribute whose states are the possible autocapitalization hints.
@ -2241,14 +2241,14 @@ HTMLElement::AutocapitalizationHint HTMLElement::own_autocapitalization_hint() c
// their state mappings are as follows: // their state mappings are as follows:
// Keyword | State // Keyword | State
// off | none // off | None
// none | // none |
// on | sentences // on | Sentences
// sentences | // sentences |
// words | words // words | Words
// characters | characters // characters | Characters
// The attribute's missing value default is the default state, and its invalid value default is the sentences state. // The attribute's missing value default is the Default state, and its invalid value default is the Sentences state.
// To compute the own autocapitalization hint of an element element, run the following steps: // To compute the own autocapitalization hint of an element element, run the following steps:
// 1. If the autocapitalize content attribute is present on element, and its value is not the empty string, return the // 1. If the autocapitalize content attribute is present on element, and its value is not the empty string, return the
@ -2270,12 +2270,13 @@ HTMLElement::AutocapitalizationHint HTMLElement::own_autocapitalization_hint() c
return AutocapitalizationHint::Sentences; return AutocapitalizationHint::Sentences;
} }
// If element is an autocapitalize-and-autocorrect inheriting element and has a non-null form owner, return the own autocapitalization hint of element's form owner. // 2. If element is an autocapitalize-and-autocorrect inheriting element and has a non-null form owner, return the
// own autocapitalization hint of element's form owner.
auto const* form_associated_element = as_if<FormAssociatedElement>(this); auto const* form_associated_element = as_if<FormAssociatedElement>(this);
if (form_associated_element && form_associated_element->is_autocapitalize_and_autocorrect_inheriting() && form_associated_element->form()) if (form_associated_element && form_associated_element->is_autocapitalize_and_autocorrect_inheriting() && form_associated_element->form())
return form_associated_element->form()->own_autocapitalization_hint(); return form_associated_element->form()->own_autocapitalization_hint();
// 3. Return default. // 3. Return Default.
return AutocapitalizationHint::Default; return AutocapitalizationHint::Default;
} }
@ -2286,9 +2287,9 @@ String HTMLElement::autocapitalize() const
// 1. Let state be the own autocapitalization hint of this. // 1. Let state be the own autocapitalization hint of this.
auto state = own_autocapitalization_hint(); auto state = own_autocapitalization_hint();
// 2. If state is default, then return the empty string. // 2. If state is Default, then return the empty string.
// 3. If state is none, then return "none". // 3. If state is None, then return "none".
// 4. If state is sentences, then return "sentences". // 4. If state is Sentences, then return "sentences".
// 5. Return the keyword value corresponding to state. // 5. Return the keyword value corresponding to state.
switch (state) { switch (state) {
case AutocapitalizationHint::Default: case AutocapitalizationHint::Default:
@ -2317,12 +2318,12 @@ HTMLElement::AutocorrectionState HTMLElement::used_autocorrection_state() const
{ {
// The autocorrect attribute is an enumerated attribute with the following keywords and states: // The autocorrect attribute is an enumerated attribute with the following keywords and states:
// Keyword | State | Brief description // Keyword | State | Brief description
// on | on | The user agent is permitted to automatically correct spelling errors while the user // 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 // (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. // | | 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. // 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. // The attribute's invalid value default and missing value default are both the On state.
auto autocorrect_attribute_state = [](Optional<String> attribute) { auto autocorrect_attribute_state = [](Optional<String> attribute) {
if (attribute.has_value() && attribute.value().equals_ignoring_ascii_case("off"sv)) if (attribute.has_value() && attribute.value().equals_ignoring_ascii_case("off"sv))
@ -2332,7 +2333,8 @@ HTMLElement::AutocorrectionState HTMLElement::used_autocorrection_state() const
}; };
// To compute the used autocorrection state of an element element, run these steps: // 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. // 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<HTMLInputElement>(this)) { if (auto const* input_element = as_if<HTMLInputElement>(this)) {
if (first_is_one_of(input_element->type_state(), HTMLInputElement::TypeAttributeState::URL, HTMLInputElement::TypeAttributeState::Email, HTMLInputElement::TypeAttributeState::Password)) if (first_is_one_of(input_element->type_state(), HTMLInputElement::TypeAttributeState::URL, HTMLInputElement::TypeAttributeState::Email, HTMLInputElement::TypeAttributeState::Password))
return AutocorrectionState::Off; return AutocorrectionState::Off;
@ -2351,21 +2353,23 @@ HTMLElement::AutocorrectionState HTMLElement::used_autocorrection_state() const
return autocorrect_attribute_state(form_associated_element->form()->attribute(HTML::AttributeNames::autocorrect)); return autocorrect_attribute_state(form_associated_element->form()->attribute(HTML::AttributeNames::autocorrect));
} }
// 4. Return on. // 4. Return On.
return AutocorrectionState::On; return AutocorrectionState::On;
} }
// https://html.spec.whatwg.org/multipage/interaction.html#dom-autocorrect // https://html.spec.whatwg.org/multipage/interaction.html#dom-autocorrect
bool HTMLElement::autocorrect() const 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. // 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; return used_autocorrection_state() == AutocorrectionState::On;
} }
// https://html.spec.whatwg.org/multipage/interaction.html#dom-autocorrect // https://html.spec.whatwg.org/multipage/interaction.html#dom-autocorrect
void HTMLElement::set_autocorrect(bool given_value) 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". // 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) if (given_value)
set_attribute_value(HTML::AttributeNames::autocorrect, "on"_string); set_attribute_value(HTML::AttributeNames::autocorrect, "on"_string);
else else