Skip to content

Commit 8dc84bd

Browse files
committed
Repeating background-image sized to the content-box fails to fill the viewport in an iframe
https://bugs.webkit.org/show_bug.cgi?id=278166 rdar://133952319 Reviewed by Alan Baradlay. 283482@main fixed background-clip to not apply to the root. This should have fixed the behavior seen in https://codepen.io/thebabydino/pen/GRbOXZp where WebKit failed to tile the gradient image, however 282712@main introduced a regression; it conflated `background-clip` and `background-origin` when passing the the `m_overrideClip` value to `calculateBackgroundImageGeometry()`, which caused us to use the border-box as the background-origin at the root. Fix by separating m_overrideClip from m_overrideOrigin in BackgroundPainter; the table code has to set both. * LayoutTests/fast/backgrounds/background-clip-on-root-expected.html: Added. * LayoutTests/fast/backgrounds/background-clip-on-root.html: Added. * Source/WebCore/rendering/BackgroundPainter.cpp: (WebCore::BackgroundPainter::paintFillLayer const): * Source/WebCore/rendering/BackgroundPainter.h: (WebCore::BackgroundPainter::setOverrideOrigin): * Source/WebCore/rendering/RenderTableCell.cpp: (WebCore::RenderTableCell::paintBackgroundsBehindCell): Canonical link: https://commits.webkit.org/284165@main
1 parent 6e02a5c commit 8dc84bd

File tree

5 files changed

+53
-2
lines changed

5 files changed

+53
-2
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<style>
5+
.box {
6+
width: 700px;
7+
height: 500px;
8+
padding: 100px;
9+
box-sizing: border-box;
10+
background-image: url('../images/resources/red-green-blue-900-300.png');
11+
background-size: contain;
12+
background-origin: content-box;
13+
}
14+
</style>
15+
</head>
16+
<body>
17+
<div class="box"></div>
18+
</body>
19+
</html>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<style>
5+
iframe {
6+
border: none;
7+
width: 700px;
8+
height: 500px;
9+
background-color: white;
10+
}
11+
</style>
12+
</head>
13+
<body>
14+
<iframe srcdoc="
15+
<style>
16+
html {
17+
height: 100%;
18+
padding: 100px;
19+
background-image: url('../images/resources/red-green-blue-900-300.png');
20+
background-size: contain;
21+
background-clip: content-box;
22+
background-origin: content-box;
23+
box-sizing: border-box;
24+
}
25+
</style>
26+
"></iframe>
27+
</body>
28+
</html>

Source/WebCore/rendering/BackgroundPainter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ void BackgroundPainter::paintFillLayer(const Color& color, const FillLayer& bgLa
442442
// Multiline inline boxes paint like the image was one long strip spanning lines. The backgroundImageStrip is this fictional rectangle.
443443
auto imageRect = backgroundImageStrip.isEmpty() ? scrolledPaintRect : backgroundImageStrip;
444444
auto paintOffset = backgroundImageStrip.isEmpty() ? rect.location() : backgroundImageStrip.location();
445-
auto geometry = calculateBackgroundImageGeometry(m_renderer, m_paintInfo.paintContainer, bgLayer, paintOffset, imageRect, m_overrideClip);
445+
auto geometry = calculateBackgroundImageGeometry(m_renderer, m_paintInfo.paintContainer, bgLayer, paintOffset, imageRect, m_overrideOrigin);
446446

447447
auto& clientForBackgroundImage = backgroundObject ? *backgroundObject : m_renderer;
448448
bgImage->setContainerContextForRenderer(clientForBackgroundImage, geometry.tileSizeWithoutPixelSnapping, m_renderer.style().usedZoom());

Source/WebCore/rendering/BackgroundPainter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class BackgroundPainter {
6060
BackgroundPainter(RenderBoxModelObject&, const PaintInfo&);
6161

6262
void setOverrideClip(FillBox overrideClip) { m_overrideClip = overrideClip; }
63+
void setOverrideOrigin(FillBox overrideOrigin) { m_overrideOrigin = overrideOrigin; }
6364

6465
void paintBackground(const LayoutRect&, BackgroundBleedAvoidance) const;
6566

@@ -84,6 +85,7 @@ class BackgroundPainter {
8485
RenderBoxModelObject& m_renderer;
8586
const PaintInfo& m_paintInfo;
8687
std::optional<FillBox> m_overrideClip;
88+
std::optional<FillBox> m_overrideOrigin;
8789
};
8890

8991
}

Source/WebCore/rendering/RenderTableCell.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1429,8 +1429,10 @@ void RenderTableCell::paintBackgroundsBehindCell(PaintInfo& paintInfo, LayoutPoi
14291429
fillRect = LayoutRect { adjustedPaintOffset, size() };
14301430
auto compositeOp = document().compositeOperatorForBackgroundColor(color, *this);
14311431
BackgroundPainter painter { *this, paintInfo };
1432-
if (backgroundObject != this)
1432+
if (backgroundObject != this) {
14331433
painter.setOverrideClip(FillBox::BorderBox);
1434+
painter.setOverrideOrigin(FillBox::BorderBox);
1435+
}
14341436
painter.paintFillLayers(color, bgLayer, fillRect, BackgroundBleedNone, compositeOp, backgroundObject);
14351437
}
14361438

0 commit comments

Comments
 (0)