mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:37:35 +00:00
LibWeb/CSS: Resolve NumericCalculationNode to percentage when requested
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
This commit is contained in:
parent
1593ff2d4c
commit
225ed58f7e
3 changed files with 15 additions and 1 deletions
1
Tests/LibWeb/Text/expected/css/css-hsl-with-calc.txt
Normal file
1
Tests/LibWeb/Text/expected/css/css-hsl-with-calc.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
rgb(30, 31, 34)
|
11
Tests/LibWeb/Text/input/css/css-hsl-with-calc.html
Normal file
11
Tests/LibWeb/Text/input/css/css-hsl-with-calc.html
Normal file
|
@ -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>
|
|
@ -220,9 +220,11 @@ bool NumericCalculationNode::contains_percentage() const
|
||||||
CalculatedStyleValue::CalculationResult NumericCalculationNode::resolve(Optional<Length::ResolutionContext const&>, CalculatedStyleValue::PercentageBasis const& percentage_basis) const
|
CalculatedStyleValue::CalculationResult NumericCalculationNode::resolve(Optional<Length::ResolutionContext const&>, CalculatedStyleValue::PercentageBasis const& percentage_basis) const
|
||||||
{
|
{
|
||||||
if (m_value.has<Percentage>()) {
|
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(
|
return percentage_basis.visit(
|
||||||
[&](Empty const&) -> CalculatedStyleValue::CalculationResult {
|
[&](Empty const&) -> CalculatedStyleValue::CalculationResult {
|
||||||
VERIFY_NOT_REACHED();
|
return m_value;
|
||||||
},
|
},
|
||||||
[&](auto const& value) {
|
[&](auto const& value) {
|
||||||
return CalculatedStyleValue::CalculationResult(value.percentage_of(m_value.get<Percentage>()));
|
return CalculatedStyleValue::CalculationResult(value.percentage_of(m_value.get<Percentage>()));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue