LibWeb/CSS: Give calc() a CalculationContext for resolving percentages

This is passed in at construction, meaning we will be able to refer to
it later, when we're no longer inside the Parser.
This commit is contained in:
Sam Atkins 2025-01-08 16:14:17 +00:00
commit 4efdb76857
Notes: github-actions[bot] 2025-01-13 11:00:31 +00:00
8 changed files with 111 additions and 84 deletions

View file

@ -16,15 +16,19 @@ String EdgeStyleValue::to_string(SerializationMode mode) const
auto flipped_percentage = 100 - offset().percentage().value();
return Percentage(flipped_percentage).to_string();
}
// FIXME: Figure out how to get the proper calculation context here
CalculationContext context = {};
Vector<NonnullOwnPtr<CalculationNode>> sum_parts;
sum_parts.append(NumericCalculationNode::create(Percentage(100)));
sum_parts.append(NumericCalculationNode::create(Percentage(100), context));
if (offset().is_length()) {
sum_parts.append(NegateCalculationNode::create(NumericCalculationNode::create(offset().length())));
sum_parts.append(NegateCalculationNode::create(NumericCalculationNode::create(offset().length(), context)));
} else {
// FIXME: Flip calculated offsets (convert CalculatedStyleValue to CalculationNode, then negate and append)
return to_string(CSSStyleValue::SerializationMode::Normal);
}
auto flipped_absolute = CalculatedStyleValue::create(SumCalculationNode::create(move(sum_parts)), CSSNumericType(CSSNumericType::BaseType::Length, 1));
auto flipped_absolute = CalculatedStyleValue::create(SumCalculationNode::create(move(sum_parts)), CSSNumericType(CSSNumericType::BaseType::Length, 1), context);
return flipped_absolute->to_string(mode);
}
return offset().to_string();