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/SVGRootPainter.h" |
| 7 |
| 8 #include "core/paint/BoxPainter.h" |
| 9 #include "core/rendering/PaintInfo.h" |
| 10 #include "core/rendering/svg/RenderSVGRoot.h" |
| 11 #include "core/rendering/svg/SVGRenderingContext.h" |
| 12 #include "core/rendering/svg/SVGResources.h" |
| 13 #include "core/rendering/svg/SVGResourcesCache.h" |
| 14 #include "core/svg/SVGSVGElement.h" |
| 15 |
| 16 namespace blink { |
| 17 |
| 18 void SVGRootPainter::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset) |
| 19 { |
| 20 // An empty viewport disables rendering. |
| 21 if (m_renderSVGRoot.pixelSnappedBorderBoxRect().isEmpty()) |
| 22 return; |
| 23 |
| 24 // SVG outlines are painted during PaintPhaseForeground. |
| 25 if (paintInfo.phase == PaintPhaseOutline || paintInfo.phase == PaintPhaseSel
fOutline) |
| 26 return; |
| 27 |
| 28 // An empty viewBox also disables rendering. |
| 29 // (http://www.w3.org/TR/SVG/coords.html#ViewBoxAttribute) |
| 30 SVGSVGElement* svg = toSVGSVGElement(m_renderSVGRoot.node()); |
| 31 ASSERT(svg); |
| 32 if (svg->hasEmptyViewBox()) |
| 33 return; |
| 34 |
| 35 // Don't paint if we don't have kids, except if we have filters we should pa
int those. |
| 36 if (!m_renderSVGRoot.firstChild()) { |
| 37 SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObj
ect(&m_renderSVGRoot); |
| 38 if (!resources || !resources->filter()) |
| 39 return; |
| 40 } |
| 41 |
| 42 // Make a copy of the PaintInfo because applyTransform will modify the damag
e rect. |
| 43 PaintInfo childPaintInfo(paintInfo); |
| 44 GraphicsContextStateSaver stateSaver(*childPaintInfo.context); |
| 45 |
| 46 // Apply initial viewport clip. |
| 47 if (m_renderSVGRoot.shouldApplyViewportClip()) |
| 48 childPaintInfo.context->clip(pixelSnappedIntRect(m_renderSVGRoot.overflo
wClipRect(paintOffset))); |
| 49 |
| 50 // Convert from container offsets (html renderers) to a relative transform (
svg renderers). |
| 51 // Transform from our paint container's coordinate system to our local coord
s. |
| 52 IntPoint adjustedPaintOffset = roundedIntPoint(paintOffset); |
| 53 childPaintInfo.applyTransform(AffineTransform::translation(adjustedPaintOffs
et.x(), adjustedPaintOffset.y()) * m_renderSVGRoot.localToBorderBoxTransform()); |
| 54 |
| 55 SVGRenderingContext renderingContext; |
| 56 if (childPaintInfo.phase == PaintPhaseForeground) { |
| 57 renderingContext.prepareToRenderSVGContent(&m_renderSVGRoot, childPaintI
nfo); |
| 58 if (!renderingContext.isRenderingPrepared()) |
| 59 return; |
| 60 } |
| 61 |
| 62 BoxPainter(m_renderSVGRoot).paint(childPaintInfo, LayoutPoint()); |
| 63 } |
| 64 |
| 65 } // namespace blink |
OLD | NEW |