mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:47:35 +00:00
LibWeb: Generate CSS::property_has_quirk() function
This lets you query if a given Quirk applies to a given PropertyID. Currently this applies only to the "Hashless hex color" and "Unitless length" quirks.
This commit is contained in:
parent
9c873fc4dc
commit
af58bddfc8
2 changed files with 59 additions and 5 deletions
|
@ -40,6 +40,8 @@ int main(int argc, char** argv)
|
||||||
VERIFY(json.has_value());
|
VERIFY(json.has_value());
|
||||||
VERIFY(json.value().is_object());
|
VERIFY(json.value().is_object());
|
||||||
|
|
||||||
|
auto& properties = json.value().as_object();
|
||||||
|
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
SourceGenerator generator { builder };
|
SourceGenerator generator { builder };
|
||||||
|
|
||||||
|
@ -55,7 +57,7 @@ PropertyID property_id_from_string(const StringView& string)
|
||||||
{
|
{
|
||||||
)~~~");
|
)~~~");
|
||||||
|
|
||||||
json.value().as_object().for_each_member([&](auto& name, auto& value) {
|
properties.for_each_member([&](auto& name, auto& value) {
|
||||||
VERIFY(value.is_object());
|
VERIFY(value.is_object());
|
||||||
|
|
||||||
auto member_generator = generator.fork();
|
auto member_generator = generator.fork();
|
||||||
|
@ -75,7 +77,7 @@ const char* string_from_property_id(PropertyID property_id) {
|
||||||
switch (property_id) {
|
switch (property_id) {
|
||||||
)~~~");
|
)~~~");
|
||||||
|
|
||||||
json.value().as_object().for_each_member([&](auto& name, auto& value) {
|
properties.for_each_member([&](auto& name, auto& value) {
|
||||||
VERIFY(value.is_object());
|
VERIFY(value.is_object());
|
||||||
|
|
||||||
auto member_generator = generator.fork();
|
auto member_generator = generator.fork();
|
||||||
|
@ -98,7 +100,7 @@ bool is_inherited_property(PropertyID property_id)
|
||||||
switch (property_id) {
|
switch (property_id) {
|
||||||
)~~~");
|
)~~~");
|
||||||
|
|
||||||
json.value().as_object().for_each_member([&](auto& name, auto& value) {
|
properties.for_each_member([&](auto& name, auto& value) {
|
||||||
VERIFY(value.is_object());
|
VERIFY(value.is_object());
|
||||||
|
|
||||||
bool inherited = false;
|
bool inherited = false;
|
||||||
|
@ -129,7 +131,7 @@ bool is_pseudo_property(PropertyID property_id)
|
||||||
switch (property_id) {
|
switch (property_id) {
|
||||||
)~~~");
|
)~~~");
|
||||||
|
|
||||||
json.value().as_object().for_each_member([&](auto& name, auto& value) {
|
properties.for_each_member([&](auto& name, auto& value) {
|
||||||
VERIFY(value.is_object());
|
VERIFY(value.is_object());
|
||||||
|
|
||||||
bool pseudo = false;
|
bool pseudo = false;
|
||||||
|
@ -162,7 +164,7 @@ RefPtr<StyleValue> property_initial_value(PropertyID property_id)
|
||||||
ParsingContext parsing_context;
|
ParsingContext parsing_context;
|
||||||
)~~~");
|
)~~~");
|
||||||
|
|
||||||
json.value().as_object().for_each_member([&](auto& name, auto& value) {
|
properties.for_each_member([&](auto& name, auto& value) {
|
||||||
VERIFY(value.is_object());
|
VERIFY(value.is_object());
|
||||||
|
|
||||||
if (value.as_object().has("initial")) {
|
if (value.as_object().has("initial")) {
|
||||||
|
@ -185,6 +187,50 @@ RefPtr<StyleValue> property_initial_value(PropertyID property_id)
|
||||||
return initial_values.get(property_id).value_or(nullptr);
|
return initial_values.get(property_id).value_or(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool property_has_quirk(PropertyID property_id, Quirk quirk)
|
||||||
|
{
|
||||||
|
switch (property_id) {
|
||||||
|
)~~~");
|
||||||
|
|
||||||
|
properties.for_each_member([&](auto& name, auto& value) {
|
||||||
|
VERIFY(value.is_object());
|
||||||
|
if (value.as_object().has("quirks")) {
|
||||||
|
auto& quirks_value = value.as_object().get("quirks");
|
||||||
|
VERIFY(quirks_value.is_array());
|
||||||
|
auto& quirks = quirks_value.as_array();
|
||||||
|
|
||||||
|
if (!quirks.is_empty()) {
|
||||||
|
auto property_generator = generator.fork();
|
||||||
|
property_generator.set("name:titlecase", title_casify(name));
|
||||||
|
property_generator.append(R"~~~(
|
||||||
|
case PropertyID::@name:titlecase@: {
|
||||||
|
switch (quirk) {
|
||||||
|
)~~~");
|
||||||
|
for (auto& quirk : quirks.values()) {
|
||||||
|
VERIFY(quirk.is_string());
|
||||||
|
auto quirk_generator = property_generator.fork();
|
||||||
|
quirk_generator.set("quirk:titlecase", title_casify(quirk.as_string()));
|
||||||
|
quirk_generator.append(R"~~~(
|
||||||
|
case Quirk::@quirk:titlecase@:
|
||||||
|
return true;
|
||||||
|
)~~~");
|
||||||
|
}
|
||||||
|
property_generator.append(R"~~~(
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)~~~");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
generator.append(R"~~~(
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Web::CSS
|
} // namespace Web::CSS
|
||||||
|
|
||||||
)~~~");
|
)~~~");
|
||||||
|
|
|
@ -76,6 +76,14 @@ bool is_inherited_property(PropertyID);
|
||||||
bool is_pseudo_property(PropertyID);
|
bool is_pseudo_property(PropertyID);
|
||||||
RefPtr<StyleValue> property_initial_value(PropertyID);
|
RefPtr<StyleValue> property_initial_value(PropertyID);
|
||||||
|
|
||||||
|
enum class Quirk {
|
||||||
|
// https://quirks.spec.whatwg.org/#the-hashless-hex-color-quirk
|
||||||
|
HashlessHexColor,
|
||||||
|
// https://quirks.spec.whatwg.org/#the-unitless-length-quirk
|
||||||
|
UnitlessLength,
|
||||||
|
};
|
||||||
|
bool property_has_quirk(PropertyID, Quirk);
|
||||||
|
|
||||||
} // namespace Web::CSS
|
} // namespace Web::CSS
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue