1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 18:15:09 +00:00

LibWeb: Use generated enum code for property value validation

This has the nice benefit of removing a lot of duplicated lists of
values from Properties.json. :^)
This commit is contained in:
Sam Atkins 2022-04-14 11:23:23 +01:00 committed by Andreas Kling
parent a797a92990
commit a20188cd91
2 changed files with 78 additions and 261 deletions

View file

@ -150,6 +150,7 @@ ErrorOr<void> generate_implementation_file(JsonObject& properties, Core::Stream:
generator.append(R"~~~( generator.append(R"~~~(
#include <AK/Assertions.h> #include <AK/Assertions.h>
#include <LibWeb/CSS/Enums.h>
#include <LibWeb/CSS/Parser/Parser.h> #include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/CSS/PropertyID.h> #include <LibWeb/CSS/PropertyID.h>
#include <LibWeb/CSS/StyleValue.h> #include <LibWeb/CSS/StyleValue.h>
@ -512,8 +513,13 @@ bool property_accepts_value(PropertyID property_id, StyleValue& style_value)
} else if (type_name == "url") { } else if (type_name == "url") {
// FIXME: Handle urls! // FIXME: Handle urls!
} else { } else {
warnln("Unrecognized valid-type name: '{}'", type_name); // Assume that any other type names are defined in Enums.json.
VERIFY_NOT_REACHED(); // If they're not, the output won't compile, but that's fine since it's invalid.
property_generator.set("type_name:snakecase", snake_casify(type_name));
property_generator.append(R"~~~(
if (auto converted_identifier = value_id_to_@type_name:snakecase@(style_value.to_identifier()); converted_identifier.has_value())
return true;
)~~~");
} }
} }
} }

View file

@ -2,12 +2,8 @@
"align-items": { "align-items": {
"inherited": false, "inherited": false,
"initial": "stretch", "initial": "stretch",
"valid-identifiers": [ "valid-types": [
"center", "align-items"
"baseline",
"flex-end",
"flex-start",
"stretch"
] ]
}, },
"background": { "background": {
@ -29,20 +25,16 @@
"affects-layout": false, "affects-layout": false,
"inherited": false, "inherited": false,
"initial": "scroll", "initial": "scroll",
"valid-identifiers": [ "valid-types": [
"fixed", "background-attachment"
"local",
"scroll"
] ]
}, },
"background-clip": { "background-clip": {
"affects-layout": false, "affects-layout": false,
"inherited": false, "inherited": false,
"initial": "border-box", "initial": "border-box",
"valid-identifiers": [ "valid-types": [
"border-box", "background-box"
"content-box",
"padding-box"
] ]
}, },
"background-color": { "background-color": {
@ -71,10 +63,8 @@
"affects-layout": false, "affects-layout": false,
"inherited": false, "inherited": false,
"initial": "padding-box", "initial": "padding-box",
"valid-identifiers": [ "valid-types": [
"border-box", "background-box"
"content-box",
"padding-box"
] ]
}, },
"background-position": { "background-position": {
@ -102,13 +92,12 @@
"inherited": false, "inherited": false,
"initial": "repeat", "initial": "repeat",
"max-values": 2, "max-values": 2,
"valid-types": [
"repeat"
],
"valid-identifiers": [ "valid-identifiers": [
"no-repeat",
"repeat",
"repeat-x", "repeat-x",
"repeat-y", "repeat-y"
"round",
"space"
] ]
}, },
"background-size": { "background-size": {
@ -206,17 +195,8 @@
"affects-layout": false, "affects-layout": false,
"initial": "none", "initial": "none",
"inherited": false, "inherited": false,
"valid-identifiers": [ "valid-types": [
"dashed", "line-style"
"dotted",
"double",
"groove",
"hidden",
"inset",
"none",
"outset",
"ridge",
"solid"
] ]
}, },
"border-bottom-width": { "border-bottom-width": {
@ -274,17 +254,8 @@
"affects-layout": false, "affects-layout": false,
"initial": "none", "initial": "none",
"inherited": false, "inherited": false,
"valid-identifiers": [ "valid-types": [
"dashed", "line-style"
"dotted",
"double",
"groove",
"hidden",
"inset",
"none",
"outset",
"ridge",
"solid"
] ]
}, },
"border-left-width": { "border-left-width": {
@ -328,17 +299,8 @@
"affects-layout": false, "affects-layout": false,
"initial": "none", "initial": "none",
"inherited": false, "inherited": false,
"valid-identifiers": [ "valid-types": [
"dashed", "line-style"
"dotted",
"double",
"groove",
"hidden",
"inset",
"none",
"outset",
"ridge",
"solid"
] ]
}, },
"border-right-width": { "border-right-width": {
@ -373,17 +335,8 @@
"border-left-style" "border-left-style"
], ],
"max-values": 4, "max-values": 4,
"valid-identifiers": [ "valid-types": [
"dashed", "line-style"
"dotted",
"double",
"groove",
"hidden",
"inset",
"none",
"outset",
"ridge",
"solid"
] ]
}, },
"border-top-color": { "border-top-color": {
@ -418,17 +371,8 @@
"affects-layout": false, "affects-layout": false,
"initial": "none", "initial": "none",
"inherited": false, "inherited": false,
"valid-identifiers": [ "valid-types": [
"dashed", "line-style"
"dotted",
"double",
"groove",
"hidden",
"inset",
"none",
"outset",
"ridge",
"solid"
] ]
}, },
"border-top-width": { "border-top-width": {
@ -492,9 +436,8 @@
"box-sizing": { "box-sizing": {
"inherited": false, "inherited": false,
"initial": "content-box", "initial": "content-box",
"valid-identifiers": [ "valid-types": [
"border-box", "box-sizing"
"content-box"
] ]
}, },
"caption-side": { "caption-side": {
@ -508,11 +451,8 @@
"clear": { "clear": {
"inherited": false, "inherited": false,
"initial": "none", "initial": "none",
"valid-identifiers": [ "valid-types": [
"both", "clear"
"left",
"none",
"right"
] ]
}, },
"clip": { "clip": {
@ -553,45 +493,8 @@
"inherited": true, "inherited": true,
"initial": "auto", "initial": "auto",
"valid-types": [ "valid-types": [
"url" "url",
], "cursor"
"valid-identifiers": [
"alias",
"all-scroll",
"auto",
"cell",
"col-resize",
"context-menu",
"copy",
"crosshair",
"default",
"e-resize",
"ew-resize",
"grab",
"grabbing",
"help",
"move",
"n-resize",
"ne-resize",
"nesw-resize",
"no-drop",
"none",
"not-allowed",
"ns-resize",
"nw-resize",
"nwse-resize",
"pointer",
"progress",
"row-resize",
"s-resize",
"se-resize",
"sw-resize",
"text",
"vertical-text",
"w-resize",
"wait",
"zoom-in",
"zoom-out"
] ]
}, },
"direction": { "direction": {
@ -660,11 +563,8 @@
"flex-direction": { "flex-direction": {
"inherited": false, "inherited": false,
"initial": "row", "initial": "row",
"valid-identifiers": [ "valid-types": [
"column", "flex-direction"
"column-reverse",
"row",
"row-reverse"
] ]
}, },
"flex-flow": { "flex-flow": {
@ -699,19 +599,15 @@
"flex-wrap": { "flex-wrap": {
"inherited": false, "inherited": false,
"initial": "nowrap", "initial": "nowrap",
"valid-identifiers": [ "valid-types": [
"nowrap", "flex-wrap"
"wrap",
"wrap-reverse"
] ]
}, },
"float": { "float": {
"inherited": false, "inherited": false,
"initial": "none", "initial": "none",
"valid-identifiers": [ "valid-types": [
"left", "float"
"none",
"right"
] ]
}, },
"font": { "font": {
@ -763,9 +659,8 @@
"font-variant": { "font-variant": {
"inherited": true, "inherited": true,
"initial": "normal", "initial": "normal",
"valid-identifiers": [ "valid-types": [
"normal", "font-variant"
"small-caps"
] ]
}, },
"font-weight": { "font-weight": {
@ -799,23 +694,15 @@
"affects-layout": false, "affects-layout": false,
"inherited": true, "inherited": true,
"initial": "auto", "initial": "auto",
"valid-identifiers": [ "valid-types": [
"auto", "image-rendering"
"crisp-edges",
"high-quality",
"pixelated",
"smooth"
] ]
}, },
"justify-content": { "justify-content": {
"inherited": false, "inherited": false,
"initial": "flex-start", "initial": "flex-start",
"valid-identifiers": [ "valid-types": [
"center", "justify-content"
"flex-end",
"flex-start",
"space-around",
"space-between"
] ]
}, },
"left": { "left": {
@ -889,21 +776,8 @@
"inherited": true, "inherited": true,
"initial": "disc", "initial": "disc",
"valid-types": [ "valid-types": [
"string" "string",
], "list-style-type"
"valid-identifiers": [
"circle",
"decimal",
"decimal-leading-zero",
"disc",
"lower-alpha",
"lower-latin",
"lower-roman",
"none",
"square",
"upper-alpha",
"upper-latin",
"upper-roman"
] ]
}, },
"margin": { "margin": {
@ -1077,17 +951,8 @@
"affects-layout": false, "affects-layout": false,
"inherited": false, "inherited": false,
"initial": "none", "initial": "none",
"valid-identifiers": [ "valid-types": [
"dashed", "line-style"
"dotted",
"double",
"groove",
"hidden",
"inset",
"none",
"outset",
"ridge",
"solid"
] ]
}, },
"outline-width": { "outline-width": {
@ -1111,34 +976,22 @@
"inherited": false, "inherited": false,
"initial": "visible", "initial": "visible",
"max-values": 2, "max-values": 2,
"valid-identifiers": [ "valid-types": [
"auto", "overflow"
"clip",
"hidden",
"scroll",
"visible"
] ]
}, },
"overflow-x": { "overflow-x": {
"inherited": false, "inherited": false,
"initial": "visible", "initial": "visible",
"valid-identifiers": [ "valid-types": [
"auto", "overflow"
"clip",
"hidden",
"scroll",
"visible"
] ]
}, },
"overflow-y": { "overflow-y": {
"inherited": false, "inherited": false,
"initial": "visible", "initial": "visible",
"valid-identifiers": [ "valid-types": [
"auto", "overflow"
"clip",
"hidden",
"scroll",
"visible"
] ]
}, },
"padding": { "padding": {
@ -1207,21 +1060,15 @@
"affects-layout": false, "affects-layout": false,
"inherited": true, "inherited": true,
"initial": "auto", "initial": "auto",
"valid-identifiers": [ "valid-types": [
"auto", "pointer-events"
"all",
"none"
] ]
}, },
"position": { "position": {
"inherited": false, "inherited": false,
"initial": "static", "initial": "static",
"valid-identifiers": [ "valid-types": [
"absolute", "position"
"fixed",
"relative",
"static",
"sticky"
] ]
}, },
"right": { "right": {
@ -1262,12 +1109,8 @@
"text-align": { "text-align": {
"inherited": true, "inherited": true,
"initial": "left", "initial": "left",
"valid-identifiers": [ "valid-types": [
"center", "text-align"
"justify",
"left",
"right",
"-libweb-center"
] ]
}, },
"text-decoration": { "text-decoration": {
@ -1294,24 +1137,16 @@
"affects-layout": false, "affects-layout": false,
"inherited": true, "inherited": true,
"initial": "none", "initial": "none",
"valid-identifiers": [ "valid-types": [
"blink", "text-decoration-line"
"line-through",
"none",
"overline",
"underline"
] ]
}, },
"text-decoration-style": { "text-decoration-style": {
"affects-layout": false, "affects-layout": false,
"inherited": false, "inherited": false,
"initial": "solid", "initial": "solid",
"valid-identifiers": [ "valid-types": [
"dashed", "text-decoration-style"
"dotted",
"double",
"solid",
"wavy"
] ]
}, },
"text-decoration-thickness": { "text-decoration-thickness": {
@ -1341,12 +1176,8 @@
"text-justify": { "text-justify": {
"inherited": true, "inherited": true,
"initial": "auto", "initial": "auto",
"valid-identifiers": [ "valid-types": [
"auto", "text-justify"
"none",
"inter-word",
"inter-character",
"distribute"
] ]
}, },
"text-shadow": { "text-shadow": {
@ -1360,13 +1191,8 @@
"text-transform": { "text-transform": {
"inherited": true, "inherited": true,
"initial": "none", "initial": "none",
"valid-identifiers": [ "valid-types": [
"capitalize", "text-transform"
"full-size-kana",
"full-width",
"lowercase",
"none",
"uppercase"
] ]
}, },
"top": { "top": {
@ -1421,17 +1247,8 @@
"initial": "baseline", "initial": "baseline",
"valid-types": [ "valid-types": [
"length", "length",
"percentage" "percentage",
], "vertical-align"
"valid-identifiers": [
"baseline",
"bottom",
"middle",
"sub",
"super",
"text-bottom",
"text-top",
"top"
], ],
"quirks": [ "quirks": [
"unitless-length" "unitless-length"
@ -1440,10 +1257,8 @@
"visibility": { "visibility": {
"inherited": true, "inherited": true,
"initial": "visible", "initial": "visible",
"valid-identifiers": [ "valid-types": [
"collapse", "visibility"
"hidden",
"visible"
] ]
}, },
"width": { "width": {
@ -1463,12 +1278,8 @@
"white-space": { "white-space": {
"inherited": true, "inherited": true,
"initial": "normal", "initial": "normal",
"valid-identifiers": [ "valid-types": [
"normal", "white-space"
"nowrap",
"pre",
"pre-line",
"pre-wrap"
] ]
}, },
"word-spacing": { "word-spacing": {