FloatSize SVGSVGElement::currentViewportSize() const { if (hasIntrinsicWidth() && hasIntrinsicHeight()) return FloatSize(floatValueForLength(intrinsicWidth(), 0), floatValueForLength(intrinsicHeight(), 0)); if (!renderer()) return { }; if (is<RenderSVGRoot>(*renderer())) { auto& root = downcast<RenderSVGRoot>(*renderer()); return root.contentBoxRect().size() / root.style().effectiveZoom(); } return downcast<RenderSVGViewportContainer>(*renderer()).viewport().size(); }
FloatRect SVGSVGElement::currentViewBoxRect() const { if (m_useCurrentView) return m_viewSpec ? m_viewSpec->viewBox()->currentValue()->value() : FloatRect(); FloatRect useViewBox = viewBox()->currentValue()->value(); if (!useViewBox.isEmpty()) return useViewBox; if (!layoutObject() || !layoutObject()->isSVGRoot()) return FloatRect(); if (!toLayoutSVGRoot(layoutObject())->isEmbeddedThroughSVGImage()) return FloatRect(); // If no viewBox is specified but non-relative width/height values, then we // should always synthesize a viewBox if we're embedded through a SVGImage. return FloatRect(FloatPoint(), FloatSize(floatValueForLength(intrinsicWidth(), 0), floatValueForLength(intrinsicHeight(), 0))); }
FloatRect SVGSVGElement::currentViewBoxRect() const { if (m_viewSpec) return m_viewSpec->viewBox()->value(); FloatRect useViewBox = viewBox()->currentValue()->value(); if (!useViewBox.isEmpty()) return useViewBox; if (!shouldSynthesizeViewBox()) return FloatRect(); // If no viewBox is specified but non-relative width/height values, then we // should always synthesize a viewBox if we're embedded through a SVGImage. FloatSize synthesizedViewBoxSize(intrinsicWidth(), intrinsicHeight()); if (!hasIntrinsicWidth()) synthesizedViewBoxSize.setWidth(width()->currentValue()->scaleByPercentage( currentViewportSize().width())); if (!hasIntrinsicHeight()) synthesizedViewBoxSize.setHeight( height()->currentValue()->scaleByPercentage( currentViewportSize().height())); return FloatRect(FloatPoint(), synthesizedViewBoxSize); }