RenderSVGForeignObject.cpp [plain text]
#include "config.h"
#if ENABLE(SVG) && ENABLE(SVG_FOREIGN_OBJECT)
#include "RenderSVGForeignObject.h"
#include "GraphicsContext.h"
#include "RenderSVGResource.h"
#include "RenderView.h"
#include "SVGForeignObjectElement.h"
#include "SVGRenderSupport.h"
#include "SVGSVGElement.h"
#include "TransformState.h"
namespace WebCore {
RenderSVGForeignObject::RenderSVGForeignObject(SVGForeignObjectElement* node)
: RenderSVGBlock(node)
, m_needsTransformUpdate(true)
{
}
RenderSVGForeignObject::~RenderSVGForeignObject()
{
}
void RenderSVGForeignObject::paint(PaintInfo& paintInfo, int, int)
{
if (paintInfo.context->paintingDisabled())
return;
PaintInfo childPaintInfo(paintInfo);
GraphicsContextStateSaver stateSaver(*childPaintInfo.context);
childPaintInfo.applyTransform(localTransform());
if (SVGRenderSupport::isOverflowHidden(this))
childPaintInfo.context->clip(m_viewport);
float opacity = style()->opacity();
if (opacity < 1.0f)
childPaintInfo.context->beginTransparencyLayer(opacity);
RenderBlock::paint(childPaintInfo, 0, 0);
if (opacity < 1.0f)
childPaintInfo.context->endTransparencyLayer();
}
IntRect RenderSVGForeignObject::clippedOverflowRectForRepaint(RenderBoxModelObject* repaintContainer)
{
return SVGRenderSupport::clippedOverflowRectForRepaint(this, repaintContainer);
}
void RenderSVGForeignObject::computeRectForRepaint(RenderBoxModelObject* repaintContainer, IntRect& repaintRect, bool fixed)
{
SVGRenderSupport::computeRectForRepaint(this, repaintContainer, repaintRect, fixed);
}
const AffineTransform& RenderSVGForeignObject::localToParentTransform() const
{
m_localToParentTransform = localTransform();
m_localToParentTransform.translate(m_viewport.x(), m_viewport.y());
return m_localToParentTransform;
}
void RenderSVGForeignObject::computeLogicalWidth()
{
setWidth(static_cast<int>(roundf(m_viewport.width())));
}
void RenderSVGForeignObject::computeLogicalHeight()
{
setHeight(static_cast<int>(roundf(m_viewport.height())));
}
void RenderSVGForeignObject::layout()
{
ASSERT(needsLayout());
ASSERT(!view()->layoutStateEnabled());
LayoutRepainter repainter(*this, checkForRepaintDuringLayout());
SVGForeignObjectElement* foreign = static_cast<SVGForeignObjectElement*>(node());
bool updateCachedBoundariesInParents = false;
if (m_needsTransformUpdate) {
m_localTransform = foreign->animatedLocalTransform();
m_needsTransformUpdate = false;
updateCachedBoundariesInParents = true;
}
FloatRect oldViewport = m_viewport;
FloatPoint viewportLocation(foreign->x().value(foreign), foreign->y().value(foreign));
m_viewport = FloatRect(viewportLocation, FloatSize(foreign->width().value(foreign), foreign->height().value(foreign)));
if (!updateCachedBoundariesInParents)
updateCachedBoundariesInParents = oldViewport != m_viewport;
setLocation(roundedIntPoint(viewportLocation));
bool layoutChanged = m_everHadLayout && selfNeedsLayout();
RenderBlock::layout();
ASSERT(!needsLayout());
if (updateCachedBoundariesInParents)
RenderSVGBlock::setNeedsBoundariesUpdate();
if (layoutChanged)
SVGResourcesCache::clientLayoutChanged(this);
repainter.repaintAfterLayout();
}
bool RenderSVGForeignObject::nodeAtFloatPoint(const HitTestRequest& request, HitTestResult& result, const FloatPoint& pointInParent, HitTestAction hitTestAction)
{
FloatPoint localPoint = localTransform().inverse().mapPoint(pointInParent);
if (SVGRenderSupport::isOverflowHidden(this) && !m_viewport.contains(localPoint))
return false;
IntPoint roundedLocalPoint = roundedIntPoint(localPoint);
return RenderBlock::nodeAtPoint(request, result, roundedLocalPoint, 0, 0, hitTestAction);
}
bool RenderSVGForeignObject::nodeAtPoint(const HitTestRequest&, HitTestResult&, const IntPoint&, int, int, HitTestAction)
{
ASSERT_NOT_REACHED();
return false;
}
void RenderSVGForeignObject::mapLocalToContainer(RenderBoxModelObject* repaintContainer, bool fixed, bool useTransforms, TransformState& transformState) const
{
if (!useTransforms)
useTransforms = true;
SVGRenderSupport::mapLocalToContainer(this, repaintContainer, fixed, useTransforms, transformState);
}
}
#endif