LibWeb: Add support for reflected boolean values

Also throw in some missing reflected DOMString values
This commit is contained in:
Luke 2020-11-09 08:15:10 +00:00 committed by Andreas Kling
parent e7173e946f
commit e2e6b03a45
Notes: sideshowbarker 2024-07-19 01:29:26 +09:00
21 changed files with 79 additions and 8 deletions

View File

@ -55,7 +55,7 @@ static String snake_name(const StringView& title_name)
static String make_input_acceptable_cpp(const String& input) static String make_input_acceptable_cpp(const String& input)
{ {
if (input == "class" || input == "template" || input == "for") { if (input == "class" || input == "template" || input == "for" || input == "default") {
StringBuilder builder; StringBuilder builder;
builder.append(input); builder.append(input);
builder.append('_'); builder.append('_');
@ -755,9 +755,15 @@ JS_DEFINE_NATIVE_GETTER(@wrapper_class@::@attribute.getter_callback@)
} }
if (attribute.extended_attributes.contains("Reflect")) { if (attribute.extended_attributes.contains("Reflect")) {
attribute_generator.append(R"~~~( if (attribute.type.name != "boolean") {
attribute_generator.append(R"~~~(
auto retval = impl->attribute(HTML::AttributeNames::@attribute.reflect_name@); auto retval = impl->attribute(HTML::AttributeNames::@attribute.reflect_name@);
)~~~"); )~~~");
} else {
attribute_generator.append(R"~~~(
auto retval = impl->has_attribute(HTML::AttributeNames::@attribute.reflect_name@);
)~~~");
}
} else { } else {
attribute_generator.append(R"~~~( attribute_generator.append(R"~~~(
auto retval = impl->@attribute.name:snakecase@(); auto retval = impl->@attribute.name:snakecase@();
@ -782,9 +788,18 @@ JS_DEFINE_NATIVE_SETTER(@wrapper_class@::@attribute.setter_callback@)
generate_to_cpp(attribute, "value", "", "cpp_value", true); generate_to_cpp(attribute, "value", "", "cpp_value", true);
if (attribute.extended_attributes.contains("Reflect")) { if (attribute.extended_attributes.contains("Reflect")) {
attribute_generator.append(R"~~~( if (attribute.type.name != "boolean") {
attribute_generator.append(R"~~~(
impl->set_attribute(HTML::AttributeNames::@attribute.reflect_name@, cpp_value); impl->set_attribute(HTML::AttributeNames::@attribute.reflect_name@, cpp_value);
)~~~"); )~~~");
} else {
attribute_generator.append(R"~~~(
if (!cpp_value)
impl->remove_attribute(HTML::AttributeNames::@attribute.reflect_name@);
else
impl->set_attribute(HTML::AttributeNames::@attribute.reflect_name@, String::empty());
)~~~");
}
} else { } else {
attribute_generator.append(R"~~~( attribute_generator.append(R"~~~(
impl->set_@attribute.name:snakecase@(cpp_value); impl->set_@attribute.name:snakecase@(cpp_value);

View File

@ -51,6 +51,7 @@ ENUMERATE_HTML_ATTRIBUTES
// NOTE: Special case for the class and for attributes since they're C++ keywords. // NOTE: Special case for the class and for attributes since they're C++ keywords.
class_ = "class"; class_ = "class";
for_ = "for"; for_ = "for";
default_ = "default";
// NOTE: Special cases for attributes with dashes in them. // NOTE: Special cases for attributes with dashes in them.
accept_charset = "accept-charset"; accept_charset = "accept-charset";

View File

@ -39,8 +39,10 @@ namespace AttributeNames {
__ENUMERATE_HTML_ATTRIBUTE(action) \ __ENUMERATE_HTML_ATTRIBUTE(action) \
__ENUMERATE_HTML_ATTRIBUTE(align) \ __ENUMERATE_HTML_ATTRIBUTE(align) \
__ENUMERATE_HTML_ATTRIBUTE(allow) \ __ENUMERATE_HTML_ATTRIBUTE(allow) \
__ENUMERATE_HTML_ATTRIBUTE(allowfullscreen) \
__ENUMERATE_HTML_ATTRIBUTE(alt) \ __ENUMERATE_HTML_ATTRIBUTE(alt) \
__ENUMERATE_HTML_ATTRIBUTE(async) \ __ENUMERATE_HTML_ATTRIBUTE(async) \
__ENUMERATE_HTML_ATTRIBUTE(autoplay) \
__ENUMERATE_HTML_ATTRIBUTE(behaviour) \ __ENUMERATE_HTML_ATTRIBUTE(behaviour) \
__ENUMERATE_HTML_ATTRIBUTE(bgcolor) \ __ENUMERATE_HTML_ATTRIBUTE(bgcolor) \
__ENUMERATE_HTML_ATTRIBUTE(checked) \ __ENUMERATE_HTML_ATTRIBUTE(checked) \
@ -51,18 +53,23 @@ namespace AttributeNames {
__ENUMERATE_HTML_ATTRIBUTE(colspan) \ __ENUMERATE_HTML_ATTRIBUTE(colspan) \
__ENUMERATE_HTML_ATTRIBUTE(content) \ __ENUMERATE_HTML_ATTRIBUTE(content) \
__ENUMERATE_HTML_ATTRIBUTE(contenteditable) \ __ENUMERATE_HTML_ATTRIBUTE(contenteditable) \
__ENUMERATE_HTML_ATTRIBUTE(controls) \
__ENUMERATE_HTML_ATTRIBUTE(data) \ __ENUMERATE_HTML_ATTRIBUTE(data) \
__ENUMERATE_HTML_ATTRIBUTE(datetime) \ __ENUMERATE_HTML_ATTRIBUTE(datetime) \
__ENUMERATE_HTML_ATTRIBUTE(default_) \
__ENUMERATE_HTML_ATTRIBUTE(defer) \
__ENUMERATE_HTML_ATTRIBUTE(disabled) \ __ENUMERATE_HTML_ATTRIBUTE(disabled) \
__ENUMERATE_HTML_ATTRIBUTE(download) \ __ENUMERATE_HTML_ATTRIBUTE(download) \
__ENUMERATE_HTML_ATTRIBUTE(defer) \
__ENUMERATE_HTML_ATTRIBUTE(direction) \ __ENUMERATE_HTML_ATTRIBUTE(direction) \
__ENUMERATE_HTML_ATTRIBUTE(dirname) \ __ENUMERATE_HTML_ATTRIBUTE(dirname) \
__ENUMERATE_HTML_ATTRIBUTE(face) \ __ENUMERATE_HTML_ATTRIBUTE(face) \
__ENUMERATE_HTML_ATTRIBUTE(for_) \ __ENUMERATE_HTML_ATTRIBUTE(for_) \
__ENUMERATE_HTML_ATTRIBUTE(formnovalidate) \
__ENUMERATE_HTML_ATTRIBUTE(formtarget) \
__ENUMERATE_HTML_ATTRIBUTE(frameborder) \ __ENUMERATE_HTML_ATTRIBUTE(frameborder) \
__ENUMERATE_HTML_ATTRIBUTE(headers) \ __ENUMERATE_HTML_ATTRIBUTE(headers) \
__ENUMERATE_HTML_ATTRIBUTE(height) \ __ENUMERATE_HTML_ATTRIBUTE(height) \
__ENUMERATE_HTML_ATTRIBUTE(hidden) \
__ENUMERATE_HTML_ATTRIBUTE(href) \ __ENUMERATE_HTML_ATTRIBUTE(href) \
__ENUMERATE_HTML_ATTRIBUTE(hreflang) \ __ENUMERATE_HTML_ATTRIBUTE(hreflang) \
__ENUMERATE_HTML_ATTRIBUTE(http_equiv) \ __ENUMERATE_HTML_ATTRIBUTE(http_equiv) \
@ -70,21 +77,32 @@ namespace AttributeNames {
__ENUMERATE_HTML_ATTRIBUTE(imagesizes) \ __ENUMERATE_HTML_ATTRIBUTE(imagesizes) \
__ENUMERATE_HTML_ATTRIBUTE(imagesrcset) \ __ENUMERATE_HTML_ATTRIBUTE(imagesrcset) \
__ENUMERATE_HTML_ATTRIBUTE(integrity) \ __ENUMERATE_HTML_ATTRIBUTE(integrity) \
__ENUMERATE_HTML_ATTRIBUTE(ismap) \
__ENUMERATE_HTML_ATTRIBUTE(label) \ __ENUMERATE_HTML_ATTRIBUTE(label) \
__ENUMERATE_HTML_ATTRIBUTE(lang) \ __ENUMERATE_HTML_ATTRIBUTE(lang) \
__ENUMERATE_HTML_ATTRIBUTE(longdesc) \ __ENUMERATE_HTML_ATTRIBUTE(longdesc) \
__ENUMERATE_HTML_ATTRIBUTE(loop) \
__ENUMERATE_HTML_ATTRIBUTE(max) \ __ENUMERATE_HTML_ATTRIBUTE(max) \
__ENUMERATE_HTML_ATTRIBUTE(media) \ __ENUMERATE_HTML_ATTRIBUTE(media) \
__ENUMERATE_HTML_ATTRIBUTE(method) \ __ENUMERATE_HTML_ATTRIBUTE(method) \
__ENUMERATE_HTML_ATTRIBUTE(min) \ __ENUMERATE_HTML_ATTRIBUTE(min) \
__ENUMERATE_HTML_ATTRIBUTE(multiple) \
__ENUMERATE_HTML_ATTRIBUTE(name) \ __ENUMERATE_HTML_ATTRIBUTE(name) \
__ENUMERATE_HTML_ATTRIBUTE(nomodule) \
__ENUMERATE_HTML_ATTRIBUTE(novalidate) \
__ENUMERATE_HTML_ATTRIBUTE(open) \
__ENUMERATE_HTML_ATTRIBUTE(pattern) \ __ENUMERATE_HTML_ATTRIBUTE(pattern) \
__ENUMERATE_HTML_ATTRIBUTE(ping) \ __ENUMERATE_HTML_ATTRIBUTE(ping) \
__ENUMERATE_HTML_ATTRIBUTE(placeholder) \ __ENUMERATE_HTML_ATTRIBUTE(placeholder) \
__ENUMERATE_HTML_ATTRIBUTE(playsinline) \
__ENUMERATE_HTML_ATTRIBUTE(poster) \ __ENUMERATE_HTML_ATTRIBUTE(poster) \
__ENUMERATE_HTML_ATTRIBUTE(readonly) \
__ENUMERATE_HTML_ATTRIBUTE(rel) \ __ENUMERATE_HTML_ATTRIBUTE(rel) \
__ENUMERATE_HTML_ATTRIBUTE(required) \
__ENUMERATE_HTML_ATTRIBUTE(reversed) \
__ENUMERATE_HTML_ATTRIBUTE(rows) \ __ENUMERATE_HTML_ATTRIBUTE(rows) \
__ENUMERATE_HTML_ATTRIBUTE(scrolling) \ __ENUMERATE_HTML_ATTRIBUTE(scrolling) \
__ENUMERATE_HTML_ATTRIBUTE(selected) \
__ENUMERATE_HTML_ATTRIBUTE(size) \ __ENUMERATE_HTML_ATTRIBUTE(size) \
__ENUMERATE_HTML_ATTRIBUTE(sizes) \ __ENUMERATE_HTML_ATTRIBUTE(sizes) \
__ENUMERATE_HTML_ATTRIBUTE(src) \ __ENUMERATE_HTML_ATTRIBUTE(src) \

View File

@ -1,5 +1,8 @@
interface HTMLButtonElement : HTMLElement { interface HTMLButtonElement : HTMLElement {
[Reflect=formnovalidate] attribute boolean formNoValidate;
[Reflect=formtarget] attribute DOMString formTarget;
[Reflect] attribute DOMString name;
[Reflect] attribute DOMString value; [Reflect] attribute DOMString value;
} }

View File

@ -1,5 +1,5 @@
interface HTMLDetailsElement : HTMLElement { interface HTMLDetailsElement : HTMLElement {
[Reflect] attribute boolean open;
} }

View File

@ -1,5 +1,5 @@
interface HTMLDialogElement : HTMLElement { interface HTMLDialogElement : HTMLElement {
[Reflect] attribute boolean open;
} }

View File

@ -3,6 +3,8 @@ interface HTMLElement : Element {
[Reflect] attribute DOMString title; [Reflect] attribute DOMString title;
[Reflect] attribute DOMString lang; [Reflect] attribute DOMString lang;
[Reflect] attribute boolean hidden;
attribute DOMString contentEditable; attribute DOMString contentEditable;
} }

View File

@ -3,5 +3,6 @@ interface HTMLFormElement : HTMLElement {
[Reflect] attribute DOMString name; [Reflect] attribute DOMString name;
[Reflect] attribute DOMString rel; [Reflect] attribute DOMString rel;
[Reflect=accept-charset] attribute DOMString acceptCharset; [Reflect=accept-charset] attribute DOMString acceptCharset;
[Reflect=novalidate] attribute boolean noValidate;
} }

View File

@ -6,6 +6,7 @@ interface HTMLIFrameElement : HTMLElement {
[Reflect] attribute DOMString allow; [Reflect] attribute DOMString allow;
[Reflect] attribute DOMString width; [Reflect] attribute DOMString width;
[Reflect] attribute DOMString height; [Reflect] attribute DOMString height;
[Reflect=allowfullscreen] attribute boolean allowFullscreen;
[ReturnNullIfCrossOrigin] readonly attribute Document? contentDocument; [ReturnNullIfCrossOrigin] readonly attribute Document? contentDocument;
} }

View File

@ -5,5 +5,6 @@ interface HTMLImageElement : HTMLElement {
[Reflect] attribute DOMString srcset; [Reflect] attribute DOMString srcset;
[Reflect] attribute DOMString sizes; [Reflect] attribute DOMString sizes;
[Reflect=usemap] attribute DOMString useMap; [Reflect=usemap] attribute DOMString useMap;
[Reflect=ismap] attribute boolean isMap;
} }

View File

@ -12,4 +12,13 @@ interface HTMLInputElement : HTMLElement {
[Reflect=value] attribute DOMString defaultValue; [Reflect=value] attribute DOMString defaultValue;
attribute boolean checked; attribute boolean checked;
[Reflect] attribute boolean disabled;
[Reflect=checked] attribute boolean defaultChecked;
[Reflect=formnovalidate] attribute boolean formNoValidate;
[Reflect=formtarget] attribute DOMString formTarget;
[Reflect] attribute boolean multiple;
[Reflect=readonly] attribute boolean readOnly;
[Reflect] attribute boolean required;
} }

View File

@ -8,5 +8,6 @@ interface HTMLLinkElement : HTMLElement {
[Reflect] attribute DOMString type; [Reflect] attribute DOMString type;
[Reflect=imagesrcset] attribute DOMString imageSrcset; [Reflect=imagesrcset] attribute DOMString imageSrcset;
[Reflect=imagesizes] attribute DOMString imageSizes; [Reflect=imagesizes] attribute DOMString imageSizes;
[Reflect] attribute boolean disabled;
} }

View File

@ -2,4 +2,9 @@ interface HTMLMediaElement : HTMLElement {
[Reflect] attribute DOMString src; [Reflect] attribute DOMString src;
[Reflect] attribute boolean autoplay;
[Reflect] attribute boolean loop;
[Reflect] attribute boolean controls;
} }

View File

@ -1,5 +1,6 @@
interface HTMLOListElement : HTMLElement { interface HTMLOListElement : HTMLElement {
[Reflect] attribute boolean reversed;
[Reflect] attribute DOMString type; [Reflect] attribute DOMString type;
} }

View File

@ -1,5 +1,6 @@
interface HTMLOptGroupElement : HTMLElement { interface HTMLOptGroupElement : HTMLElement {
[Reflect] attribute boolean disabled;
[Reflect] attribute DOMString label; [Reflect] attribute DOMString label;
} }

View File

@ -1,5 +1,6 @@
interface HTMLOptionElement : HTMLElement { interface HTMLOptionElement : HTMLElement {
[Reflect] attribute boolean disabled;
[Reflect=selected] attribute boolean defaultSelected;
} }

View File

@ -2,6 +2,8 @@ interface HTMLScriptElement : HTMLElement {
[Reflect] attribute DOMString src; [Reflect] attribute DOMString src;
[Reflect] attribute DOMString type; [Reflect] attribute DOMString type;
[Reflect=nomodule] attribute boolean noModule;
[Reflect] attribute boolean defer;
[Reflect] attribute DOMString integrity; [Reflect] attribute DOMString integrity;
} }

View File

@ -1,5 +1,7 @@
interface HTMLSelectElement : HTMLElement { interface HTMLSelectElement : HTMLElement {
[Reflect] attribute boolean disabled;
[Reflect] attribute boolean multiple;
[Reflect] attribute boolean required;
} }

View File

@ -1,7 +1,12 @@
interface HTMLTextAreaElement : HTMLElement { interface HTMLTextAreaElement : HTMLElement {
[Reflect] attribute DOMString placeholder; [Reflect] attribute DOMString placeholder;
[Reflect] attribute DOMString name;
[Reflect] attribute DOMString wrap; [Reflect] attribute DOMString wrap;
readonly attribute DOMString type; readonly attribute DOMString type;
[Reflect] attribute boolean disabled;
[Reflect=readonly] attribute boolean readOnly;
[Reflect] attribute boolean required;
} }

View File

@ -3,5 +3,6 @@ interface HTMLTrackElement : HTMLElement {
[Reflect] attribute DOMString src; [Reflect] attribute DOMString src;
[Reflect] attribute DOMString srclang; [Reflect] attribute DOMString srclang;
[Reflect] attribute DOMString label; [Reflect] attribute DOMString label;
[Reflect] attribute boolean default;
} }

View File

@ -1,5 +1,6 @@
interface HTMLVideoElement : HTMLMediaElement { interface HTMLVideoElement : HTMLMediaElement {
[Reflect] attribute DOMString poster; [Reflect] attribute DOMString poster;
[Reflect=playsinline] attribute boolean playsInline;
} }