RenderSVGContainer.cpp [plain text]
#include "config.h"
#if ENABLE(SVG)
#include "RenderSVGContainer.h"
#include "AXObjectCache.h"
#include "FloatQuad.h"
#include "GraphicsContext.h"
#include "RenderView.h"
#include "SVGRenderSupport.h"
#include "SVGResourceFilter.h"
#include "SVGStyledElement.h"
#include "SVGURIReference.h"
namespace WebCore {
RenderSVGContainer::RenderSVGContainer(SVGStyledElement* node)
: RenderSVGModelObject(node)
, m_drawsContents(true)
{
}
RenderSVGContainer::~RenderSVGContainer()
{
}
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();
for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
if (selfNeedsLayout())
child->setNeedsLayout(true);
child->layoutIfNeeded();
ASSERT(!child->needsLayout());
}
repainter.repaintAfterLayout();
setNeedsLayout(false);
}
bool RenderSVGContainer::selfWillPaint() const
{
#if ENABLE(FILTERS)
const SVGRenderStyle* svgStyle = style()->svgStyle();
SVGResourceFilter* filter = getFilterById(document(), svgStyle->filter());
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());
SVGResourceFilter* filter = 0;
FloatRect boundingBox = repaintRectInLocalCoordinates();
if (childPaintInfo.phase == PaintPhaseForeground)
prepareToRenderSVGContent(this, childPaintInfo, boundingBox, filter);
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(), style());
}
void RenderSVGContainer::addFocusRingRects(GraphicsContext* graphicsContext, int, int)
{
IntRect paintRectInParent = enclosingIntRect(localToParentTransform().mapRect(repaintRectInLocalCoordinates()));
graphicsContext->addFocusRingRect(paintRectInParent);
}
FloatRect RenderSVGContainer::objectBoundingBox() const
{
return computeContainerBoundingBox(this, false);
}
FloatRect RenderSVGContainer::repaintRectInLocalCoordinates() const
{
FloatRect repaintRect = computeContainerBoundingBox(this, true);
repaintRect.unite(filterBoundingBoxForRenderer(this));
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)