mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-07 21:59:54 +00:00
LibWeb: Properly simplify sum nodes containing negated sum nodes
This is ad-hoc, see https://github.com/w3c/csswg-drafts/issues/13020 Gains us 5 WPT tests
This commit is contained in:
parent
9c06d58b2e
commit
c2ca712406
Notes:
github-actions[bot]
2025-10-30 12:19:35 +00:00
Author: https://github.com/Calme1709
Commit: c2ca712406
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6612
Reviewed-by: https://github.com/AtkinsSJ ✅
3 changed files with 120 additions and 0 deletions
|
|
@ -3070,6 +3070,22 @@ NonnullRefPtr<CalculationNode const> simplify_a_calculation_tree(CalculationNode
|
|||
if (child.type() == CalculationNode::Type::Negate)
|
||||
return as<NegateCalculationNode>(child).child();
|
||||
|
||||
// AD-HOC: Convert negated sums into sums of negated nodes - see https://github.com/w3c/csswg-drafts/issues/13020
|
||||
if (child.type() == CalculationNode::Type::Sum) {
|
||||
Vector<NonnullRefPtr<CalculationNode const>> negated_sum_components;
|
||||
|
||||
for (auto const& sum_child : child.children()) {
|
||||
if (sum_child->type() == CalculationNode::Type::Numeric)
|
||||
negated_sum_components.append(as<NumericCalculationNode>(*sum_child).negated(context));
|
||||
else if (sum_child->type() == CalculationNode::Type::Negate)
|
||||
negated_sum_components.append(as<NegateCalculationNode>(*sum_child).child());
|
||||
else
|
||||
negated_sum_components.append(NegateCalculationNode::create(sum_child));
|
||||
}
|
||||
|
||||
return SumCalculationNode::create(negated_sum_components);
|
||||
}
|
||||
|
||||
// 3. Return root.
|
||||
// NOTE: Because our root is immutable, we have to return a new node if the child was modified.
|
||||
if (&child == &root_negate.child())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue