From bec07d4af7892818055eb2277b680fc3267feae4 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Sun, 23 Jul 2023 01:09:39 +0200 Subject: [PATCH] LibWeb: Use fixed-point saturated arithmetics for CSSPixels Using fixed-point saturated arithmetics for CSSPixels allows to avoid accumulating floating-point errors. This implementation is not complete yet: currently saturated arithmetics implemented only for addition. But it is enough to not regress any of layout tests we have :) See https://github.com/SerenityOS/serenity/issues/18566 --- .../abspos-box-with-replaced-element.txt | 8 +- Tests/LibWeb/Layout/expected/acid1.txt | 110 ++++----- ...continue-to-inherit-style-after-change.txt | 12 +- ...-inline-with-percentage-vertical-align.txt | 8 +- ...-consider-all-currently-stacked-floats.txt | 4 +- .../block-with-min-content-width.txt | 30 +-- ...egative-margin-and-no-intruding-floats.txt | 10 +- .../expected/block-and-inline/float-1.txt | 78 +++--- .../expected/block-and-inline/float-3.txt | 2 +- .../expected/block-and-inline/float-4.txt | 6 +- ...d-right-with-justified-text-in-between.txt | 214 ++++++++--------- ...at-left-and-right-with-text-in-between.txt | 74 +++--- .../block-and-inline/float-stress-1.txt | 2 +- .../inline-box-positioned-with-top-left.txt | 8 +- ...th-vertical-margins-vertical-align-top.txt | 6 +- .../inline-box-with-vertical-margins.txt | 12 +- .../block-and-inline/margin-collapse-5.txt | 14 +- ...bfc-width-to-avoid-overlap-with-floats.txt | 22 +- ...-with-indefinite-containing-block-size.txt | 4 +- ...ns-set-zero-if-containing-size-smaller.txt | 14 +- ...-box-for-definite-sizes-without-layout.txt | 16 +- Tests/LibWeb/Layout/expected/css-ex-unit.txt | 6 +- .../Layout/expected/css-font-size-calc.txt | 8 +- .../Layout/expected/css-import-rule.txt | 6 +- .../css-imported-sheet-with-media-rule.txt | 6 +- ...css-line-height-percentage-inheritance.txt | 4 +- ...should-not-be-affected-by-inline-style.txt | 4 +- ...ot-be-affected-by-presentational-hints.txt | 8 +- Tests/LibWeb/Layout/expected/div_align.txt | 44 ++-- .../Layout/expected/div_align_nested.txt | 20 +- Tests/LibWeb/Layout/expected/flex-auto.txt | 10 +- .../flex-column-constrained-nowrap.txt | 10 +- ...n-height-constrained-width-constrained.txt | 10 +- .../flex-column-height-constrained.txt | 10 +- ...mn-item-with-auto-height-and-max-width.txt | 22 +- ...g-auto-width-with-max-width-constraint.txt | 26 +- ...th-auto-height-depending-on-auto-width.txt | 22 +- .../flex-container-constrained-nowrap.txt | 10 +- .../flex-container-width-constrained.txt | 10 +- Tests/LibWeb/Layout/expected/flex-grow-1.txt | 10 +- Tests/LibWeb/Layout/expected/flex-grow-2.txt | 10 +- .../LibWeb/Layout/expected/flex-shrink-1.txt | 22 +- .../LibWeb/Layout/expected/flex-shrink-2.txt | 6 +- .../Layout/expected/flex/calc-flex-basis.txt | 16 +- ...-sizing-border-box-and-nonzero-padding.txt | 32 +-- .../flex/flex-item-min-width-fit-content.txt | 6 +- ...layout-dependent-containing-block-size.txt | 16 +- ...-intrinsic-aspect-ratio-and-max-height.txt | 6 +- ...ut-with-space-between-and-space-around.txt | 24 +- .../flex/stretch-alignment-with-cross-gap.txt | 8 +- .../expected/font-with-many-normal-values.txt | 18 +- ...etComputedStyle-on-unconnected-element.txt | 8 +- .../LibWeb/Layout/expected/grid/auto-fill.txt | 10 +- .../LibWeb/Layout/expected/grid/auto-fit.txt | 10 +- Tests/LibWeb/Layout/expected/grid/borders.txt | 6 +- .../Layout/expected/grid/grid-gap-2.txt | 6 +- .../grid/grid-item-fixed-paddings.txt | 30 +-- .../grid-item-horizontal-margins-auto.txt | 80 +++---- .../grid/grid-item-percentage-margins.txt | 4 +- .../grid/grid-item-percentage-width-2.txt | 72 +++--- .../grid/grid-item-percentage-width.txt | 4 +- ...id-row-height-affected-by-item-margins.txt | 8 +- .../Layout/expected/grid/image-in-grid.txt | 12 +- .../expected/grid/item-column-span-2.txt | 16 +- .../Layout/expected/grid/justify-items.txt | 4 +- .../Layout/expected/grid/justify-self.txt | 4 +- .../grid/minmax-with-max-function-inside.txt | 12 +- .../Layout/expected/grid/named-tracks.txt | 14 +- .../expected/grid/positions-and-spans.txt | 12 +- .../expected/grid/row-span-2-maxcontent.txt | 116 ++++----- .../expected/grid/row-span-2-mincontent.txt | 222 +++++++++--------- .../expected/grid/row-span-2-with-gaps.txt | 120 +++++----- .../Layout/expected/grid/row-span-2.txt | 116 ++++----- .../grid/template-lines-and-areas.txt | 6 +- .../grid/track-size-calc-with-percentage.txt | 12 +- .../grid/unresolvable-percentage-track.txt | 2 +- ...-of-absolute-position-box-with-padding.txt | 6 +- ...ge-with-multiple-constraint-violations.txt | 6 +- ...and-min-content-containing-block-width.txt | 4 +- Tests/LibWeb/Layout/expected/inline-size.txt | 20 +- .../input-element-with-display-inline.txt | 14 +- .../place-content-shorthand-property.txt | 4 +- ...seudo-element-with-custom-properties-2.txt | 68 +++--- .../pseudo-element-with-custom-properties.txt | 4 +- .../replaced-box-with-vertical-margins.txt | 12 +- ...ero-when-available-size-is-min-content.txt | 4 +- .../expected/svg-preserve-aspect-ratio.txt | 30 +-- .../expected/svg-transforms-and-viewboxes.txt | 26 +- ...with-indefinite-containing-block-width.txt | 4 +- .../Layout/expected/svg/svg-as-image.txt | 2 +- .../expected/svg/svg-fill-with-bogus-url.txt | 2 +- .../svg-negative-elliptical-arg-number.txt | 2 +- .../expected/svg/svg-with-display-block.txt | 2 +- ...ith-zero-intrinsic-size-and-no-viewbox.txt | 10 +- .../Layout/expected/svg/text-fill-none.txt | 10 +- .../expected/table/align-top-and-bottom.txt | 28 +-- Tests/LibWeb/Layout/expected/table/basic.txt | 26 +- .../table/border-collapse-is-inherited.txt | 94 ++++---- .../border-conflict-resolution-with-cell.txt | 36 +-- .../border-conflict-resolution-with-col.txt | 36 +-- .../border-conflict-resolution-with-row.txt | 38 +-- ...rder-conflict-resolution-with-rowgroup.txt | 40 ++-- .../expected/table/border-spacing-colspan.txt | 68 +++--- .../expected/table/border-spacing-rowspan.txt | 68 +++--- .../border-spacing-with-percentage-width.txt | 18 +- .../Layout/expected/table/border-spacing.txt | 72 +++--- .../LibWeb/Layout/expected/table/borders.txt | 144 ++++++------ .../Layout/expected/table/bottom-caption.txt | 26 +- ...-auto-max-width-table-percentage-width.txt | 14 +- ...cell-relative-to-specified-table-width.txt | 30 +-- .../table/clip-spans-to-table-end.txt | 38 +-- .../table/colspan-percentage-width.txt | 20 +- .../colspan-weighted-width-distribution.txt | 6 +- .../table/colspan-width-distribution.txt | 20 +- .../table/columns-width-distribution-1.txt | 36 +-- .../Layout/expected/table/fixed-margins.txt | 16 +- .../table/long-caption-increases-width.txt | 54 ++--- .../Layout/expected/table/multi-line-cell.txt | 26 +- .../table/percentage-width-columns.txt | 22 +- .../row-outer-size-with-computed-size.txt | 4 +- .../table/row-span-and-nested-tables.txt | 28 +-- .../table/rows-height-distribution-1.txt | 6 +- ...percentage-column-widths-less-than-100.txt | 14 +- ...e-formation-with-rowspan-in-the-middle.txt | 50 ++-- ...th-distribution-of-max-width-increment.txt | 22 +- .../text-align-justify-with-forced-break.txt | 68 +++--- Tests/LibWeb/Layout/expected/text-indent.txt | 18 +- .../tolerate-css-percentage-overshoot.txt | 6 +- Userland/Libraries/LibWeb/CMakeLists.txt | 1 + .../LibWeb/Layout/FlexFormattingContext.cpp | 4 +- .../LibWeb/Layout/GridFormattingContext.cpp | 4 +- .../LibWeb/Layout/SVGFormattingContext.cpp | 2 +- Userland/Libraries/LibWeb/Page/Page.cpp | 4 +- .../LibWeb/Painting/PaintableBox.cpp | 2 +- Userland/Libraries/LibWeb/PixelUnits.cpp | 169 +++++++++++++ Userland/Libraries/LibWeb/PixelUnits.h | 204 +++++----------- 136 files changed, 1938 insertions(+), 1844 deletions(-) create mode 100644 Userland/Libraries/LibWeb/PixelUnits.cpp diff --git a/Tests/LibWeb/Layout/expected/abspos-box-with-replaced-element.txt b/Tests/LibWeb/Layout/expected/abspos-box-with-replaced-element.txt index 56daa46912..dc6cd03789 100644 --- a/Tests/LibWeb/Layout/expected/abspos-box-with-replaced-element.txt +++ b/Tests/LibWeb/Layout/expected/abspos-box-with-replaced-element.txt @@ -1,7 +1,7 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline BlockContainer at (1,1) content-size 798x0 [BFC] children: not-inline BlockContainer at (10,10) content-size 500x100 positioned [BFC] children: not-inline - BlockContainer at (261,11) content-size 248x28.4836 positioned [BFC] children: inline - line 0 width: 250, height: 28.4836, bottom: 28.4836, baseline: 28.4836 - frag 0 from ImageBox start: 0, length: 0, rect: [262,12 248x26.4836] - ImageBox at (262,12) content-size 248x26.4836 children: not-inline + BlockContainer at (261,11) content-size 248x25.25 positioned [BFC] children: inline + line 0 width: 250, height: 25.25, bottom: 25.25, baseline: 25.25 + frag 0 from ImageBox start: 0, length: 0, rect: [262,12 248x23.25] + ImageBox at (262,12) content-size 248x23.25 children: not-inline diff --git a/Tests/LibWeb/Layout/expected/acid1.txt b/Tests/LibWeb/Layout/expected/acid1.txt index db5ff8566b..6932035f2e 100644 --- a/Tests/LibWeb/Layout/expected/acid1.txt +++ b/Tests/LibWeb/Layout/expected/acid1.txt @@ -1,15 +1,15 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline - BlockContainer at (0,0) content-size 800x419.999999 [BFC] children: not-inline + BlockContainer at (0,0) content-size 800x419.921875 [BFC] children: not-inline BlockContainer <(anonymous)> at (0,0) content-size 800x0 children: inline TextNode <#text> - BlockContainer at (20,20) content-size 480x379.999999 children: not-inline + BlockContainer at (20,20) content-size 480x379.921875 children: not-inline BlockContainer <(anonymous)> at (20,20) content-size 480x0 children: inline TextNode <#text> BlockContainer
at (25,25) content-size 470x0 children: inline TextNode <#text> - BlockContainer
at (40,40) content-size 49.999x280 floating [BFC] children: inline - line 0 width: 28.310546, height: 10, bottom: 10, baseline: 7.998046 - frag 0 from TextNode start: 0, length: 6, rect: [40,40 28.310546x10] + BlockContainer
at (40,40) content-size 49.984375x280 floating [BFC] children: inline + line 0 width: 28.296875, height: 10, bottom: 10, baseline: 7.984375 + frag 0 from TextNode start: 0, length: 6, rect: [40,40 28.296875x10] "toggle" TextNode <#text> TextNode <#text> @@ -19,56 +19,56 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline BlockContainer