From a426263deef9e2441c2d565749222472203884fd Mon Sep 17 00:00:00 2001 From: Andi Gallo Date: Fri, 11 Aug 2023 06:20:48 +0000 Subject: [PATCH] LibWeb: Remove 3 decimal places rounding hack in Length::percentage_of CSSPixels uses fixed point now. --- .../Layout/expected/grid/min-max-content.txt | 16 ++++++++-------- Userland/Libraries/LibWeb/CSS/Length.cpp | 10 +--------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/Tests/LibWeb/Layout/expected/grid/min-max-content.txt b/Tests/LibWeb/Layout/expected/grid/min-max-content.txt index 5eab751075a..6b9c3d748c1 100644 --- a/Tests/LibWeb/Layout/expected/grid/min-max-content.txt +++ b/Tests/LibWeb/Layout/expected/grid/min-max-content.txt @@ -4,23 +4,23 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline Box at (8,8) content-size 784x17.46875 [GFC] children: not-inline BlockContainer <(anonymous)> (not painted) [BFC] children: inline TextNode <#text> - BlockContainer at (8,8) content-size 46.890625x17.46875 [BFC] children: inline + BlockContainer at (8,8) content-size 46.875x17.46875 [BFC] children: inline line 0 width: 93.765625, height: 17.46875, bottom: 17.46875, baseline: 13.53125 frag 0 from TextNode start: 0, length: 11, rect: [8,8 93.765625x17.46875] "min-content" TextNode <#text> BlockContainer <(anonymous)> (not painted) [BFC] children: inline TextNode <#text> - BlockContainer at (54.890625,8) content-size 98.640625x17.46875 [BFC] children: inline + BlockContainer at (54.875,8) content-size 98.640625x17.46875 [BFC] children: inline line 0 width: 98.640625, height: 17.46875, bottom: 17.46875, baseline: 13.53125 - frag 0 from TextNode start: 0, length: 11, rect: [54.890625,8 98.640625x17.46875] + frag 0 from TextNode start: 0, length: 11, rect: [54.875,8 98.640625x17.46875] "max-content" TextNode <#text> BlockContainer <(anonymous)> (not painted) [BFC] children: inline TextNode <#text> - BlockContainer at (153.53125,8) content-size 638.46875x17.46875 [BFC] children: inline + BlockContainer at (153.515625,8) content-size 638.484375x17.46875 [BFC] children: inline line 0 width: 21.609375, height: 17.46875, bottom: 17.46875, baseline: 13.53125 - frag 0 from TextNode start: 0, length: 3, rect: [153.53125,8 21.609375x17.46875] + frag 0 from TextNode start: 0, length: 3, rect: [153.515625,8 21.609375x17.46875] "1fr" TextNode <#text> BlockContainer <(anonymous)> (not painted) [BFC] children: inline @@ -30,9 +30,9 @@ PaintableWithLines (Viewport<#document>) [0,0 800x600] PaintableWithLines (BlockContainer) [0,0 800x600] PaintableWithLines (BlockContainer) [8,8 784x17.46875] PaintableBox (Box
.grid-container) [8,8 784x17.46875] - PaintableWithLines (BlockContainer
.grid-item) [8,8 46.890625x17.46875] overflow: [8,8 93.765625x17.46875] + PaintableWithLines (BlockContainer
.grid-item) [8,8 46.875x17.46875] overflow: [8,8 93.765625x17.46875] TextPaintable (TextNode<#text>) - PaintableWithLines (BlockContainer
.grid-item) [54.890625,8 98.640625x17.46875] + PaintableWithLines (BlockContainer
.grid-item) [54.875,8 98.640625x17.46875] TextPaintable (TextNode<#text>) - PaintableWithLines (BlockContainer
.grid-item) [153.53125,8 638.46875x17.46875] + PaintableWithLines (BlockContainer
.grid-item) [153.515625,8 638.484375x17.46875] TextPaintable (TextNode<#text>) diff --git a/Userland/Libraries/LibWeb/CSS/Length.cpp b/Userland/Libraries/LibWeb/CSS/Length.cpp index 279135019ee..5b7e8e4075c 100644 --- a/Userland/Libraries/LibWeb/CSS/Length.cpp +++ b/Userland/Libraries/LibWeb/CSS/Length.cpp @@ -59,15 +59,7 @@ Length Length::percentage_of(Percentage const& percentage) const return *this; } - // HACK: We round to 3 decimal places to emulate what happens in browsers that used fixed point math. - // FIXME: Remove this when converting CSSPixels to a fixed-point type. - // https://github.com/SerenityOS/serenity/issues/18566 - auto value = percentage.as_fraction() * raw_value(); - value *= 1000; - value = round(value); - value /= 1000; - - return Length { value, m_type }; + return Length { percentage.as_fraction() * raw_value(), m_type }; } CSSPixels Length::font_relative_length_to_px(Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const