mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 21:47:43 +00:00
LibWeb: Stop generating now-unused property_accepts_value()
function
This commit is contained in:
parent
c0e61f92c0
commit
6b8f484114
1 changed files with 0 additions and 174 deletions
|
@ -135,7 +135,6 @@ enum class ValueType {
|
||||||
};
|
};
|
||||||
bool property_accepts_type(PropertyID, ValueType);
|
bool property_accepts_type(PropertyID, ValueType);
|
||||||
bool property_accepts_identifier(PropertyID, ValueID);
|
bool property_accepts_identifier(PropertyID, ValueID);
|
||||||
bool property_accepts_value(PropertyID, StyleValue&);
|
|
||||||
size_t property_maximum_value_count(PropertyID);
|
size_t property_maximum_value_count(PropertyID);
|
||||||
|
|
||||||
bool property_affects_layout(PropertyID);
|
bool property_affects_layout(PropertyID);
|
||||||
|
@ -555,179 +554,6 @@ bool property_accepts_identifier(PropertyID property_id, ValueID identifier)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool property_accepts_value(PropertyID property_id, StyleValue& style_value)
|
|
||||||
{
|
|
||||||
if (style_value.is_builtin())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
switch (property_id) {
|
|
||||||
)~~~");
|
|
||||||
|
|
||||||
properties.for_each_member([&](auto& name, auto& value) {
|
|
||||||
VERIFY(value.is_object());
|
|
||||||
auto& object = value.as_object();
|
|
||||||
bool has_valid_types = object.has("valid-types"sv);
|
|
||||||
auto has_valid_identifiers = object.has("valid-identifiers"sv);
|
|
||||||
if (has_valid_types || has_valid_identifiers) {
|
|
||||||
auto property_generator = generator.fork();
|
|
||||||
property_generator.set("name:titlecase", title_casify(name));
|
|
||||||
property_generator.append(R"~~~(
|
|
||||||
case PropertyID::@name:titlecase@: {
|
|
||||||
)~~~");
|
|
||||||
|
|
||||||
auto output_numeric_value_check = [](SourceGenerator& generator, StringView type_check_function, StringView value_getter, Span<StringView> resolved_type_names, StringView min_value, StringView max_value) {
|
|
||||||
auto test_generator = generator.fork();
|
|
||||||
test_generator.set("type_check_function", type_check_function);
|
|
||||||
test_generator.set("value_getter", value_getter);
|
|
||||||
test_generator.append(R"~~~(
|
|
||||||
if ((style_value.@type_check_function@())~~~");
|
|
||||||
if (!min_value.is_empty() && min_value != "-∞") {
|
|
||||||
test_generator.set("minvalue", min_value);
|
|
||||||
test_generator.append(" && (style_value.@value_getter@ >= @minvalue@)");
|
|
||||||
}
|
|
||||||
if (!max_value.is_empty() && max_value != "∞") {
|
|
||||||
test_generator.set("maxvalue", max_value);
|
|
||||||
test_generator.append(" && (style_value.@value_getter@ <= @maxvalue@)");
|
|
||||||
}
|
|
||||||
test_generator.append(")");
|
|
||||||
if (!resolved_type_names.is_empty()) {
|
|
||||||
test_generator.append(R"~~~(
|
|
||||||
|| (style_value.is_calculated() && ()~~~");
|
|
||||||
bool first = true;
|
|
||||||
for (auto& type_name : resolved_type_names) {
|
|
||||||
test_generator.set("resolved_type_name", type_name);
|
|
||||||
if (!first)
|
|
||||||
test_generator.append(" || ");
|
|
||||||
test_generator.append("style_value.as_calculated().resolved_type() == CalculatedStyleValue::ResolvedType::@resolved_type_name@");
|
|
||||||
first = false;
|
|
||||||
}
|
|
||||||
test_generator.append("))");
|
|
||||||
}
|
|
||||||
test_generator.append(R"~~~() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
)~~~");
|
|
||||||
};
|
|
||||||
|
|
||||||
if (has_valid_types) {
|
|
||||||
auto valid_types_value = object.get_array("valid-types"sv);
|
|
||||||
VERIFY(valid_types_value.has_value());
|
|
||||||
auto& valid_types = valid_types_value.value();
|
|
||||||
if (!valid_types.is_empty()) {
|
|
||||||
for (auto& type : valid_types.values()) {
|
|
||||||
VERIFY(type.is_string());
|
|
||||||
auto type_parts = type.as_string().split_view(' ');
|
|
||||||
auto type_name = type_parts.first();
|
|
||||||
auto type_args = type_parts.size() > 1 ? type_parts[1] : ""sv;
|
|
||||||
StringView min_value;
|
|
||||||
StringView max_value;
|
|
||||||
if (!type_args.is_empty()) {
|
|
||||||
VERIFY(type_args.starts_with('[') && type_args.ends_with(']'));
|
|
||||||
auto comma_index = type_args.find(',').value();
|
|
||||||
min_value = type_args.substring_view(1, comma_index - 1);
|
|
||||||
max_value = type_args.substring_view(comma_index + 1, type_args.length() - comma_index - 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type_name == "angle") {
|
|
||||||
output_numeric_value_check(property_generator, "is_angle"sv, "as_angle().angle().to_degrees()"sv, Array { "Angle"sv }, min_value, max_value);
|
|
||||||
} else if (type_name == "color") {
|
|
||||||
property_generator.append(R"~~~(
|
|
||||||
if (style_value.has_color())
|
|
||||||
return true;
|
|
||||||
)~~~");
|
|
||||||
} else if (type_name == "filter-value-list") {
|
|
||||||
property_generator.append(R"~~~(
|
|
||||||
if (style_value.is_filter_value_list())
|
|
||||||
return true;
|
|
||||||
)~~~");
|
|
||||||
} else if (type_name == "frequency") {
|
|
||||||
output_numeric_value_check(property_generator, "is_frequency"sv, "as_frequency().frequency().to_hertz()"sv, Array { "Frequency"sv }, min_value, max_value);
|
|
||||||
} else if (type_name == "image") {
|
|
||||||
property_generator.append(R"~~~(
|
|
||||||
if (style_value.is_abstract_image())
|
|
||||||
return true;
|
|
||||||
)~~~");
|
|
||||||
} else if (type_name == "integer") {
|
|
||||||
output_numeric_value_check(property_generator, "has_integer"sv, "to_integer()"sv, Array { "Integer"sv }, min_value, max_value);
|
|
||||||
} else if (type_name == "length") {
|
|
||||||
output_numeric_value_check(property_generator, "has_length"sv, "to_length().raw_value()"sv, Array { "Length"sv }, min_value, max_value);
|
|
||||||
} else if (type_name == "number") {
|
|
||||||
output_numeric_value_check(property_generator, "has_number"sv, "to_number()"sv, Array { "Integer"sv, "Number"sv }, min_value, max_value);
|
|
||||||
} else if (type_name == "percentage") {
|
|
||||||
output_numeric_value_check(property_generator, "is_percentage"sv, "as_percentage().percentage().value()"sv, Array { "Percentage"sv }, min_value, max_value);
|
|
||||||
} else if (type_name == "rect") {
|
|
||||||
property_generator.append(R"~~~(
|
|
||||||
if (style_value.has_rect())
|
|
||||||
return true;
|
|
||||||
)~~~");
|
|
||||||
} else if (type_name == "resolution") {
|
|
||||||
output_numeric_value_check(property_generator, "is_resolution"sv, "as_resolution().resolution().to_dots_per_pixel()"sv, Array<StringView, 0> {}, min_value, max_value);
|
|
||||||
} else if (type_name == "string") {
|
|
||||||
property_generator.append(R"~~~(
|
|
||||||
if (style_value.is_string())
|
|
||||||
return true;
|
|
||||||
)~~~");
|
|
||||||
} else if (type_name == "time") {
|
|
||||||
output_numeric_value_check(property_generator, "is_time"sv, "as_time().time().to_seconds()"sv, Array { "Time"sv }, min_value, max_value);
|
|
||||||
} else if (type_name == "url") {
|
|
||||||
// FIXME: Handle urls!
|
|
||||||
} else if (type_name == "paint") {
|
|
||||||
// https://svgwg.org/svg2-draft/painting.html#SpecifyingPaint
|
|
||||||
property_generator.append(R"~~~(
|
|
||||||
if (style_value.has_color() || style_value.is_url())
|
|
||||||
return true;
|
|
||||||
)~~~");
|
|
||||||
} else {
|
|
||||||
// Assume that any other type names are defined in Enums.json.
|
|
||||||
// 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;
|
|
||||||
)~~~");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (has_valid_identifiers) {
|
|
||||||
auto valid_identifiers_value = object.get_array("valid-identifiers"sv);
|
|
||||||
VERIFY(valid_identifiers_value.has_value());
|
|
||||||
auto& valid_identifiers = valid_identifiers_value.value();
|
|
||||||
if (!valid_identifiers.is_empty()) {
|
|
||||||
property_generator.append(R"~~~(
|
|
||||||
switch (style_value.to_identifier()) {
|
|
||||||
)~~~");
|
|
||||||
for (auto& identifier : valid_identifiers.values()) {
|
|
||||||
VERIFY(identifier.is_string());
|
|
||||||
auto identifier_generator = generator.fork();
|
|
||||||
identifier_generator.set("identifier:titlecase", title_casify(identifier.as_string()));
|
|
||||||
identifier_generator.append(R"~~~(
|
|
||||||
case ValueID::@identifier:titlecase@:
|
|
||||||
)~~~");
|
|
||||||
}
|
|
||||||
property_generator.append(R"~~~(
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
)~~~");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
generator.append(R"~~~(
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
)~~~");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
generator.append(R"~~~(
|
|
||||||
default:
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t property_maximum_value_count(PropertyID property_id)
|
size_t property_maximum_value_count(PropertyID property_id)
|
||||||
{
|
{
|
||||||
switch (property_id) {
|
switch (property_id) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue