LibWeb: Set color filter value to 1 if omitted

This commit is contained in:
Tim Ledbetter 2025-04-04 11:37:46 +01:00 committed by Sam Atkins
commit 61f76c7ec5
Notes: github-actions[bot] 2025-04-04 16:14:08 +00:00
4 changed files with 22 additions and 26 deletions

View file

@ -4433,7 +4433,7 @@ RefPtr<CSSStyleValue> Parser::parse_filter_value_list_value(TokenStream<Componen
if (amount->is_number() && amount->number().value() < 0)
return {};
}
return if_no_more_tokens_return(FilterOperation::Color { filter_token_to_operation(filter_token), amount });
return if_no_more_tokens_return(FilterOperation::Color { filter_token_to_operation(filter_token), amount.value_or(Number { Number::Type::Integer, 1 }) });
}
};

View file

@ -32,23 +32,19 @@ float FilterOperation::HueRotate::angle_degrees(Layout::Node const& node) const
float FilterOperation::Color::resolved_amount() const
{
// Default value when omitted is 1.
if (!amount.has_value())
return 1;
if (amount.is_number())
return amount.number().value();
if (amount->is_number())
return amount->number().value();
if (amount.is_percentage())
return amount.percentage().as_fraction();
if (amount->is_percentage())
return amount->percentage().as_fraction();
if (amount->is_calculated()) {
if (amount.is_calculated()) {
CalculationResolutionContext context {};
if (amount->calculated()->resolves_to_number())
return amount->calculated()->resolve_number(context).value();
if (amount.calculated()->resolves_to_number())
return amount.calculated()->resolve_number(context).value();
if (amount->calculated()->resolves_to_percentage())
return amount->calculated()->resolve_percentage(context)->as_fraction();
if (amount.calculated()->resolves_to_percentage())
return amount.calculated()->resolve_percentage(context)->as_fraction();
}
VERIFY_NOT_REACHED();
@ -111,8 +107,8 @@ String FilterValueListStyleValue::to_string(SerializationMode) const
VERIFY_NOT_REACHED();
}
}());
if (color.amount.has_value())
builder.append(color.amount->to_string());
builder.append(color.amount.to_string());
});
builder.append(')');
first = false;

View file

@ -46,7 +46,7 @@ struct HueRotate {
struct Color {
Gfx::ColorFilter::Type operation;
Optional<NumberPercentage> amount {};
NumberPercentage amount { Number { Number::Type::Integer, 1.0 } };
float resolved_amount() const;
bool operator==(Color const&) const = default;
};