Home | History | Annotate | Download | only in paint
      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/SVGForeignObjectPainter.h"
      7 
      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"
     14 
     15 namespace blink {
     16 
     17 void SVGForeignObjectPainter::paint(PaintInfo& paintInfo)
     18 {
     19     if (paintInfo.phase != PaintPhaseForeground && paintInfo.phase != PaintPhaseSelection)
     20         return;
     21 
     22     PaintInfo childPaintInfo(paintInfo);
     23     GraphicsContextStateSaver stateSaver(*childPaintInfo.context);
     24     childPaintInfo.applyTransform(m_renderSVGForeignObject.localTransform());
     25 
     26     if (SVGRenderSupport::isOverflowHidden(&m_renderSVGForeignObject))
     27         childPaintInfo.context->clip(m_renderSVGForeignObject.viewportRect());
     28 
     29     SVGRenderingContext renderingContext;
     30     bool continueRendering = true;
     31     if (paintInfo.phase == PaintPhaseForeground) {
     32         renderingContext.prepareToRenderSVGContent(&m_renderSVGForeignObject, childPaintInfo);
     33         continueRendering = renderingContext.isRenderingPrepared();
     34     }
     35 
     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);
     42         if (!preservePhase) {
     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);
     51         }
     52     }
     53 }
     54 
     55 } // namespace blink
     56