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/SVGForeignObjectPainter.h"
8 #include "core/paint/BlockPainter.h"
9 #include "core/rendering/PaintInfo.h"
10 #include "core/rendering/svg/RenderSVGForeignObject.h"
11 #include "core/rendering/svg/SVGRenderSupport.h"
12 #include "core/rendering/svg/SVGRenderingContext.h"
13 #include "platform/graphics/GraphicsContextStateSaver.h"
17 void SVGForeignObjectPainter::paint(PaintInfo& paintInfo)
19 if (paintInfo.phase != PaintPhaseForeground && paintInfo.phase != PaintPhaseSelection)
22 PaintInfo childPaintInfo(paintInfo);
23 GraphicsContextStateSaver stateSaver(*childPaintInfo.context);
24 childPaintInfo.applyTransform(m_renderSVGForeignObject.localTransform());
26 if (SVGRenderSupport::isOverflowHidden(&m_renderSVGForeignObject))
27 childPaintInfo.context->clip(m_renderSVGForeignObject.viewportRect());
29 SVGRenderingContext renderingContext;
30 bool continueRendering = true;
31 if (paintInfo.phase == PaintPhaseForeground) {
32 renderingContext.prepareToRenderSVGContent(&m_renderSVGForeignObject, childPaintInfo);
33 continueRendering = renderingContext.isRenderingPrepared();
36 if (continueRendering) {
37 // Paint all phases of FO elements atomically as though the FO element established its own stacking context.
38 bool preservePhase = paintInfo.phase == PaintPhaseSelection || paintInfo.phase == PaintPhaseTextClip;
39 const LayoutPoint childPoint = IntPoint();
40 childPaintInfo.phase = preservePhase ? paintInfo.phase : PaintPhaseBlockBackground;
41 BlockPainter(m_renderSVGForeignObject).paint(childPaintInfo, childPoint);
43 childPaintInfo.phase = PaintPhaseChildBlockBackgrounds;
44 BlockPainter(m_renderSVGForeignObject).paint(childPaintInfo, childPoint);
45 childPaintInfo.phase = PaintPhaseFloat;
46 BlockPainter(m_renderSVGForeignObject).paint(childPaintInfo, childPoint);
47 childPaintInfo.phase = PaintPhaseForeground;
48 BlockPainter(m_renderSVGForeignObject).paint(childPaintInfo, childPoint);
49 childPaintInfo.phase = PaintPhaseOutline;
50 BlockPainter(m_renderSVGForeignObject).paint(childPaintInfo, childPoint);