diff --git a/Tests/LibWeb/Layout/expected/border-spacing-calc-dont-crash.txt b/Tests/LibWeb/Layout/expected/border-spacing-calc-dont-crash.txt new file mode 100644 index 00000000000..9e323a97139 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/border-spacing-calc-dont-crash.txt @@ -0,0 +1,10 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x600 [BFC] children: not-inline + BlockContainer at (8,8) content-size 784x0 children: not-inline + BlockContainer
at (8,8) content-size 784x0 children: inline + TextNode <#text> + +ViewportPaintable (Viewport<#document>) [0,0 800x600] + PaintableWithLines (BlockContainer) [0,0 800x600] + PaintableWithLines (BlockContainer) [8,8 784x0] + PaintableWithLines (BlockContainer
) [8,8 784x0] diff --git a/Tests/LibWeb/Layout/input/border-spacing-calc-dont-crash.html b/Tests/LibWeb/Layout/input/border-spacing-calc-dont-crash.html new file mode 100644 index 00000000000..e9e3d654ccf --- /dev/null +++ b/Tests/LibWeb/Layout/input/border-spacing-calc-dont-crash.html @@ -0,0 +1,6 @@ + +
diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp index ade20579b67..5fde4e031f4 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp @@ -402,20 +402,24 @@ Optional StyleProperties::image_rendering() const return keyword_to_image_rendering(value->to_keyword()); } -CSS::Length StyleProperties::border_spacing_horizontal() const +CSS::Length StyleProperties::border_spacing_horizontal(Layout::Node const& layout_node) const { auto value = property(CSS::PropertyID::BorderSpacing); if (value->is_length()) return value->as_length().length(); + if (value->is_math()) + return value->as_math().resolve_length(layout_node).value_or(CSS::Length(0, CSS::Length::Type::Px)); auto const& list = value->as_value_list(); return list.value_at(0, false)->as_length().length(); } -CSS::Length StyleProperties::border_spacing_vertical() const +CSS::Length StyleProperties::border_spacing_vertical(Layout::Node const& layout_node) const { auto value = property(CSS::PropertyID::BorderSpacing); if (value->is_length()) return value->as_length().length(); + if (value->is_math()) + return value->as_math().resolve_length(layout_node).value_or(CSS::Length(0, CSS::Length::Type::Px)); auto const& list = value->as_value_list(); return list.value_at(1, false)->as_length().length(); } diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.h b/Userland/Libraries/LibWeb/CSS/StyleProperties.h index 7d6f14e9950..bbdb5884b38 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.h +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.h @@ -98,8 +98,8 @@ public: Optional text_align() const; Optional text_justify() const; Optional text_overflow() const; - CSS::Length border_spacing_horizontal() const; - CSS::Length border_spacing_vertical() const; + CSS::Length border_spacing_horizontal(Layout::Node const&) const; + CSS::Length border_spacing_vertical(Layout::Node const&) const; Optional caption_side() const; CSS::Clip clip() const; CSS::Display display() const; diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index 19714009228..b1d070dd356 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -613,8 +613,8 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style) if (float_.has_value()) computed_values.set_float(float_.value()); - computed_values.set_border_spacing_horizontal(computed_style.border_spacing_horizontal()); - computed_values.set_border_spacing_vertical(computed_style.border_spacing_vertical()); + computed_values.set_border_spacing_horizontal(computed_style.border_spacing_horizontal(*this)); + computed_values.set_border_spacing_vertical(computed_style.border_spacing_vertical(*this)); auto caption_side = computed_style.caption_side(); if (caption_side.has_value())