| 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 |
| 44 OwnPtr<RoundedInnerRectClipper> clipper; |
| 41 if (m_renderPart.style()->hasBorderRadius()) { | 45 if (m_renderPart.style()->hasBorderRadius()) { |
| 42 LayoutRect borderRect = LayoutRect(adjustedPaintOffset, m_renderPart.siz
e()); | |
| 43 | |
| 44 if (borderRect.isEmpty()) | |
| 45 return; | |
| 46 | |
| 47 // Push a clip if we have a border radius, since we want to round the fo
reground content that gets painted. | |
| 48 paintInfo.context->save(); | |
| 49 FloatRoundedRect roundedInnerRect = m_renderPart.style()->getRoundedInne
rBorderFor(borderRect, | 46 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); | 47 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); | 48 clipper = adoptPtr(new RoundedInnerRectClipper(m_renderPart, paintInfo,
borderRect, roundedInnerRect, ApplyToDisplayListIfEnabled)); |
| 52 } | 49 } |
| 53 | 50 |
| 54 if (m_renderPart.widget()) | 51 if (m_renderPart.widget()) |
| 55 m_renderPart.paintContents(paintInfo, paintOffset); | 52 m_renderPart.paintContents(paintInfo, paintOffset); |
| 56 | 53 clipper.clear(); |
| 57 if (m_renderPart.style()->hasBorderRadius()) | |
| 58 paintInfo.context->restore(); | |
| 59 | 54 |
| 60 // Paint a partially transparent wash over selected widgets. | 55 // Paint a partially transparent wash over selected widgets. |
| 61 if (m_renderPart.isSelected() && !m_renderPart.document().printing()) { | 56 if (m_renderPart.isSelected() && !m_renderPart.document().printing()) { |
| 62 LayoutRect rect = m_renderPart.localSelectionRect(); | 57 LayoutRect rect = m_renderPart.localSelectionRect(); |
| 63 rect.moveBy(adjustedPaintOffset); | 58 rect.moveBy(adjustedPaintOffset); |
| 64 paintInfo.context->fillRect(pixelSnappedIntRect(rect), m_renderPart.sele
ctionBackgroundColor()); | 59 IntRect selectionRect = pixelSnappedIntRect(rect); |
| 60 RenderDrawingRecorder recorder(paintInfo.context, m_renderPart, paintInf
o.phase, selectionRect); |
| 61 paintInfo.context->fillRect(selectionRect, m_renderPart.selectionBackgro
undColor()); |
| 65 } | 62 } |
| 66 | 63 |
| 67 if (m_renderPart.canResize()) | 64 if (m_renderPart.canResize()) |
| 68 ScrollableAreaPainter(*m_renderPart.layer()->scrollableArea()).paintResi
zer(paintInfo.context, roundedIntPoint(adjustedPaintOffset), paintInfo.rect); | 65 ScrollableAreaPainter(*m_renderPart.layer()->scrollableArea()).paintResi
zer(paintInfo.context, roundedIntPoint(adjustedPaintOffset), paintInfo.rect); |
| 69 } | 66 } |
| 70 | 67 |
| 71 void PartPainter::paintContents(const PaintInfo& paintInfo, const LayoutPoint& p
aintOffset) | 68 void PartPainter::paintContents(const PaintInfo& paintInfo, const LayoutPoint& p
aintOffset) |
| 72 { | 69 { |
| 73 LayoutPoint adjustedPaintOffset = paintOffset + m_renderPart.location(); | 70 LayoutPoint adjustedPaintOffset = paintOffset + m_renderPart.location(); |
| 74 | 71 |
| 75 Widget* widget = m_renderPart.widget(); | 72 Widget* widget = m_renderPart.widget(); |
| 76 RELEASE_ASSERT(widget); | 73 RELEASE_ASSERT(widget); |
| 77 | 74 |
| 78 // Tell the widget to paint now. This is the only time the widget is allowed | 75 // 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. | 76 // to paint itself. That way it will composite properly with z-indexed layer
s. |
| 80 IntPoint widgetLocation = widget->frameRect().location(); | 77 IntPoint widgetLocation = widget->frameRect().location(); |
| 81 IntPoint paintLocation(roundToInt(adjustedPaintOffset.x() + m_renderPart.bor
derLeft() + m_renderPart.paddingLeft()), | 78 IntPoint paintLocation(roundToInt(adjustedPaintOffset.x() + m_renderPart.bor
derLeft() + m_renderPart.paddingLeft()), |
| 82 roundToInt(adjustedPaintOffset.y() + m_renderPart.borderTop() + m_render
Part.paddingTop())); | 79 roundToInt(adjustedPaintOffset.y() + m_renderPart.borderTop() + m_render
Part.paddingTop())); |
| 83 IntRect paintRect = paintInfo.rect; | 80 IntRect paintRect = paintInfo.rect; |
| 84 | 81 |
| 85 IntSize widgetPaintOffset = paintLocation - widgetLocation; | 82 IntSize widgetPaintOffset = paintLocation - widgetLocation; |
| 86 // When painting widgets into compositing layers, tx and ty are relative to
the enclosing compositing layer, | 83 // 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. | 84 // 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()) { | 85 TransformRecorder transform(*paintInfo.context, m_renderPart.displayItemClie
nt(), |
| 89 paintInfo.context->translate(widgetPaintOffset.width(), widgetPaintOffse
t.height()); | 86 AffineTransform::translation(widgetPaintOffset.width(), widgetPaintOffse
t.height())); |
| 90 paintRect.move(-widgetPaintOffset); | |
| 91 } | |
| 92 widget->paint(paintInfo.context, paintRect); | 87 widget->paint(paintInfo.context, paintRect); |
| 93 | |
| 94 if (!widgetPaintOffset.isZero()) | |
| 95 paintInfo.context->translate(-widgetPaintOffset.width(), -widgetPaintOff
set.height()); | |
| 96 } | 88 } |
| 97 | 89 |
| 98 } // namespace blink | 90 } // namespace blink |
| OLD | NEW |