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