Truly independent web browser
LibWeb: Truncate absolute lengths to layout precision
sideshowbarker558121d01bc5
diff --git a/Libraries/LibWeb/Rust/src/css/computed_value_views.rs b/Libraries/LibWeb/Rust/src/css/computed_value_views.rsindex 27acc6d643f..83340b5c74a 100644--- a/Libraries/LibWeb/Rust/src/css/computed_value_views.rs+++ b/Libraries/LibWeb/Rust/src/css/computed_value_views.rs@@ -79,7 +79,7 @@ impl LengthPercentageRef<'_> {};let ratio = crate::css::style_compute::LENGTH_UNIT_CANONICAL_PX_RATIOS[*unit as usize];assert!(ratio.is_finite(), "computed length is not absolute");- CssPixels::nearest_value_for(value * ratio)+ CssPixels::truncated_value_for(f64::from((value * ratio) as f32))}/// Matches Percentage::as_fraction(); the multiplication order is@@ -161,7 +161,7 @@ impl InlineLengthPercentage {let ratio = crate::css::style_compute::LENGTH_UNIT_CANONICAL_PX_RATIOS[*unit as usize];ratio.is_finite()- .then(|| Self::Length(CssPixels::nearest_value_for(value * ratio)))+ .then(|| Self::Length(CssPixels::truncated_value_for(f64::from((value * ratio) as f32))))}StyleValueData::Percentage { value } => {let narrowed = *value as f32;diff --git a/Tests/LibWeb/Layout/expected/css-values/trigonometric-functions.txt b/Tests/LibWeb/Layout/expected/css-values/trigonometric-functions.txtindex 8d7eb67ebd1..8d624eae5dd 100644--- a/Tests/LibWeb/Layout/expected/css-values/trigonometric-functions.txt+++ b/Tests/LibWeb/Layout/expected/css-values/trigonometric-functions.txt@@ -3,7 +3,7 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] childrenBlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 980 0+0+8] children: not-inlineBlockContainer <div.sin> at [8,8] positioned [0+0+0 80 0+0+704] [0+0+0 100 0+0+0] children: not-inlineBlockContainer <div.cos> at [8,108] positioned [0+0+0 100 0+0+684] [0+0+0 100 0+0+0] children: not-inline- BlockContainer <div.tan> at [8,208] positioned [0+0+0 120 0+0+664] [0+0+0 100 0+0+0] children: not-inline+ BlockContainer <div.tan> at [8,208] positioned [0+0+0 119.984375 0+0+664.015625] [0+0+0 100 0+0+0] children: not-inlineBlockContainer <div.asin> at [8,308] positioned [0+0+0 100 0+0+684] [0+0+0 140 0+0+0] children: not-inlineBlockContainer <div.acos> at [8,448] positioned [0+0+0 100 0+0+684] [0+0+0 160 0+0+0] children: not-inlineBlockContainer <div.atan> at [8,608] positioned [0+0+0 100 0+0+684] [0+0+0 180 0+0+0] children: not-inline@@ -13,7 +13,7 @@ SC for Viewport<#document> [0,0 800x600] (z-index: auto)SC for BlockContainer<HTML> [0,0 800x996] (z-index: auto)SC for BlockContainer<DIV>.sin [8,8 80x100] (z-index: auto), has_transformSC for BlockContainer<DIV>.cos [8,108 100x100] (z-index: auto), has_transform- SC for BlockContainer<DIV>.tan [8,208 120x100] (z-index: auto), has_transform+ SC for BlockContainer<DIV>.tan [8,208 119.984375x100] (z-index: auto), has_transformSC for BlockContainer<DIV>.asin [8,308 100x140] (z-index: auto), has_transformSC for BlockContainer<DIV>.acos [8,448 100x160] (z-index: auto), has_transformSC for BlockContainer<DIV>.atan [8,608 100x180] (z-index: auto), has_transformdiff --git a/Tests/LibWeb/Layout/expected/height-of-absolute-position-box-with-padding.txt b/Tests/LibWeb/Layout/expected/height-of-absolute-position-box-with-padding.txtindex dcc0194b744..fb9fcb468b0 100644--- a/Tests/LibWeb/Layout/expected/height-of-absolute-position-box-with-padding.txt+++ b/Tests/LibWeb/Layout/expected/height-of-absolute-position-box-with-padding.txt@@ -1,8 +1,8 @@Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children: not-inlineBlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 16 0+0+0] [BFC] children: not-inlineBlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 0 0+0+8] children: not-inline- BlockContainer <h1> at [76.59375,103.765625] positioned [0+1+0 126 0+1+0] [13.40625+1+44 38 44+1+13.40625] [BFC] children: inline- frag 0 from TextNode start: 0, length: 4, rect: [116.3125,103.765625 46.546875x20] baseline: 16+ BlockContainer <h1> at [76.578125,103.734375] positioned [0+1+0 126 0+1+0] [13.390625+1+44 38 44+1+13.390625] [BFC] children: inline+ frag 0 from TextNode start: 0, length: 4, rect: [116.296875,103.734375 46.546875x20] baseline: 16"Test"TextNode <#text> (not painted)diff --git a/Tests/LibWeb/Layout/expected/select-list-box-optgroup-attribute-changes.txt b/Tests/LibWeb/Layout/expected/select-list-box-optgroup-attribute-changes.txtindex 87e0599a480..65f405b9185 100644--- a/Tests/LibWeb/Layout/expected/select-list-box-optgroup-attribute-changes.txt+++ b/Tests/LibWeb/Layout/expected/select-list-box-optgroup-attribute-changes.txt@@ -1,9 +1,9 @@Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children: not-inline- BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 147.953125 0+0+0] [BFC] children: not-inline- BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 131.953125 0+0+8] children: inline- frag 0 from BlockContainer start: 0, length: 0, rect: [9,10 69.84375x127.953125] baseline: 128.953125- BlockContainer <select> at [9,10] inline-block [0+1+0 69.84375 0+1+0] [0+1+1 127.953125 1+1+0] [BFC] children: not-inline- BlockContainer <div> at [9,10] [0+0+0 69.84375 0+0+0] [0+0+0 127.953125 0+0+0] [BFC] children: not-inline+ BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 147.9375 0+0+0] [BFC] children: not-inline+ BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 131.9375 0+0+8] children: inline+ frag 0 from BlockContainer start: 0, length: 0, rect: [9,10 69.84375x127.9375] baseline: 128.9375+ BlockContainer <select> at [9,10] inline-block [0+1+0 69.84375 0+1+0] [0+1+1 127.9375 1+1+0] [BFC] children: not-inline+ BlockContainer <div> at [9,10] [0+0+0 69.84375 0+0+0] [0+0+0 127.9375 0+0+0] [BFC] children: not-inlineBlockContainer <div> at [13,10] [0+0+4 61.84375 4+0+0] [0+0+0 16 0+0+0] children: inlinefrag 0 from TextNode start: 0, length: 9, rect: [13,11 61.84375x14] baseline: 11"New label"@@ -23,4 +23,4 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] childrenTextNode <#text> (not painted)SC for Viewport<#document> [0,0 800x600] (z-index: auto)- SC for BlockContainer<HTML> [0,0 800x147.953125] (z-index: auto)+ SC for BlockContainer<HTML> [0,0 800x147.9375] (z-index: auto)diff --git a/Tests/LibWeb/Layout/expected/tab-size-chars-should-vertically-align.txt b/Tests/LibWeb/Layout/expected/tab-size-chars-should-vertically-align.txtindex 10fcf53975a..b5f36845aca 100644--- a/Tests/LibWeb/Layout/expected/tab-size-chars-should-vertically-align.txt+++ b/Tests/LibWeb/Layout/expected/tab-size-chars-should-vertically-align.txt@@ -14,10 +14,10 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] childrenBlockContainer <span#s2> at [8,31] inline-block [0+0+0 54.578125 0+0+0] [0+0+0 0 0+0+0] [BFC] children: not-inlineTextNode <#text> (not painted)BlockContainer <div> at [8,34] [0+0+0 784 0+0+0] [0+0+0 13 0+0+0] children: inline- frag 0 from BlockContainer start: 0, length: 0, rect: [8,44 56.921875x0] baseline: 0- frag 1 from TextNode start: 0, length: 2, rect: [64.921875,34 58.671875x13] baseline: 10+ frag 0 from BlockContainer start: 0, length: 0, rect: [8,44 56.90625x0] baseline: 0+ frag 1 from TextNode start: 0, length: 2, rect: [64.90625,34 58.6875x13] baseline: 10" A"- BlockContainer <span#s3> at [8,44] inline-block [0+0+0 56.921875 0+0+0] [0+0+0 0 0+0+0] [BFC] children: not-inline+ BlockContainer <span#s3> at [8,44] inline-block [0+0+0 56.90625 0+0+0] [0+0+0 0 0+0+0] [BFC] children: not-inlineTextNode <#text> (not painted)BlockContainer <div> at [8,47] [0+0+0 784 0+0+0] [0+0+0 13 0+0+0] children: inlinefrag 0 from TextNode start: 0, length: 9, rect: [8,47 63.59375x13] baseline: 10diff --git a/Tests/LibWeb/Screenshot/expected-macos/video-object-fit.png b/Tests/LibWeb/Screenshot/expected-macos/video-object-fit.pngindex f2cc302f0e1..fa8757f7d40 100644Binary files a/Tests/LibWeb/Screenshot/expected-macos/video-object-fit.png and b/Tests/LibWeb/Screenshot/expected-macos/video-object-fit.png differdiff --git a/Tests/LibWeb/Screenshot/expected/css-background-clip-text.png b/Tests/LibWeb/Screenshot/expected/css-background-clip-text.pngindex 24c4fa008e4..3091abfaa07 100644Binary files a/Tests/LibWeb/Screenshot/expected/css-background-clip-text.png and b/Tests/LibWeb/Screenshot/expected/css-background-clip-text.png differdiff --git a/Tests/LibWeb/Screenshot/expected/object-fit-position.png b/Tests/LibWeb/Screenshot/expected/object-fit-position.pngindex 9cab7bc2619..39b9d6fdd6b 100644Binary files a/Tests/LibWeb/Screenshot/expected/object-fit-position.png and b/Tests/LibWeb/Screenshot/expected/object-fit-position.png differdiff --git a/Tests/LibWeb/Screenshot/expected/svg-image-document-nested-clip-path.png b/Tests/LibWeb/Screenshot/expected/svg-image-document-nested-clip-path.pngindex 1db6823dff7..7ea0ed67af6 100644Binary files a/Tests/LibWeb/Screenshot/expected/svg-image-document-nested-clip-path.png and b/Tests/LibWeb/Screenshot/expected/svg-image-document-nested-clip-path.png differdiff --git a/Tests/LibWeb/Screenshot/expected/video-object-fit.png b/Tests/LibWeb/Screenshot/expected/video-object-fit.pngindex 0a7977e357c..110995eaa04 100644Binary files a/Tests/LibWeb/Screenshot/expected/video-object-fit.png and b/Tests/LibWeb/Screenshot/expected/video-object-fit.png differdiff --git a/Tests/LibWeb/Text/expected/css/flex-wrap-fractional-item-widths.txt b/Tests/LibWeb/Text/expected/css/flex-wrap-fractional-item-widths.txtnew file mode 100644index 00000000000..ca37b9a36bb--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/flex-wrap-fractional-item-widths.txt@@ -0,0 +1,8 @@+row length: container=133.328125; items=66.65625,66.65625; same-line=true+row calculation: container=133.328125; items=66.65625,66.65625; same-line=true+row percentage: container=133.328125; items=66.65625,66.65625; same-line=true+row overflow: container=133.328125; items=66.671875,66.671875; same-line=false+column length: container=133.328125; items=66.65625,66.65625; same-line=true+column calculation: container=133.328125; items=66.65625,66.65625; same-line=true+column percentage: container=133.328125; items=66.65625,66.65625; same-line=true+column overflow: container=133.328125; items=66.671875,66.671875; same-line=falsediff --git a/Tests/LibWeb/Text/input/css/flex-wrap-fractional-item-widths.html b/Tests/LibWeb/Text/input/css/flex-wrap-fractional-item-widths.htmlnew file mode 100644index 00000000000..35c12e2ba8a--- /dev/null+++ b/Tests/LibWeb/Text/input/css/flex-wrap-fractional-item-widths.html@@ -0,0 +1,28 @@+<!doctype html>+<script src="../include.js"></script>+<script>+ test(() => {+ for (const direction of ["row", "column"]) {+ for (const [name, containerSize, itemSize] of [+ ["length", "133.333333333333333px", "66.6666666666666666px"],+ ["calculation", "calc(400px / 3)", "calc(200px / 3)"],+ ["percentage", "133.333333333333333px", "50%"],+ ["overflow", "133.333333333333333px", "66.671875px"],+ ]) {+ const container = document.createElement("div");+ const main = direction === "row" ? "width" : "height";+ const cross = direction === "row" ? "height" : "width";+ container.style.cssText = `display:flex; flex-wrap:wrap; flex-direction:${direction}; ${main}:${containerSize}; ${cross}:100px`;+ for (let i = 0; i < 2; ++i) {+ const child = document.createElement("div");+ child.style.cssText = `${main}:${itemSize}; ${cross}:100px`;+ container.append(child);+ }+ document.body.append(container);+ const [a, b] = [...container.children].map(child => child.getBoundingClientRect());+ println(`${direction} ${name}: container=${container.getBoundingClientRect()[main]}; items=${a[main]},${b[main]}; same-line=${direction === "row" ? a.top === b.top : a.left === b.left}`);+ container.remove();+ }+ }+ });+</script>