Skip to content

Commit

Permalink
[LBSE] Cleanup SVGSVGElements svgAttributeChanged() / currentViewBoxR…
Browse files Browse the repository at this point in the history
…ect()

https://bugs.webkit.org/show_bug.cgi?id=246017

Reviewed by Alejandro G. Castro.

Modernize the code and clean it up.

* Source/WebCore/svg/SVGSVGElement.cpp:
(WebCore::SVGSVGElement::svgAttributeChanged):
(WebCore::SVGSVGElement::currentViewBoxRect const):

Canonical link: https://commits.webkit.org/255264@main
  • Loading branch information
nikolaszimmermann committed Oct 7, 2022
1 parent d4d2eaf commit ff25888
Showing 1 changed file with 34 additions and 19 deletions.
53 changes: 34 additions & 19 deletions Source/WebCore/svg/SVGSVGElement.cpp
Expand Up @@ -208,21 +208,26 @@ void SVGSVGElement::parseAttribute(const QualifiedName& name, const AtomString&

void SVGSVGElement::svgAttributeChanged(const QualifiedName& attrName)
{
auto isEmbeddedThroughFrameContainingSVGDocument = [](const RenderElement& renderer) -> bool {
if (auto* svgRoot = dynamicDowncast<LegacyRenderSVGRoot>(renderer))
return svgRoot->isEmbeddedThroughFrameContainingSVGDocument();

#if ENABLE(LAYER_BASED_SVG_ENGINE)
if (auto* svgRoot = dynamicDowncast<RenderSVGRoot>(renderer))
return svgRoot->isEmbeddedThroughFrameContainingSVGDocument();
#endif

return false;
};

if (PropertyRegistry::isKnownAttribute(attrName)) {
InstanceInvalidationGuard guard(*this);
setPresentationalHintStyleIsDirty();

if (attrName == SVGNames::widthAttr || attrName == SVGNames::heightAttr) {
// FIXME: try to get rid of this custom handling of embedded SVG invalidation, maybe through abstraction.
if (auto* renderer = this->renderer()) {
bool embeddedThroughFrame = false;
#if ENABLE(LAYER_BASED_SVG_ENGINE)
if (is<RenderSVGRoot>(renderer) && downcast<RenderSVGRoot>(renderer)->isEmbeddedThroughFrameContainingSVGDocument())
embeddedThroughFrame = true;
#endif
if (!embeddedThroughFrame && is<LegacyRenderSVGRoot>(renderer) && downcast<LegacyRenderSVGRoot>(renderer)->isEmbeddedThroughFrameContainingSVGDocument())
embeddedThroughFrame = true;
if (embeddedThroughFrame)
if (isEmbeddedThroughFrameContainingSVGDocument(*renderer))
renderer->view().setNeedsLayout(MarkOnlyThis);
}
}
Expand Down Expand Up @@ -526,26 +531,36 @@ bool SVGSVGElement::hasTransformRelatedAttributes() const

FloatRect SVGSVGElement::currentViewBoxRect() const
{
if (m_useCurrentView)
return m_viewSpec ? m_viewSpec->viewBox() : FloatRect();
if (m_useCurrentView) {
if (m_viewSpec)
return m_viewSpec->viewBox();
return { };
}

FloatRect viewBox = this->viewBox();
auto viewBox = this->viewBox();
if (!viewBox.isEmpty())
return viewBox;

bool isEmbeddedThroughSVGImage = false;
if (is<LegacyRenderSVGRoot>(renderer()) && downcast<LegacyRenderSVGRoot>(*renderer()).isEmbeddedThroughSVGImage())
isEmbeddedThroughSVGImage = true;
auto isEmbeddedThroughSVGImage = [](const RenderElement* renderer) -> bool {
if (!renderer)
return false;

if (auto* svgRoot = dynamicDowncast<LegacyRenderSVGRoot>(renderer))
return svgRoot->isEmbeddedThroughSVGImage();

#if ENABLE(LAYER_BASED_SVG_ENGINE)
else if (is<RenderSVGRoot>(renderer()) && downcast<RenderSVGRoot>(*renderer()).isEmbeddedThroughSVGImage())
isEmbeddedThroughSVGImage = true;
if (auto* svgRoot = dynamicDowncast<RenderSVGRoot>(renderer))
return svgRoot->isEmbeddedThroughSVGImage();
#endif

if (!isEmbeddedThroughSVGImage)
return false;
};

if (!isEmbeddedThroughSVGImage(renderer()))
return { };

Length intrinsicWidth = this->intrinsicWidth();
Length intrinsicHeight = this->intrinsicHeight();
auto intrinsicWidth = this->intrinsicWidth();
auto intrinsicHeight = this->intrinsicHeight();
if (!intrinsicWidth.isFixed() || !intrinsicHeight.isFixed())
return { };

Expand Down

0 comments on commit ff25888

Please sign in to comment.