OLD | NEW |
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 28 matching lines...) Expand all Loading... |
39 { | 39 { |
40 LayoutPoint adjustedPaintOffset = paintOffset + m_layoutBox.location(); | 40 LayoutPoint adjustedPaintOffset = paintOffset + m_layoutBox.location(); |
41 // Default implementation. Just pass paint through to the children. | 41 // Default implementation. Just pass paint through to the children. |
42 PaintInfo childInfo(paintInfo); | 42 PaintInfo childInfo(paintInfo); |
43 for (LayoutObject* child = m_layoutBox.slowFirstChild(); child; child = chil
d->nextSibling()) | 43 for (LayoutObject* child = m_layoutBox.slowFirstChild(); child; child = chil
d->nextSibling()) |
44 child->paint(childInfo, adjustedPaintOffset); | 44 child->paint(childInfo, adjustedPaintOffset); |
45 } | 45 } |
46 | 46 |
47 void BoxPainter::paintBoxDecorationBackground(const PaintInfo& paintInfo, const
LayoutPoint& paintOffset) | 47 void BoxPainter::paintBoxDecorationBackground(const PaintInfo& paintInfo, const
LayoutPoint& paintOffset) |
48 { | 48 { |
49 LayoutRect paintRect = m_layoutBox.borderBoxRect(); | 49 LayoutRect paintRect; |
| 50 if ((paintInfo.paintFlags() & PaintLayerPaintingCompositingBackgroundPhase) |
| 51 || !(paintInfo.paintFlags() & PaintLayerPaintingRootBackgroundOntoForegr
ound)) { |
| 52 paintRect = m_layoutBox.borderBoxRect(); |
| 53 } else { |
| 54 // Need to include overflow when drawing into the scrolling contents lay
er. |
| 55 paintRect = m_layoutBox.layoutOverflowRect(); |
| 56 paintRect.move(-m_layoutBox.scrolledContentOffset()); |
| 57 |
| 58 // The background painting code assumes that the borders are part of the
paintRect so we |
| 59 // expand the paintRect by the border size when painting the background
into the |
| 60 // scrolling contents layer. |
| 61 paintRect.expandEdges( |
| 62 LayoutUnit(m_layoutBox.borderTop()), |
| 63 LayoutUnit(m_layoutBox.borderRight()), |
| 64 LayoutUnit(m_layoutBox.borderBottom()), |
| 65 LayoutUnit(m_layoutBox.borderLeft())); |
| 66 } |
| 67 |
50 paintRect.moveBy(paintOffset); | 68 paintRect.moveBy(paintOffset); |
51 paintBoxDecorationBackgroundWithRect(paintInfo, paintOffset, paintRect); | 69 paintBoxDecorationBackgroundWithRect(paintInfo, paintOffset, paintRect); |
52 } | 70 } |
53 | 71 |
54 LayoutRect BoxPainter::boundsForDrawingRecorder(const LayoutPoint& adjustedPaint
Offset) | 72 LayoutRect BoxPainter::boundsForDrawingRecorder(const PaintInfo& paintInfo, cons
t LayoutPoint& adjustedPaintOffset) |
55 { | 73 { |
56 LayoutRect bounds = m_layoutBox.selfVisualOverflowRect(); | 74 LayoutRect bounds = |
| 75 (paintInfo.paintFlags() & PaintLayerPaintingCompositingBackgroundPhase |
| 76 || !(paintInfo.paintFlags() & PaintLayerPaintingRootBackgroundOntoFo
reground)) |
| 77 ? m_layoutBox.selfVisualOverflowRect() |
| 78 : m_layoutBox.layoutOverflowRect(); |
57 bounds.moveBy(adjustedPaintOffset); | 79 bounds.moveBy(adjustedPaintOffset); |
58 return bounds; | 80 return bounds; |
59 } | 81 } |
60 | 82 |
61 namespace { | 83 namespace { |
62 | 84 |
63 bool bleedAvoidanceIsClipping(BackgroundBleedAvoidance bleedAvoidance) | 85 bool bleedAvoidanceIsClipping(BackgroundBleedAvoidance bleedAvoidance) |
64 { | 86 { |
65 return bleedAvoidance == BackgroundBleedClipOnly || bleedAvoidance == Backgr
oundBleedClipLayer; | 87 return bleedAvoidance == BackgroundBleedClipOnly || bleedAvoidance == Backgr
oundBleedClipLayer; |
66 } | 88 } |
67 | 89 |
68 } // anonymous namespace | 90 } // anonymous namespace |
69 | 91 |
70 void BoxPainter::paintBoxDecorationBackgroundWithRect(const PaintInfo& paintInfo
, const LayoutPoint& paintOffset, const LayoutRect& paintRect) | 92 void BoxPainter::paintBoxDecorationBackgroundWithRect(const PaintInfo& paintInfo
, const LayoutPoint& paintOffset, const LayoutRect& paintRect) |
71 { | 93 { |
| 94 bool paintBackgroundOnly = !(paintInfo.paintFlags() & PaintLayerPaintingComp
ositingBackgroundPhase) |
| 95 && (paintInfo.paintFlags() & PaintLayerPaintingRootBackgroundOntoForegro
und); |
72 const ComputedStyle& style = m_layoutBox.styleRef(); | 96 const ComputedStyle& style = m_layoutBox.styleRef(); |
73 | 97 |
74 // FIXME: For now we don't have notification on media buffered range change
from media player | 98 // 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. | 99 // and miss paint invalidation on buffered range change. crbug.com/484288. |
76 Optional<DisplayItemCacheSkipper> cacheSkipper; | 100 Optional<DisplayItemCacheSkipper> cacheSkipper; |
77 if (style.appearance() == MediaSliderPart) | 101 if (style.appearance() == MediaSliderPart) |
78 cacheSkipper.emplace(paintInfo.context); | 102 cacheSkipper.emplace(paintInfo.context); |
79 | 103 |
80 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(paintInfo.contex
t, m_layoutBox, DisplayItem::BoxDecorationBackground)) | 104 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(paintInfo.contex
t, m_layoutBox, DisplayItem::BoxDecorationBackground)) |
81 return; | 105 return; |
82 | 106 |
83 LayoutObjectDrawingRecorder recorder(paintInfo.context, m_layoutBox, Display
Item::BoxDecorationBackground, boundsForDrawingRecorder(paintOffset)); | 107 LayoutObjectDrawingRecorder recorder(paintInfo.context, m_layoutBox, Display
Item::BoxDecorationBackground, boundsForDrawingRecorder(paintInfo, paintOffset))
; |
84 | 108 |
85 BoxDecorationData boxDecorationData(m_layoutBox); | 109 BoxDecorationData boxDecorationData(m_layoutBox); |
| 110 GraphicsContextStateSaver stateSaver(paintInfo.context, false); |
86 | 111 |
87 // FIXME: Should eventually give the theme control over whether the box shad
ow should paint, since controls could have | 112 if (!paintBackgroundOnly) { |
88 // custom shadows of their own. | 113 // 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)) | 114 // custom shadows of their own. |
90 paintBoxShadow(paintInfo, paintRect, style, Normal); | 115 if (!m_layoutBox.boxShadowShouldBeAppliedToBackground(boxDecorationData.
bleedAvoidance)) { |
| 116 paintBoxShadow(paintInfo, paintRect, style, Normal); |
| 117 } |
91 | 118 |
92 GraphicsContextStateSaver stateSaver(paintInfo.context, false); | 119 if (bleedAvoidanceIsClipping(boxDecorationData.bleedAvoidance)) { |
93 if (bleedAvoidanceIsClipping(boxDecorationData.bleedAvoidance)) { | 120 stateSaver.save(); |
94 stateSaver.save(); | 121 FloatRoundedRect border = style.getRoundedBorderFor(paintRect); |
95 FloatRoundedRect border = style.getRoundedBorderFor(paintRect); | 122 paintInfo.context.clipRoundedRect(border); |
96 paintInfo.context.clipRoundedRect(border); | |
97 | 123 |
98 if (boxDecorationData.bleedAvoidance == BackgroundBleedClipLayer) | 124 if (boxDecorationData.bleedAvoidance == BackgroundBleedClipLayer) |
99 paintInfo.context.beginLayer(); | 125 paintInfo.context.beginLayer(); |
| 126 } |
100 } | 127 } |
101 | 128 |
102 // If we have a native theme appearance, paint that before painting our back
ground. | 129 // 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. | 130 // The theme will tell us whether or not we should also paint the CSS backgr
ound. |
104 IntRect snappedPaintRect(pixelSnappedIntRect(paintRect)); | 131 IntRect snappedPaintRect(pixelSnappedIntRect(paintRect)); |
105 ThemePainter& themePainter = LayoutTheme::theme().painter(); | 132 ThemePainter& themePainter = LayoutTheme::theme().painter(); |
106 bool themePainted = boxDecorationData.hasAppearance && !themePainter.paint(m
_layoutBox, paintInfo, snappedPaintRect); | 133 bool themePainted = boxDecorationData.hasAppearance && !themePainter.paint(m
_layoutBox, paintInfo, snappedPaintRect); |
107 if (!themePainted) { | 134 bool shouldPaintBackground = !themePainted |
| 135 && (paintBackgroundOnly || !(paintInfo.paintFlags() & PaintLayerPainting
RootBackgroundOntoForeground)); |
| 136 if (shouldPaintBackground) { |
108 paintBackground(paintInfo, paintRect, boxDecorationData.backgroundColor,
boxDecorationData.bleedAvoidance); | 137 paintBackground(paintInfo, paintRect, boxDecorationData.backgroundColor,
boxDecorationData.bleedAvoidance); |
109 | 138 |
110 if (boxDecorationData.hasAppearance) | 139 if (boxDecorationData.hasAppearance) |
111 themePainter.paintDecorations(m_layoutBox, paintInfo, snappedPaintRe
ct); | 140 themePainter.paintDecorations(m_layoutBox, paintInfo, snappedPaintRe
ct); |
112 } | 141 } |
113 paintBoxShadow(paintInfo, paintRect, style, Inset); | |
114 | 142 |
115 // The theme will tell us whether or not we should also paint the CSS border
. | 143 if (!paintBackgroundOnly) { |
116 if (boxDecorationData.hasBorderDecoration | 144 paintBoxShadow(paintInfo, paintRect, style, Inset); |
117 && (!boxDecorationData.hasAppearance || (!themePainted && LayoutTheme::t
heme().painter().paintBorderOnly(m_layoutBox, paintInfo, snappedPaintRect))) | 145 |
118 && !(m_layoutBox.isTable() && toLayoutTable(&m_layoutBox)->collapseBorde
rs())) | 146 // 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); | 147 if (boxDecorationData.hasBorderDecoration |
| 148 && (!boxDecorationData.hasAppearance || (!themePainted && LayoutThem
e::theme().painter().paintBorderOnly(m_layoutBox, paintInfo, snappedPaintRect))) |
| 149 && !(m_layoutBox.isTable() && toLayoutTable(&m_layoutBox)->collapseB
orders())) { |
| 150 paintBorder(m_layoutBox, paintInfo, paintRect, style, boxDecorationD
ata.bleedAvoidance); |
| 151 } |
| 152 } |
120 | 153 |
121 if (boxDecorationData.bleedAvoidance == BackgroundBleedClipLayer) | 154 if (boxDecorationData.bleedAvoidance == BackgroundBleedClipLayer) |
122 paintInfo.context.endLayer(); | 155 paintInfo.context.endLayer(); |
123 } | 156 } |
124 | 157 |
125 void BoxPainter::paintBackground(const PaintInfo& paintInfo, const LayoutRect& p
aintRect, const Color& backgroundColor, BackgroundBleedAvoidance bleedAvoidance) | 158 void BoxPainter::paintBackground(const PaintInfo& paintInfo, const LayoutRect& p
aintRect, const Color& backgroundColor, BackgroundBleedAvoidance bleedAvoidance) |
126 { | 159 { |
127 if (m_layoutBox.isDocumentElement()) | 160 if (m_layoutBox.isDocumentElement()) |
128 return; | 161 return; |
129 if (m_layoutBox.backgroundStolenForBeingBody()) | 162 if (m_layoutBox.backgroundStolenForBeingBody()) |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 clipToBorder.emplace(obj, paintInfo, rect, border, ApplyToContext); | 532 clipToBorder.emplace(obj, paintInfo, rect, border, ApplyToContext); |
500 } | 533 } |
501 | 534 |
502 int bLeft = info.includeLeftEdge ? obj.borderLeft() : 0; | 535 int bLeft = info.includeLeftEdge ? obj.borderLeft() : 0; |
503 int bRight = info.includeRightEdge ? obj.borderRight() : 0; | 536 int bRight = info.includeRightEdge ? obj.borderRight() : 0; |
504 LayoutUnit pLeft = info.includeLeftEdge ? obj.paddingLeft() : LayoutUnit(); | 537 LayoutUnit pLeft = info.includeLeftEdge ? obj.paddingLeft() : LayoutUnit(); |
505 LayoutUnit pRight = info.includeRightEdge ? obj.paddingRight() : LayoutUnit(
); | 538 LayoutUnit pRight = info.includeRightEdge ? obj.paddingRight() : LayoutUnit(
); |
506 | 539 |
507 GraphicsContextStateSaver clipWithScrollingStateSaver(context, info.isClippe
dWithLocalScrolling); | 540 GraphicsContextStateSaver clipWithScrollingStateSaver(context, info.isClippe
dWithLocalScrolling); |
508 LayoutRect scrolledPaintRect = rect; | 541 LayoutRect scrolledPaintRect = rect; |
509 if (info.isClippedWithLocalScrolling) { | 542 bool isPaintingScrollingContentsLayer = !(paintInfo.paintFlags() & PaintLaye
rPaintingCompositingBackgroundPhase) |
| 543 && paintInfo.paintFlags() & PaintLayerPaintingRootBackgroundOntoForegrou
nd; |
| 544 if (info.isClippedWithLocalScrolling && !isPaintingScrollingContentsLayer) { |
510 // Clip to the overflow area. | 545 // Clip to the overflow area. |
511 const LayoutBox& thisBox = toLayoutBox(obj); | 546 const LayoutBox& thisBox = toLayoutBox(obj); |
512 // TODO(chrishtr): this should be pixel-snapped. | 547 // TODO(chrishtr): this should be pixel-snapped. |
513 context.clip(FloatRect(thisBox.overflowClipRect(rect.location()))); | 548 context.clip(FloatRect(thisBox.overflowClipRect(rect.location()))); |
514 | 549 |
515 // Adjust the paint rect to reflect a scrolled content box with borders
at the ends. | 550 // Adjust the paint rect to reflect a scrolled content box with borders
at the ends. |
516 IntSize offset = thisBox.scrolledContentOffset(); | 551 IntSize offset = thisBox.scrolledContentOffset(); |
517 scrolledPaintRect.move(-offset); | 552 scrolledPaintRect.move(-offset); |
518 scrolledPaintRect.setWidth(bLeft + thisBox.scrollWidth() + bRight); | 553 scrolledPaintRect.setWidth(bLeft + thisBox.scrollWidth() + bRight); |
519 scrolledPaintRect.setHeight(thisBox.borderTop() + thisBox.scrollHeight()
+ thisBox.borderBottom()); | 554 scrolledPaintRect.setHeight(thisBox.borderTop() + thisBox.scrollHeight()
+ thisBox.borderBottom()); |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 } | 855 } |
821 } | 856 } |
822 | 857 |
823 bool BoxPainter::shouldForceWhiteBackgroundForPrintEconomy(const ComputedStyle&
style, const Document& document) | 858 bool BoxPainter::shouldForceWhiteBackgroundForPrintEconomy(const ComputedStyle&
style, const Document& document) |
824 { | 859 { |
825 return document.printing() && style.getPrintColorAdjust() == PrintColorAdjus
tEconomy | 860 return document.printing() && style.getPrintColorAdjust() == PrintColorAdjus
tEconomy |
826 && (!document.settings() || !document.settings()->shouldPrintBackgrounds
()); | 861 && (!document.settings() || !document.settings()->shouldPrintBackgrounds
()); |
827 } | 862 } |
828 | 863 |
829 } // namespace blink | 864 } // namespace blink |
OLD | NEW |