mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:57:44 +00:00
LibWeb: Make serializing basic CSS types infallible
This commit is contained in:
parent
b5893ee115
commit
6bee81cfb6
38 changed files with 128 additions and 121 deletions
|
@ -67,12 +67,12 @@ static ErrorOr<void> serialize_color_stop_list(StringBuilder& builder, auto cons
|
|||
TRY(builder.try_append(", "sv));
|
||||
|
||||
if (element.transition_hint.has_value())
|
||||
TRY(builder.try_appendff("{}, "sv, TRY(element.transition_hint->value.to_string())));
|
||||
TRY(builder.try_appendff("{}, "sv, element.transition_hint->value.to_string()));
|
||||
|
||||
TRY(builder.try_append(TRY(element.color_stop.color->to_string())));
|
||||
for (auto position : Array { &element.color_stop.position, &element.color_stop.second_position }) {
|
||||
if (position->has_value())
|
||||
TRY(builder.try_appendff(" {}"sv, TRY((*position)->to_string())));
|
||||
TRY(builder.try_appendff(" {}"sv, (*position)->to_string()));
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ BackgroundSizeStyleValue::~BackgroundSizeStyleValue() = default;
|
|||
|
||||
ErrorOr<String> BackgroundSizeStyleValue::to_string() const
|
||||
{
|
||||
return String::formatted("{} {}", TRY(m_properties.size_x.to_string()), TRY(m_properties.size_y.to_string()));
|
||||
return String::formatted("{} {}", m_properties.size_x.to_string(), m_properties.size_y.to_string());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,7 +13,15 @@ namespace Web::CSS {
|
|||
|
||||
ErrorOr<String> BorderRadiusShorthandStyleValue::to_string() const
|
||||
{
|
||||
return String::formatted("{} {} {} {} / {} {} {} {}", TRY(m_properties.top_left->horizontal_radius().to_string()), TRY(m_properties.top_right->horizontal_radius().to_string()), TRY(m_properties.bottom_right->horizontal_radius().to_string()), TRY(m_properties.bottom_left->horizontal_radius().to_string()), TRY(m_properties.top_left->vertical_radius().to_string()), TRY(m_properties.top_right->vertical_radius().to_string()), TRY(m_properties.bottom_right->vertical_radius().to_string()), TRY(m_properties.bottom_left->vertical_radius().to_string()));
|
||||
return String::formatted("{} {} {} {} / {} {} {} {}",
|
||||
m_properties.top_left->horizontal_radius().to_string(),
|
||||
m_properties.top_right->horizontal_radius().to_string(),
|
||||
m_properties.bottom_right->horizontal_radius().to_string(),
|
||||
m_properties.bottom_left->horizontal_radius().to_string(),
|
||||
m_properties.top_left->vertical_radius().to_string(),
|
||||
m_properties.top_right->vertical_radius().to_string(),
|
||||
m_properties.bottom_right->vertical_radius().to_string(),
|
||||
m_properties.bottom_left->vertical_radius().to_string());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ ErrorOr<String> BorderRadiusStyleValue::to_string() const
|
|||
{
|
||||
if (m_properties.horizontal_radius == m_properties.vertical_radius)
|
||||
return m_properties.horizontal_radius.to_string();
|
||||
return String::formatted("{} / {}", TRY(m_properties.horizontal_radius.to_string()), TRY(m_properties.vertical_radius.to_string()));
|
||||
return String::formatted("{} / {}", m_properties.horizontal_radius.to_string(), m_properties.vertical_radius.to_string());
|
||||
}
|
||||
|
||||
ValueComparingNonnullRefPtr<StyleValue const> BorderRadiusStyleValue::absolutized(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const
|
||||
|
|
|
@ -208,7 +208,7 @@ CalculatedStyleValue::CalculationResult NumericCalculationNode::resolve(Optional
|
|||
|
||||
ErrorOr<void> NumericCalculationNode::dump(StringBuilder& builder, int indent) const
|
||||
{
|
||||
return builder.try_appendff("{: >{}}NUMERIC({})\n", "", indent, TRY(m_value.visit([](auto& it) { return it.to_string(); })));
|
||||
return builder.try_appendff("{: >{}}NUMERIC({})\n", "", indent, m_value.visit([](auto& it) { return it.to_string(); }));
|
||||
}
|
||||
|
||||
NonnullOwnPtr<SumCalculationNode> SumCalculationNode::create(Vector<NonnullOwnPtr<CalculationNode>> values)
|
||||
|
|
|
@ -21,12 +21,12 @@ ErrorOr<String> ConicGradientStyleValue::to_string() const
|
|||
bool has_from_angle = false;
|
||||
bool has_at_position = false;
|
||||
if ((has_from_angle = m_properties.from_angle.to_degrees() != 0))
|
||||
TRY(builder.try_appendff("from {}", TRY(m_properties.from_angle.to_string())));
|
||||
TRY(builder.try_appendff("from {}", m_properties.from_angle.to_string()));
|
||||
if ((has_at_position = m_properties.position != PositionValue::center())) {
|
||||
if (has_from_angle)
|
||||
TRY(builder.try_append(' '));
|
||||
TRY(builder.try_appendff("at "sv));
|
||||
TRY(m_properties.position.serialize(builder));
|
||||
m_properties.position.serialize(builder);
|
||||
}
|
||||
if (has_from_angle || has_at_position)
|
||||
TRY(builder.try_append(", "sv));
|
||||
|
|
|
@ -24,7 +24,7 @@ ErrorOr<String> EdgeStyleValue::to_string() const
|
|||
VERIFY_NOT_REACHED();
|
||||
};
|
||||
|
||||
return String::formatted("{} {}", to_string(m_properties.edge), TRY(m_properties.offset.to_string()));
|
||||
return String::formatted("{} {}", to_string(m_properties.edge), m_properties.offset.to_string());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -65,14 +65,14 @@ ErrorOr<String> FilterValueListStyleValue::to_string() const
|
|||
[&](Filter::Blur const& blur) -> ErrorOr<void> {
|
||||
TRY(builder.try_append("blur("sv));
|
||||
if (blur.radius.has_value())
|
||||
TRY(builder.try_append(TRY(blur.radius->to_string())));
|
||||
TRY(builder.try_append(blur.radius->to_string()));
|
||||
return {};
|
||||
},
|
||||
[&](Filter::DropShadow const& drop_shadow) -> ErrorOr<void> {
|
||||
TRY(builder.try_appendff("drop-shadow({} {}"sv,
|
||||
drop_shadow.offset_x, drop_shadow.offset_y));
|
||||
if (drop_shadow.radius.has_value())
|
||||
TRY(builder.try_appendff(" {}", TRY(drop_shadow.radius->to_string())));
|
||||
TRY(builder.try_appendff(" {}", drop_shadow.radius->to_string()));
|
||||
if (drop_shadow.color.has_value()) {
|
||||
TRY(builder.try_append(' '));
|
||||
serialize_a_srgb_value(builder, *drop_shadow.color);
|
||||
|
@ -84,7 +84,7 @@ ErrorOr<String> FilterValueListStyleValue::to_string() const
|
|||
if (hue_rotate.angle.has_value()) {
|
||||
TRY(hue_rotate.angle->visit(
|
||||
[&](Angle const& angle) -> ErrorOr<void> {
|
||||
return builder.try_append(TRY(angle.to_string()));
|
||||
return builder.try_append(angle.to_string());
|
||||
},
|
||||
[&](auto&) -> ErrorOr<void> {
|
||||
return builder.try_append('0');
|
||||
|
@ -115,7 +115,7 @@ ErrorOr<String> FilterValueListStyleValue::to_string() const
|
|||
}
|
||||
}()));
|
||||
if (color.amount.has_value())
|
||||
TRY(builder.try_append(TRY(color.amount->to_string())));
|
||||
TRY(builder.try_append(color.amount->to_string()));
|
||||
return {};
|
||||
}));
|
||||
TRY(builder.try_append(')'));
|
||||
|
|
|
@ -47,7 +47,7 @@ ErrorOr<String> LinearGradientStyleValue::to_string() const
|
|||
return builder.try_appendff("{}{}, "sv, m_properties.gradient_type == GradientType::Standard ? "to "sv : ""sv, side_or_corner_to_string(side_or_corner));
|
||||
},
|
||||
[&](Angle const& angle) -> ErrorOr<void> {
|
||||
return builder.try_appendff("{}, "sv, TRY(angle.to_string()));
|
||||
return builder.try_appendff("{}, "sv, angle.to_string());
|
||||
}));
|
||||
|
||||
TRY(serialize_color_stop_list(builder, m_properties.color_stop_list));
|
||||
|
|
|
@ -38,15 +38,15 @@ ErrorOr<String> RadialGradientStyleValue::to_string() const
|
|||
}());
|
||||
},
|
||||
[&](CircleSize const& circle_size) -> ErrorOr<void> {
|
||||
return builder.try_append(TRY(circle_size.radius.to_string()));
|
||||
return builder.try_append(circle_size.radius.to_string());
|
||||
},
|
||||
[&](EllipseSize const& ellipse_size) -> ErrorOr<void> {
|
||||
return builder.try_appendff("{} {}", TRY(ellipse_size.radius_a.to_string()), TRY(ellipse_size.radius_b.to_string()));
|
||||
return builder.try_appendff("{} {}", ellipse_size.radius_a.to_string(), ellipse_size.radius_b.to_string());
|
||||
}));
|
||||
|
||||
if (m_properties.position != PositionValue::center()) {
|
||||
TRY(builder.try_appendff(" at "sv));
|
||||
TRY(m_properties.position.serialize(builder));
|
||||
m_properties.position.serialize(builder);
|
||||
}
|
||||
|
||||
TRY(builder.try_append(", "sv));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue