LibWeb: Define <opacity-value> as a ValueType

Since `<opacity-value>` is used across multiple properties it makes
sense to have it defined as a value.
This commit is contained in:
Callum Law 2025-10-17 02:15:11 +13:00 committed by Tim Ledbetter
commit 0e82ab2966
Notes: github-actions[bot] 2025-10-17 10:11:38 +00:00
7 changed files with 68 additions and 74 deletions

View file

@ -4458,6 +4458,21 @@ RefPtr<CalculationNode const> Parser::parse_a_calculation(Vector<ComponentValue>
return simplify_a_calculation_tree(*calculation_tree, context, CalculationResolutionContext {});
}
// https://drafts.csswg.org/css-color-4/#typedef-opacity-opacity-value
RefPtr<StyleValue const> Parser::parse_opacity_value(TokenStream<ComponentValue>& tokens)
{
auto value = parse_number_percentage_value(tokens);
if (!value)
return nullptr;
// Percentages map to the range [0,1] for opacity values
if (value->is_percentage())
return NumberStyleValue::create(value->as_percentage().percentage().as_fraction());
return value;
}
// https://drafts.csswg.org/css-fonts/#typedef-opentype-tag
RefPtr<StringStyleValue const> Parser::parse_opentype_tag_value(TokenStream<ComponentValue>& tokens)
{
@ -4869,6 +4884,8 @@ RefPtr<StyleValue const> Parser::parse_value(ValueType value_type, TokenStream<C
return parse_length_value(tokens);
case ValueType::Number:
return parse_number_value(tokens);
case ValueType::Opacity:
return parse_opacity_value(tokens);
case ValueType::OpentypeTag:
return parse_opentype_tag_value(tokens);
case ValueType::Paint: