Skip to content

Commit 6a5390c

Browse files
smfraperezdc
authored andcommitted
Fix handling of non-renderable inner rounded corners https://bugs.webkit.org/show_bug.cgi?id=278348 rdar://134291462 Reviewed by Alan Baradlay. 117367@main added some code for non-renderable inner borders, but this is really a bug in RoundedRect::adjustRadii(), which used `int` for `maxRadiusWidth` and `maxRadiusHeight` which caused the adjustment to fail to make the rect renderable for some rects (tested by fast/css/background-clip-radius-values.html). After fixing that, I could not find any layout tests that entered `BackgroundPainter::clipRoundedInnerRect()` with a non-renderable rect, but add a clause to fix up the rect if necessary. * Source/WebCore/rendering/BackgroundPainter.cpp: (WebCore::BackgroundPainter::paintFillLayer const): (WebCore::BackgroundPainter::clipRoundedInnerRect): * Source/WebCore/rendering/BackgroundPainter.h: * Source/WebCore/rendering/RenderReplaced.cpp: (WebCore::RenderReplaced::paint): * Source/WebCore/rendering/RenderWidget.cpp: (WebCore::RenderWidget::paint): Canonical link: https://commits.webkit.org/282503@main Canonical link: https://commits.webkit.org/282416.62@webkitglib/2.46
1 parent 41fc21b commit 6a5390c

File tree

5 files changed

+13
-34
lines changed

5 files changed

+13
-34
lines changed

Source/WebCore/platform/graphics/RoundedRect.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ bool RoundedRect::isRenderable() const
178178

179179
void RoundedRect::adjustRadii()
180180
{
181-
int maxRadiusWidth = std::max(m_radii.topLeft().width() + m_radii.topRight().width(), m_radii.bottomLeft().width() + m_radii.bottomRight().width());
182-
int maxRadiusHeight = std::max(m_radii.topLeft().height() + m_radii.bottomLeft().height(), m_radii.topRight().height() + m_radii.bottomRight().height());
181+
auto maxRadiusWidth = std::max(m_radii.topLeft().width() + m_radii.topRight().width(), m_radii.bottomLeft().width() + m_radii.bottomRight().width());
182+
auto maxRadiusHeight = std::max(m_radii.topLeft().height() + m_radii.bottomLeft().height(), m_radii.topRight().height() + m_radii.bottomRight().height());
183183

184184
if (maxRadiusWidth <= 0 || maxRadiusHeight <= 0) {
185185
m_radii.scale(0.0f);

Source/WebCore/rendering/BackgroundPainter.cpp

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ void BackgroundPainter::paintFillLayer(const Color& color, const FillLayer& bgLa
253253
context.setCompositeOperation(previousOperator);
254254
} else {
255255
context.save();
256-
clipRoundedInnerRect(context, pixelSnappedRect, pixelSnappedBorder);
256+
clipRoundedInnerRect(context, pixelSnappedBorder);
257257
context.fillRect(pixelSnappedBorder.rect(), bgColor, op);
258258
context.restore();
259259
}
@@ -275,7 +275,7 @@ void BackgroundPainter::paintFillLayer(const Color& color, const FillLayer& bgLa
275275
else if (bgLayer.clip() == FillBox::PaddingBox)
276276
border = style.getRoundedInnerBorderFor(border.rect(), includeLeftEdge, includeRightEdge);
277277

278-
clipRoundedInnerRect(context, pixelSnappedRect, border.pixelSnappedRoundedRectForPainting(deviceScaleFactor));
278+
clipRoundedInnerRect(context, border.pixelSnappedRoundedRectForPainting(deviceScaleFactor));
279279
}
280280

281281
LayoutUnit bLeft = includeLeftEdge ? m_renderer.borderLeft() : 0_lu;
@@ -469,37 +469,16 @@ void BackgroundPainter::paintFillLayer(const Color& color, const FillLayer& bgLa
469469
}
470470
}
471471

472-
void BackgroundPainter::clipRoundedInnerRect(GraphicsContext& context, const FloatRect& rect, const FloatRoundedRect& clipRect)
472+
void BackgroundPainter::clipRoundedInnerRect(GraphicsContext& context, const FloatRoundedRect& clipRect)
473473
{
474-
if (clipRect.isRenderable()) {
475-
context.clipRoundedRect(clipRect);
474+
if (UNLIKELY(!clipRect.isRenderable())) {
475+
auto adjustedClipRect = clipRect;
476+
adjustedClipRect.adjustRadii();
477+
context.clipRoundedRect(adjustedClipRect);
476478
return;
477479
}
478480

479-
// We create a rounded rect for each of the corners and clip it, while making sure we clip opposing corners together.
480-
if (!clipRect.radii().topLeft().isEmpty() || !clipRect.radii().bottomRight().isEmpty()) {
481-
FloatRect topCorner(clipRect.rect().x(), clipRect.rect().y(), rect.maxX() - clipRect.rect().x(), rect.maxY() - clipRect.rect().y());
482-
FloatRoundedRect::Radii topCornerRadii;
483-
topCornerRadii.setTopLeft(clipRect.radii().topLeft());
484-
context.clipRoundedRect(FloatRoundedRect(topCorner, topCornerRadii));
485-
486-
FloatRect bottomCorner(rect.x(), rect.y(), clipRect.rect().maxX() - rect.x(), clipRect.rect().maxY() - rect.y());
487-
FloatRoundedRect::Radii bottomCornerRadii;
488-
bottomCornerRadii.setBottomRight(clipRect.radii().bottomRight());
489-
context.clipRoundedRect(FloatRoundedRect(bottomCorner, bottomCornerRadii));
490-
}
491-
492-
if (!clipRect.radii().topRight().isEmpty() || !clipRect.radii().bottomLeft().isEmpty()) {
493-
FloatRect topCorner(rect.x(), clipRect.rect().y(), clipRect.rect().maxX() - rect.x(), rect.maxY() - clipRect.rect().y());
494-
FloatRoundedRect::Radii topCornerRadii;
495-
topCornerRadii.setTopRight(clipRect.radii().topRight());
496-
context.clipRoundedRect(FloatRoundedRect(topCorner, topCornerRadii));
497-
498-
FloatRect bottomCorner(clipRect.rect().x(), rect.y(), rect.maxX() - clipRect.rect().x(), clipRect.rect().maxY() - rect.y());
499-
FloatRoundedRect::Radii bottomCornerRadii;
500-
bottomCornerRadii.setBottomLeft(clipRect.radii().bottomLeft());
501-
context.clipRoundedRect(FloatRoundedRect(bottomCorner, bottomCornerRadii));
502-
}
481+
context.clipRoundedRect(clipRect);
503482
}
504483

505484
RoundedRect BackgroundPainter::backgroundRoundedRectAdjustedForBleedAvoidance(const LayoutRect& borderRect, BackgroundBleedAvoidance bleedAvoidance, const InlineIterator::InlineBoxIterator& inlineBoxIterator, bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const

Source/WebCore/rendering/BackgroundPainter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class BackgroundPainter {
6868

6969
static bool paintsOwnBackground(const RenderBoxModelObject&);
7070
static BackgroundImageGeometry calculateBackgroundImageGeometry(const RenderBoxModelObject&, const RenderLayerModelObject* paintContainer, const FillLayer&, const LayoutPoint& paintOffset, const LayoutRect& borderBoxRect);
71-
static void clipRoundedInnerRect(GraphicsContext&, const FloatRect&, const FloatRoundedRect& clipRect);
71+
static void clipRoundedInnerRect(GraphicsContext&, const FloatRoundedRect& clipRect);
7272
static bool boxShadowShouldBeAppliedToBackground(const RenderBoxModelObject&, const LayoutPoint& paintOffset, BackgroundBleedAvoidance, const InlineIterator::InlineBoxIterator&);
7373

7474
private:

Source/WebCore/rendering/RenderReplaced.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ void RenderReplaced::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
304304
// Push a clip if we have a border radius, since we want to round the foreground content that gets painted.
305305
paintInfo.context().save();
306306
auto pixelSnappedRoundedRect = roundedContentBoxRect(paintRect).pixelSnappedRoundedRectForPainting(document().deviceScaleFactor());
307-
BackgroundPainter::clipRoundedInnerRect(paintInfo.context(), paintRect, pixelSnappedRoundedRect);
307+
BackgroundPainter::clipRoundedInnerRect(paintInfo.context(), pixelSnappedRoundedRect);
308308
}
309309
}
310310

Source/WebCore/rendering/RenderWidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ void RenderWidget::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
328328
// Push a clip if we have a border radius, since we want to round the foreground content that gets painted.
329329
paintInfo.context().save();
330330
auto roundedInnerRect = FloatRoundedRect(roundedContentBoxRect(borderRect));
331-
BackgroundPainter::clipRoundedInnerRect(paintInfo.context(), borderRect, roundedInnerRect);
331+
BackgroundPainter::clipRoundedInnerRect(paintInfo.context(), roundedInnerRect);
332332
}
333333

334334
if (m_widget && !isSkippedContentRoot())

0 commit comments

Comments
 (0)