LibWeb: Support border radius in rect() function

This commit is contained in:
Callum Law
2026-01-05 22:44:11 +13:00
committed by Jelle Raaijmakers
parent 1b7567cc86
commit 02a8d22a4e
Notes: github-actions[bot] 2026-01-06 09:51:22 +00:00
5 changed files with 41 additions and 19 deletions

View File

@@ -81,7 +81,15 @@ String Xywh::to_string(SerializationMode mode) const
String Rect::to_string(SerializationMode mode) const
{
return MUST(String::formatted("rect({} {} {} {})", top->to_string(mode), right->to_string(mode), bottom->to_string(mode), left->to_string(mode)));
StringBuilder builder;
builder.appendff("{} {} {} {}", top->to_string(mode), right->to_string(mode), bottom->to_string(mode), left->to_string(mode));
auto serialized_border_radius = border_radius->to_string(mode);
if (serialized_border_radius != "0px"sv)
builder.appendff(" round {}", serialized_border_radius);
return MUST(String::formatted("rect({})", builder.to_string_without_validation()));
}
Gfx::Path Circle::to_path(CSSPixelRect reference_box, Layout::Node const& node) const
@@ -322,9 +330,9 @@ ValueComparingNonnullRefPtr<StyleValue const> BasicShapeStyleValue::absolutized(
auto absolutized_right = one_hundred_percent_minus({ resolve_auto(shape.right, Percentage { 100 }) }, calculation_context)->absolutized(computation_context);
auto absolutized_bottom = one_hundred_percent_minus({ resolve_auto(shape.bottom, Percentage { 100 }) }, calculation_context)->absolutized(computation_context);
auto absolutized_left = resolve_auto(shape.left, Percentage { 0 })->absolutized(computation_context);
auto absolutized_border_radius = shape.border_radius->absolutized(computation_context);
// FIXME: Pass actual border radius once we parse it
return Inset { *absolutized_top, *absolutized_right, *absolutized_bottom, *absolutized_left, BorderRadiusRectStyleValue::create_zero() };
return Inset { *absolutized_top, *absolutized_right, *absolutized_bottom, *absolutized_left, absolutized_border_radius };
},
[&](Circle const& shape) -> BasicShape {
auto absolutized_radius = shape.radius->absolutized(computation_context);