mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 11:49:44 +00:00
LibWeb: Properly serialize position/edge style values
This commit is contained in:
parent
583ca6af89
commit
84150f972f
Notes:
github-actions[bot]
2024-12-13 11:36:34 +00:00
Author: https://github.com/Gingeh
Commit: 84150f972f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2651
Reviewed-by: https://github.com/AtkinsSJ ✅
Reviewed-by: https://github.com/awesomekling
21 changed files with 461 additions and 288 deletions
|
@ -8,9 +8,40 @@
|
|||
|
||||
namespace Web::CSS {
|
||||
|
||||
String EdgeStyleValue::to_string(SerializationMode) const
|
||||
String EdgeStyleValue::to_string(SerializationMode mode) const
|
||||
{
|
||||
return MUST(String::formatted("{} {}", CSS::to_string(m_properties.edge), m_properties.offset.to_string()));
|
||||
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();
|
||||
}
|
||||
Vector<NonnullOwnPtr<CalculationNode>> sum_parts;
|
||||
sum_parts.append(NumericCalculationNode::create(Percentage(100)));
|
||||
if (offset().is_length()) {
|
||||
sum_parts.append(NegateCalculationNode::create(NumericCalculationNode::create(offset().length())));
|
||||
} else {
|
||||
// FIXME: Flip calculated offsets (convert CSSMathValue to CalculationNode, then negate and append)
|
||||
return to_string(CSSStyleValue::SerializationMode::Normal);
|
||||
}
|
||||
auto flipped_absolute = CSSMathValue::create(SumCalculationNode::create(move(sum_parts)), CSSNumericType(CSSNumericType::BaseType::Length, 1));
|
||||
return flipped_absolute->to_string(mode);
|
||||
}
|
||||
return offset().to_string();
|
||||
}
|
||||
|
||||
StringBuilder builder;
|
||||
|
||||
if (m_properties.edge.has_value())
|
||||
builder.append(CSS::to_string(m_properties.edge.value()));
|
||||
|
||||
if (m_properties.edge.has_value() && m_properties.offset.has_value())
|
||||
builder.append(' ');
|
||||
|
||||
if (m_properties.offset.has_value())
|
||||
builder.append(m_properties.offset->to_string());
|
||||
|
||||
return builder.to_string_without_validation();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue