mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:17:34 +00:00
LibWeb: Clarify StyleValue API with new naming scheme
This does a few things, that are hard to separate. For a while now, it's been confuzing what `StyleValue::is_foo()` actually means. It sometimes was used to check the type, and sometimes to see if it could return a certain value type. The new naming scheme is: - `is_length()` - is it a LengthStyleValue? - `as_length()` - casts it to LengthStyleValue - `has_length()` - can it return a Length? - `to_length()` - gets the internal value out (eg, Length) This also means, no more `static_cast<LengthStyleValue const&>(*this)` stuff when dealing with StyleValues. :^) Hopefully this will be a bit clearer going forward. There are lots of places using the original methods, so I'll be going through them to hopefully catch any issues.
This commit is contained in:
parent
1ae0781ce1
commit
4b554ba92a
6 changed files with 263 additions and 60 deletions
|
@ -284,7 +284,7 @@ bool property_accepts_value(PropertyID property_id, StyleValue& style_value)
|
|||
auto type_args = type_parts.size() > 1 ? type_parts[1] : ""sv;
|
||||
if (type_name == "color") {
|
||||
property_generator.append(R"~~~(
|
||||
if (style_value.is_color())
|
||||
if (style_value.has_color())
|
||||
return true;
|
||||
)~~~");
|
||||
} else if (type_name == "image") {
|
||||
|
@ -295,7 +295,7 @@ bool property_accepts_value(PropertyID property_id, StyleValue& style_value)
|
|||
} else if (type_name == "length" || type_name == "percentage") {
|
||||
// FIXME: Handle lengths and percentages separately
|
||||
property_generator.append(R"~~~(
|
||||
if (style_value.is_length() || style_value.is_calculated())
|
||||
if (style_value.has_length() || style_value.is_calculated())
|
||||
return true;
|
||||
)~~~");
|
||||
} else if (type_name == "number" || type_name == "integer") {
|
||||
|
@ -309,14 +309,14 @@ bool property_accepts_value(PropertyID property_id, StyleValue& style_value)
|
|||
max_value = type_args.substring_view(comma_index + 1, type_args.length() - comma_index - 2);
|
||||
}
|
||||
property_generator.append(R"~~~(
|
||||
if (style_value.is_numeric())~~~");
|
||||
if (style_value.has_number())~~~");
|
||||
if (!min_value.is_empty()) {
|
||||
property_generator.set("minvalue", min_value);
|
||||
property_generator.append(" && (style_value.as_number() >= (float)@minvalue@)");
|
||||
property_generator.append(" && (style_value.to_number() >= (float)@minvalue@)");
|
||||
}
|
||||
if (!max_value.is_empty()) {
|
||||
property_generator.set("maxvalue", max_value);
|
||||
property_generator.append(" && (style_value.as_number() <= (float)@maxvalue@)");
|
||||
property_generator.append(" && (style_value.to_number() <= (float)@maxvalue@)");
|
||||
}
|
||||
property_generator.append(R"~~~()
|
||||
return true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue