This source file includes following definitions.
- m_needsBoundariesOrTransformUpdate
- computeIntrinsicRatioInformation
- isEmbeddedThroughSVGImage
- isEmbeddedThroughFrameContainingSVGDocument
- resolveLengthAttributeForSVG
- computeReplacedLogicalWidth
- computeReplacedLogicalHeight
- layout
- paintReplaced
- willBeDestroyed
- styleDidChange
- isChildAllowed
- addChild
- removeChild
- insertedIntoTree
- willBeRemovedFromTree
- buildLocalToBorderBoxTransform
- localToParentTransform
- clippedOverflowRectForRepaint
- computeFloatRectForRepaint
- mapLocalToContainer
- pushMappingToContainer
- updateCachedBoundaries
- nodeAtPoint
- hasRelativeIntrinsicLogicalWidth
- hasRelativeLogicalHeight
#include "config.h"
#include "core/rendering/svg/RenderSVGRoot.h"
#include "core/frame/LocalFrame.h"
#include "core/rendering/HitTestResult.h"
#include "core/rendering/LayoutRectRecorder.h"
#include "core/rendering/LayoutRepainter.h"
#include "core/rendering/RenderPart.h"
#include "core/rendering/RenderView.h"
#include "core/rendering/svg/RenderSVGResourceContainer.h"
#include "core/rendering/svg/SVGRenderingContext.h"
#include "core/rendering/svg/SVGResources.h"
#include "core/rendering/svg/SVGResourcesCache.h"
#include "core/svg/SVGElement.h"
#include "core/svg/SVGSVGElement.h"
#include "core/svg/graphics/SVGImage.h"
#include "platform/LengthFunctions.h"
#include "platform/graphics/GraphicsContext.h"
using namespace std;
namespace WebCore {
RenderSVGRoot::RenderSVGRoot(SVGElement* node)
: RenderReplaced(node)
, m_objectBoundingBoxValid(false)
, m_isLayoutSizeChanged(false)
, m_needsBoundariesOrTransformUpdate(true)
{
}
RenderSVGRoot::~RenderSVGRoot()
{
}
void RenderSVGRoot::computeIntrinsicRatioInformation(FloatSize& intrinsicSize, double& intrinsicRatio, bool& isPercentageIntrinsicSize) const
{
SVGSVGElement* svg = toSVGSVGElement(node());
ASSERT(svg);
Length intrinsicWidthAttribute = svg->intrinsicWidth(SVGSVGElement::IgnoreCSSProperties);
Length intrinsicHeightAttribute = svg->intrinsicHeight(SVGSVGElement::IgnoreCSSProperties);
if (intrinsicWidthAttribute.isFixed() || intrinsicHeightAttribute.isFixed()) {
if (intrinsicWidthAttribute.isFixed())
intrinsicSize.setWidth(floatValueForLength(intrinsicWidthAttribute, 0));
if (intrinsicHeightAttribute.isFixed())
intrinsicSize.setHeight(floatValueForLength(intrinsicHeightAttribute, 0));
if (!intrinsicSize.isEmpty())
intrinsicRatio = intrinsicSize.width() / static_cast<double>(intrinsicSize.height());
return;
}
intrinsicSize = svg->viewBox()->currentValue()->value().size();
if (!intrinsicSize.isEmpty()) {
intrinsicRatio = intrinsicSize.width() / static_cast<double>(intrinsicSize.height());
intrinsicSize = FloatSize();
return;
}
if (intrinsicWidthAttribute.isPercent() && intrinsicHeightAttribute.isPercent()) {
isPercentageIntrinsicSize = true;
intrinsicSize = FloatSize(intrinsicWidthAttribute.percent(), intrinsicHeightAttribute.percent());
}
}
bool RenderSVGRoot::isEmbeddedThroughSVGImage() const
{
return SVGImage::isInSVGImage(toSVGSVGElement(node()));
}
bool RenderSVGRoot::isEmbeddedThroughFrameContainingSVGDocument() const
{
if (!node())
return false;
LocalFrame* frame = node()->document().frame();
if (!frame)
return false;
if (!frame->ownerRenderer())
return false;
return frame->document()->isSVGDocument();
}
static inline LayoutUnit resolveLengthAttributeForSVG(const Length& length, float scale, float maxSize)
{
return static_cast<LayoutUnit>(valueForLength(length, maxSize) * (length.isFixed() ? scale : 1));
}
LayoutUnit RenderSVGRoot::computeReplacedLogicalWidth(ShouldComputePreferred shouldComputePreferred) const
{
SVGSVGElement* svg = toSVGSVGElement(node());
ASSERT(svg);
if (!m_containerSize.isEmpty())
return m_containerSize.width();
if (style()->logicalWidth().isSpecified() || style()->logicalMaxWidth().isSpecified())
return RenderReplaced::computeReplacedLogicalWidth(shouldComputePreferred);
if (svg->widthAttributeEstablishesViewport())
return resolveLengthAttributeForSVG(svg->intrinsicWidth(SVGSVGElement::IgnoreCSSProperties), style()->effectiveZoom(), containingBlock()->availableLogicalWidth().toFloat());
if (isEmbeddedThroughFrameContainingSVGDocument())
return document().frame()->ownerRenderer()->availableLogicalWidth();
return RenderReplaced::computeReplacedLogicalWidth(shouldComputePreferred);
}
LayoutUnit RenderSVGRoot::computeReplacedLogicalHeight() const
{
SVGSVGElement* svg = toSVGSVGElement(node());
ASSERT(svg);
if (!m_containerSize.isEmpty())
return m_containerSize.height();
if (style()->logicalHeight().isSpecified() || style()->logicalMaxHeight().isSpecified())
return RenderReplaced::computeReplacedLogicalHeight();
if (svg->heightAttributeEstablishesViewport()) {
Length height = svg->intrinsicHeight(SVGSVGElement::IgnoreCSSProperties);
if (height.isPercent()) {
RenderBlock* cb = containingBlock();
ASSERT(cb);
while (cb->isAnonymous())
cb = cb->containingBlock();
cb->addPercentHeightDescendant(const_cast<RenderSVGRoot*>(this));
} else
RenderBlock::removePercentHeightDescendant(const_cast<RenderSVGRoot*>(this));
return resolveLengthAttributeForSVG(height, style()->effectiveZoom(), containingBlock()->availableLogicalHeight(IncludeMarginBorderPadding).toFloat());
}
if (isEmbeddedThroughFrameContainingSVGDocument())
return document().frame()->ownerRenderer()->availableLogicalHeight(IncludeMarginBorderPadding);
return RenderReplaced::computeReplacedLogicalHeight();
}
void RenderSVGRoot::layout()
{
ASSERT(needsLayout());
LayoutStateDisabler layoutStateDisabler(*this);
bool needsLayout = selfNeedsLayout();
LayoutRectRecorder recorder(*this, checkForRepaint() && needsLayout);
LayoutRepainter repainter(*this, checkForRepaintDuringLayout() && needsLayout);
LayoutSize oldSize = size();
updateLogicalWidth();
updateLogicalHeight();
buildLocalToBorderBoxTransform();
SVGRenderSupport::layoutResourcesIfNeeded(this);
SVGSVGElement* svg = toSVGSVGElement(node());
ASSERT(svg);
m_isLayoutSizeChanged = needsLayout || (svg->hasRelativeLengths() && oldSize != size());
SVGRenderSupport::layoutChildren(this, needsLayout || SVGRenderSupport::filtersForceContainerLayout(this));
if (m_needsBoundariesOrTransformUpdate) {
updateCachedBoundaries();
m_needsBoundariesOrTransformUpdate = false;
}
updateLayerTransform();
repainter.repaintAfterLayout();
clearNeedsLayout();
}
void RenderSVGRoot::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
{
if (pixelSnappedBorderBoxRect().isEmpty())
return;
if (paintInfo.context->paintingDisabled())
return;
SVGSVGElement* svg = toSVGSVGElement(node());
ASSERT(svg);
if (svg->hasEmptyViewBox())
return;
if (!firstChild()) {
SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObject(this);
if (!resources || !resources->filter())
return;
}
PaintInfo childPaintInfo(paintInfo);
childPaintInfo.context->save();
childPaintInfo.context->clip(pixelSnappedIntRect(overflowClipRect(paintOffset)));
IntPoint adjustedPaintOffset = roundedIntPoint(paintOffset);
childPaintInfo.applyTransform(AffineTransform::translation(adjustedPaintOffset.x(), adjustedPaintOffset.y()) * localToBorderBoxTransform());
{
SVGRenderingContext renderingContext;
bool continueRendering = true;
if (childPaintInfo.phase == PaintPhaseForeground) {
renderingContext.prepareToRenderSVGContent(this, childPaintInfo);
continueRendering = renderingContext.isRenderingPrepared();
}
if (continueRendering)
RenderBox::paint(childPaintInfo, LayoutPoint());
}
childPaintInfo.context->restore();
}
void RenderSVGRoot::willBeDestroyed()
{
RenderBlock::removePercentHeightDescendant(const_cast<RenderSVGRoot*>(this));
SVGResourcesCache::clientDestroyed(this);
RenderReplaced::willBeDestroyed();
}
void RenderSVGRoot::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
{
if (diff == StyleDifferenceLayout)
setNeedsBoundariesUpdate();
RenderReplaced::styleDidChange(diff, oldStyle);
SVGResourcesCache::clientStyleChanged(this, diff, style());
}
bool RenderSVGRoot::isChildAllowed(RenderObject* child, RenderStyle*) const
{
return child->isSVG() && !(child->isSVGInline() || child->isSVGInlineText());
}
void RenderSVGRoot::addChild(RenderObject* child, RenderObject* beforeChild)
{
RenderReplaced::addChild(child, beforeChild);
SVGResourcesCache::clientWasAddedToTree(child, child->style());
}
void RenderSVGRoot::removeChild(RenderObject* child)
{
SVGResourcesCache::clientWillBeRemovedFromTree(child);
RenderReplaced::removeChild(child);
}
void RenderSVGRoot::insertedIntoTree()
{
RenderReplaced::insertedIntoTree();
SVGResourcesCache::clientWasAddedToTree(this, style());
}
void RenderSVGRoot::willBeRemovedFromTree()
{
SVGResourcesCache::clientWillBeRemovedFromTree(this);
RenderReplaced::willBeRemovedFromTree();
}
void RenderSVGRoot::buildLocalToBorderBoxTransform()
{
SVGSVGElement* svg = toSVGSVGElement(node());
ASSERT(svg);
float scale = style()->effectiveZoom();
FloatPoint translate = svg->currentTranslate();
LayoutSize borderAndPadding(borderLeft() + paddingLeft(), borderTop() + paddingTop());
m_localToBorderBoxTransform = svg->viewBoxToViewTransform(contentWidth() / scale, contentHeight() / scale);
if (borderAndPadding.isEmpty() && scale == 1 && translate == FloatPoint::zero())
return;
m_localToBorderBoxTransform = AffineTransform(scale, 0, 0, scale, borderAndPadding.width() + translate.x(), borderAndPadding.height() + translate.y()) * m_localToBorderBoxTransform;
}
const AffineTransform& RenderSVGRoot::localToParentTransform() const
{
m_localToParentTransform = m_localToBorderBoxTransform;
if (x())
m_localToParentTransform.setE(m_localToParentTransform.e() + roundToInt(x()));
if (y())
m_localToParentTransform.setF(m_localToParentTransform.f() + roundToInt(y()));
return m_localToParentTransform;
}
LayoutRect RenderSVGRoot::clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const
{
return SVGRenderSupport::clippedOverflowRectForRepaint(this, repaintContainer);
}
void RenderSVGRoot::computeFloatRectForRepaint(const RenderLayerModelObject* repaintContainer, FloatRect& repaintRect, bool fixed) const
{
repaintRect = m_localToBorderBoxTransform.mapRect(repaintRect);
repaintRect.intersect(pixelSnappedBorderBoxRect());
LayoutRect rect = enclosingIntRect(repaintRect);
RenderReplaced::computeRectForRepaint(repaintContainer, rect, fixed);
repaintRect = rect;
}
void RenderSVGRoot::mapLocalToContainer(const RenderLayerModelObject* repaintContainer, TransformState& transformState, MapCoordinatesFlags mode, bool* wasFixed) const
{
ASSERT(mode & ~IsFixed);
ASSERT(mode & UseTransforms);
RenderReplaced::mapLocalToContainer(repaintContainer, transformState, mode | ApplyContainerFlip, wasFixed);
}
const RenderObject* RenderSVGRoot::pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap& geometryMap) const
{
return RenderReplaced::pushMappingToContainer(ancestorToStopAt, geometryMap);
}
void RenderSVGRoot::updateCachedBoundaries()
{
SVGRenderSupport::computeContainerBoundingBoxes(this, m_objectBoundingBox, m_objectBoundingBoxValid, m_strokeBoundingBox, m_repaintBoundingBox);
SVGRenderSupport::intersectRepaintRectWithResources(this, m_repaintBoundingBox);
m_repaintBoundingBox.inflate(borderAndPaddingWidth().toFloat());
}
bool RenderSVGRoot::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction hitTestAction)
{
LayoutPoint pointInParent = locationInContainer.point() - toLayoutSize(accumulatedOffset);
LayoutPoint pointInBorderBox = pointInParent - toLayoutSize(location());
if (contentBoxRect().contains(pointInBorderBox)) {
FloatPoint localPoint = localToParentTransform().inverse().mapPoint(FloatPoint(pointInParent));
for (RenderObject* child = lastChild(); child; child = child->previousSibling()) {
if (child->nodeAtFloatPoint(request, result, localPoint, hitTestAction)) {
updateHitTestResult(result, pointInBorderBox);
if (!result.addNodeToRectBasedTestResult(child->node(), request, locationInContainer))
return true;
}
}
}
if (hitTestAction == HitTestBlockBackground && visibleToHitTestRequest(request)) {
LayoutRect boundsRect(accumulatedOffset + location(), size());
if (locationInContainer.intersects(boundsRect)) {
updateHitTestResult(result, pointInBorderBox);
if (!result.addNodeToRectBasedTestResult(node(), request, locationInContainer, boundsRect))
return true;
}
}
return false;
}
bool RenderSVGRoot::hasRelativeIntrinsicLogicalWidth() const
{
SVGSVGElement* svg = toSVGSVGElement(node());
ASSERT(svg);
return svg->intrinsicWidth(SVGSVGElement::IgnoreCSSProperties).isPercent();
}
bool RenderSVGRoot::hasRelativeLogicalHeight() const
{
SVGSVGElement* svg = toSVGSVGElement(node());
ASSERT(svg);
return svg->intrinsicHeight(SVGSVGElement::IgnoreCSSProperties).isPercent();
}
}