LibWeb: Implement writingSuggestions attribute

This commit is contained in:
Callum Law 2025-05-26 13:43:11 +12:00 committed by Luke Wilde
parent 87e0523664
commit e539990c7f
Notes: github-actions[bot] 2025-08-29 14:48:45 +00:00
6 changed files with 727 additions and 1 deletions

View file

@ -314,7 +314,8 @@ namespace AttributeNames {
__ENUMERATE_HTML_ATTRIBUTE(vspace, "vspace") \
__ENUMERATE_HTML_ATTRIBUTE(width, "width") \
__ENUMERATE_HTML_ATTRIBUTE(willvalidate, "willvalidate") \
__ENUMERATE_HTML_ATTRIBUTE(wrap, "wrap")
__ENUMERATE_HTML_ATTRIBUTE(wrap, "wrap") \
__ENUMERATE_HTML_ATTRIBUTE(writingsuggestions, "writingsuggestions")
#define __ENUMERATE_HTML_ATTRIBUTE(name, attribute) extern WEB_API FlyString name;
ENUMERATE_HTML_ATTRIBUTES

View file

@ -2195,4 +2195,41 @@ void HTMLElement::set_spellcheck(bool spellcheck)
MUST(set_attribute(HTML::AttributeNames::spellcheck, "false"_string));
}
// https://html.spec.whatwg.org/multipage/interaction.html#dom-writingsuggestions
String HTMLElement::writing_suggestions() const
{
// The writingsuggestions content attribute is an enumerated attribute with the following keywords and states:
// Keyword | State | Brief description
// true | True | Writing suggestions should be offered on this element.
// (the empty string) | |
// false | False | Writing suggestions should not be offered on this element.
// The attribute's missing value default is the Default state. The default state indicates that the element is to
// act according to a default behavior, possibly based on the parent element's own writingsuggestions state, as
// defined below.
// The attribute's invalid value default is the True state.
// 1. If element's writingsuggestions content attribute is in the False state, return "false".
auto maybe_writing_suggestions_attribute = attribute(HTML::AttributeNames::writingsuggestions);
if (maybe_writing_suggestions_attribute.has_value() && maybe_writing_suggestions_attribute.value().equals_ignoring_ascii_case("false"sv))
return "false"_string;
// 2. If element's writingsuggestions content attribute is in the Default state, element has a parent element, and the computed writing suggestions value of element's parent element is "false", then return "false".
if (!maybe_writing_suggestions_attribute.has_value() && first_ancestor_of_type<HTMLElement>() && first_ancestor_of_type<HTMLElement>()->writing_suggestions() == "false"sv) {
return "false"_string;
}
// 3. Return "true".
return "true"_string;
}
// https://html.spec.whatwg.org/multipage/interaction.html#dom-writingsuggestions
void HTMLElement::set_writing_suggestions(String const& given_value)
{
// 1. Set this's writingsuggestions content attribute to the given value.
MUST(set_attribute(HTML::AttributeNames::writingsuggestions, given_value));
}
}

View file

@ -120,6 +120,9 @@ public:
bool spellcheck() const;
void set_spellcheck(bool);
String writing_suggestions() const;
void set_writing_suggestions(String const&);
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

View file

@ -25,6 +25,7 @@ interface HTMLElement : Element {
readonly attribute DOMString accessKeyLabel;
[CEReactions] attribute boolean draggable;
[CEReactions] attribute boolean spellcheck;
[CEReactions] attribute DOMString writingSuggestions;
[FIXME, CEReactions] attribute DOMString autocapitalize;
[FIXME, CEReactions] attribute boolean autocorrect;