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 "config.h" | 5 #include "config.h" |
6 #include "core/paint/PartPainter.h" | 6 #include "core/paint/PartPainter.h" |
7 | 7 |
8 #include "core/paint/BoxPainter.h" | 8 #include "core/paint/BoxPainter.h" |
9 | |
10 #include "core/paint/GraphicsContextAnnotator.h" | 9 #include "core/paint/GraphicsContextAnnotator.h" |
| 10 #include "core/paint/RenderDrawingRecorder.h" |
| 11 #include "core/paint/RoundedInnerRectClipper.h" |
11 #include "core/paint/ScrollableAreaPainter.h" | 12 #include "core/paint/ScrollableAreaPainter.h" |
| 13 #include "core/paint/TransformRecorder.h" |
12 #include "core/rendering/PaintInfo.h" | 14 #include "core/rendering/PaintInfo.h" |
13 #include "core/rendering/RenderLayer.h" | 15 #include "core/rendering/RenderLayer.h" |
14 #include "core/rendering/RenderPart.h" | 16 #include "core/rendering/RenderPart.h" |
15 | 17 |
16 namespace blink { | 18 namespace blink { |
17 | 19 |
18 void PartPainter::paint(const PaintInfo& paintInfo, const LayoutPoint& paintOffs
et) | 20 void PartPainter::paint(const PaintInfo& paintInfo, const LayoutPoint& paintOffs
et) |
19 { | 21 { |
20 ANNOTATE_GRAPHICS_CONTEXT(paintInfo, &m_renderPart); | 22 ANNOTATE_GRAPHICS_CONTEXT(paintInfo, &m_renderPart); |
21 | 23 |
22 if (!m_renderPart.shouldPaint(paintInfo, paintOffset)) | 24 if (!m_renderPart.shouldPaint(paintInfo, paintOffset)) |
23 return; | 25 return; |
24 | 26 |
25 LayoutPoint adjustedPaintOffset = paintOffset + m_renderPart.location(); | 27 LayoutPoint adjustedPaintOffset = paintOffset + m_renderPart.location(); |
| 28 LayoutRect borderRect(adjustedPaintOffset, m_renderPart.size()); |
26 | 29 |
27 if (m_renderPart.hasBoxDecorationBackground() && (paintInfo.phase == PaintPh
aseForeground || paintInfo.phase == PaintPhaseSelection)) | 30 if (m_renderPart.hasBoxDecorationBackground() && (paintInfo.phase == PaintPh
aseForeground || paintInfo.phase == PaintPhaseSelection)) |
28 BoxPainter(m_renderPart).paintBoxDecorationBackground(paintInfo, adjuste
dPaintOffset); | 31 BoxPainter(m_renderPart).paintBoxDecorationBackground(paintInfo, adjuste
dPaintOffset); |
29 | 32 |
30 if (paintInfo.phase == PaintPhaseMask) { | 33 if (paintInfo.phase == PaintPhaseMask) { |
31 BoxPainter(m_renderPart).paintMask(paintInfo, adjustedPaintOffset); | 34 BoxPainter(m_renderPart).paintMask(paintInfo, adjustedPaintOffset); |
32 return; | 35 return; |
33 } | 36 } |
34 | 37 |
35 if ((paintInfo.phase == PaintPhaseOutline || paintInfo.phase == PaintPhaseSe
lfOutline) && m_renderPart.style()->hasOutline()) | 38 if ((paintInfo.phase == PaintPhaseOutline || paintInfo.phase == PaintPhaseSe
lfOutline) && m_renderPart.style()->hasOutline()) |
36 ObjectPainter(m_renderPart).paintOutline(paintInfo, LayoutRect(adjustedP
aintOffset, m_renderPart.size())); | 39 ObjectPainter(m_renderPart).paintOutline(paintInfo, borderRect); |
37 | 40 |
38 if (paintInfo.phase != PaintPhaseForeground) | 41 if (paintInfo.phase != PaintPhaseForeground) |
39 return; | 42 return; |
40 | 43 |
41 if (m_renderPart.style()->hasBorderRadius()) { | 44 { |
42 LayoutRect borderRect = LayoutRect(adjustedPaintOffset, m_renderPart.siz
e()); | 45 OwnPtr<RoundedInnerRectClipper> clipper; |
| 46 if (m_renderPart.style()->hasBorderRadius()) { |
| 47 if (borderRect.isEmpty()) |
| 48 return; |
43 | 49 |
44 if (borderRect.isEmpty()) | 50 FloatRoundedRect roundedInnerRect = m_renderPart.style()->getRounded
InnerBorderFor(borderRect, |
45 return; | 51 m_renderPart.paddingTop() + m_renderPart.borderTop(), m_renderPa
rt.paddingBottom() + m_renderPart.borderBottom(), m_renderPart.paddingLeft() + m
_renderPart.borderLeft(), m_renderPart.paddingRight() + m_renderPart.borderRight
(), true, true); |
| 52 clipper = adoptPtr(new RoundedInnerRectClipper(m_renderPart, paintIn
fo, borderRect, roundedInnerRect, ApplyToDisplayListIfEnabled)); |
| 53 } |
46 | 54 |
47 // Push a clip if we have a border radius, since we want to round the fo
reground content that gets painted. | 55 if (m_renderPart.widget()) |
48 paintInfo.context->save(); | 56 m_renderPart.paintContents(paintInfo, paintOffset); |
49 FloatRoundedRect roundedInnerRect = m_renderPart.style()->getRoundedInne
rBorderFor(borderRect, | |
50 m_renderPart.paddingTop() + m_renderPart.borderTop(), m_renderPart.p
addingBottom() + m_renderPart.borderBottom(), m_renderPart.paddingLeft() + m_ren
derPart.borderLeft(), m_renderPart.paddingRight() + m_renderPart.borderRight(),
true, true); | |
51 BoxPainter::clipRoundedInnerRect(paintInfo.context, borderRect, roundedI
nnerRect); | |
52 } | 57 } |
53 | 58 |
54 if (m_renderPart.widget()) | |
55 m_renderPart.paintContents(paintInfo, paintOffset); | |
56 | |
57 if (m_renderPart.style()->hasBorderRadius()) | |
58 paintInfo.context->restore(); | |
59 | |
60 // Paint a partially transparent wash over selected widgets. | 59 // Paint a partially transparent wash over selected widgets. |
61 if (m_renderPart.isSelected() && !m_renderPart.document().printing()) { | 60 if (m_renderPart.isSelected() && !m_renderPart.document().printing()) { |
62 LayoutRect rect = m_renderPart.localSelectionRect(); | 61 LayoutRect rect = m_renderPart.localSelectionRect(); |
63 rect.moveBy(adjustedPaintOffset); | 62 rect.moveBy(adjustedPaintOffset); |
64 paintInfo.context->fillRect(pixelSnappedIntRect(rect), m_renderPart.sele
ctionBackgroundColor()); | 63 IntRect selectionRect = pixelSnappedIntRect(rect); |
| 64 RenderDrawingRecorder recorder(paintInfo.context, m_renderPart, paintInf
o.phase, selectionRect); |
| 65 paintInfo.context->fillRect(selectionRect, m_renderPart.selectionBackgro
undColor()); |
65 } | 66 } |
66 | 67 |
67 if (m_renderPart.canResize()) | 68 if (m_renderPart.canResize()) |
68 ScrollableAreaPainter(*m_renderPart.layer()->scrollableArea()).paintResi
zer(paintInfo.context, roundedIntPoint(adjustedPaintOffset), paintInfo.rect); | 69 ScrollableAreaPainter(*m_renderPart.layer()->scrollableArea()).paintResi
zer(paintInfo.context, roundedIntPoint(adjustedPaintOffset), paintInfo.rect); |
69 } | 70 } |
70 | 71 |
71 void PartPainter::paintContents(const PaintInfo& paintInfo, const LayoutPoint& p
aintOffset) | 72 void PartPainter::paintContents(const PaintInfo& paintInfo, const LayoutPoint& p
aintOffset) |
72 { | 73 { |
73 LayoutPoint adjustedPaintOffset = paintOffset + m_renderPart.location(); | 74 LayoutPoint adjustedPaintOffset = paintOffset + m_renderPart.location(); |
74 | 75 |
75 Widget* widget = m_renderPart.widget(); | 76 Widget* widget = m_renderPart.widget(); |
76 RELEASE_ASSERT(widget); | 77 RELEASE_ASSERT(widget); |
77 | 78 |
78 // Tell the widget to paint now. This is the only time the widget is allowed | 79 // Tell the widget to paint now. This is the only time the widget is allowed |
79 // to paint itself. That way it will composite properly with z-indexed layer
s. | 80 // to paint itself. That way it will composite properly with z-indexed layer
s. |
80 IntPoint widgetLocation = widget->frameRect().location(); | 81 IntPoint widgetLocation = widget->frameRect().location(); |
81 IntPoint paintLocation(roundToInt(adjustedPaintOffset.x() + m_renderPart.bor
derLeft() + m_renderPart.paddingLeft()), | 82 IntPoint paintLocation(roundToInt(adjustedPaintOffset.x() + m_renderPart.bor
derLeft() + m_renderPart.paddingLeft()), |
82 roundToInt(adjustedPaintOffset.y() + m_renderPart.borderTop() + m_render
Part.paddingTop())); | 83 roundToInt(adjustedPaintOffset.y() + m_renderPart.borderTop() + m_render
Part.paddingTop())); |
83 IntRect paintRect = paintInfo.rect; | 84 IntRect paintRect = paintInfo.rect; |
84 | 85 |
85 IntSize widgetPaintOffset = paintLocation - widgetLocation; | 86 IntSize widgetPaintOffset = paintLocation - widgetLocation; |
86 // When painting widgets into compositing layers, tx and ty are relative to
the enclosing compositing layer, | 87 // When painting widgets into compositing layers, tx and ty are relative to
the enclosing compositing layer, |
87 // not the root. In this case, shift the CTM and adjust the paintRect to be
root-relative to fix plug-in drawing. | 88 // not the root. In this case, shift the CTM and adjust the paintRect to be
root-relative to fix plug-in drawing. |
88 if (!widgetPaintOffset.isZero()) { | 89 TransformRecorder transform(*paintInfo.context, m_renderPart.displayItemClie
nt(), |
89 paintInfo.context->translate(widgetPaintOffset.width(), widgetPaintOffse
t.height()); | 90 AffineTransform::translation(widgetPaintOffset.width(), widgetPaintOffse
t.height())); |
90 paintRect.move(-widgetPaintOffset); | 91 paintRect.move(-widgetPaintOffset); |
91 } | |
92 widget->paint(paintInfo.context, paintRect); | 92 widget->paint(paintInfo.context, paintRect); |
93 | |
94 if (!widgetPaintOffset.isZero()) | |
95 paintInfo.context->translate(-widgetPaintOffset.width(), -widgetPaintOff
set.height()); | |
96 } | 93 } |
97 | 94 |
98 } // namespace blink | 95 } // namespace blink |
OLD | NEW |