Bläddra i källkod

LibWeb: Add support for reflected boolean values

Also throw in some missing reflected DOMString values
Luke 4 år sedan
förälder
incheckning
e2e6b03a45

+ 18 - 3
Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp

@@ -55,7 +55,7 @@ static String snake_name(const StringView& title_name)
 
 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;
         builder.append(input);
         builder.append('_');
@@ -755,9 +755,15 @@ JS_DEFINE_NATIVE_GETTER(@wrapper_class@::@attribute.getter_callback@)
         }
 
         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@);
 )~~~");
+            } else {
+                attribute_generator.append(R"~~~(
+    auto retval = impl->has_attribute(HTML::AttributeNames::@attribute.reflect_name@);
+)~~~");
+            }
         } else {
             attribute_generator.append(R"~~~(
     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);
 
             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);
 )~~~");
+                } 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 {
                 attribute_generator.append(R"~~~(
     impl->set_@attribute.name:snakecase@(cpp_value);

+ 1 - 0
Libraries/LibWeb/HTML/AttributeNames.cpp

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

+ 19 - 1
Libraries/LibWeb/HTML/AttributeNames.h

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

+ 3 - 0
Libraries/LibWeb/HTML/HTMLButtonElement.idl

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

+ 1 - 1
Libraries/LibWeb/HTML/HTMLDetailsElement.idl

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

+ 1 - 1
Libraries/LibWeb/HTML/HTMLDialogElement.idl

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

+ 2 - 0
Libraries/LibWeb/HTML/HTMLElement.idl

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

+ 1 - 0
Libraries/LibWeb/HTML/HTMLFormElement.idl

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

+ 1 - 0
Libraries/LibWeb/HTML/HTMLIFrameElement.idl

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

+ 1 - 0
Libraries/LibWeb/HTML/HTMLImageElement.idl

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

+ 9 - 0
Libraries/LibWeb/HTML/HTMLInputElement.idl

@@ -12,4 +12,13 @@ interface HTMLInputElement : HTMLElement {
     [Reflect=value] attribute DOMString defaultValue;
 
     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;
+
 }

+ 1 - 0
Libraries/LibWeb/HTML/HTMLLinkElement.idl

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

+ 5 - 0
Libraries/LibWeb/HTML/HTMLMediaElement.idl

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

+ 1 - 0
Libraries/LibWeb/HTML/HTMLOListElement.idl

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

+ 1 - 0
Libraries/LibWeb/HTML/HTMLOptGroupElement.idl

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

+ 2 - 1
Libraries/LibWeb/HTML/HTMLOptionElement.idl

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

+ 2 - 0
Libraries/LibWeb/HTML/HTMLScriptElement.idl

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

+ 3 - 1
Libraries/LibWeb/HTML/HTMLSelectElement.idl

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

+ 5 - 0
Libraries/LibWeb/HTML/HTMLTextAreaElement.idl

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

+ 1 - 0
Libraries/LibWeb/HTML/HTMLTrackElement.idl

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

+ 1 - 0
Libraries/LibWeb/HTML/HTMLVideoElement.idl

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