At default zoom a 96x96 box tiled with a 32x32 image at
background-repeat: space
paints a tidy 3x3 grid with no gap. Pressing Ctrl + once (110%)
drops a row and a column: Chromium paints only 2x2 tiles and leaves a wide
white gap in the middle, even though the box-to-image ratio has not changed.
BackgroundImageGeometry::GetSpaceBetweenImageTiles() counts tiles
with (area_size / tile_size).ToInt() where area_size
is the device-pixel snapped positioning area and tile_size
is the unsnapped, zoom-scaled image size. At 110% a 32px image becomes
35.2px, which LayoutUnit::FromFloatFloor stores as 35.1875
(2253/64), and a 96px box becomes 105.6px which snaps to either 105 or 106
depending on sub-pixel offset. When snapping lands on 105,
105 / 35.1875 = 2.98 and ToInt() truncates to 2 - one
tile short of what actually fits. The caller only distinguishes > 1
from ≤ 1, so this silently drops the third tile.
Chromium at 110% browser zoom, same page both captures. Before uses main at
816b52acbd236; after is the same build with the patch below.
Same page, 110% zoom. Chromium pre-fix and WebKit2GTK 2.50.6 both drop a row
and a column; Firefox 153 is clean. Firefox's
ComputeSpacedRepeatSize divides as float (not
fixed-point LayoutUnit), so 105.6 / 35.2 lands on a clean 3.0.
Each card renders live in your browser (Rendered, requires
Ctrl + once to simulate the reporter's step) next to the
pre-fix (Before, main at 816b52acbd236) and
post-fix (After) captures. On a build with the fix,
Rendered at 110% matches After; on pre-fix
Chrome the aqua grid loses a row and a column.


| Test | Before | After |
|---|---|---|
wpt_internal/css/css-backgrounds/background-repeat-space-zoomed.html (new reftest) |
fail (reference mismatch) | pass |
web tests: external/wpt/css/css-backgrounds + fast/backgrounds + fast/borders + wpt_internal/css/css-backgrounds (984) |
all ran as expected | |
// third_party/blink/renderer/core/paint/background_image_geometry.cc
inline LayoutUnit GetSpaceBetweenImageTiles(LayoutUnit area_size,
LayoutUnit tile_size,
LayoutUnit count_area_size) {
int number_of_tiles = (count_area_size / tile_size).ToInt();
LayoutUnit space(-1);
if (number_of_tiles > 1) {
space = (area_size - number_of_tiles * tile_size).ClampNegativeToZero() /
(number_of_tiles - 1);
}
return space;
}
// Caller now passes the unsnapped positioning area for counting so a
// sub-pixel of snapping loss cannot drop a whole tile:
LayoutUnit space = GetSpaceBetweenImageTiles(
snapped_positioning_area_size.width, tile_size_.width,
unsnapped_positioning_area_size.width);
Issue 589817018 · full repro · CSS Backgrounds 3 - the background-repeat property