mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 19:59:17 +00:00
LibWeb: Implement interpolation of edge values
This commit is contained in:
parent
31dea89fe0
commit
0beb22f19e
Notes:
github-actions[bot]
2025-04-23 08:39:39 +00:00
Author: https://github.com/tcl3
Commit: 0beb22f19e
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4315
Reviewed-by: https://github.com/AtkinsSJ
Reviewed-by: https://github.com/shannonbooth
3 changed files with 47 additions and 21 deletions
|
@ -11,27 +11,9 @@ namespace Web::CSS {
|
|||
String EdgeStyleValue::to_string(SerializationMode mode) const
|
||||
{
|
||||
if (mode == CSSStyleValue::SerializationMode::ResolvedValue) {
|
||||
if (edge() == PositionEdge::Right || edge() == PositionEdge::Bottom) {
|
||||
if (offset().is_percentage()) {
|
||||
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<NonnullRefPtr<CalculationNode const>> sum_parts;
|
||||
sum_parts.append(NumericCalculationNode::create(Percentage(100), context));
|
||||
if (offset().is_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), context);
|
||||
return flipped_absolute->to_string(mode);
|
||||
}
|
||||
return offset().to_string();
|
||||
// FIXME: Figure out how to get the proper calculation context here
|
||||
CalculationContext context {};
|
||||
return resolved_value(context)->offset().to_string();
|
||||
}
|
||||
|
||||
StringBuilder builder;
|
||||
|
@ -48,4 +30,27 @@ String EdgeStyleValue::to_string(SerializationMode mode) const
|
|||
return builder.to_string_without_validation();
|
||||
}
|
||||
|
||||
ValueComparingNonnullRefPtr<EdgeStyleValue const> EdgeStyleValue::resolved_value(CalculationContext context) const
|
||||
{
|
||||
if (edge() == PositionEdge::Right || edge() == PositionEdge::Bottom) {
|
||||
if (offset().is_percentage()) {
|
||||
auto flipped_percentage = 100 - offset().percentage().value();
|
||||
return create({}, Percentage(flipped_percentage));
|
||||
}
|
||||
|
||||
Vector<NonnullRefPtr<CalculationNode const>> sum_parts;
|
||||
sum_parts.append(NumericCalculationNode::create(Percentage(100), context));
|
||||
if (offset().is_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 *this;
|
||||
}
|
||||
auto flipped_absolute = CalculatedStyleValue::create(SumCalculationNode::create(move(sum_parts)), CSSNumericType(CSSNumericType::BaseType::Length, 1), context);
|
||||
return create({}, flipped_absolute);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue