OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 #include "core/paint/PartPainter.h" |
| 7 |
| 8 #include "core/frame/FrameView.h" |
| 9 #include "core/paint/BoxPainter.h" |
| 10 #include "core/paint/ClipRecorder.h" |
| 11 #include "core/paint/DrawingRecorder.h" |
| 12 #include "core/paint/TranslationRecorder.h" |
| 13 #include "core/paint/ViewDisplayList.h" |
| 14 #include "core/rendering/GraphicsContextAnnotator.h" |
| 15 #include "core/rendering/PaintInfo.h" |
| 16 #include "core/rendering/RenderLayer.h" |
| 17 #include "core/rendering/RenderPart.h" |
| 18 |
| 19 namespace blink { |
| 20 |
| 21 void PartPainter::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset) |
| 22 { |
| 23 ANNOTATE_GRAPHICS_CONTEXT(paintInfo, &m_renderPart); |
| 24 |
| 25 if (!m_renderPart.shouldPaint(paintInfo, paintOffset)) |
| 26 return; |
| 27 |
| 28 LayoutPoint adjustedPaintOffset = paintOffset + m_renderPart.location(); |
| 29 |
| 30 LayoutRect bounds; |
| 31 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { |
| 32 bounds = m_renderPart.visualOverflowRect(); |
| 33 bounds.moveBy(paintOffset); |
| 34 } |
| 35 |
| 36 if (m_renderPart.hasBoxDecorationBackground() && (paintInfo.phase == PaintPh
aseForeground || paintInfo.phase == PaintPhaseSelection)) { |
| 37 DrawingRecorder recorder(paintInfo.context, &m_renderPart, paintInfo.pha
se, bounds); |
| 38 m_renderPart.paintBoxDecorationBackground(paintInfo, adjustedPaintOffset
); |
| 39 } |
| 40 |
| 41 if (paintInfo.phase == PaintPhaseMask) { |
| 42 DrawingRecorder recorder(paintInfo.context, &m_renderPart, paintInfo.pha
se, bounds); |
| 43 m_renderPart.paintMask(paintInfo, adjustedPaintOffset); |
| 44 return; |
| 45 } |
| 46 |
| 47 if ((paintInfo.phase == PaintPhaseOutline || paintInfo.phase == PaintPhaseSe
lfOutline) && m_renderPart.style()->hasOutline()) { |
| 48 DrawingRecorder recorder(paintInfo.context, &m_renderPart, paintInfo.pha
se, bounds); |
| 49 m_renderPart.paintOutline(paintInfo, LayoutRect(adjustedPaintOffset, m_r
enderPart.size())); |
| 50 } |
| 51 |
| 52 if (paintInfo.phase != PaintPhaseForeground) |
| 53 return; |
| 54 |
| 55 OwnPtr<ClipRecorder> clipRecorder; |
| 56 if (m_renderPart.style()->hasBorderRadius()) { |
| 57 LayoutRect borderRect = LayoutRect(adjustedPaintOffset, m_renderPart.siz
e()); |
| 58 if (borderRect.isEmpty()) |
| 59 return; |
| 60 |
| 61 RoundedRect roundedInnerRect = m_renderPart.style()->getRoundedInnerBord
erFor(borderRect, |
| 62 m_renderPart.paddingTop() + m_renderPart.borderTop(), |
| 63 m_renderPart.paddingBottom() + m_renderPart.borderBottom(), |
| 64 m_renderPart.paddingLeft() + m_renderPart.borderLeft(), |
| 65 m_renderPart.paddingRight() + m_renderPart.borderRight(), true, true
); |
| 66 |
| 67 // FIXME: Need a proper identifier (layer and phase pair) for this clip
item. |
| 68 clipRecorder = adoptPtr(new ClipRecorder(m_renderPart.layer(), paintInfo
.context, DisplayItem::ClipLayerFragmentForeground, borderRect)); |
| 69 // FIXME: Copied from BoxPainter::clipRoundedInnerRect. Should make it w
ork with ClipRecorder. |
| 70 if (roundedInnerRect.isRenderable()) { |
| 71 clipRecorder->addRoundedRectClip(roundedInnerRect); |
| 72 } else { |
| 73 if (!roundedInnerRect.radii().topLeft().isEmpty() || !roundedInnerRe
ct.radii().bottomRight().isEmpty()) { |
| 74 IntRect topCorner(roundedInnerRect.rect().x(), roundedInnerRect.
rect().y(), borderRect.maxX() - roundedInnerRect.rect().x(), borderRect.maxY() -
roundedInnerRect.rect().y()); |
| 75 RoundedRect::Radii topCornerRadii; |
| 76 topCornerRadii.setTopLeft(roundedInnerRect.radii().topLeft()); |
| 77 clipRecorder->addRoundedRectClip(RoundedRect(topCorner, topCorne
rRadii)); |
| 78 |
| 79 IntRect bottomCorner(borderRect.x(), borderRect.y(), roundedInne
rRect.rect().maxX() - borderRect.x(), roundedInnerRect.rect().maxY() - borderRec
t.y()); |
| 80 RoundedRect::Radii bottomCornerRadii; |
| 81 bottomCornerRadii.setBottomRight(roundedInnerRect.radii().bottom
Right()); |
| 82 clipRecorder->addRoundedRectClip(RoundedRect(bottomCorner, botto
mCornerRadii)); |
| 83 } |
| 84 |
| 85 if (!roundedInnerRect.radii().topRight().isEmpty() || !roundedInnerR
ect.radii().bottomLeft().isEmpty()) { |
| 86 IntRect topCorner(borderRect.x(), roundedInnerRect.rect().y(), r
oundedInnerRect.rect().maxX() - borderRect.x(), borderRect.maxY() - roundedInner
Rect.rect().y()); |
| 87 RoundedRect::Radii topCornerRadii; |
| 88 topCornerRadii.setTopRight(roundedInnerRect.radii().topRight()); |
| 89 clipRecorder->addRoundedRectClip(RoundedRect(topCorner, topCorne
rRadii)); |
| 90 |
| 91 IntRect bottomCorner(roundedInnerRect.rect().x(), borderRect.y()
, borderRect.maxX() - roundedInnerRect.rect().x(), roundedInnerRect.rect().maxY(
) - borderRect.y()); |
| 92 RoundedRect::Radii bottomCornerRadii; |
| 93 bottomCornerRadii.setBottomLeft(roundedInnerRect.radii().bottomL
eft()); |
| 94 clipRecorder->addRoundedRectClip(RoundedRect(bottomCorner, botto
mCornerRadii)); |
| 95 } |
| 96 } |
| 97 } |
| 98 |
| 99 paintContents(paintInfo, paintOffset); |
| 100 |
| 101 clipRecorder.clear(); |
| 102 |
| 103 DrawingRecorder recorder(paintInfo.context, &m_renderPart, paintInfo.phase,
bounds); |
| 104 // Paint a partially transparent wash over selected widgets. |
| 105 if (m_renderPart.isSelected() && !m_renderPart.document().printing()) { |
| 106 LayoutRect rect = m_renderPart.localSelectionRect(); |
| 107 rect.moveBy(adjustedPaintOffset); |
| 108 paintInfo.context->fillRect(pixelSnappedIntRect(rect), m_renderPart.sele
ctionBackgroundColor()); |
| 109 } |
| 110 |
| 111 if (m_renderPart.canResize()) |
| 112 m_renderPart.layer()->scrollableArea()->paintResizer(paintInfo.context,
roundedIntPoint(adjustedPaintOffset), paintInfo.rect); |
| 113 } |
| 114 |
| 115 void PartPainter::paintContents(PaintInfo& paintInfo, const LayoutPoint& paintOf
fset) |
| 116 { |
| 117 if (!m_renderPart.widget()) |
| 118 return; |
| 119 Widget* widget = m_renderPart.widget(); |
| 120 |
| 121 LayoutPoint adjustedPaintOffset = paintOffset + m_renderPart.location() + m_
renderPart.contentBoxRect().location(); |
| 122 IntSize widgetPaintOffset = roundedIntPoint(adjustedPaintOffset) - widget->f
rameRect().location(); |
| 123 |
| 124 TranslationRecorder translationRecorder(&m_renderPart, paintInfo.context, wi
dgetPaintOffset); |
| 125 IntRect paintRect = paintInfo.rect; |
| 126 paintRect.move(-widgetPaintOffset); |
| 127 widget->paint(paintInfo.context, paintRect); |
| 128 } |
| 129 |
| 130 } // namespace blink |
OLD | NEW |