RenderSVGForeignObject.cpp [plain text]
#include "config.h"
#include "RenderSVGForeignObject.h"
#include "GraphicsContext.h"
#include "HitTestResult.h"
#include "LayoutRepainter.h"
#include "RenderObject.h"
#include "RenderSVGResource.h"
#include "RenderView.h"
#include "SVGForeignObjectElement.h"
#include "SVGRenderingContext.h"
#include "SVGResourcesCache.h"
#include "TransformState.h"
#include <wtf/IsoMallocInlines.h>
#include <wtf/StackStats.h>
namespace WebCore {
WTF_MAKE_ISO_ALLOCATED_IMPL(RenderSVGForeignObject);
RenderSVGForeignObject::RenderSVGForeignObject(SVGForeignObjectElement& element, RenderStyle&& style)
: RenderSVGBlock(element, WTFMove(style))
{
}
RenderSVGForeignObject::~RenderSVGForeignObject() = default;
SVGForeignObjectElement& RenderSVGForeignObject::foreignObjectElement() const
{
return downcast<SVGForeignObjectElement>(RenderSVGBlock::graphicsElement());
}
void RenderSVGForeignObject::paint(PaintInfo& paintInfo, const LayoutPoint&)
{
if (paintInfo.context().paintingDisabled())
return;
if (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;
if (paintInfo.phase == PaintPhaseForeground) {
renderingContext.prepareToRenderSVGContent(*this, childPaintInfo);
if (!renderingContext.isRenderingPrepared())
return;
}
LayoutPoint childPoint = IntPoint();
if (paintInfo.phase == PaintPhaseSelection) {
RenderBlock::paint(childPaintInfo, childPoint);
return;
}
childPaintInfo.phase = PaintPhaseBlockBackground;
RenderBlock::paint(childPaintInfo, childPoint);
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);
}
LayoutRect RenderSVGForeignObject::clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const
{
return SVGRenderSupport::clippedOverflowRectForRepaint(*this, repaintContainer);
}
FloatRect RenderSVGForeignObject::computeFloatRectForRepaint(const FloatRect& repaintRect, const RenderLayerModelObject* repaintContainer, bool fixed) const
{
return SVGRenderSupport::computeFloatRectForRepaint(*this, repaintRect, repaintContainer, fixed);
}
LayoutRect RenderSVGForeignObject::computeRectForRepaint(const LayoutRect& repaintRect, const RenderLayerModelObject* repaintContainer, RepaintContext context) const
{
return enclosingLayoutRect(computeFloatRectForRepaint(repaintRect, repaintContainer, context.m_hasPositionFixedDescendant));
}
const AffineTransform& RenderSVGForeignObject::localToParentTransform() const
{
m_localToParentTransform = localTransform();
m_localToParentTransform.translate(m_viewport.location());
return m_localToParentTransform;
}
void RenderSVGForeignObject::updateLogicalWidth()
{
setWidth(static_cast<int>(roundf(m_viewport.width())));
}
RenderBox::LogicalExtentComputedValues RenderSVGForeignObject::computeLogicalHeight(LayoutUnit, LayoutUnit logicalTop) const
{
return { static_cast<int>(roundf(m_viewport.height())), logicalTop, ComputedMarginValues() };
}
void RenderSVGForeignObject::layout()
{
StackStats::LayoutCheckPoint layoutCheckPoint;
ASSERT(needsLayout());
ASSERT(!view().frameView().layoutContext().isPaintOffsetCacheEnabled());
LayoutRepainter repainter(*this, SVGRenderSupport::checkForSVGRepaintDuringLayout(*this));
bool updateCachedBoundariesInParents = false;
if (m_needsTransformUpdate) {
m_localTransform = foreignObjectElement().animatedLocalTransform();
m_needsTransformUpdate = false;
updateCachedBoundariesInParents = true;
}
FloatRect oldViewport = m_viewport;
SVGLengthContext lengthContext(&foreignObjectElement());
FloatPoint viewportLocation(foreignObjectElement().x().value(lengthContext), foreignObjectElement().y().value(lengthContext));
m_viewport = FloatRect(viewportLocation, FloatSize(foreignObjectElement().width().value(lengthContext), foreignObjectElement().height().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();
}
bool RenderSVGForeignObject::nodeAtFloatPoint(const HitTestRequest& request, HitTestResult& result, const FloatPoint& pointInParent, HitTestAction hitTestAction)
{
if (hitTestAction != HitTestForeground)
return false;
FloatPoint localPoint = localTransform().inverse().value_or(AffineTransform()).mapPoint(pointInParent);
if (SVGRenderSupport::isOverflowHidden(*this) && !m_viewport.contains(localPoint))
return false;
HitTestLocation hitTestLocation(localPoint);
return RenderBlock::nodeAtPoint(request, result, hitTestLocation, LayoutPoint(), HitTestForeground)
|| RenderBlock::nodeAtPoint(request, result, hitTestLocation, LayoutPoint(), HitTestFloat)
|| RenderBlock::nodeAtPoint(request, result, hitTestLocation, LayoutPoint(), HitTestChildBlockBackgrounds);
}
bool RenderSVGForeignObject::nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation&, const LayoutPoint&, HitTestAction)
{
ASSERT_NOT_REACHED();
return false;
}
void RenderSVGForeignObject::mapLocalToContainer(const RenderLayerModelObject* repaintContainer, TransformState& transformState, MapCoordinatesFlags, bool* wasFixed) const
{
SVGRenderSupport::mapLocalToContainer(*this, repaintContainer, transformState, wasFixed);
}
const RenderObject* RenderSVGForeignObject::pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap& geometryMap) const
{
return SVGRenderSupport::pushMappingToContainer(*this, ancestorToStopAt, geometryMap);
}
}