mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:17:44 +00:00
LibWeb/CSS: Fix incorrect calc(<percentage> - <value>)
computations
When swapping both values to perform the actual calculation, we need to consider that `A + B == B + A`, but `A - B != B - A`, so turn it into `-B + A`. Co-Authored-By: Sam Atkins <atkinssj@serenityos.org>
This commit is contained in:
parent
c1acb587d7
commit
26fc01eecb
1 changed files with 6 additions and 3 deletions
|
@ -478,10 +478,13 @@ void CalculatedStyleValue::CalculationResult::add_or_subtract_internal(SumOperat
|
|||
|
||||
// Other side isn't a percentage, so the easiest way to handle it without duplicating all the logic, is just to swap `this` and `other`.
|
||||
CalculationResult new_value = other;
|
||||
if (op == SumOperation::Add)
|
||||
if (op == SumOperation::Add) {
|
||||
new_value.add(*this, layout_node, percentage_basis);
|
||||
else
|
||||
new_value.subtract(*this, layout_node, percentage_basis);
|
||||
} else {
|
||||
// Turn 'this - other' into '-other + this', as 'A + B == B + A', but 'A - B != B - A'
|
||||
new_value.multiply_by({ Number { Number::Type::Integer, -1.0f } }, layout_node);
|
||||
new_value.add(*this, layout_node, percentage_basis);
|
||||
}
|
||||
|
||||
*this = new_value;
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue