LibWeb: Implement the translate attribute

This commit is contained in:
Callum Law 2025-05-23 22:36:33 +12:00 committed by Jelle Raaijmakers
commit 279913a223
Notes: github-actions[bot] 2025-05-23 12:35:07 +00:00
24 changed files with 399 additions and 1 deletions

View file

@ -299,6 +299,7 @@ namespace AttributeNames {
__ENUMERATE_HTML_ATTRIBUTE(text, "text") \
__ENUMERATE_HTML_ATTRIBUTE(title, "title") \
__ENUMERATE_HTML_ATTRIBUTE(topmargin, "topmargin") \
__ENUMERATE_HTML_ATTRIBUTE(translate, "translate") \
__ENUMERATE_HTML_ATTRIBUTE(truespeed, "truespeed") \
__ENUMERATE_HTML_ATTRIBUTE(type, "type") \
__ENUMERATE_HTML_ATTRIBUTE(usemap, "usemap") \

View file

@ -104,6 +104,25 @@ bool HTMLElement::is_potentially_render_blocking()
return is_implicitly_potentially_render_blocking();
}
// https://html.spec.whatwg.org/multipage/dom.html#dom-translate
bool HTMLElement::translate() const
{
// The translate IDL attribute must, on getting, return true if the element's translation mode is
// translate-enabled, and false otherwise
return translation_mode() == TranslationMode::TranslateEnabled;
}
// https://html.spec.whatwg.org/multipage/dom.html#dom-translate
void HTMLElement::set_translate(bool new_value)
{
// On setting, it must set the content attribute's value to "yes" if the new value is true, and set the content
// attribute's value to "no" otherwise.
if (new_value)
MUST(set_attribute(HTML::AttributeNames::translate, "yes"_string));
else
MUST(set_attribute(HTML::AttributeNames::translate, "no"_string));
}
// https://html.spec.whatwg.org/multipage/dom.html#dom-dir
StringView HTMLElement::dir() const
{

View file

@ -82,6 +82,9 @@ public:
Optional<String> title() const { return attribute(HTML::AttributeNames::title); }
bool translate() const;
void set_translate(bool);
StringView dir() const;
void set_dir(String const&);

View file

@ -14,7 +14,7 @@ interface HTMLElement : Element {
// metadata attributes
[Reflect, CEReactions] attribute DOMString title;
[Reflect, CEReactions] attribute DOMString lang;
[FIXME, CEReactions] attribute boolean translate;
[CEReactions] attribute boolean translate;
[CEReactions] attribute DOMString dir;
// user interaction