Skip to content

Commit

Permalink
LibWeb/CSS: Resolve NumericCalculationNode to percentage when requested
Browse files Browse the repository at this point in the history
When the caller of `NumericCalculationNode::resolve()` does not provide
a percentage_basis, it expects the method to return a raw percentage
value.

Fixes crashing on https://discord.com/login
  • Loading branch information
kalenikaliaksandr committed Jan 11, 2024
1 parent 1593ff2 commit ad41b08
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions Tests/LibWeb/Text/expected/css/css-hsl-with-calc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rgb(30, 31, 34)
11 changes: 11 additions & 0 deletions Tests/LibWeb/Text/input/css/css-hsl-with-calc.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!doctype html><script src="../include.js"></script><style>
body {
--saturation-factor: 1;
background: hsl(225, calc(var(--saturation-factor, 1) * 6.3%), 12.5%);
}
</style><body></body><script>
test(() => {
const bodyStyle = window.getComputedStyle(document.body);
println(bodyStyle.backgroundColor);
});
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,11 @@ bool NumericCalculationNode::contains_percentage() const
CalculatedStyleValue::CalculationResult NumericCalculationNode::resolve(Optional<Length::ResolutionContext const&>, CalculatedStyleValue::PercentageBasis const& percentage_basis) const
{
if (m_value.has<Percentage>()) {
// NOTE: Depending on whether percentage_basis is set, the caller of resolve() is expecting a raw percentage or
// resolved length.
return percentage_basis.visit(
[&](Empty const&) -> CalculatedStyleValue::CalculationResult {
VERIFY_NOT_REACHED();
return m_value;
},
[&](auto const& value) {
return CalculatedStyleValue::CalculationResult(value.percentage_of(m_value.get<Percentage>()));
Expand Down

0 comments on commit ad41b08

Please sign in to comment.