at (9,9) content-size 598.015625x21.46875 table-row children: not-inline
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
- BlockContainer at (11,11) content-size 95.65625x17.46875 table-cell [BFC] children: inline
+ BlockContainer | at (11,11) content-size 95.671875x17.46875 table-cell [BFC] children: inline
line 0 width: 26.078125, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 4, rect: [11,11 26.078125x17.46875]
"cell"
TextNode <#text>
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
- BlockContainer | at (110.65625,11) content-size 95.65625x17.46875 table-cell [BFC] children: inline
+ BlockContainer | at (110.671875,11) content-size 95.671875x17.46875 table-cell [BFC] children: inline
line 0 width: 26.078125, height: 17.46875, bottom: 17.46875, baseline: 13.53125
- frag 0 from TextNode start: 0, length: 4, rect: [110.65625,11 26.078125x17.46875]
+ frag 0 from TextNode start: 0, length: 4, rect: [110.671875,11 26.078125x17.46875]
"cell"
TextNode <#text>
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
- BlockContainer | at (210.3125,11) content-size 95.65625x17.46875 table-cell [BFC] children: inline
+ BlockContainer | at (210.34375,11) content-size 95.671875x17.46875 table-cell [BFC] children: inline
line 0 width: 94.96875, height: 17.46875, bottom: 17.46875, baseline: 13.53125
- frag 0 from TextNode start: 0, length: 12, rect: [210.3125,11 94.96875x17.46875]
+ frag 0 from TextNode start: 0, length: 12, rect: [210.34375,11 94.96875x17.46875]
"A table cell"
TextNode <#text>
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
- BlockContainer | at (309.96875,11) content-size 295x17.46875 table-cell [BFC] children: inline
+ BlockContainer | at (310.015625,11) content-size 295x17.46875 table-cell [BFC] children: inline
line 0 width: 94.96875, height: 17.46875, bottom: 17.46875, baseline: 13.53125
- frag 0 from TextNode start: 0, length: 12, rect: [309.96875,11 94.96875x17.46875]
+ frag 0 from TextNode start: 0, length: 12, rect: [310.015625,11 94.96875x17.46875]
"A table cell"
TextNode <#text>
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
- Box |
at (9,30.46875) content-size 598.015625x21.46875 table-row children: not-inline
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
- BlockContainer at (11,32.46875) content-size 95.65625x17.46875 table-cell [BFC] children: inline
+ BlockContainer | at (11,32.46875) content-size 95.671875x17.46875 table-cell [BFC] children: inline
line 0 width: 26.078125, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 4, rect: [11,32.46875 26.078125x17.46875]
"cell"
TextNode <#text>
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
- BlockContainer | at (110.65625,32.46875) content-size 95.65625x17.46875 table-cell [BFC] children: inline
+ BlockContainer | at (110.671875,32.46875) content-size 95.671875x17.46875 table-cell [BFC] children: inline
line 0 width: 26.078125, height: 17.46875, bottom: 17.46875, baseline: 13.53125
- frag 0 from TextNode start: 0, length: 4, rect: [110.65625,32.46875 26.078125x17.46875]
+ frag 0 from TextNode start: 0, length: 4, rect: [110.671875,32.46875 26.078125x17.46875]
"cell"
TextNode <#text>
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
- BlockContainer | at (210.3125,32.46875) content-size 95.65625x17.46875 table-cell [BFC] children: inline
+ BlockContainer | at (210.34375,32.46875) content-size 95.671875x17.46875 table-cell [BFC] children: inline
line 0 width: 94.96875, height: 17.46875, bottom: 17.46875, baseline: 13.53125
- frag 0 from TextNode start: 0, length: 12, rect: [210.3125,32.46875 94.96875x17.46875]
+ frag 0 from TextNode start: 0, length: 12, rect: [210.34375,32.46875 94.96875x17.46875]
"A table cell"
TextNode <#text>
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
- BlockContainer | at (309.96875,32.46875) content-size 295x17.46875 table-cell [BFC] children: inline
+ BlockContainer | at (310.015625,32.46875) content-size 295x17.46875 table-cell [BFC] children: inline
line 0 width: 94.96875, height: 17.46875, bottom: 17.46875, baseline: 13.53125
- frag 0 from TextNode start: 0, length: 12, rect: [309.96875,32.46875 94.96875x17.46875]
+ frag 0 from TextNode start: 0, length: 12, rect: [310.015625,32.46875 94.96875x17.46875]
"A table cell"
TextNode <#text>
BlockContainer <(anonymous)> (not painted) children: inline
@@ -77,23 +77,23 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600]
PaintableWithLines (BlockContainer) [0,0 800x600]
PaintableWithLines (BlockContainer) [8,8 784x44.9375]
PaintableWithLines (TableWrapper(anonymous)) [8,8 600x44.9375]
- PaintableBox (Box) [8,8 600x44.9375]
- PaintableBox (Box) [9,9 597.96875x42.9375]
- PaintableBox (Box) [9,9 597.96875x21.46875]
- PaintableWithLines (BlockContainer) [9,9 99.65625x21.46875]
+ PaintableBox (Box) [8,8 600x44.9375] overflow: [9,9 598.015625x42.9375]
+ PaintableBox (Box) [9,9 598.015625x42.9375]
+ PaintableBox (Box) [9,9 598.015625x21.46875]
+ PaintableWithLines (BlockContainer) [9,9 99.671875x21.46875]
TextPaintable (TextNode<#text>)
- PaintableWithLines (BlockContainer | ) [108.65625,9 99.65625x21.46875]
+ PaintableWithLines (BlockContainer | ) [108.671875,9 99.671875x21.46875]
TextPaintable (TextNode<#text>)
- PaintableWithLines (BlockContainer | ) [208.3125,9 99.65625x21.46875]
+ PaintableWithLines (BlockContainer | ) [208.34375,9 99.671875x21.46875]
TextPaintable (TextNode<#text>)
- PaintableWithLines (BlockContainer | ) [307.96875,9 299x21.46875]
+ PaintableWithLines (BlockContainer | ) [308.015625,9 299x21.46875]
TextPaintable (TextNode<#text>)
- PaintableBox (Box | ) [9,30.46875 597.96875x21.46875]
- PaintableWithLines (BlockContainer) [9,30.46875 99.65625x21.46875]
+ PaintableBox (Box | ) [9,30.46875 598.015625x21.46875]
+ PaintableWithLines (BlockContainer) [9,30.46875 99.671875x21.46875]
TextPaintable (TextNode<#text>)
- PaintableWithLines (BlockContainer | ) [108.65625,30.46875 99.65625x21.46875]
+ PaintableWithLines (BlockContainer | ) [108.671875,30.46875 99.671875x21.46875]
TextPaintable (TextNode<#text>)
- PaintableWithLines (BlockContainer | ) [208.3125,30.46875 99.65625x21.46875]
+ PaintableWithLines (BlockContainer | ) [208.34375,30.46875 99.671875x21.46875]
TextPaintable (TextNode<#text>)
- PaintableWithLines (BlockContainer | ) [307.96875,30.46875 299x21.46875]
+ PaintableWithLines (BlockContainer | ) [308.015625,30.46875 299x21.46875]
TextPaintable (TextNode<#text>)
diff --git a/Tests/LibWeb/Layout/expected/table/row-outer-size-with-computed-size.txt b/Tests/LibWeb/Layout/expected/table/row-outer-size-with-computed-size.txt
index c14f0a77d82..9eedd718266 100644
--- a/Tests/LibWeb/Layout/expected/table/row-outer-size-with-computed-size.txt
+++ b/Tests/LibWeb/Layout/expected/table/row-outer-size-with-computed-size.txt
@@ -9,7 +9,7 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline
Box | at (10,10) content-size 43.21875x9.734375 table-row children: not-inline
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
- BlockContainer at (11,14.859375) content-size 0x0 table-cell [BFC] children: not-inline
+ BlockContainer | at (11,14.875) content-size 0x0 table-cell [BFC] children: not-inline
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
BlockContainer | at (16,12) content-size 37.21875x17.46875 table-cell [BFC] children: inline
@@ -27,7 +27,7 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline
Box | at (10,21.734375) content-size 43.21875x9.734375 table-row children: not-inline
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
- BlockContainer at (11,26.59375) content-size 0x0 table-cell [BFC] children: not-inline
+ BlockContainer | at (11,26.609375) content-size 0x0 table-cell [BFC] children: not-inline
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
BlockContainer <(anonymous)> (not painted) children: inline
@@ -38,11 +38,11 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600]
PaintableWithLines (BlockContainer) [8,8 784x25.46875]
PaintableWithLines (TableWrapper(anonymous)) [8,8 49.21875x25.46875]
PaintableBox (Box) [8,8 49.21875x25.46875]
- PaintableBox (Box) [8,8 43.21875x19.46875] overflow: [8,8 47.21875x23.46875]
+ PaintableBox (Box) [8,8 43.21875x19.46875] overflow: [8,8 47.21875x23.484375]
PaintableBox (Box) [10,10 43.21875x9.734375] overflow: [10,10 45.21875x21.46875]
- PaintableWithLines (BlockContainer) [10,10 2x9.71875]
+ PaintableWithLines (BlockContainer | ) [10,10 2x9.75]
PaintableWithLines (BlockContainer | ) [14,10 41.21875x21.46875]
InlinePaintable (InlineNode)
TextPaintable (TextNode<#text>)
- PaintableBox (Box) [10,21.734375 43.21875x9.734375]
- PaintableWithLines (BlockContainer) [10,21.734375 2x9.71875]
+ PaintableBox (Box | ) [10,21.734375 43.21875x9.734375] overflow: [10,21.734375 43.21875x9.75]
+ PaintableWithLines (BlockContainer) [10,21.734375 2x9.75]
diff --git a/Tests/LibWeb/Layout/expected/table/row-span-and-nested-tables.txt b/Tests/LibWeb/Layout/expected/table/row-span-and-nested-tables.txt
index 347394518ff..a0ec10d97ed 100644
--- a/Tests/LibWeb/Layout/expected/table/row-span-and-nested-tables.txt
+++ b/Tests/LibWeb/Layout/expected/table/row-span-and-nested-tables.txt
@@ -15,9 +15,9 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline
Box | at (11,11) content-size 67.828125x54.203125 table-row children: not-inline
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
- BlockContainer at (17,29.359375) content-size 11.5625x17.46875 table-cell [BFC] children: inline
+ BlockContainer | at (17,29.375) content-size 11.5625x17.46875 table-cell [BFC] children: inline
line 0 width: 11.5625, height: 17.46875, bottom: 17.46875, baseline: 13.53125
- frag 0 from TextNode start: 0, length: 1, rect: [17,29.359375 11.5625x17.46875]
+ frag 0 from TextNode start: 0, length: 1, rect: [17,29.375 11.5625x17.46875]
"X"
TextNode <#text>
BlockContainer <(anonymous)> (not painted) children: inline
@@ -79,9 +79,9 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline
Box | at (11,67.203125) content-size 67.828125x54.203125 table-row children: not-inline
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
- BlockContainer at (17,85.5625) content-size 11.5625x17.46875 table-cell [BFC] children: inline
+ BlockContainer | at (17,85.578125) content-size 11.5625x17.46875 table-cell [BFC] children: inline
line 0 width: 11.09375, height: 17.46875, bottom: 17.46875, baseline: 13.53125
- frag 0 from TextNode start: 0, length: 1, rect: [17,85.5625 11.09375x17.46875]
+ frag 0 from TextNode start: 0, length: 1, rect: [17,85.578125 11.09375x17.46875]
"Y"
TextNode <#text>
BlockContainer <(anonymous)> (not painted) children: inline
@@ -100,9 +100,9 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600]
PaintableWithLines (BlockContainer(anonymous)) [8,8 784x0]
PaintableWithLines (TableWrapper(anonymous)) [8,8 75.828125x116.40625]
PaintableBox (Box) [8,8 75.828125x116.40625]
- PaintableBox (Box) [9,9 67.828125x108.40625] overflow: [9,9 71.828125x112.40625]
+ PaintableBox (Box) [9,9 67.828125x108.40625] overflow: [9,9 71.828125x112.421875]
PaintableBox (Box) [11,11 67.828125x54.203125] overflow: [11,11 69.828125x110.40625]
- PaintableWithLines (BlockContainer) [11,11 23.5625x54.1875]
+ PaintableWithLines (BlockContainer | ) [11,11 23.5625x54.21875]
TextPaintable (TextNode<#text>)
PaintableWithLines (BlockContainer | ) [36.5625,11 44.265625x110.40625]
PaintableWithLines (BlockContainer(anonymous)) [42.5625,17 32.265625x0]
@@ -122,7 +122,7 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600]
PaintableWithLines (BlockContainer(anonymous)) [42.5625,17 0x0]
PaintableWithLines (BlockContainer(anonymous)) [42.5625,17 0x0]
PaintableWithLines (BlockContainer(anonymous)) [42.5625,115.40625 32.265625x0]
- PaintableBox (Box | ) [11,67.203125 67.828125x54.203125]
- PaintableWithLines (BlockContainer) [11,67.203125 23.5625x54.1875]
+ PaintableBox (Box | ) [11,67.203125 67.828125x54.203125] overflow: [11,67.203125 67.828125x54.21875]
+ PaintableWithLines (BlockContainer) [11,67.203125 23.5625x54.21875]
TextPaintable (TextNode<#text>)
PaintableWithLines (BlockContainer(anonymous)) [8,124.40625 784x0]
diff --git a/Tests/LibWeb/TestCSSPixels.cpp b/Tests/LibWeb/TestCSSPixels.cpp
index 4851c298438..33b53d8c5a0 100644
--- a/Tests/LibWeb/TestCSSPixels.cpp
+++ b/Tests/LibWeb/TestCSSPixels.cpp
@@ -36,6 +36,15 @@ TEST_CASE(division1)
b = CSSPixels(0.25);
EXPECT(!a.might_be_saturated());
EXPECT((a / b).might_be_saturated());
+
+ // Results should be rounded:
+ a = CSSPixels::smallest_positive_value() * 3;
+ b = 2;
+ EXPECT((a / b) == CSSPixels::smallest_positive_value() * 2);
+
+ a = CSSPixels::smallest_positive_value() * -5;
+ b = 3;
+ EXPECT((a / b) == CSSPixels::smallest_positive_value() * -2);
}
TEST_CASE(multiplication1)
diff --git a/Userland/Libraries/LibWeb/PixelUnits.h b/Userland/Libraries/LibWeb/PixelUnits.h
index cace3f9bf3f..841dfe6137f 100644
--- a/Userland/Libraries/LibWeb/PixelUnits.h
+++ b/Userland/Libraries/LibWeb/PixelUnits.h
@@ -284,6 +284,14 @@ constexpr CSSPixels operator*(unsigned long left, CSSPixels right) { return righ
inline float operator*(float left, CSSPixels right) { return right.to_float() * left; }
inline double operator*(double left, CSSPixels right) { return right.to_double() * left; }
+template
+constexpr static T rounding_divide(T dividend, T divisor)
+{
+ if ((dividend < 0) == (divisor < 0))
+ return (dividend + (divisor / 2)) / divisor;
+ return (dividend - (divisor / 2)) / divisor;
+}
+
class CSSPixelFraction {
public:
constexpr CSSPixelFraction(CSSPixels numerator, CSSPixels denominator)
@@ -309,7 +317,7 @@ public:
{
i64 wide_value = m_numerator.raw_value();
wide_value <<= CSSPixels::fractional_bits;
- wide_value /= m_denominator.raw_value();
+ wide_value = rounding_divide(wide_value, m_denominator.raw_value());
return CSSPixels::from_raw(AK::clamp_to_int(wide_value));
}
@@ -347,7 +355,7 @@ constexpr CSSPixels CSSPixels::operator*(CSSPixelFraction const& other) const
{
i64 wide_value = raw_value();
wide_value *= other.numerator().raw_value();
- wide_value /= other.denominator().raw_value();
+ wide_value = rounding_divide(wide_value, other.denominator().raw_value());
return CSSPixels::from_raw(AK::clamp_to_int(wide_value));
}
@@ -359,7 +367,7 @@ constexpr CSSPixels CSSPixels::operator/(CSSPixelFraction const& other) const
{
i64 wide_value = raw_value();
wide_value *= other.denominator().raw_value();
- wide_value /= other.numerator().raw_value();
+ wide_value = rounding_divide(wide_value, other.numerator().raw_value());
return CSSPixels::from_raw(AK::clamp_to_int(wide_value));
}
| | | | | |