Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / paint / SVGContainerPainter.cpp
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/SVGContainerPainter.h"
7
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"
19
20 namespace blink {
21
22 void SVGContainerPainter::paint(PaintInfo& paintInfo)
23 {
24     ANNOTATE_GRAPHICS_CONTEXT(paintInfo, &m_renderSVGContainer);
25
26     // Spec: groups w/o children still may render filter content.
27     if (!m_renderSVGContainer.firstChild() && !m_renderSVGContainer.selfWillPaint())
28         return;
29
30     FloatRect paintInvalidationRect = m_renderSVGContainer.paintInvalidationRectInLocalCoordinates();
31     if (!SVGRenderSupport::paintInfoIntersectsPaintInvalidationRect(paintInvalidationRect, m_renderSVGContainer.localToParentTransform(), paintInfo))
32         return;
33
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())
37         return;
38
39     PaintInfo childPaintInfo(paintInfo);
40     {
41         GraphicsContextStateSaver stateSaver(*childPaintInfo.context);
42
43         if (m_renderSVGContainer.isSVGViewportContainer() && SVGRenderSupport::isOverflowHidden(&m_renderSVGContainer))
44             paintInfo.context->clip(toRenderSVGViewportContainer(m_renderSVGContainer).viewport());
45
46         childPaintInfo.applyTransform(m_renderSVGContainer.localToParentTransform());
47
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();
54
55             if (continueRendering && m_renderSVGContainer.document().settings()->containerCullingEnabled())
56                 cullSaver.cull(paintInvalidationRect);
57         }
58
59         if (continueRendering) {
60             childPaintInfo.updatePaintingRootForChildren(&m_renderSVGContainer);
61             for (RenderObject* child = m_renderSVGContainer.firstChild(); child; child = child->nextSibling())
62                 child->paint(childPaintInfo, IntPoint());
63         }
64     }
65
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);
74     }
75 }
76
77 } // namespace blink