Remove the SVG elements' attributes macros
[WebKit-https.git] / Source / WebCore / svg / SVGFELightElement.cpp
index 1bd725c..891fedd 100644 (file)
@@ -2,6 +2,7 @@
  * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
  * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org>
  * Copyright (C) 2005 Oliver Hunt <oliver@nerget.com>
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
  */
 
 #include "config.h"
-
-#if ENABLE(SVG) && ENABLE(FILTERS)
 #include "SVGFELightElement.h"
 
-#include "Attribute.h"
 #include "ElementIterator.h"
 #include "RenderObject.h"
 #include "RenderSVGResource.h"
-#include "SVGElementInstance.h"
 #include "SVGFEDiffuseLightingElement.h"
+#include "SVGFEDistantLightElement.h"
+#include "SVGFEPointLightElement.h"
 #include "SVGFESpecularLightingElement.h"
+#include "SVGFESpotLightElement.h"
 #include "SVGFilterElement.h"
 #include "SVGFilterPrimitiveStandardAttributes.h"
 #include "SVGNames.h"
+#include <wtf/IsoMallocInlines.h>
 
 namespace WebCore {
 
-// Animated property definitions
-DEFINE_ANIMATED_NUMBER(SVGFELightElement, SVGNames::azimuthAttr, Azimuth, azimuth)
-DEFINE_ANIMATED_NUMBER(SVGFELightElement, SVGNames::elevationAttr, Elevation, elevation)
-DEFINE_ANIMATED_NUMBER(SVGFELightElement, SVGNames::xAttr, X, x)
-DEFINE_ANIMATED_NUMBER(SVGFELightElement, SVGNames::yAttr, Y, y)
-DEFINE_ANIMATED_NUMBER(SVGFELightElement, SVGNames::zAttr, Z, z)
-DEFINE_ANIMATED_NUMBER(SVGFELightElement, SVGNames::pointsAtXAttr, PointsAtX, pointsAtX)
-DEFINE_ANIMATED_NUMBER(SVGFELightElement, SVGNames::pointsAtYAttr, PointsAtY, pointsAtY)
-DEFINE_ANIMATED_NUMBER(SVGFELightElement, SVGNames::pointsAtZAttr, PointsAtZ, pointsAtZ)
-DEFINE_ANIMATED_NUMBER(SVGFELightElement, SVGNames::specularExponentAttr, SpecularExponent, specularExponent)
-DEFINE_ANIMATED_NUMBER(SVGFELightElement, SVGNames::limitingConeAngleAttr, LimitingConeAngle, limitingConeAngle)
-
-BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGFELightElement)
-    REGISTER_LOCAL_ANIMATED_PROPERTY(azimuth)
-    REGISTER_LOCAL_ANIMATED_PROPERTY(elevation)
-    REGISTER_LOCAL_ANIMATED_PROPERTY(x)
-    REGISTER_LOCAL_ANIMATED_PROPERTY(y)
-    REGISTER_LOCAL_ANIMATED_PROPERTY(z)
-    REGISTER_LOCAL_ANIMATED_PROPERTY(pointsAtX)
-    REGISTER_LOCAL_ANIMATED_PROPERTY(pointsAtY)
-    REGISTER_LOCAL_ANIMATED_PROPERTY(pointsAtZ)
-    REGISTER_LOCAL_ANIMATED_PROPERTY(specularExponent)
-    REGISTER_LOCAL_ANIMATED_PROPERTY(limitingConeAngle)
-END_REGISTER_ANIMATED_PROPERTIES
+WTF_MAKE_ISO_ALLOCATED_IMPL(SVGFELightElement);
 
 SVGFELightElement::SVGFELightElement(const QualifiedName& tagName, Document& document)
     : SVGElement(tagName, document)
-    , m_specularExponent(1)
 {
-    registerAnimatedPropertiesForSVGFELightElement();
+    registerAttributes();
 }
 
 SVGFELightElement* SVGFELightElement::findLightElement(const SVGElement* svgElement)
 {
-    auto children = childrenOfType<SVGElement>(*svgElement);
-    for (auto child = children.begin(), end = children.end(); child != end; ++child) {
-        if (isSVGFEDistantLightElement(*child) || isSVGFEPointLightElement(*child) || isSVGFESpotLightElement(*child))
-            return static_cast<SVGFELightElement*>(const_cast<SVGElement*>(&*child));
+    for (auto& child : childrenOfType<SVGElement>(*svgElement)) {
+        if (is<SVGFEDistantLightElement>(child) || is<SVGFEPointLightElement>(child) || is<SVGFESpotLightElement>(child))
+            return static_cast<SVGFELightElement*>(const_cast<SVGElement*>(&child));
     }
-    return 0;
+    return nullptr;
 }
 
-PassRefPtr<LightSource> SVGFELightElement::findLightSource(const SVGElement* svgElement)
+void SVGFELightElement::registerAttributes()
 {
-    SVGFELightElement* lightNode = findLightElement(svgElement);
-    if (!lightNode)
-        return 0;
-    return lightNode->lightSource();
-}
-
-bool SVGFELightElement::isSupportedAttribute(const QualifiedName& attrName)
-{
-    DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
-    if (supportedAttributes.isEmpty()) {
-        supportedAttributes.add(SVGNames::azimuthAttr);
-        supportedAttributes.add(SVGNames::elevationAttr);
-        supportedAttributes.add(SVGNames::xAttr);
-        supportedAttributes.add(SVGNames::yAttr);
-        supportedAttributes.add(SVGNames::zAttr);
-        supportedAttributes.add(SVGNames::pointsAtXAttr);
-        supportedAttributes.add(SVGNames::pointsAtYAttr);
-        supportedAttributes.add(SVGNames::pointsAtZAttr);
-        supportedAttributes.add(SVGNames::specularExponentAttr);
-        supportedAttributes.add(SVGNames::limitingConeAngleAttr);
-    }
-    return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
+    auto& registry = attributeRegistry();
+    if (!registry.isEmpty())
+        return;
+    registry.registerAttribute<SVGNames::azimuthAttr, &SVGFELightElement::m_azimuth>();
+    registry.registerAttribute<SVGNames::elevationAttr, &SVGFELightElement::m_elevation>();
+    registry.registerAttribute<SVGNames::xAttr, &SVGFELightElement::m_x>();
+    registry.registerAttribute<SVGNames::yAttr, &SVGFELightElement::m_y>();
+    registry.registerAttribute<SVGNames::zAttr, &SVGFELightElement::m_z>();
+    registry.registerAttribute<SVGNames::pointsAtXAttr, &SVGFELightElement::m_pointsAtX>();
+    registry.registerAttribute<SVGNames::pointsAtYAttr, &SVGFELightElement::m_pointsAtY>();
+    registry.registerAttribute<SVGNames::pointsAtZAttr, &SVGFELightElement::m_pointsAtZ>();
+    registry.registerAttribute<SVGNames::specularExponentAttr, &SVGFELightElement::m_specularExponent>();
+    registry.registerAttribute<SVGNames::limitingConeAngleAttr, &SVGFELightElement::m_limitingConeAngle>();
 }
 
 void SVGFELightElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
 {
-    if (!isSupportedAttribute(name)) {
-        SVGElement::parseAttribute(name, value);
-        return;
-    }
-
     if (name == SVGNames::azimuthAttr) {
-        setAzimuthBaseValue(value.toFloat());
+        m_azimuth.setValue(value.toFloat());
         return;
     }
 
     if (name == SVGNames::elevationAttr) {
-        setElevationBaseValue(value.toFloat());
+        m_elevation.setValue(value.toFloat());
         return;
     }
 
     if (name == SVGNames::xAttr) {
-        setXBaseValue(value.toFloat());
+        m_x.setValue(value.toFloat());
         return;
     }
 
     if (name == SVGNames::yAttr) {
-        setYBaseValue(value.toFloat());
+        m_y.setValue(value.toFloat());
         return;
     }
 
     if (name == SVGNames::zAttr) {
-        setZBaseValue(value.toFloat());
+        m_z.setValue(value.toFloat());
         return;
     }
 
     if (name == SVGNames::pointsAtXAttr) {
-        setPointsAtXBaseValue(value.toFloat());
+        m_pointsAtX.setValue(value.toFloat());
         return;
     }
 
     if (name == SVGNames::pointsAtYAttr) {
-        setPointsAtYBaseValue(value.toFloat());
+        m_pointsAtY.setValue(value.toFloat());
         return;
     }
 
     if (name == SVGNames::pointsAtZAttr) {
-        setPointsAtZBaseValue(value.toFloat());
+        m_pointsAtZ.setValue(value.toFloat());
         return;
     }
 
     if (name == SVGNames::specularExponentAttr) {
-        setSpecularExponentBaseValue(value.toFloat());
+        m_specularExponent.setValue(value.toFloat());
         return;
     }
 
     if (name == SVGNames::limitingConeAngleAttr) {
-        setLimitingConeAngleBaseValue(value.toFloat());
+        m_limitingConeAngle.setValue(value.toFloat());
         return;
     }
 
-    ASSERT_NOT_REACHED();
+    SVGElement::parseAttribute(name, value);
 }
 
 void SVGFELightElement::svgAttributeChanged(const QualifiedName& attrName)
 {
-    if (!isSupportedAttribute(attrName)) {
-        SVGElement::svgAttributeChanged(attrName);
-        return;
-    }
-
-    SVGElementInstance::InvalidationGuard invalidationGuard(this);
-    
-    if (attrName == SVGNames::azimuthAttr
-        || attrName == SVGNames::elevationAttr
-        || attrName == SVGNames::xAttr
-        || attrName == SVGNames::yAttr
-        || attrName == SVGNames::zAttr
-        || attrName == SVGNames::pointsAtXAttr
-        || attrName == SVGNames::pointsAtYAttr
-        || attrName == SVGNames::pointsAtZAttr
-        || attrName == SVGNames::specularExponentAttr
-        || attrName == SVGNames::limitingConeAngleAttr) {
-        ContainerNode* parent = parentNode();
+    if (isKnownAttribute(attrName)) {
+        auto parent = makeRefPtr(parentElement());
         if (!parent)
             return;
 
-        RenderObject* renderer = parent->renderer();
+        auto* renderer = parent->renderer();
         if (!renderer || !renderer->isSVGResourceFilterPrimitive())
             return;
 
-        if (parent->hasTagName(SVGNames::feDiffuseLightingTag)) {
-            SVGFEDiffuseLightingElement* diffuseLighting = static_cast<SVGFEDiffuseLightingElement*>(parent);
-            diffuseLighting->lightElementAttributeChanged(this, attrName);
-            return;
-        } else if (parent->hasTagName(SVGNames::feSpecularLightingTag)) {
-            SVGFESpecularLightingElement* specularLighting = static_cast<SVGFESpecularLightingElement*>(parent);
-            specularLighting->lightElementAttributeChanged(this, attrName);
-            return;
+        if (is<SVGFEDiffuseLightingElement>(*parent)) {
+            InstanceInvalidationGuard guard(*this);
+            downcast<SVGFEDiffuseLightingElement>(*parent).lightElementAttributeChanged(this, attrName);
+        } else if (is<SVGFESpecularLightingElement>(*parent)) {
+            InstanceInvalidationGuard guard(*this);
+            downcast<SVGFESpecularLightingElement>(*parent).lightElementAttributeChanged(this, attrName);
         }
+
+        return;
     }
 
-    ASSERT_NOT_REACHED();
+    SVGElement::svgAttributeChanged(attrName);
 }
 
 void SVGFELightElement::childrenChanged(const ChildChange& change)
 {
     SVGElement::childrenChanged(change);
 
-    if (change.source == ChildChangeSourceParser)
+    if (change.source == ChildChangeSource::Parser)
         return;
-    ContainerNode* parent = parentNode();
+    auto parent = makeRefPtr(parentNode());
     if (!parent)
         return;
-    RenderObject* renderer = parent->renderer();
+    RenderElement* renderer = parent->renderer();
     if (renderer && renderer->isSVGResourceFilterPrimitive())
-        RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer);
+        RenderSVGResource::markForLayoutAndParentResourceInvalidation(*renderer);
 }
 
 }
-
-#endif // ENABLE(SVG)