Modernize the toRenderSVGResourceContainer() helper.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 3 Feb 2014 04:50:00 +0000 (04:50 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 3 Feb 2014 04:50:00 +0000 (04:50 +0000)
<https://webkit.org/b/128091>

Make toRenderSVGResourceContainer() a free function like all the
other casting helpers. Use references instead of pointers where
applicable.

Reviewed by Anders Carlsson.

* rendering/RenderLayerFilterInfo.cpp:
(WebCore::RenderLayer::FilterInfo::updateReferenceFilterClients):
(WebCore::RenderLayer::FilterInfo::removeReferenceFilterClients):
* rendering/RenderObject.cpp:
* rendering/RenderObject.h:
* rendering/svg/RenderSVGGradientStop.cpp:
(WebCore::RenderSVGGradientStop::styleDidChange):
* rendering/svg/RenderSVGResource.cpp:
(WebCore::RenderSVGResource::markForLayoutAndParentResourceInvalidation):
* rendering/svg/RenderSVGResourceContainer.cpp:
(WebCore::RenderSVGResourceContainer::markAllClientsForInvalidation):
* rendering/svg/RenderSVGResourceContainer.h:
* rendering/svg/RenderSVGResourceFilter.cpp:
(WebCore::RenderSVGResourceFilter::buildPrimitives):
* rendering/svg/RenderSVGResourceFilter.h:
* rendering/svg/SVGRenderTreeAsText.cpp:
(WebCore::writeSVGResourceContainer):
* rendering/svg/SVGResourcesCycleSolver.cpp:
(WebCore::SVGResourcesCycleSolver::resolveCycles):
* svg/SVGElement.cpp:
(WebCore::SVGElement::svgAttributeChanged):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@163283 268f45cc-cd09-0410-ab3c-d52691b4dbfc

13 files changed:
Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderLayerFilterInfo.cpp
Source/WebCore/rendering/RenderObject.cpp
Source/WebCore/rendering/RenderObject.h
Source/WebCore/rendering/svg/RenderSVGGradientStop.cpp
Source/WebCore/rendering/svg/RenderSVGResource.cpp
Source/WebCore/rendering/svg/RenderSVGResourceContainer.cpp
Source/WebCore/rendering/svg/RenderSVGResourceContainer.h
Source/WebCore/rendering/svg/RenderSVGResourceFilter.cpp
Source/WebCore/rendering/svg/RenderSVGResourceFilter.h
Source/WebCore/rendering/svg/SVGRenderTreeAsText.cpp
Source/WebCore/rendering/svg/SVGResourcesCycleSolver.cpp
Source/WebCore/svg/SVGElement.cpp

index 845d58e9c726e0854de995a214102e2b4a759d61..00cf9bb9c8bce3851573c5370ec59ac0bf30d417 100644 (file)
@@ -1,3 +1,36 @@
+2014-02-02  Andreas Kling  <akling@apple.com>
+
+        Modernize the toRenderSVGResourceContainer() helper.
+        <https://webkit.org/b/128091>
+
+        Make toRenderSVGResourceContainer() a free function like all the
+        other casting helpers. Use references instead of pointers where
+        applicable.
+
+        Reviewed by Anders Carlsson.
+
+        * rendering/RenderLayerFilterInfo.cpp:
+        (WebCore::RenderLayer::FilterInfo::updateReferenceFilterClients):
+        (WebCore::RenderLayer::FilterInfo::removeReferenceFilterClients):
+        * rendering/RenderObject.cpp:
+        * rendering/RenderObject.h:
+        * rendering/svg/RenderSVGGradientStop.cpp:
+        (WebCore::RenderSVGGradientStop::styleDidChange):
+        * rendering/svg/RenderSVGResource.cpp:
+        (WebCore::RenderSVGResource::markForLayoutAndParentResourceInvalidation):
+        * rendering/svg/RenderSVGResourceContainer.cpp:
+        (WebCore::RenderSVGResourceContainer::markAllClientsForInvalidation):
+        * rendering/svg/RenderSVGResourceContainer.h:
+        * rendering/svg/RenderSVGResourceFilter.cpp:
+        (WebCore::RenderSVGResourceFilter::buildPrimitives):
+        * rendering/svg/RenderSVGResourceFilter.h:
+        * rendering/svg/SVGRenderTreeAsText.cpp:
+        (WebCore::writeSVGResourceContainer):
+        * rendering/svg/SVGResourcesCycleSolver.cpp:
+        (WebCore::SVGResourcesCycleSolver::resolveCycles):
+        * svg/SVGElement.cpp:
+        (WebCore::SVGElement::svgAttributeChanged):
+
 2014-02-02  Andreas Kling  <akling@apple.com>
 
         Minor SVGRootInlineBox cleanup.
index 3125ef63e55310de85eebfb04e79dcaca0bce034..f5bb2ebcb2f8ec0798f46be5796b01968ab3f255 100644 (file)
@@ -122,7 +122,7 @@ void RenderLayer::FilterInfo::updateReferenceFilterClients(const FilterOperation
             Element* filter = m_layer.renderer().element()->document().getElementById(referenceFilterOperation->fragment());
             if (!filter || !filter->renderer() || !filter->renderer()->isSVGResourceFilter())
                 continue;
-            filter->renderer()->toRenderSVGResourceContainer()->addClientRenderLayer(&m_layer);
+            toRenderSVGResourceContainer(*filter->renderer()).addClientRenderLayer(&m_layer);
             m_internalSVGReferences.append(filter);
         }
     }
@@ -137,7 +137,7 @@ void RenderLayer::FilterInfo::removeReferenceFilterClients()
         Element* filter = m_internalSVGReferences[i].get();
         if (!filter->renderer())
             continue;
-        filter->renderer()->toRenderSVGResourceContainer()->removeClientRenderLayer(&m_layer);
+        toRenderSVGResourceContainer(*filter->renderer()).removeClientRenderLayer(&m_layer);
     }
     m_internalSVGReferences.clear();
 }
index c34ff72751f2b14a5661bc041cf14aec219cbed7..289d99eb8359d62e3e83d4a22426d0dc92aad478 100644 (file)
@@ -2414,12 +2414,6 @@ bool RenderObject::canBeReplacedWithInlineRunIn() const
 
 #if ENABLE(SVG)
 
-RenderSVGResourceContainer* RenderObject::toRenderSVGResourceContainer()
-{
-    ASSERT_NOT_REACHED();
-    return 0;
-}
-
 void RenderObject::setNeedsBoundariesUpdate()
 {
     if (auto renderer = parent())
index 01da1084374cec233dd68fe73346236b8c299600..a69ef820c561e1b982281c07a025f829d0f94ac2 100644 (file)
@@ -441,8 +441,6 @@ public:
     virtual bool isSVGResourceFilter() const { return false; }
     virtual bool isSVGResourceFilterPrimitive() const { return false; }
 
-    virtual RenderSVGResourceContainer* toRenderSVGResourceContainer();
-
     // FIXME: Those belong into a SVG specific base-class for all renderers (see above)
     // Unfortunately we don't have such a class yet, because it's not possible for all renderers
     // to inherit from RenderSVGObject -> RenderObject (some need RenderBlock inheritance for instance)
index 6e90d6e012f5654c17d07e576f2d85e9c86a7f28..bc852cb9c338c12c25350ab651b75aa430c5d9f4 100644 (file)
@@ -58,9 +58,7 @@ void RenderSVGGradientStop::styleDidChange(StyleDifference diff, const RenderSty
     if (!renderer)
         return;
 
-    ASSERT(renderer->isSVGResourceContainer());
-    RenderSVGResourceContainer* container = renderer->toRenderSVGResourceContainer();
-    container->removeAllClientsFromCache();
+    toRenderSVGResourceContainer(*renderer).removeAllClientsFromCache();
 }
 
 void RenderSVGGradientStop::layout()
index d9e1d835ebb4d2d1b1c607a8717c7cda2480f1a2..5f96f78f7d3e71728c5249bc6b693f82f69c23db 100644 (file)
@@ -197,7 +197,7 @@ void RenderSVGResource::markForLayoutAndParentResourceInvalidation(RenderObject&
 
         if (current->isSVGResourceContainer()) {
             // This will process the rest of the ancestors.
-            current->toRenderSVGResourceContainer()->removeAllClientsFromCache();
+            toRenderSVGResourceContainer(*current).removeAllClientsFromCache();
             break;
         }
 
index be01b5a5d060865a7a1dda0fa254a6452d56cef0..7a33cd56880112b9a566df3f7b2c592f19653f5e 100644 (file)
@@ -100,7 +100,7 @@ void RenderSVGResourceContainer::markAllClientsForInvalidation(InvalidationMode
 
     for (auto client : m_clients) {
         if (client->isSVGResourceContainer()) {
-            client->toRenderSVGResourceContainer()->removeAllClientsFromCache(markForInvalidation);
+            toRenderSVGResourceContainer(*client).removeAllClientsFromCache(markForInvalidation);
             continue;
         }
 
index d0da46a6105bc871f20899aa4556744aff385a0f..00d90a3c11fa5495c1df4fc4b3b3e134a5e41e90 100644 (file)
@@ -37,7 +37,6 @@ public:
     virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle) override final;
 
     virtual bool isSVGResourceContainer() const override final { return true; }
-    virtual RenderSVGResourceContainer* toRenderSVGResourceContainer() override final { return this; }
 
     static bool shouldTransformOnTextPainting(RenderObject*, AffineTransform&);
     static AffineTransform transformOnNonScalingStroke(RenderObject*, const AffineTransform& resourceTransform);
@@ -77,6 +76,8 @@ private:
     HashSet<RenderLayer*> m_clientLayers;
 };
 
+RENDER_OBJECT_TYPE_CASTS(RenderSVGResourceContainer, isSVGResourceContainer())
+
 inline RenderSVGResourceContainer* getRenderSVGResourceContainerById(Document& document, const AtomicString& id)
 {
     if (id.isEmpty())
index a96be72f9bda70a7e560c99fc5b51225f5987c48..032ccfa9649da18016f86b684f48b33ff6c1ab97 100644 (file)
@@ -76,7 +76,7 @@ void RenderSVGResourceFilter::removeClientFromCache(RenderObject& client, bool m
     markClientForInvalidation(client, markForInvalidation ? BoundariesInvalidation : ParentOnlyInvalidation);
 }
 
-std::unique_ptr<SVGFilterBuilder> RenderSVGResourceFilter::buildPrimitives(SVGFilter* filter)
+std::unique_ptr<SVGFilterBuilder> RenderSVGResourceFilter::buildPrimitives(SVGFilter* filter) const
 {
     FloatRect targetBoundingBox = filter->targetBoundingBox();
 
index 97e6fdbf9c42ba3fe9ad478231c988df177117bf..86816babe099544cd3876b55806f3c0dd7f705ef 100644 (file)
@@ -76,7 +76,7 @@ public:
 
     virtual FloatRect resourceBoundingBox(const RenderObject&) override;
 
-    std::unique_ptr<SVGFilterBuilder> buildPrimitives(SVGFilter*);
+    std::unique_ptr<SVGFilterBuilder> buildPrimitives(SVGFilter*) const;
 
     SVGUnitTypes::SVGUnitType filterUnits() const { return filterElement().filterUnits(); }
     SVGUnitTypes::SVGUnitType primitiveUnits() const { return filterElement().primitiveUnits(); }
index aa6040968ed786797c6cac2c2da4750124d805a6..0a82f924f7cf88d0750059364a74ac9634ed1550 100644 (file)
@@ -476,48 +476,47 @@ void writeSVGResourceContainer(TextStream& ts, const RenderObject& object, int i
     const AtomicString& id = element->getIdAttribute();
     writeNameAndQuotedValue(ts, "id", id);    
 
-    RenderSVGResourceContainer* resource = const_cast<RenderObject&>(object).toRenderSVGResourceContainer();
-    ASSERT(resource);
+    const auto& resource = toRenderSVGResourceContainer(object);
 
-    if (resource->resourceType() == MaskerResourceType) {
-        RenderSVGResourceMasker* masker = static_cast<RenderSVGResourceMasker*>(resource);
-        writeNameValuePair(ts, "maskUnits", masker->maskUnits());
-        writeNameValuePair(ts, "maskContentUnits", masker->maskContentUnits());
+    if (resource.resourceType() == MaskerResourceType) {
+        const auto& masker = static_cast<const RenderSVGResourceMasker&>(resource);
+        writeNameValuePair(ts, "maskUnits", masker.maskUnits());
+        writeNameValuePair(ts, "maskContentUnits", masker.maskContentUnits());
         ts << "\n";
 #if ENABLE(FILTERS)
-    } else if (resource->resourceType() == FilterResourceType) {
-        RenderSVGResourceFilter* filter = static_cast<RenderSVGResourceFilter*>(resource);
-        writeNameValuePair(ts, "filterUnits", filter->filterUnits());
-        writeNameValuePair(ts, "primitiveUnits", filter->primitiveUnits());
+    } else if (resource.resourceType() == FilterResourceType) {
+        const auto& filter = static_cast<const RenderSVGResourceFilter&>(resource);
+        writeNameValuePair(ts, "filterUnits", filter.filterUnits());
+        writeNameValuePair(ts, "primitiveUnits", filter.primitiveUnits());
         ts << "\n";
         // Creating a placeholder filter which is passed to the builder.
         FloatRect dummyRect;
         RefPtr<SVGFilter> dummyFilter = SVGFilter::create(AffineTransform(), dummyRect, dummyRect, dummyRect, true);
-        if (auto builder = filter->buildPrimitives(dummyFilter.get())) {
+        if (auto builder = filter.buildPrimitives(dummyFilter.get())) {
             if (FilterEffect* lastEffect = builder->lastEffect())
                 lastEffect->externalRepresentation(ts, indent + 1);
         }
 #endif
-    } else if (resource->resourceType() == ClipperResourceType) {
-        RenderSVGResourceClipper* clipper = static_cast<RenderSVGResourceClipper*>(resource);
-        writeNameValuePair(ts, "clipPathUnits", clipper->clipPathUnits());
+    } else if (resource.resourceType() == ClipperResourceType) {
+        const auto& clipper = static_cast<const RenderSVGResourceClipper&>(resource);
+        writeNameValuePair(ts, "clipPathUnits", clipper.clipPathUnits());
         ts << "\n";
-    } else if (resource->resourceType() == MarkerResourceType) {
-        RenderSVGResourceMarker* marker = static_cast<RenderSVGResourceMarker*>(resource);
-        writeNameValuePair(ts, "markerUnits", marker->markerUnits());
-        ts << " [ref at " << marker->referencePoint() << "]";
+    } else if (resource.resourceType() == MarkerResourceType) {
+        const auto& marker = static_cast<const RenderSVGResourceMarker&>(resource);
+        writeNameValuePair(ts, "markerUnits", marker.markerUnits());
+        ts << " [ref at " << marker.referencePoint() << "]";
         ts << " [angle=";
-        if (marker->angle() == -1)
+        if (marker.angle() == -1)
             ts << "auto" << "]\n";
         else
-            ts << marker->angle() << "]\n";
-    } else if (resource->resourceType() == PatternResourceType) {
-        RenderSVGResourcePattern* pattern = static_cast<RenderSVGResourcePattern*>(resource);
+            ts << marker.angle() << "]\n";
+    } else if (resource.resourceType() == PatternResourceType) {
+        const auto& pattern = static_cast<const RenderSVGResourcePattern&>(resource);
 
         // Dump final results that are used for rendering. No use in asking SVGPatternElement for its patternUnits(), as it may
         // link to other patterns using xlink:href, we need to build the full inheritance chain, aka. collectPatternProperties()
         PatternAttributes attributes;
-        pattern->patternElement().collectPatternAttributes(attributes);
+        pattern.patternElement().collectPatternAttributes(attributes);
 
         writeNameValuePair(ts, "patternUnits", attributes.patternUnits());
         writeNameValuePair(ts, "patternContentUnits", attributes.patternContentUnits());
@@ -526,29 +525,29 @@ void writeSVGResourceContainer(TextStream& ts, const RenderObject& object, int i
         if (!transform.isIdentity())
             ts << " [patternTransform=" << transform << "]";
         ts << "\n";
-    } else if (resource->resourceType() == LinearGradientResourceType) {
-        RenderSVGResourceLinearGradient* gradient = static_cast<RenderSVGResourceLinearGradient*>(resource);
+    } else if (resource.resourceType() == LinearGradientResourceType) {
+        const auto& gradient = static_cast<const RenderSVGResourceLinearGradient&>(resource);
 
         // Dump final results that are used for rendering. No use in asking SVGGradientElement for its gradientUnits(), as it may
         // link to other gradients using xlink:href, we need to build the full inheritance chain, aka. collectGradientProperties()
         LinearGradientAttributes attributes;
-        gradient->linearGradientElement().collectGradientAttributes(attributes);
+        gradient.linearGradientElement().collectGradientAttributes(attributes);
         writeCommonGradientProperties(ts, attributes.spreadMethod(), attributes.gradientTransform(), attributes.gradientUnits());
 
-        ts << " [start=" << gradient->startPoint(attributes) << "] [end=" << gradient->endPoint(attributes) << "]\n";
-    }  else if (resource->resourceType() == RadialGradientResourceType) {
-        RenderSVGResourceRadialGradient* gradient = static_cast<RenderSVGResourceRadialGradient*>(resource);
+        ts << " [start=" << gradient.startPoint(attributes) << "] [end=" << gradient.endPoint(attributes) << "]\n";
+    }  else if (resource.resourceType() == RadialGradientResourceType) {
+        const auto& gradient = static_cast<const RenderSVGResourceRadialGradient&>(resource);
 
         // Dump final results that are used for rendering. No use in asking SVGGradientElement for its gradientUnits(), as it may
         // link to other gradients using xlink:href, we need to build the full inheritance chain, aka. collectGradientProperties()
         RadialGradientAttributes attributes;
-        gradient->radialGradientElement().collectGradientAttributes(attributes);
+        gradient.radialGradientElement().collectGradientAttributes(attributes);
         writeCommonGradientProperties(ts, attributes.spreadMethod(), attributes.gradientTransform(), attributes.gradientUnits());
 
-        FloatPoint focalPoint = gradient->focalPoint(attributes);
-        FloatPoint centerPoint = gradient->centerPoint(attributes);
-        float radius = gradient->radius(attributes);
-        float focalRadius = gradient->focalRadius(attributes);
+        FloatPoint focalPoint = gradient.focalPoint(attributes);
+        FloatPoint centerPoint = gradient.centerPoint(attributes);
+        float radius = gradient.radius(attributes);
+        float focalRadius = gradient.focalRadius(attributes);
 
         ts << " [center=" << centerPoint << "] [focal=" << focalPoint << "] [radius=" << radius << "] [focalRadius=" << focalRadius << "]\n";
     } else
index c6776f66736d62ae67470a8b9e25da3da4f59ac2..9f3a8fecb36596320e37ec791645f03ca052086a 100644 (file)
@@ -108,7 +108,7 @@ void SVGResourcesCycleSolver::resolveCycles()
     auto parent = m_renderer.parent();
     while (parent) {
         if (parent->isSVGResourceContainer())
-            parentResources.add(parent->toRenderSVGResourceContainer());
+            parentResources.add(toRenderSVGResourceContainer(parent));
         parent = parent->parent();
     }
 
@@ -132,7 +132,7 @@ void SVGResourcesCycleSolver::resolveCycles()
 
     // If we're a resource, add ourselves to the HashSet.
     if (m_renderer.isSVGResourceContainer())
-        m_allResources.add(m_renderer.toRenderSVGResourceContainer());
+        m_allResources.add(&toRenderSVGResourceContainer(m_renderer));
 
     ASSERT(!m_allResources.isEmpty());
 
index 637c3608a7a32f936e09ee9ee278be418322e094..3866314140f17b136bdcf777ea8a8d03e49ca350 100644 (file)
@@ -1010,10 +1010,10 @@ void SVGElement::svgAttributeChanged(const QualifiedName& attrName)
     }
 
     if (isIdAttributeName(attrName)) {
-        RenderObject* object = renderer();
+        auto renderer = this->renderer();
         // Notify resources about id changes, this is important as we cache resources by id in SVGDocumentExtensions
-        if (object && object->isSVGResourceContainer())
-            object->toRenderSVGResourceContainer()->idChanged();
+        if (renderer && renderer->isSVGResourceContainer())
+            toRenderSVGResourceContainer(*renderer).idChanged();
         if (inDocument())
             buildPendingResourcesIfNeeded();
         SVGElementInstance::invalidateAllInstancesOfElement(this);