RenderSVGContainer.cpp [plain text]
#include "config.h"
#if ENABLE(SVG)
#include "RenderSVGContainer.h"
#include "GraphicsContext.h"
#include "RenderSVGResourceFilter.h"
#include "RenderView.h"
#include "SVGRenderSupport.h"
#include "SVGStyledElement.h"
namespace WebCore {
RenderSVGContainer::RenderSVGContainer(SVGStyledElement* node)
: RenderSVGModelObject(node)
, m_drawsContents(true)
{
}
bool RenderSVGContainer::drawsContents() const
{
return m_drawsContents;
}
void RenderSVGContainer::setDrawsContents(bool drawsContents)
{
m_drawsContents = drawsContents;
}
void RenderSVGContainer::layout()
{
ASSERT(needsLayout());
ASSERT(!view()->layoutStateEnabled());
calcViewport();
LayoutRepainter repainter(*this, checkForRepaintDuringLayout() || selfWillPaint());
calculateLocalTransform();
layoutChildren(this, selfNeedsLayout());
repainter.repaintAfterLayout();
setNeedsLayout(false);
}
bool RenderSVGContainer::selfWillPaint() const
{
#if ENABLE(FILTERS)
const SVGRenderStyle* svgStyle = style()->svgStyle();
RenderSVGResourceFilter* filter = getRenderSVGResourceById<RenderSVGResourceFilter>(document(), svgStyle->filterResource());
if (filter)
return true;
#endif
return false;
}
void RenderSVGContainer::paint(PaintInfo& paintInfo, int, int)
{
if (paintInfo.context->paintingDisabled() || !drawsContents())
return;
if (!firstChild() && !selfWillPaint())
return;
PaintInfo childPaintInfo(paintInfo);
childPaintInfo.context->save();
applyViewportClip(childPaintInfo);
applyTransformToPaintInfo(childPaintInfo, localToParentTransform());
RenderSVGResourceFilter* filter = 0;
FloatRect boundingBox = repaintRectInLocalCoordinates();
bool continueRendering = true;
if (childPaintInfo.phase == PaintPhaseForeground)
continueRendering = prepareToRenderSVGContent(this, childPaintInfo, boundingBox, filter);
if (continueRendering) {
childPaintInfo.paintingRoot = paintingRootForChildren(childPaintInfo);
for (RenderObject* child = firstChild(); child; child = child->nextSibling())
child->paint(childPaintInfo, 0, 0);
}
if (paintInfo.phase == PaintPhaseForeground)
finishRenderSVGContent(this, childPaintInfo, filter, paintInfo.context);
childPaintInfo.context->restore();
IntRect paintRectInParent = enclosingIntRect(localToParentTransform().mapRect(repaintRectInLocalCoordinates()));
if ((paintInfo.phase == PaintPhaseOutline || paintInfo.phase == PaintPhaseSelfOutline) && style()->outlineWidth() && style()->visibility() == VISIBLE)
paintOutline(paintInfo.context, paintRectInParent.x(), paintRectInParent.y(), paintRectInParent.width(), paintRectInParent.height());
}
void RenderSVGContainer::addFocusRingRects(Vector<IntRect>& rects, int, int)
{
IntRect paintRectInParent = enclosingIntRect(localToParentTransform().mapRect(repaintRectInLocalCoordinates()));
if (!paintRectInParent.isEmpty())
rects.append(paintRectInParent);
}
FloatRect RenderSVGContainer::objectBoundingBox() const
{
return computeContainerBoundingBox(this, false);
}
FloatRect RenderSVGContainer::strokeBoundingBox() const
{
return computeContainerBoundingBox(this, true);
}
FloatRect RenderSVGContainer::repaintRectInLocalCoordinates() const
{
FloatRect repaintRect = computeContainerBoundingBox(this, true);
intersectRepaintRectWithResources(this, repaintRect);
return repaintRect;
}
bool RenderSVGContainer::nodeAtFloatPoint(const HitTestRequest& request, HitTestResult& result, const FloatPoint& pointInParent, HitTestAction hitTestAction)
{
if (!pointIsInsideViewportClip(pointInParent))
return false;
FloatPoint localPoint = localToParentTransform().inverse().mapPoint(pointInParent);
for (RenderObject* child = lastChild(); child; child = child->previousSibling()) {
if (child->nodeAtFloatPoint(request, result, localPoint, hitTestAction)) {
updateHitTestResult(result, roundedIntPoint(localPoint));
return true;
}
}
return false;
}
}
#endif // ENABLE(SVG)