Explorar el Código

LibWeb: Don't crash when encountering `border-spacing: calc(...)`

This allows us to progress further on this WPT test:
https://wpt.live/quirks/unitless-length/quirks.html

...although it still crashes before finishing.
Andreas Kling hace 10 meses
padre
commit
5e240f997c

+ 10 - 0
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 <html> at (0,0) content-size 800x600 [BFC] children: not-inline
+    BlockContainer <body> at (8,8) content-size 784x0 children: not-inline
+      BlockContainer <div> at (8,8) content-size 784x0 children: inline
+        TextNode <#text>
+
+ViewportPaintable (Viewport<#document>) [0,0 800x600]
+  PaintableWithLines (BlockContainer<HTML>) [0,0 800x600]
+    PaintableWithLines (BlockContainer<BODY>) [8,8 784x0]
+      PaintableWithLines (BlockContainer<DIV>) [8,8 784x0]

+ 6 - 0
Tests/LibWeb/Layout/input/border-spacing-calc-dont-crash.html

@@ -0,0 +1,6 @@
+<style>
+div {
+    border-spacing: calc(2px);
+}
+</style>
+<div>

+ 6 - 2
Userland/Libraries/LibWeb/CSS/StyleProperties.cpp

@@ -402,20 +402,24 @@ Optional<CSS::ImageRendering> 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();
 }

+ 2 - 2
Userland/Libraries/LibWeb/CSS/StyleProperties.h

@@ -98,8 +98,8 @@ public:
     Optional<CSS::TextAlign> text_align() const;
     Optional<CSS::TextJustify> text_justify() const;
     Optional<CSS::TextOverflow> 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<CSS::CaptionSide> caption_side() const;
     CSS::Clip clip() const;
     CSS::Display display() const;

+ 2 - 2
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())