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.
6 #include "core/paint/SVGContainerPainter.h"
8 #include "core/frame/Settings.h"
9 #include "core/paint/ObjectPainter.h"
10 #include "core/rendering/GraphicsContextAnnotator.h"
11 #include "core/rendering/PaintInfo.h"
12 #include "core/rendering/svg/RenderSVGContainer.h"
13 #include "core/rendering/svg/RenderSVGViewportContainer.h"
14 #include "core/rendering/svg/SVGRenderSupport.h"
15 #include "core/rendering/svg/SVGRenderingContext.h"
16 #include "core/svg/SVGSVGElement.h"
17 #include "platform/graphics/GraphicsContextCullSaver.h"
18 #include "platform/graphics/GraphicsContextStateSaver.h"
22 void SVGContainerPainter::paint(PaintInfo& paintInfo)
24 ANNOTATE_GRAPHICS_CONTEXT(paintInfo, &m_renderSVGContainer);
26 // Spec: groups w/o children still may render filter content.
27 if (!m_renderSVGContainer.firstChild() && !m_renderSVGContainer.selfWillPaint())
30 FloatRect paintInvalidationRect = m_renderSVGContainer.paintInvalidationRectInLocalCoordinates();
31 if (!SVGRenderSupport::paintInfoIntersectsPaintInvalidationRect(paintInvalidationRect, m_renderSVGContainer.localToParentTransform(), paintInfo))
34 // Spec: An empty viewBox on the <svg> element disables rendering.
35 ASSERT(m_renderSVGContainer.element());
36 if (isSVGSVGElement(*m_renderSVGContainer.element()) && toSVGSVGElement(*m_renderSVGContainer.element()).hasEmptyViewBox())
39 PaintInfo childPaintInfo(paintInfo);
41 GraphicsContextStateSaver stateSaver(*childPaintInfo.context);
43 if (m_renderSVGContainer.isSVGViewportContainer() && SVGRenderSupport::isOverflowHidden(&m_renderSVGContainer))
44 paintInfo.context->clip(toRenderSVGViewportContainer(m_renderSVGContainer).viewport());
46 childPaintInfo.applyTransform(m_renderSVGContainer.localToParentTransform());
48 SVGRenderingContext renderingContext;
49 GraphicsContextCullSaver cullSaver(*childPaintInfo.context);
50 bool continueRendering = true;
51 if (childPaintInfo.phase == PaintPhaseForeground) {
52 renderingContext.prepareToRenderSVGContent(&m_renderSVGContainer, childPaintInfo);
53 continueRendering = renderingContext.isRenderingPrepared();
55 if (continueRendering && m_renderSVGContainer.document().settings()->containerCullingEnabled())
56 cullSaver.cull(paintInvalidationRect);
59 if (continueRendering) {
60 childPaintInfo.updatePaintingRootForChildren(&m_renderSVGContainer);
61 for (RenderObject* child = m_renderSVGContainer.firstChild(); child; child = child->nextSibling())
62 child->paint(childPaintInfo, IntPoint());
66 // FIXME: This really should be drawn from local coordinates, but currently we hack it
67 // to avoid our clip killing our outline rect. Thus we translate our
68 // outline rect into parent coords before drawing.
69 // FIXME: This means our focus ring won't share our rotation like it should.
70 // We should instead disable our clip during PaintPhaseOutline
71 if (paintInfo.phase == PaintPhaseForeground && m_renderSVGContainer.style()->outlineWidth() && m_renderSVGContainer.style()->visibility() == VISIBLE) {
72 IntRect paintRectInParent = enclosingIntRect(m_renderSVGContainer.localToParentTransform().mapRect(paintInvalidationRect));
73 ObjectPainter(m_renderSVGContainer).paintOutline(paintInfo, paintRectInParent);