Truly independent web browser
LibWeb: Enclose fractional far edges when clipping backgrounds
sideshowbarker28da275a4adc
diff --git a/Libraries/LibCompositing/Rust/src/display_list/device_pixels.rs b/Libraries/LibCompositing/Rust/src/display_list/device_pixels.rsindex 0d25579a102..9ebac278068 100644--- a/Libraries/LibCompositing/Rust/src/display_list/device_pixels.rs+++ b/Libraries/LibCompositing/Rust/src/display_list/device_pixels.rs@@ -50,11 +50,21 @@ impl DevicePixelConverter {pub fn enclosing_device_rect(&self, rect: CssPixelRect) -> IntRect {let scale = self.device_pixels_per_css_pixel;+ let x = (rect.x.to_double() * scale).floor();+ let y = (rect.y.to_double() * scale).floor();IntRect {- x: to_device_pixels((rect.x.to_double() * scale).floor()),- y: to_device_pixels((rect.y.to_double() * scale).floor()),- width: to_device_pixels((rect.width.to_double() * scale).ceil()),- height: to_device_pixels((rect.height.to_double() * scale).ceil()),+ x: to_device_pixels(x),+ y: to_device_pixels(y),+ width: if rect.width > CssPixels::default() {+ to_device_pixels(((rect.x.to_double() + rect.width.to_double()) * scale).ceil() - x)+ } else {+ 0+ },+ height: if rect.height > CssPixels::default() {+ to_device_pixels(((rect.y.to_double() + rect.height.to_double()) * scale).ceil() - y)+ } else {+ 0+ },}}@@ -77,3 +87,30 @@ impl DevicePixelConverter {}}}++#[cfg(test)]+mod tests {+ use super::*;++ #[test]+ fn enclosing_rect_covers_fractional_far_edges() {+ for (scale, x, y, width, height, expected) in [+ (1.0, 0.75, 0.75, 200.0, 200.0, IntRect::new(0, 0, 201, 201)),+ (1.0, -0.25, -0.25, 200.0, 200.0, IntRect::new(-1, -1, 201, 201)),+ (2.0, 0.75, 0.75, 200.0, 200.0, IntRect::new(1, 1, 401, 401)),+ (1.5, 0.5, 0.5, 10.0, 20.0, IntRect::new(0, 0, 16, 31)),+ (1.0, 10.0, 20.0, 200.0, 100.0, IntRect::new(10, 20, 200, 100)),+ (1.0, 0.75, 0.75, 0.0, 0.0, IntRect::new(0, 0, 0, 0)),+ (1.0, 0.75, 0.75, 0.0, 200.0, IntRect::new(0, 0, 0, 201)),+ (1.0, 0.75, 0.75, -0.25, 200.0, IntRect::new(0, 0, 0, 201)),+ ] {+ let rect = CssPixelRect::new(+ CssPixels::nearest_value_for(x),+ CssPixels::nearest_value_for(y),+ CssPixels::nearest_value_for(width),+ CssPixels::nearest_value_for(height),+ );+ assert_eq!(DevicePixelConverter::new(scale).enclosing_device_rect(rect), expected);+ }+ }+}diff --git a/Libraries/LibWeb/Rust/src/painting/record/paint/form_controls.rs b/Libraries/LibWeb/Rust/src/painting/record/paint/form_controls.rsindex 73dd9d5f7a5..d12f96c906d 100644--- a/Libraries/LibWeb/Rust/src/painting/record/paint/form_controls.rs+++ b/Libraries/LibWeb/Rust/src/painting/record/paint/form_controls.rs@@ -102,8 +102,13 @@ fn centered_square_device_rect<O: Observer>() -> IntRect {let center_x = outer_rect.x + outer_rect.width / 2usize;let center_y = outer_rect.y + outer_rect.height / 2usize;- let rect = CssPixelRect::new(center_x - size / 2usize, center_y - size / 2usize, size, size);- recorder.converter.enclosing_device_rect(rect)+ let device_size = recorder.converter.enclosing_device_pixels(size);+ IntRect::new(+ recorder.converter.floored_device_pixels(center_x - size / 2usize),+ recorder.converter.floored_device_pixels(center_y - size / 2usize),+ device_size,+ device_size,+ )}fn check_mark_path(checkbox_rect: IntRect) -> Path {diff --git a/Tests/LibWeb/Ref/expected/background-attachment-local-fractional-far-edge-ref.html b/Tests/LibWeb/Ref/expected/background-attachment-local-fractional-far-edge-ref.htmlnew file mode 100644index 00000000000..c82c84ec20a--- /dev/null+++ b/Tests/LibWeb/Ref/expected/background-attachment-local-fractional-far-edge-ref.html@@ -0,0 +1,13 @@+<!doctype html>+<style>+body { margin: 0; }+div { position: absolute; width: 100px; height: 100px; background: green; }+.both { left: 10.75px; top: 10.75px; }+.horizontal { left: 130.75px; top: 10px; }+.vertical { left: 250px; top: 10.75px; }+.negative { left: -0.25px; top: 130.75px; }+</style>+<div class="both"></div>+<div class="horizontal"></div>+<div class="vertical"></div>+<div class="negative"></div>diff --git a/Tests/LibWeb/Ref/input/background-attachment-local-fractional-far-edge.html b/Tests/LibWeb/Ref/input/background-attachment-local-fractional-far-edge.htmlnew file mode 100644index 00000000000..92446b3e7bc--- /dev/null+++ b/Tests/LibWeb/Ref/input/background-attachment-local-fractional-far-edge.html@@ -0,0 +1,27 @@+<!doctype html>+<link rel="match" href="../expected/background-attachment-local-fractional-far-edge-ref.html">+<style>+body { margin: 0; }+.scroller {+ position: absolute;+ width: 100px;+ height: 100px;+ overflow: hidden;+ background: linear-gradient(green, green) 0 0 / 4px 4px local;+}+.scroller > div { width: 200px; height: 200px; }+.both { left: 10.75px; top: 10.75px; }+.horizontal { left: 130.75px; top: 10px; }+.vertical { left: 250px; top: 10.75px; }+.negative { left: -0.25px; top: 130.75px; }+</style>+<div class="scroller both"><div></div></div>+<div class="scroller horizontal"><div></div></div>+<div class="scroller vertical"><div></div></div>+<div class="scroller negative"><div></div></div>+<script>+for (const scroller of document.querySelectorAll(".scroller")) {+ scroller.scrollLeft = scroller.scrollWidth;+ scroller.scrollTop = scroller.scrollHeight;+}+</script>diff --git a/Tests/LibWeb/Screenshot/expected/svg-maskContentUnits.png b/Tests/LibWeb/Screenshot/expected/svg-maskContentUnits.pngindex a6a8edac408..9f5fcc8c93d 100644Binary files a/Tests/LibWeb/Screenshot/expected/svg-maskContentUnits.png and b/Tests/LibWeb/Screenshot/expected/svg-maskContentUnits.png differdiff --git a/Tests/LibWeb/Text/expected/css/text-underline-position.txt b/Tests/LibWeb/Text/expected/css/text-underline-position.txtindex 854e6813eec..64f5ce77d10 100644--- a/Tests/LibWeb/Text/expected/css/text-underline-position.txt+++ b/Tests/LibWeb/Text/expected/css/text-underline-position.txt@@ -8,7 +8,7 @@ AccumulatedVisualContext Tree:DisplayList:DrawGlyphRun@s1/e0 rect=[8,8 28x16] translation=[8,21] color=rgb(0, 0, 0)DrawLine@s1/e0 from=[8,24] to=[35,24] color=rgb(0, 0, 0) thickness=2 style=Solid-DrawGlyphRun@s1/e0 rect=[35,8 8x16] translation=[35.15625,21] color=rgb(0, 0, 0)+DrawGlyphRun@s1/e0 rect=[35,8 9x16] translation=[35.15625,21] color=rgb(0, 0, 0)DrawGlyphRun@s1/e0 rect=[43,8 28x16] translation=[43.15625,21] color=rgb(0, 0, 0)DrawLine@s1/e0 from=[43,27] to=[71,27] color=rgb(0, 0, 0) thickness=2 style=Soliddiff --git a/Tests/LibWeb/Text/expected/display_list/color-and-file-input-appearance.txt b/Tests/LibWeb/Text/expected/display_list/color-and-file-input-appearance.txtindex 9566f038011..1ab220bb5fc 100644--- a/Tests/LibWeb/Text/expected/display_list/color-and-file-input-appearance.txt+++ b/Tests/LibWeb/Text/expected/display_list/color-and-file-input-appearance.txt@@ -17,5 +17,5 @@ DrawGlyphRun@s1/e0 rect=[58,16 8x16] translation=[58,29] color=rgb(0, 0, 0)FillRectWithRoundedCorners@s1/c1/e0 rect=[66,15 97x20] color=rgb(239, 239, 239)FillRoundedRectRing@s1/c1/e0 rect=[66,15 97x20] corner_radii=[4x4,4x4,4x4,4x4] widths=[1,1,1,1] color=rgb(118, 118, 118)DrawGlyphRun@s1/c1/e0 rect=[75,18 79x14] translation=[75,29] color=rgb(0, 0, 0)-DrawGlyphRun@s1/c1/e0 rect=[166,18 107x14] translation=[166.65625,29] color=rgb(0, 0, 0)+DrawGlyphRun@s1/c1/e0 rect=[166,18 108x14] translation=[166.65625,29] color=rgb(0, 0, 0)diff --git a/Tests/LibWeb/Text/expected/display_list/fieldset-background-with-legend.txt b/Tests/LibWeb/Text/expected/display_list/fieldset-background-with-legend.txtindex 20b51d1f238..c4cc6ce093b 100644--- a/Tests/LibWeb/Text/expected/display_list/fieldset-background-with-legend.txt+++ b/Tests/LibWeb/Text/expected/display_list/fieldset-background-with-legend.txt@@ -16,5 +16,5 @@ FillPath@s1/e0 path_bounding_rect=[11,56 778x1] inline_clips=[clip=[24,15 57x2]FillPath@s1/e0 path_bounding_rect=[10,15 1x43] inline_clips=[clip=[24,15 57x2] mode=difference]FillPath@s1/e0 path_bounding_rect=[11,16 1x41] inline_clips=[clip=[24,15 57x2] mode=difference]DrawGlyphRun@s1/e0 rect=[26,8 54x16] translation=[26,21] color=rgb(0, 0, 0)-DrawGlyphRun@s1/e0 rect=[24,29 63x16] translation=[24,42.59375] color=rgb(0, 0, 0)+DrawGlyphRun@s1/e0 rect=[24,29 63x17] translation=[24,42.59375] color=rgb(0, 0, 0)diff --git a/Tests/LibWeb/Text/expected/display_list/fieldset-legend-rounded-dashed-border.txt b/Tests/LibWeb/Text/expected/display_list/fieldset-legend-rounded-dashed-border.txtindex 1e8d1db33ae..63aa06f4371 100644--- a/Tests/LibWeb/Text/expected/display_list/fieldset-legend-rounded-dashed-border.txt+++ b/Tests/LibWeb/Text/expected/display_list/fieldset-legend-rounded-dashed-border.txt@@ -8,5 +8,5 @@ AccumulatedVisualContext Tree:DisplayList:StrokePath@s1/e0 path_bounding_rect=[10,15 230x44] thickness=3 color=rgb(0, 0, 255) dash_array_size=2 dash_offset=9.03 inline_clips=[clip=[25,15 57x3] mode=difference]DrawGlyphRun@s1/e0 rect=[27,8 54x16] translation=[27,21] color=rgb(0, 0, 0)-DrawGlyphRun@s1/e0 rect=[25,29 63x16] translation=[25,42.59375] color=rgb(0, 0, 0)+DrawGlyphRun@s1/e0 rect=[25,29 63x17] translation=[25,42.59375] color=rgb(0, 0, 0)diff --git a/Tests/LibWeb/Text/expected/display_list/input-focus-switch-selection-and-caret.txt b/Tests/LibWeb/Text/expected/display_list/input-focus-switch-selection-and-caret.txtindex 10cf0f77478..688f2d88f82 100644--- a/Tests/LibWeb/Text/expected/display_list/input-focus-switch-selection-and-caret.txt+++ b/Tests/LibWeb/Text/expected/display_list/input-focus-switch-selection-and-caret.txt@@ -14,7 +14,7 @@ DisplayList:FillRectWithRoundedCorners@s1/e0 rect=[8,8 170x20] color=rgb(255, 255, 255)FillRoundedRectRing@s1/e0 rect=[8,8 170x20] corner_radii=[4x4,4x4,4x4,4x4] widths=[1,1,1,1] color=rgb(118, 118, 118)DrawGlyphRun@s1/c1/e0 rect=[13,11 23x14] translation=[13,22] color=rgb(0, 0, 0)-DrawGlyphRun@s1/e0 rect=[177,9 8x16] translation=[177.6875,22] color=rgb(0, 0, 0)+DrawGlyphRun@s1/e0 rect=[177,9 9x16] translation=[177.6875,22] color=rgb(0, 0, 0)FillRectWithRoundedCorners@s1/e0 rect=[186,8 169x20] color=rgb(255, 255, 255)FillRoundedRectRing@s1/e0 rect=[186,8 169x20] corner_radii=[4x4,4x4,4x4,4x4] widths=[1,1,1,1] color=rgb(118, 118, 118)DrawGlyphRun@s1/c3/e0 rect=[190,11 24x14] translation=[190.6875,22] color=rgb(0, 0, 0)diff --git a/Tests/LibWeb/Text/expected/display_list/sibling-scrollables-in-fixed.txt b/Tests/LibWeb/Text/expected/display_list/sibling-scrollables-in-fixed.txtindex 6279bdce093..6364e787731 100644--- a/Tests/LibWeb/Text/expected/display_list/sibling-scrollables-in-fixed.txt+++ b/Tests/LibWeb/Text/expected/display_list/sibling-scrollables-in-fixed.txt@@ -36,7 +36,7 @@ CompositorWheelHitTestTarget@s0/e0 target_scroll_node_index=s3 rect=[125.328125,FillRoundedRectRing@s0/e0 rect=[125,22 94x152] widths=[1,1,1,1] color=rgb(0, 0, 255)CompositorWheelHitTestTarget@s3/c1/e0 target_scroll_node_index=s3 rect=[126.328125,23 200x300]FillRect@s3/c1/e0 rect=[126,23 200x300] color=rgb(144, 238, 144)-DrawGlyphRun@s3/c1/e0 rect=[126,23 66x16] translation=[126.328125,36] color=rgb(0, 0, 0)+DrawGlyphRun@s3/c1/e0 rect=[126,23 67x16] translation=[126.328125,36] color=rgb(0, 0, 0)CompositorScrollbar@s0/e0 scroll_node_index=s3 gutter_rect=[0,0 0x0] thumb_rect=[209,25 7x73] track_rect=[209,23 9x150] expanded_gutter_rect=[203,23 15x150] expanded_thumb_rect=[205,25 11x73] scroll_size=0.4866666666666667 expanded_scroll_size=0.4866666666666667 min_scroll_offset=0 max_scroll_offset=150 thumb_color=rgba(0, 0, 0, 0.5) thumb_outline_color=rgba(255, 255, 255, 0.25) track_color=rgba(0, 0, 0, 0.098) vertical=true is_painted_by_compositor=falsePaintScrollBar@s0/e0CompositorScrollbar@s0/e0 scroll_node_index=s3 gutter_rect=[0,0 0x0] thumb_rect=[128,164 33x7] track_rect=[126,164 77x9] expanded_gutter_rect=[126,158 77x15] expanded_thumb_rect=[128,160 33x11] scroll_size=0.36180615473109 expanded_scroll_size=0.36180615473109 min_scroll_offset=0 max_scroll_offset=108.65625 thumb_color=rgba(0, 0, 0, 0.5) thumb_outline_color=rgba(255, 255, 255, 0.25) track_color=rgba(0, 0, 0, 0.098) vertical=false is_painted_by_compositor=false@@ -45,7 +45,7 @@ CompositorWheelHitTestTarget@s0/e0 target_scroll_node_index=s4 rect=[228.67188,2FillRoundedRectRing@s0/e0 rect=[229,22 93x152] widths=[1,1,1,1] color=rgb(0, 0, 255)CompositorWheelHitTestTarget@s4/c2/e0 target_scroll_node_index=s4 rect=[229.67188,23 200x300]FillRect@s4/c2/e0 rect=[230,23 200x300] color=rgb(173, 216, 230)-DrawGlyphRun@s4/c2/e0 rect=[229,23 67x16] translation=[229.67188,36] color=rgb(0, 0, 0)+DrawGlyphRun@s4/c2/e0 rect=[229,23 68x16] translation=[229.67188,36] color=rgb(0, 0, 0)CompositorScrollbar@s0/e0 scroll_node_index=s4 gutter_rect=[0,0 0x0] thumb_rect=[312,25 7x73] track_rect=[312,23 9x150] expanded_gutter_rect=[306,23 15x150] expanded_thumb_rect=[308,25 11x73] scroll_size=0.4866666666666667 expanded_scroll_size=0.4866666666666667 min_scroll_offset=0 max_scroll_offset=150 thumb_color=rgba(0, 0, 0, 0.5) thumb_outline_color=rgba(255, 255, 255, 0.25) track_color=rgba(0, 0, 0, 0.098) vertical=true is_painted_by_compositor=falsePaintScrollBar@s0/e0CompositorScrollbar@s0/e0 scroll_node_index=s4 gutter_rect=[0,0 0x0] thumb_rect=[232,164 33x7] track_rect=[230,164 76x9] expanded_gutter_rect=[230,158 76x15] expanded_thumb_rect=[232,160 33x11] scroll_size=0.3617541337167505 expanded_scroll_size=0.3617541337167505 min_scroll_offset=0 max_scroll_offset=108.671875 thumb_color=rgba(0, 0, 0, 0.5) thumb_outline_color=rgba(255, 255, 255, 0.25) track_color=rgba(0, 0, 0, 0.098) vertical=false is_painted_by_compositor=false