at (407.796875,8) content-size 376.3125x100 floating [BFC] children: inline
+ line 0 width: 23.015625, height: 17.46875, bottom: 17.46875, baseline: 13.53125
+ frag 0 from TextNode start: 0, length: 3, rect: [407.796875,8 23.015625x17.46875]
+ "def"
+ TextNode <#text>
+ BlockContainer
at (15.828125,108) content-size 376.3125x100 floating [BFC] children: inline
+ line 0 width: 21.421875, height: 17.46875, bottom: 17.46875, baseline: 13.53125
+ frag 0 from TextNode start: 0, length: 3, rect: [15.828125,108 21.421875x17.46875]
+ "ghi"
+ TextNode <#text>
+ BlockContainer
at (407.796875,108) content-size 376.3125x100 floating [BFC] children: inline
+ line 0 width: 18.40625, height: 17.46875, bottom: 17.46875, baseline: 13.53125
+ frag 0 from TextNode start: 0, length: 3, rect: [407.796875,108 18.40625x17.46875]
+ "jkl"
+ TextNode <#text>
+
+ViewportPaintable (Viewport<#document>) [0,0 800x600]
+ PaintableWithLines (BlockContainer) [0,0 800x208]
+ PaintableWithLines (BlockContainer) [8,8 784x0] overflow: [15.828125,8 768.28125x200]
+ PaintableWithLines (BlockContainer
) [15.828125,8 376.3125x100]
+ TextPaintable (TextNode<#text>)
+ PaintableWithLines (BlockContainer
) [407.796875,8 376.3125x100]
+ TextPaintable (TextNode<#text>)
+ PaintableWithLines (BlockContainer
) [15.828125,108 376.3125x100]
+ TextPaintable (TextNode<#text>)
+ PaintableWithLines (BlockContainer
) [407.796875,108 376.3125x100]
+ TextPaintable (TextNode<#text>)
diff --git a/Tests/LibWeb/Layout/input/block-and-inline/small-percentage-margin.html b/Tests/LibWeb/Layout/input/block-and-inline/small-percentage-margin.html
new file mode 100644
index 0000000000..e90f0ee826
--- /dev/null
+++ b/Tests/LibWeb/Layout/input/block-and-inline/small-percentage-margin.html
@@ -0,0 +1,10 @@
+
abc
def
ghi
jkl
\ No newline at end of file
diff --git a/Userland/Libraries/LibWeb/CSS/PercentageOr.cpp b/Userland/Libraries/LibWeb/CSS/PercentageOr.cpp
index 12ddfb1022..f55454af9d 100644
--- a/Userland/Libraries/LibWeb/CSS/PercentageOr.cpp
+++ b/Userland/Libraries/LibWeb/CSS/PercentageOr.cpp
@@ -23,6 +23,11 @@ Length LengthPercentage::resolve_calculated(NonnullRefPtr
return calculated->resolve_length_percentage(layout_node, reference_value).value();
}
+Length LengthPercentage::resolve_calculated(NonnullRefPtr const& calculated, Layout::Node const& layout_node, CSSPixels reference_value) const
+{
+ return calculated->resolve_length_percentage(layout_node, reference_value).value();
+}
+
Time TimePercentage::resolve_calculated(NonnullRefPtr const& calculated, Layout::Node const&, Time const& reference_value) const
{
return calculated->resolve_time_percentage(reference_value).value();
diff --git a/Userland/Libraries/LibWeb/CSS/PercentageOr.h b/Userland/Libraries/LibWeb/CSS/PercentageOr.h
index 57131423d9..0f7c39d6bb 100644
--- a/Userland/Libraries/LibWeb/CSS/PercentageOr.h
+++ b/Userland/Libraries/LibWeb/CSS/PercentageOr.h
@@ -83,8 +83,15 @@ public:
return m_value.template get>();
}
- virtual T resolve_calculated(NonnullRefPtr const&, [[maybe_unused]] Layout::Node const&, [[maybe_unused]] T const& reference_value) const
+ virtual T resolve_calculated(NonnullRefPtr const&, Layout::Node const&, T const& reference_value) const
{
+ (void)reference_value;
+ VERIFY_NOT_REACHED();
+ }
+
+ virtual T resolve_calculated(NonnullRefPtr const&, Layout::Node const&, CSSPixels reference_value) const
+ {
+ (void)reference_value;
VERIFY_NOT_REACHED();
}
@@ -112,6 +119,25 @@ public:
});
}
+ T resolved(Layout::Node const& layout_node, CSSPixels reference_value) const
+ {
+ return m_value.visit(
+ [&](T const& t) {
+ if constexpr (requires { t.is_calculated(); }) {
+ if (t.is_calculated())
+ return resolve_calculated(t.calculated_style_value(), layout_node, reference_value);
+ }
+
+ return t;
+ },
+ [&](Percentage const& percentage) {
+ return Length::make_px(CSSPixels(percentage.value() * reference_value) / 100);
+ },
+ [&](NonnullRefPtr const& calculated) {
+ return resolve_calculated(calculated, layout_node, reference_value);
+ });
+ }
+
String to_string() const
{
if (is_calculated())
@@ -193,6 +219,7 @@ public:
bool is_length() const { return is_t(); }
Length const& length() const { return get_t(); }
virtual Length resolve_calculated(NonnullRefPtr const&, Layout::Node const&, Length const& reference_value) const override;
+ virtual Length resolve_calculated(NonnullRefPtr const&, Layout::Node const&, CSSPixels reference_value) const override;
};
class TimePercentage : public PercentageOr