Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(680)

Side by Side Diff: third_party/WebKit/Source/core/paint/BoxPainter.cpp

Issue 2196583002: Paint local background colors onto foreground layer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename PaintLayer::shouldPaintBackgroundOntoForeground to PaintLayer::shouldPaintBackgroundOntoScro… Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/paint/BoxPainter.h" 5 #include "core/paint/BoxPainter.h"
6 6
7 #include "core/HTMLNames.h" 7 #include "core/HTMLNames.h"
8 #include "core/frame/Settings.h" 8 #include "core/frame/Settings.h"
9 #include "core/html/HTMLFrameOwnerElement.h" 9 #include "core/html/HTMLFrameOwnerElement.h"
10 #include "core/layout/ImageQualityController.h" 10 #include "core/layout/ImageQualityController.h"
(...skipping 17 matching lines...) Expand all
28 #include "core/paint/ThemePainter.h" 28 #include "core/paint/ThemePainter.h"
29 #include "platform/LengthFunctions.h" 29 #include "platform/LengthFunctions.h"
30 #include "platform/geometry/LayoutPoint.h" 30 #include "platform/geometry/LayoutPoint.h"
31 #include "platform/geometry/LayoutRectOutsets.h" 31 #include "platform/geometry/LayoutRectOutsets.h"
32 #include "platform/graphics/GraphicsContextStateSaver.h" 32 #include "platform/graphics/GraphicsContextStateSaver.h"
33 #include "platform/graphics/paint/CompositingDisplayItem.h" 33 #include "platform/graphics/paint/CompositingDisplayItem.h"
34 #include "wtf/Optional.h" 34 #include "wtf/Optional.h"
35 35
36 namespace blink { 36 namespace blink {
37 37
38 namespace {
39
40 bool isPaintingScrollingContentsLayerBackground(const LayoutBoxModelObject* obj, const PaintInfo& paintInfo)
chrishtr 2016/08/05 00:40:08 isPaintingBackgroundOfPaintContainerIntoScrollingC
flackr 2016/08/08 18:01:30 Done.
41 {
42 return paintInfo.paintFlags() & PaintLayerPaintingOverflowContents
43 && obj == paintInfo.paintContainer();
44 }
45
46 } // namespace
47
38 void BoxPainter::paint(const PaintInfo& paintInfo, const LayoutPoint& paintOffse t) 48 void BoxPainter::paint(const PaintInfo& paintInfo, const LayoutPoint& paintOffse t)
39 { 49 {
40 LayoutPoint adjustedPaintOffset = paintOffset + m_layoutBox.location(); 50 LayoutPoint adjustedPaintOffset = paintOffset + m_layoutBox.location();
41 // Default implementation. Just pass paint through to the children. 51 // Default implementation. Just pass paint through to the children.
42 PaintInfo childInfo(paintInfo); 52 PaintInfo childInfo(paintInfo);
43 for (LayoutObject* child = m_layoutBox.slowFirstChild(); child; child = chil d->nextSibling()) 53 for (LayoutObject* child = m_layoutBox.slowFirstChild(); child; child = chil d->nextSibling())
44 child->paint(childInfo, adjustedPaintOffset); 54 child->paint(childInfo, adjustedPaintOffset);
45 } 55 }
46 56
47 void BoxPainter::paintBoxDecorationBackground(const PaintInfo& paintInfo, const LayoutPoint& paintOffset) 57 void BoxPainter::paintBoxDecorationBackground(const PaintInfo& paintInfo, const LayoutPoint& paintOffset)
48 { 58 {
49 LayoutRect paintRect = m_layoutBox.borderBoxRect(); 59 LayoutRect paintRect;
60 if (isPaintingScrollingContentsLayerBackground(&m_layoutBox, paintInfo)) {
61 // For the case where we are painting the background into the scrolling contents layer
62 // of a composited scroller we need to include the entire overflow rect.
63 paintRect = m_layoutBox.layoutOverflowRect();
64 paintRect.move(-m_layoutBox.scrolledContentOffset());
65
66 // The background painting code assumes that the borders are part of the paintRect so we
67 // expand the paintRect by the border size when painting the background into the
68 // scrolling contents layer.
69 paintRect.expandEdges(
70 LayoutUnit(m_layoutBox.borderTop()),
71 LayoutUnit(m_layoutBox.borderRight()),
72 LayoutUnit(m_layoutBox.borderBottom()),
73 LayoutUnit(m_layoutBox.borderLeft()));
74 } else {
75 paintRect = m_layoutBox.borderBoxRect();
76 }
77
50 paintRect.moveBy(paintOffset); 78 paintRect.moveBy(paintOffset);
51 paintBoxDecorationBackgroundWithRect(paintInfo, paintOffset, paintRect); 79 paintBoxDecorationBackgroundWithRect(paintInfo, paintOffset, paintRect);
52 } 80 }
53 81
54 LayoutRect BoxPainter::boundsForDrawingRecorder(const LayoutPoint& adjustedPaint Offset) 82 LayoutRect BoxPainter::boundsForDrawingRecorder(const PaintInfo& paintInfo, cons t LayoutPoint& adjustedPaintOffset)
55 { 83 {
56 LayoutRect bounds = m_layoutBox.selfVisualOverflowRect(); 84 LayoutRect bounds = isPaintingScrollingContentsLayerBackground(&m_layoutBox, paintInfo)
85 ? m_layoutBox.layoutOverflowRect()
86 : m_layoutBox.selfVisualOverflowRect();
57 bounds.moveBy(adjustedPaintOffset); 87 bounds.moveBy(adjustedPaintOffset);
58 return bounds; 88 return bounds;
59 } 89 }
60 90
61 namespace { 91 namespace {
62 92
63 bool bleedAvoidanceIsClipping(BackgroundBleedAvoidance bleedAvoidance) 93 bool bleedAvoidanceIsClipping(BackgroundBleedAvoidance bleedAvoidance)
64 { 94 {
65 return bleedAvoidance == BackgroundBleedClipOnly || bleedAvoidance == Backgr oundBleedClipLayer; 95 return bleedAvoidance == BackgroundBleedClipOnly || bleedAvoidance == Backgr oundBleedClipLayer;
66 } 96 }
67 97
68 } // anonymous namespace 98 } // anonymous namespace
69 99
70 void BoxPainter::paintBoxDecorationBackgroundWithRect(const PaintInfo& paintInfo , const LayoutPoint& paintOffset, const LayoutRect& paintRect) 100 void BoxPainter::paintBoxDecorationBackgroundWithRect(const PaintInfo& paintInfo , const LayoutPoint& paintOffset, const LayoutRect& paintRect)
71 { 101 {
102 bool paintingOverflowContents = isPaintingScrollingContentsLayerBackground(& m_layoutBox, paintInfo);
72 const ComputedStyle& style = m_layoutBox.styleRef(); 103 const ComputedStyle& style = m_layoutBox.styleRef();
73 104
74 // FIXME: For now we don't have notification on media buffered range change from media player 105 // FIXME: For now we don't have notification on media buffered range change from media player
75 // and miss paint invalidation on buffered range change. crbug.com/484288. 106 // and miss paint invalidation on buffered range change. crbug.com/484288.
76 Optional<DisplayItemCacheSkipper> cacheSkipper; 107 Optional<DisplayItemCacheSkipper> cacheSkipper;
77 if (style.appearance() == MediaSliderPart) 108 if (style.appearance() == MediaSliderPart)
78 cacheSkipper.emplace(paintInfo.context); 109 cacheSkipper.emplace(paintInfo.context);
79 110
80 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(paintInfo.contex t, m_layoutBox, DisplayItem::BoxDecorationBackground)) 111 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(paintInfo.contex t, m_layoutBox, DisplayItem::BoxDecorationBackground))
81 return; 112 return;
82 113
83 LayoutObjectDrawingRecorder recorder(paintInfo.context, m_layoutBox, Display Item::BoxDecorationBackground, boundsForDrawingRecorder(paintOffset)); 114 LayoutObjectDrawingRecorder recorder(paintInfo.context, m_layoutBox, Display Item::BoxDecorationBackground, boundsForDrawingRecorder(paintInfo, paintOffset)) ;
84 115
85 BoxDecorationData boxDecorationData(m_layoutBox); 116 BoxDecorationData boxDecorationData(m_layoutBox);
117 GraphicsContextStateSaver stateSaver(paintInfo.context, false);
86 118
87 // FIXME: Should eventually give the theme control over whether the box shad ow should paint, since controls could have 119 if (!paintingOverflowContents) {
88 // custom shadows of their own. 120 // FIXME: Should eventually give the theme control over whether the box shadow should paint, since controls could have
89 if (!m_layoutBox.boxShadowShouldBeAppliedToBackground(boxDecorationData.blee dAvoidance)) 121 // custom shadows of their own.
90 paintBoxShadow(paintInfo, paintRect, style, Normal); 122 if (!m_layoutBox.boxShadowShouldBeAppliedToBackground(boxDecorationData. bleedAvoidance)) {
123 paintBoxShadow(paintInfo, paintRect, style, Normal);
124 }
91 125
92 GraphicsContextStateSaver stateSaver(paintInfo.context, false); 126 if (bleedAvoidanceIsClipping(boxDecorationData.bleedAvoidance)) {
93 if (bleedAvoidanceIsClipping(boxDecorationData.bleedAvoidance)) { 127 stateSaver.save();
94 stateSaver.save(); 128 FloatRoundedRect border = style.getRoundedBorderFor(paintRect);
95 FloatRoundedRect border = style.getRoundedBorderFor(paintRect); 129 paintInfo.context.clipRoundedRect(border);
96 paintInfo.context.clipRoundedRect(border);
97 130
98 if (boxDecorationData.bleedAvoidance == BackgroundBleedClipLayer) 131 if (boxDecorationData.bleedAvoidance == BackgroundBleedClipLayer)
99 paintInfo.context.beginLayer(); 132 paintInfo.context.beginLayer();
133 }
100 } 134 }
101 135
102 // If we have a native theme appearance, paint that before painting our back ground. 136 // If we have a native theme appearance, paint that before painting our back ground.
103 // The theme will tell us whether or not we should also paint the CSS backgr ound. 137 // The theme will tell us whether or not we should also paint the CSS backgr ound.
104 IntRect snappedPaintRect(pixelSnappedIntRect(paintRect)); 138 IntRect snappedPaintRect(pixelSnappedIntRect(paintRect));
105 ThemePainter& themePainter = LayoutTheme::theme().painter(); 139 ThemePainter& themePainter = LayoutTheme::theme().painter();
106 bool themePainted = boxDecorationData.hasAppearance && !themePainter.paint(m _layoutBox, paintInfo, snappedPaintRect); 140 bool themePainted = boxDecorationData.hasAppearance && !themePainter.paint(m _layoutBox, paintInfo, snappedPaintRect);
107 if (!themePainted) { 141 bool shouldPaintBackground = !themePainted
142 && (!paintInfo.skipRootBackground()
143 || paintInfo.paintContainer() != &m_layoutBox);
144 if (shouldPaintBackground) {
108 paintBackground(paintInfo, paintRect, boxDecorationData.backgroundColor, boxDecorationData.bleedAvoidance); 145 paintBackground(paintInfo, paintRect, boxDecorationData.backgroundColor, boxDecorationData.bleedAvoidance);
109 146
110 if (boxDecorationData.hasAppearance) 147 if (boxDecorationData.hasAppearance)
111 themePainter.paintDecorations(m_layoutBox, paintInfo, snappedPaintRe ct); 148 themePainter.paintDecorations(m_layoutBox, paintInfo, snappedPaintRe ct);
112 } 149 }
113 paintBoxShadow(paintInfo, paintRect, style, Inset);
114 150
115 // The theme will tell us whether or not we should also paint the CSS border . 151 if (!paintingOverflowContents) {
116 if (boxDecorationData.hasBorderDecoration 152 paintBoxShadow(paintInfo, paintRect, style, Inset);
117 && (!boxDecorationData.hasAppearance || (!themePainted && LayoutTheme::t heme().painter().paintBorderOnly(m_layoutBox, paintInfo, snappedPaintRect))) 153
118 && !(m_layoutBox.isTable() && toLayoutTable(&m_layoutBox)->collapseBorde rs())) 154 // The theme will tell us whether or not we should also paint the CSS bo rder.
119 paintBorder(m_layoutBox, paintInfo, paintRect, style, boxDecorationData. bleedAvoidance); 155 if (boxDecorationData.hasBorderDecoration
156 && (!boxDecorationData.hasAppearance || (!themePainted && LayoutThem e::theme().painter().paintBorderOnly(m_layoutBox, paintInfo, snappedPaintRect)))
157 && !(m_layoutBox.isTable() && toLayoutTable(&m_layoutBox)->collapseB orders())) {
158 paintBorder(m_layoutBox, paintInfo, paintRect, style, boxDecorationD ata.bleedAvoidance);
159 }
160 }
120 161
121 if (boxDecorationData.bleedAvoidance == BackgroundBleedClipLayer) 162 if (boxDecorationData.bleedAvoidance == BackgroundBleedClipLayer)
122 paintInfo.context.endLayer(); 163 paintInfo.context.endLayer();
123 } 164 }
124 165
125 void BoxPainter::paintBackground(const PaintInfo& paintInfo, const LayoutRect& p aintRect, const Color& backgroundColor, BackgroundBleedAvoidance bleedAvoidance) 166 void BoxPainter::paintBackground(const PaintInfo& paintInfo, const LayoutRect& p aintRect, const Color& backgroundColor, BackgroundBleedAvoidance bleedAvoidance)
126 { 167 {
127 if (m_layoutBox.isDocumentElement()) 168 if (m_layoutBox.isDocumentElement())
128 return; 169 return;
129 if (m_layoutBox.backgroundStolenForBeingBody()) 170 if (m_layoutBox.backgroundStolenForBeingBody())
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 clipToBorder.emplace(obj, paintInfo, rect, border, ApplyToContext); 540 clipToBorder.emplace(obj, paintInfo, rect, border, ApplyToContext);
500 } 541 }
501 542
502 int bLeft = info.includeLeftEdge ? obj.borderLeft() : 0; 543 int bLeft = info.includeLeftEdge ? obj.borderLeft() : 0;
503 int bRight = info.includeRightEdge ? obj.borderRight() : 0; 544 int bRight = info.includeRightEdge ? obj.borderRight() : 0;
504 LayoutUnit pLeft = info.includeLeftEdge ? obj.paddingLeft() : LayoutUnit(); 545 LayoutUnit pLeft = info.includeLeftEdge ? obj.paddingLeft() : LayoutUnit();
505 LayoutUnit pRight = info.includeRightEdge ? obj.paddingRight() : LayoutUnit( ); 546 LayoutUnit pRight = info.includeRightEdge ? obj.paddingRight() : LayoutUnit( );
506 547
507 GraphicsContextStateSaver clipWithScrollingStateSaver(context, info.isClippe dWithLocalScrolling); 548 GraphicsContextStateSaver clipWithScrollingStateSaver(context, info.isClippe dWithLocalScrolling);
508 LayoutRect scrolledPaintRect = rect; 549 LayoutRect scrolledPaintRect = rect;
509 if (info.isClippedWithLocalScrolling) { 550 if (info.isClippedWithLocalScrolling && !isPaintingScrollingContentsLayerBac kground(&obj, paintInfo)) {
510 // Clip to the overflow area. 551 // Clip to the overflow area.
511 const LayoutBox& thisBox = toLayoutBox(obj); 552 const LayoutBox& thisBox = toLayoutBox(obj);
512 // TODO(chrishtr): this should be pixel-snapped. 553 // TODO(chrishtr): this should be pixel-snapped.
513 context.clip(FloatRect(thisBox.overflowClipRect(rect.location()))); 554 context.clip(FloatRect(thisBox.overflowClipRect(rect.location())));
514 555
515 // Adjust the paint rect to reflect a scrolled content box with borders at the ends. 556 // Adjust the paint rect to reflect a scrolled content box with borders at the ends.
516 IntSize offset = thisBox.scrolledContentOffset(); 557 IntSize offset = thisBox.scrolledContentOffset();
517 scrolledPaintRect.move(-offset); 558 scrolledPaintRect.move(-offset);
518 scrolledPaintRect.setWidth(bLeft + thisBox.scrollWidth() + bRight); 559 scrolledPaintRect.setWidth(bLeft + thisBox.scrollWidth() + bRight);
519 scrolledPaintRect.setHeight(thisBox.borderTop() + thisBox.scrollHeight() + thisBox.borderBottom()); 560 scrolledPaintRect.setHeight(thisBox.borderTop() + thisBox.scrollHeight() + thisBox.borderBottom());
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 } 861 }
821 } 862 }
822 863
823 bool BoxPainter::shouldForceWhiteBackgroundForPrintEconomy(const ComputedStyle& style, const Document& document) 864 bool BoxPainter::shouldForceWhiteBackgroundForPrintEconomy(const ComputedStyle& style, const Document& document)
824 { 865 {
825 return document.printing() && style.getPrintColorAdjust() == PrintColorAdjus tEconomy 866 return document.printing() && style.getPrintColorAdjust() == PrintColorAdjus tEconomy
826 && (!document.settings() || !document.settings()->shouldPrintBackgrounds ()); 867 && (!document.settings() || !document.settings()->shouldPrintBackgrounds ());
827 } 868 }
828 869
829 } // namespace blink 870 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698