From 0fb571c1c2612940d7a23260807a5cbd39d022bc Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Tue, 29 Aug 2023 18:57:09 +0200 Subject: [PATCH] LibWeb: Add `Length::resolved()` overload for CSSPixels Since we always pass the px value as an argument to resolved(), we can pass it directly as CSSPixels instead of wrapping it in Length. This approach allows us to avoid converting to a double, resulting in fewer precision issues. --- Tests/LibWeb/Layout/expected/acid1.txt | 42 +++++++++---------- .../small-percentage-margin.txt | 35 ++++++++++++++++ .../small-percentage-margin.html | 10 +++++ .../Libraries/LibWeb/CSS/PercentageOr.cpp | 5 +++ Userland/Libraries/LibWeb/CSS/PercentageOr.h | 29 ++++++++++++- Userland/Libraries/LibWeb/CSS/Size.cpp | 5 +++ Userland/Libraries/LibWeb/CSS/Size.h | 1 + .../CSS/StyleValues/CalculatedStyleValue.cpp | 16 +++++++ .../CSS/StyleValues/CalculatedStyleValue.h | 1 + .../StyleValues/RadialGradientStyleValue.cpp | 4 +- .../LibWeb/Layout/BlockFormattingContext.cpp | 35 +++++++--------- .../LibWeb/Layout/FormattingContext.cpp | 40 +++++++----------- .../Libraries/LibWeb/Layout/LayoutState.cpp | 4 +- .../LibWeb/Layout/TableFormattingContext.cpp | 2 - 14 files changed, 154 insertions(+), 75 deletions(-) create mode 100644 Tests/LibWeb/Layout/expected/block-and-inline/small-percentage-margin.txt create mode 100644 Tests/LibWeb/Layout/input/block-and-inline/small-percentage-margin.html diff --git a/Tests/LibWeb/Layout/expected/acid1.txt b/Tests/LibWeb/Layout/expected/acid1.txt index d76ed21f4a..e1d8ccbe9e 100644 --- a/Tests/LibWeb/Layout/expected/acid1.txt +++ b/Tests/LibWeb/Layout/expected/acid1.txt @@ -7,7 +7,7 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline TextNode <#text> BlockContainer
at (25,25) content-size 470x0 children: inline TextNode <#text> - BlockContainer
at (40,40) content-size 50x280 floating [BFC] children: inline + BlockContainer
at (40,40) content-size 49.984375x280 floating [BFC] children: inline line 0 width: 28.3125, height: 10, bottom: 10, baseline: 8 frag 0 from TextNode start: 0, length: 6, rect: [40,40 28.3125x10] "toggle" @@ -24,21 +24,21 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline "the way" TextNode <#text> TextNode <#text> - BlockContainer at (235,55) content-size 139.984375x90 floating [BFC] children: not-inline - BlockContainer <(anonymous)> at (235,55) content-size 139.984375x0 children: inline + BlockContainer at (235,55) content-size 139.96875x90 floating [BFC] children: not-inline + BlockContainer <(anonymous)> at (235,55) content-size 139.96875x0 children: inline TextNode <#text> - BlockContainer

at (235,55) content-size 139.984375x10 children: inline + BlockContainer

at (235,55) content-size 139.96875x10 children: inline line 0 width: 74.3125, height: 10, bottom: 10, baseline: 8 frag 0 from TextNode start: 0, length: 14, rect: [235,55 74.3125x10] "the world ends" TextNode <#text> - BlockContainer <(anonymous)> at (235,65) content-size 139.984375x0 children: inline + BlockContainer <(anonymous)> at (235,65) content-size 139.96875x0 children: inline TextNode <#text> InlineNode

TextNode <#text> TextNode <#text> TextNode <#text> - BlockContainer

at (235,65) content-size 139.984375x19 children: inline + BlockContainer

at (235,65) content-size 139.96875x19 children: inline line 0 width: 39.484375, height: 19, bottom: 19, baseline: 12.5 frag 0 from TextNode start: 1, length: 5, rect: [235,65 27.484375x19] "bang " @@ -46,7 +46,7 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline TextNode <#text> RadioButton at (262,65) content-size 12x12 inline-block children: not-inline TextNode <#text> - BlockContainer

at (235,84) content-size 139.984375x19 children: inline + BlockContainer

at (235,84) content-size 139.96875x19 children: inline line 0 width: 57.15625, height: 19, bottom: 19, baseline: 12.5 frag 0 from TextNode start: 1, length: 8, rect: [235,84 45.15625x19] "whimper " @@ -54,15 +54,15 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline TextNode <#text> RadioButton at (280,84) content-size 12x12 inline-block children: not-inline TextNode <#text> - BlockContainer <(anonymous)> at (235,103) content-size 139.984375x0 children: inline + BlockContainer <(anonymous)> at (235,103) content-size 139.96875x0 children: inline TextNode <#text> TextNode <#text> - BlockContainer

  • at (409.984375,60) content-size 50x90 floating [BFC] children: inline + BlockContainer
  • at (409.96875,60) content-size 50x90 floating [BFC] children: inline line 0 width: 31.578125, height: 10, bottom: 10, baseline: 8 - frag 0 from TextNode start: 0, length: 6, rect: [409.984375,60 31.578125x10] + frag 0 from TextNode start: 0, length: 6, rect: [409.96875,60 31.578125x10] "i grow" line 1 width: 14.03125, height: 10, bottom: 20, baseline: 8 - frag 0 from TextNode start: 7, length: 3, rect: [409.984375,70 14.03125x10] + frag 0 from TextNode start: 7, length: 3, rect: [409.96875,70 14.03125x10] "old" TextNode <#text> TextNode <#text> @@ -140,27 +140,27 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600] PaintableWithLines (BlockContainer) [15,15 490x390] PaintableWithLines (BlockContainer(anonymous)) [20,20 480x0] PaintableWithLines (BlockContainer
    ) [20,20 480x10] - PaintableWithLines (BlockContainer
    ) [25,25 80x310] + PaintableWithLines (BlockContainer
    ) [25,25 79.984375x310] TextPaintable (TextNode<#text>) PaintableWithLines (BlockContainer
    ) [115,25 380x310] PaintableWithLines (BlockContainer(anonymous)) [135,45 340x0] PaintableWithLines (BlockContainer