mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:17:45 +00:00
LibWeb: Allow calc() in opacity
This is mostly a test to make sure that resolving calc() to a number or percentage works correctly. I don't love how this ended up.
This commit is contained in:
parent
8bd1854406
commit
e4251f3327
1 changed files with 22 additions and 5 deletions
|
@ -164,13 +164,30 @@ float StyleProperties::opacity() const
|
||||||
return 1.0f;
|
return 1.0f;
|
||||||
auto& value = maybe_value.value();
|
auto& value = maybe_value.value();
|
||||||
|
|
||||||
if (value->has_number())
|
float unclamped_opacity = 1.0f;
|
||||||
return clamp(value->to_number(), 0.0f, 1.0f);
|
|
||||||
|
|
||||||
if (value->is_percentage())
|
if (value->has_number()) {
|
||||||
return clamp(value->as_percentage().percentage().as_fraction(), 0.0f, 1.0f);
|
unclamped_opacity = value->to_number();
|
||||||
|
} else if (value->is_calculated()) {
|
||||||
|
auto& calculated = value->as_calculated();
|
||||||
|
if (calculated.resolved_type() == CalculatedStyleValue::ResolvedType::Percentage) {
|
||||||
|
auto maybe_percentage = value->as_calculated().resolve_percentage();
|
||||||
|
if (maybe_percentage.has_value())
|
||||||
|
unclamped_opacity = maybe_percentage->as_fraction();
|
||||||
|
else
|
||||||
|
dbgln("Unable to resolve calc() as opacity (percentage): {}", value->to_string());
|
||||||
|
} else {
|
||||||
|
auto maybe_number = value->as_calculated().resolve_number();
|
||||||
|
if (maybe_number.has_value())
|
||||||
|
unclamped_opacity = maybe_number.value();
|
||||||
|
else
|
||||||
|
dbgln("Unable to resolve calc() as opacity (number): {}", value->to_string());
|
||||||
|
}
|
||||||
|
} else if (value->is_percentage()) {
|
||||||
|
unclamped_opacity = value->as_percentage().percentage().as_fraction();
|
||||||
|
}
|
||||||
|
|
||||||
return 1.0f;
|
return clamp(unclamped_opacity, 0.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<CSS::FlexDirection> StyleProperties::flex_direction() const
|
Optional<CSS::FlexDirection> StyleProperties::flex_direction() const
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue