This source file includes following definitions.
- m_needsTransformUpdate
- isChildAllowed
- paint
- localToParentTransform
- updateLogicalWidth
- computeLogicalHeight
- layout
- computeRectForRepaint
- nodeAtFloatPoint
#include "config.h"
#include "core/rendering/svg/RenderSVGForeignObject.h"
#include "core/rendering/HitTestResult.h"
#include "core/rendering/LayoutRectRecorder.h"
#include "core/rendering/LayoutRepainter.h"
#include "core/rendering/RenderView.h"
#include "core/rendering/svg/SVGRenderSupport.h"
#include "core/rendering/svg/SVGRenderingContext.h"
#include "core/rendering/svg/SVGResourcesCache.h"
#include "core/svg/SVGForeignObjectElement.h"
#include "platform/graphics/GraphicsContextStateSaver.h"
namespace WebCore {
RenderSVGForeignObject::RenderSVGForeignObject(SVGForeignObjectElement* node)
: RenderSVGBlock(node)
, m_needsTransformUpdate(true)
{
}
RenderSVGForeignObject::~RenderSVGForeignObject()
{
}
bool RenderSVGForeignObject::isChildAllowed(RenderObject* child, RenderStyle* style) const
{
return !child->isSVG() || child->isSVGRoot();
}
void RenderSVGForeignObject::paint(PaintInfo& paintInfo, const LayoutPoint&)
{
if (paintInfo.context->paintingDisabled()
|| (paintInfo.phase != PaintPhaseForeground && paintInfo.phase != PaintPhaseSelection))
return;
PaintInfo childPaintInfo(paintInfo);
GraphicsContextStateSaver stateSaver(*childPaintInfo.context);
childPaintInfo.applyTransform(localTransform());
if (SVGRenderSupport::isOverflowHidden(this))
childPaintInfo.context->clip(m_viewport);
SVGRenderingContext renderingContext;
bool continueRendering = true;
if (paintInfo.phase == PaintPhaseForeground) {
renderingContext.prepareToRenderSVGContent(this, childPaintInfo);
continueRendering = renderingContext.isRenderingPrepared();
}
if (continueRendering) {
bool preservePhase = paintInfo.phase == PaintPhaseSelection || paintInfo.phase == PaintPhaseTextClip;
LayoutPoint childPoint = IntPoint();
childPaintInfo.phase = preservePhase ? paintInfo.phase : PaintPhaseBlockBackground;
RenderBlock::paint(childPaintInfo, IntPoint());
if (!preservePhase) {
childPaintInfo.phase = PaintPhaseChildBlockBackgrounds;
RenderBlock::paint(childPaintInfo, childPoint);
childPaintInfo.phase = PaintPhaseFloat;
RenderBlock::paint(childPaintInfo, childPoint);
childPaintInfo.phase = PaintPhaseForeground;
RenderBlock::paint(childPaintInfo, childPoint);
childPaintInfo.phase = PaintPhaseOutline;
RenderBlock::paint(childPaintInfo, childPoint);
}
}
}
const AffineTransform& RenderSVGForeignObject::localToParentTransform() const
{
m_localToParentTransform = localTransform();
m_localToParentTransform.translate(m_viewport.x(), m_viewport.y());
return m_localToParentTransform;
}
void RenderSVGForeignObject::updateLogicalWidth()
{
setWidth(static_cast<int>(roundf(m_viewport.width())));
}
void RenderSVGForeignObject::computeLogicalHeight(LayoutUnit, LayoutUnit logicalTop, LogicalExtentComputedValues& computedValues) const
{
computedValues.m_extent = static_cast<int>(roundf(m_viewport.height()));
computedValues.m_position = logicalTop;
}
void RenderSVGForeignObject::layout()
{
ASSERT(needsLayout());
ASSERT(!view()->layoutStateEnabled());
LayoutRectRecorder recorder(*this);
LayoutRepainter repainter(*this, SVGRenderSupport::checkForSVGRepaintDuringLayout(this));
SVGForeignObjectElement* foreign = toSVGForeignObjectElement(node());
bool updateCachedBoundariesInParents = false;
if (m_needsTransformUpdate) {
m_localTransform = foreign->animatedLocalTransform();
m_needsTransformUpdate = false;
updateCachedBoundariesInParents = true;
}
FloatRect oldViewport = m_viewport;
SVGLengthContext lengthContext(foreign);
FloatPoint viewportLocation(foreign->x()->currentValue()->value(lengthContext), foreign->y()->currentValue()->value(lengthContext));
m_viewport = FloatRect(viewportLocation, FloatSize(foreign->width()->currentValue()->value(lengthContext), foreign->height()->currentValue()->value(lengthContext)));
if (!updateCachedBoundariesInParents)
updateCachedBoundariesInParents = oldViewport != m_viewport;
setLocation(roundedIntPoint(viewportLocation));
bool layoutChanged = everHadLayout() && selfNeedsLayout();
RenderBlock::layout();
ASSERT(!needsLayout());
if (updateCachedBoundariesInParents)
RenderSVGBlock::setNeedsBoundariesUpdate();
if (layoutChanged)
SVGResourcesCache::clientLayoutChanged(this);
repainter.repaintAfterLayout();
}
void RenderSVGForeignObject::computeRectForRepaint(const RenderLayerModelObject* repaintContainer,
LayoutRect& rect, bool fixed) const
{
FloatRect r(rect);
SVGRenderSupport::computeFloatRectForRepaint(this, repaintContainer, r, fixed);
rect = enclosingLayoutRect(r);
}
bool RenderSVGForeignObject::nodeAtFloatPoint(const HitTestRequest& request, HitTestResult& result, const FloatPoint& pointInParent, HitTestAction hitTestAction)
{
if (hitTestAction != HitTestForeground)
return false;
FloatPoint localPoint = localTransform().inverse().mapPoint(pointInParent);
if (SVGRenderSupport::isOverflowHidden(this) && !m_viewport.contains(localPoint))
return false;
HitTestLocation hitTestLocation(roundedLayoutPoint(localPoint));
return RenderBlock::nodeAtPoint(request, result, hitTestLocation, LayoutPoint(), HitTestForeground)
|| RenderBlock::nodeAtPoint(request, result, hitTestLocation, LayoutPoint(), HitTestFloat)
|| RenderBlock::nodeAtPoint(request, result, hitTestLocation, LayoutPoint(), HitTestChildBlockBackgrounds);
}
}