Chromium Code Reviews| Index: third_party/WebKit/Source/core/paint/BoxPainter.cpp |
| diff --git a/third_party/WebKit/Source/core/paint/BoxPainter.cpp b/third_party/WebKit/Source/core/paint/BoxPainter.cpp |
| index b7e005a61ba2af7da17a4dfb21571ceabfc4df5e..20f9cec6c7439874e126d9c143066caac866e4b6 100644 |
| --- a/third_party/WebKit/Source/core/paint/BoxPainter.cpp |
| +++ b/third_party/WebKit/Source/core/paint/BoxPainter.cpp |
| @@ -46,14 +46,25 @@ void BoxPainter::paint(const PaintInfo& paintInfo, const LayoutPoint& paintOffse |
| void BoxPainter::paintBoxDecorationBackground(const PaintInfo& paintInfo, const LayoutPoint& paintOffset) |
| { |
| - LayoutRect paintRect = m_layoutBox.borderBoxRect(); |
| + LayoutRect paintRect; |
| + if ((paintInfo.paintFlags() & PaintLayerPaintingCompositingBackgroundPhase) |
| + || !m_layoutBox.scrollsOverflow()) { |
| + paintRect = m_layoutBox.borderBoxRect(); |
| + } else { |
| + // Need to include overflow when drawing into the scrolling contents layer. |
| + paintRect = m_layoutBox.layoutOverflowRect(); |
| + paintRect.move(-m_layoutBox.scrolledContentOffset()); |
| + } |
| + |
| paintRect.moveBy(paintOffset); |
| paintBoxDecorationBackgroundWithRect(paintInfo, paintOffset, paintRect); |
| } |
| -LayoutRect BoxPainter::boundsForDrawingRecorder(const LayoutPoint& adjustedPaintOffset) |
| +LayoutRect BoxPainter::boundsForDrawingRecorder(const PaintInfo& paintInfo, const LayoutPoint& adjustedPaintOffset) |
| { |
| - LayoutRect bounds = m_layoutBox.selfVisualOverflowRect(); |
| + LayoutRect bounds = paintInfo.paintFlags() & PaintLayerPaintingCompositingBackgroundPhase |
| + ? m_layoutBox.selfVisualOverflowRect() |
| + : m_layoutBox.layoutOverflowRect(); |
| bounds.moveBy(adjustedPaintOffset); |
| return bounds; |
| } |
| @@ -69,6 +80,8 @@ bool bleedAvoidanceIsClipping(BackgroundBleedAvoidance bleedAvoidance) |
| void BoxPainter::paintBoxDecorationBackgroundWithRect(const PaintInfo& paintInfo, const LayoutPoint& paintOffset, const LayoutRect& paintRect) |
| { |
| + bool paintBackgroundOnly = !(paintInfo.paintFlags() & PaintLayerPaintingCompositingBackgroundPhase) |
| + && (paintInfo.paintFlags() & PaintLayerPaintingBackgroundOntoForeground); |
| const ComputedStyle& style = m_layoutBox.styleRef(); |
| // FIXME: For now we don't have notification on media buffered range change from media player |
| @@ -80,17 +93,20 @@ void BoxPainter::paintBoxDecorationBackgroundWithRect(const PaintInfo& paintInfo |
| if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(paintInfo.context, m_layoutBox, DisplayItem::BoxDecorationBackground)) |
| return; |
| - LayoutObjectDrawingRecorder recorder(paintInfo.context, m_layoutBox, DisplayItem::BoxDecorationBackground, boundsForDrawingRecorder(paintOffset)); |
| + LayoutObjectDrawingRecorder recorder(paintInfo.context, m_layoutBox, DisplayItem::BoxDecorationBackground, boundsForDrawingRecorder(paintInfo, paintOffset)); |
| BoxDecorationData boxDecorationData(m_layoutBox); |
| // FIXME: Should eventually give the theme control over whether the box shadow should paint, since controls could have |
| // custom shadows of their own. |
| - if (!m_layoutBox.boxShadowShouldBeAppliedToBackground(boxDecorationData.bleedAvoidance)) |
| + if (!paintBackgroundOnly |
|
Stephen Chennney
2016/07/27 22:33:36
You can have 1 if and put both of the remaining bl
flackr
2016/07/28 14:39:20
Done.
|
| + && !m_layoutBox.boxShadowShouldBeAppliedToBackground(boxDecorationData.bleedAvoidance)) { |
| paintBoxShadow(paintInfo, paintRect, style, Normal); |
| + } |
| GraphicsContextStateSaver stateSaver(paintInfo.context, false); |
| - if (bleedAvoidanceIsClipping(boxDecorationData.bleedAvoidance)) { |
| + if (!paintBackgroundOnly |
|
Stephen Chennney
2016/07/27 22:33:36
i.e unify this if with the one above.
flackr
2016/07/28 14:39:20
Done.
|
| + && bleedAvoidanceIsClipping(boxDecorationData.bleedAvoidance)) { |
| stateSaver.save(); |
| FloatRoundedRect border = style.getRoundedBorderFor(paintRect); |
| paintInfo.context.clipRoundedRect(border); |
| @@ -104,19 +120,26 @@ void BoxPainter::paintBoxDecorationBackgroundWithRect(const PaintInfo& paintInfo |
| IntRect snappedPaintRect(pixelSnappedIntRect(paintRect)); |
| ThemePainter& themePainter = LayoutTheme::theme().painter(); |
| bool themePainted = boxDecorationData.hasAppearance && !themePainter.paint(m_layoutBox, paintInfo, snappedPaintRect); |
| - if (!themePainted) { |
| + bool shouldPaintBackground = !themePainted |
| + && (paintInfo.paintFlags() & PaintLayerPaintingCompositingForegroundPhase |
| + || !(paintInfo.paintFlags() & PaintLayerPaintingBackgroundOntoForeground)); |
| + if (shouldPaintBackground) { |
| paintBackground(paintInfo, paintRect, boxDecorationData.backgroundColor, boxDecorationData.bleedAvoidance); |
| if (boxDecorationData.hasAppearance) |
| themePainter.paintDecorations(m_layoutBox, paintInfo, snappedPaintRect); |
| } |
| - paintBoxShadow(paintInfo, paintRect, style, Inset); |
| + |
| + if (!paintBackgroundOnly) |
|
Stephen Chennney
2016/07/27 22:33:36
And here too.
flackr
2016/07/28 14:39:20
Done.
|
| + paintBoxShadow(paintInfo, paintRect, style, Inset); |
| // The theme will tell us whether or not we should also paint the CSS border. |
| - if (boxDecorationData.hasBorderDecoration |
| + if (!paintBackgroundOnly |
| + && boxDecorationData.hasBorderDecoration |
| && (!boxDecorationData.hasAppearance || (!themePainted && LayoutTheme::theme().painter().paintBorderOnly(m_layoutBox, paintInfo, snappedPaintRect))) |
| - && !(m_layoutBox.isTable() && toLayoutTable(&m_layoutBox)->collapseBorders())) |
| + && !(m_layoutBox.isTable() && toLayoutTable(&m_layoutBox)->collapseBorders())) { |
| paintBorder(m_layoutBox, paintInfo, paintRect, style, boxDecorationData.bleedAvoidance); |
| + } |
| if (boxDecorationData.bleedAvoidance == BackgroundBleedClipLayer) |
| paintInfo.context.endLayer(); |
| @@ -477,6 +500,7 @@ void BoxPainter::paintFillLayer(const LayoutBoxModelObject& obj, const PaintInfo |
| return; |
| } |
| + bool avoidBorder = paintInfo.paintFlags() & PaintLayerPaintingCompositingBackgroundPhase; |
| Optional<RoundedInnerRectClipper> clipToBorder; |
| if (info.isRoundedFill) { |
| FloatRoundedRect border = info.isBorderFill |
| @@ -487,10 +511,10 @@ void BoxPainter::paintFillLayer(const LayoutBoxModelObject& obj, const PaintInfo |
| if (bgLayer.clip() == ContentFillBox) { |
| border = obj.style()->getRoundedInnerBorderFor(LayoutRect(border.rect()), |
| LayoutRectOutsets( |
| - -(obj.paddingTop() + obj.borderTop()), |
| - -(obj.paddingRight() + obj.borderRight()), |
| - -(obj.paddingBottom() + obj.borderBottom()), |
| - -(obj.paddingLeft() + obj.borderLeft())), |
| + -(obj.paddingTop() + (avoidBorder ? obj.borderTop() : 0)), |
| + -(obj.paddingRight() + (avoidBorder ? obj.borderRight() : 0)), |
| + -(obj.paddingBottom() + (avoidBorder ? obj.borderBottom() : 0)), |
| + -(obj.paddingLeft() + (avoidBorder ? obj.borderLeft() : 0))), |
| info.includeLeftEdge, info.includeRightEdge); |
| } else if (bgLayer.clip() == PaddingFillBox) { |
| border = obj.style()->getRoundedInnerBorderFor(LayoutRect(border.rect()), info.includeLeftEdge, info.includeRightEdge); |
| @@ -499,14 +523,14 @@ void BoxPainter::paintFillLayer(const LayoutBoxModelObject& obj, const PaintInfo |
| clipToBorder.emplace(obj, paintInfo, rect, border, ApplyToContext); |
| } |
| - int bLeft = info.includeLeftEdge ? obj.borderLeft() : 0; |
| - int bRight = info.includeRightEdge ? obj.borderRight() : 0; |
| + int bLeft = info.includeLeftEdge && avoidBorder ? obj.borderLeft() : 0; |
| + int bRight = info.includeRightEdge && avoidBorder ? obj.borderRight() : 0; |
| LayoutUnit pLeft = info.includeLeftEdge ? obj.paddingLeft() : LayoutUnit(); |
| LayoutUnit pRight = info.includeRightEdge ? obj.paddingRight() : LayoutUnit(); |
| GraphicsContextStateSaver clipWithScrollingStateSaver(context, info.isClippedWithLocalScrolling); |
| LayoutRect scrolledPaintRect = rect; |
| - if (info.isClippedWithLocalScrolling) { |
| + if (info.isClippedWithLocalScrolling && paintInfo.paintFlags() & PaintLayerPaintingCompositingBackgroundPhase) { |
| // Clip to the overflow area. |
| const LayoutBox& thisBox = toLayoutBox(obj); |
| // TODO(chrishtr): this should be pixel-snapped. |
| @@ -516,7 +540,7 @@ void BoxPainter::paintFillLayer(const LayoutBoxModelObject& obj, const PaintInfo |
| IntSize offset = thisBox.scrolledContentOffset(); |
| scrolledPaintRect.move(-offset); |
| scrolledPaintRect.setWidth(bLeft + thisBox.scrollWidth() + bRight); |
| - scrolledPaintRect.setHeight(thisBox.borderTop() + thisBox.scrollHeight() + thisBox.borderBottom()); |
| + scrolledPaintRect.setHeight((avoidBorder ? thisBox.borderTop() : 0) + thisBox.scrollHeight() + (avoidBorder ? thisBox.borderBottom() : 0)); |
| } |
| GraphicsContextStateSaver backgroundClipStateSaver(context, false); |
| @@ -531,9 +555,9 @@ void BoxPainter::paintFillLayer(const LayoutBoxModelObject& obj, const PaintInfo |
| // Clip to the padding or content boxes as necessary. |
| bool includePadding = bgLayer.clip() == ContentFillBox; |
| LayoutRect clipRect(scrolledPaintRect.x() + bLeft + (includePadding ? pLeft : LayoutUnit()), |
| - scrolledPaintRect.y() + obj.borderTop() + (includePadding ? obj.paddingTop() : LayoutUnit()), |
| + scrolledPaintRect.y() + (avoidBorder ? obj.borderTop() : 0) + (includePadding ? obj.paddingTop() : LayoutUnit()), |
| scrolledPaintRect.width() - bLeft - bRight - (includePadding ? pLeft + pRight : LayoutUnit()), |
| - scrolledPaintRect.height() - obj.borderTop() - obj.borderBottom() - (includePadding ? obj.paddingTop() + obj.paddingBottom() : LayoutUnit())); |
| + scrolledPaintRect.height() - (avoidBorder ? obj.borderTop() + obj.borderBottom() : 0) - (includePadding ? obj.paddingTop() + obj.paddingBottom() : LayoutUnit())); |
| backgroundClipStateSaver.save(); |
| // TODO(chrishtr): this should be pixel-snapped. |
| context.clip(FloatRect(clipRect)); |
| @@ -575,7 +599,7 @@ void BoxPainter::paintFillLayer(const LayoutBoxModelObject& obj, const PaintInfo |
| if (info.shouldPaintImage) { |
| if (!geometry) { |
| geometry.emplace(); |
| - geometry->calculate(obj, paintInfo.paintContainer(), paintInfo.getGlobalPaintFlags(), bgLayer, scrolledPaintRect); |
| + geometry->calculate(obj, paintInfo.paintContainer(), paintInfo.getGlobalPaintFlags(), bgLayer, scrolledPaintRect, paintInfo.paintFlags() & PaintLayerPaintingCompositingBackgroundPhase); |
| } else { |
| // The geometry was calculated in paintFastBottomLayer(). |
| DCHECK(info.isBottomLayer && info.isBorderFill && !info.isClippedWithLocalScrolling); |