Use #pragma once in WebCore
[WebKit-https.git] / Source / WebCore / svg / SVGFELightElement.cpp
index 58a2f26..9a85b40 100644 (file)
  */
 
 #include "config.h"
-
-#if ENABLE(SVG) && ENABLE(FILTERS)
 #include "SVGFELightElement.h"
 
-#include "Attribute.h"
+#include "ElementIterator.h"
 #include "RenderObject.h"
 #include "RenderSVGResource.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"
@@ -46,145 +48,139 @@ DEFINE_ANIMATED_NUMBER(SVGFELightElement, SVGNames::pointsAtZAttr, PointsAtZ, po
 DEFINE_ANIMATED_NUMBER(SVGFELightElement, SVGNames::specularExponentAttr, SpecularExponent, specularExponent)
 DEFINE_ANIMATED_NUMBER(SVGFELightElement, SVGNames::limitingConeAngleAttr, LimitingConeAngle, limitingConeAngle)
 
-SVGFELightElement::SVGFELightElement(const QualifiedName& tagName, Document* document)
+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
+
+SVGFELightElement::SVGFELightElement(const QualifiedName& tagName, Document& document)
     : SVGElement(tagName, document)
     , m_specularExponent(1)
 {
+    registerAnimatedPropertiesForSVGFELightElement();
+}
+
+SVGFELightElement* SVGFELightElement::findLightElement(const SVGElement* svgElement)
+{
+    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 nullptr;
+}
+
+RefPtr<LightSource> SVGFELightElement::findLightSource(const SVGElement* svgElement)
+{
+    SVGFELightElement* lightNode = findLightElement(svgElement);
+    if (!lightNode)
+        return 0;
+    return lightNode->lightSource();
 }
 
-void SVGFELightElement::parseMappedAttribute(Attribute* attr)
+void SVGFELightElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
 {
-    const String& value = attr->value();
-    if (attr->name() == SVGNames::azimuthAttr)
+    if (name == SVGNames::azimuthAttr) {
         setAzimuthBaseValue(value.toFloat());
-    else if (attr->name() == SVGNames::elevationAttr)
+        return;
+    }
+
+    if (name == SVGNames::elevationAttr) {
         setElevationBaseValue(value.toFloat());
-    else if (attr->name() == SVGNames::xAttr)
+        return;
+    }
+
+    if (name == SVGNames::xAttr) {
         setXBaseValue(value.toFloat());
-    else if (attr->name() == SVGNames::yAttr)
+        return;
+    }
+
+    if (name == SVGNames::yAttr) {
         setYBaseValue(value.toFloat());
-    else if (attr->name() == SVGNames::zAttr)
+        return;
+    }
+
+    if (name == SVGNames::zAttr) {
         setZBaseValue(value.toFloat());
-    else if (attr->name() == SVGNames::pointsAtXAttr)
+        return;
+    }
+
+    if (name == SVGNames::pointsAtXAttr) {
         setPointsAtXBaseValue(value.toFloat());
-    else if (attr->name() == SVGNames::pointsAtYAttr)
+        return;
+    }
+
+    if (name == SVGNames::pointsAtYAttr) {
         setPointsAtYBaseValue(value.toFloat());
-    else if (attr->name() == SVGNames::pointsAtZAttr)
+        return;
+    }
+
+    if (name == SVGNames::pointsAtZAttr) {
         setPointsAtZBaseValue(value.toFloat());
-    else if (attr->name() == SVGNames::specularExponentAttr)
+        return;
+    }
+
+    if (name == SVGNames::specularExponentAttr) {
         setSpecularExponentBaseValue(value.toFloat());
-    else if (attr->name() == SVGNames::limitingConeAngleAttr)
+        return;
+    }
+
+    if (name == SVGNames::limitingConeAngleAttr) {
         setLimitingConeAngleBaseValue(value.toFloat());
-    else
-        SVGElement::parseMappedAttribute(attr);
+        return;
+    }
+
+    SVGElement::parseAttribute(name, value);
 }
 
 void SVGFELightElement::svgAttributeChanged(const QualifiedName& attrName)
 {
-    SVGElement::svgAttributeChanged(attrName);
+    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) {
 
-    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();
+        auto* parent = 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;
+        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);
         }
-        // Handler for SpecularLighting has not implemented yet.
-        RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer);
-    }
-}
 
-void SVGFELightElement::synchronizeProperty(const QualifiedName& attrName)
-{
-    SVGElement::synchronizeProperty(attrName);
-
-    if (attrName == anyQName()) {
-        synchronizeAzimuth();
-        synchronizeElevation();
-        synchronizeX();
-        synchronizeY();
-        synchronizeZ();
-        synchronizePointsAtX();
-        synchronizePointsAtY();
-        synchronizePointsAtZ();
-        synchronizeSpecularExponent();
-        synchronizeLimitingConeAngle();
         return;
     }
 
-    if (attrName == SVGNames::azimuthAttr)
-        synchronizeAzimuth();
-    else if (attrName == SVGNames::elevationAttr)
-        synchronizeElevation();
-    else if (attrName == SVGNames::xAttr)
-        synchronizeX();
-    else if (attrName == SVGNames::yAttr)
-        synchronizeY();
-    else if (attrName == SVGNames::zAttr)
-        synchronizeZ();
-    else if (attrName == SVGNames::pointsAtXAttr)
-        synchronizePointsAtX();
-    else if (attrName == SVGNames::pointsAtYAttr)
-        synchronizePointsAtY();
-    else if (attrName == SVGNames::pointsAtZAttr)
-        synchronizePointsAtZ();
-    else if (attrName == SVGNames::specularExponentAttr)
-        synchronizeSpecularExponent();
-    else if (attrName == SVGNames::limitingConeAngleAttr)
-        synchronizeLimitingConeAngle();
-}
-
-AttributeToPropertyTypeMap& SVGFELightElement::attributeToPropertyTypeMap()
-{
-    DEFINE_STATIC_LOCAL(AttributeToPropertyTypeMap, s_attributeToPropertyTypeMap, ());
-    return s_attributeToPropertyTypeMap;
-}
-
-void SVGFELightElement::fillAttributeToPropertyTypeMap()
-{
-    AttributeToPropertyTypeMap& attributeToPropertyTypeMap = this->attributeToPropertyTypeMap();
-    attributeToPropertyTypeMap.set(SVGNames::azimuthAttr, AnimatedNumber);
-    attributeToPropertyTypeMap.set(SVGNames::elevationAttr, AnimatedNumber);
-    attributeToPropertyTypeMap.set(SVGNames::xAttr, AnimatedNumber);
-    attributeToPropertyTypeMap.set(SVGNames::yAttr, AnimatedNumber);
-    attributeToPropertyTypeMap.set(SVGNames::zAttr, AnimatedNumber);
-    attributeToPropertyTypeMap.set(SVGNames::pointsAtXAttr, AnimatedNumber);
-    attributeToPropertyTypeMap.set(SVGNames::pointsAtYAttr, AnimatedNumber);
-    attributeToPropertyTypeMap.set(SVGNames::pointsAtZAttr, AnimatedNumber);
-    attributeToPropertyTypeMap.set(SVGNames::specularExponentAttr, AnimatedNumber);
-    attributeToPropertyTypeMap.set(SVGNames::limitingConeAngleAttr, AnimatedNumber);
+    SVGElement::svgAttributeChanged(attrName);
 }
 
-void SVGFELightElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
+void SVGFELightElement::childrenChanged(const ChildChange& change)
 {
-    SVGElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
+    SVGElement::childrenChanged(change);
 
-    if (!changedByParser) {
-        if (ContainerNode* parent = parentNode()) {
-            RenderObject* renderer = parent->renderer();
-            if (renderer && renderer->isSVGResourceFilterPrimitive())
-                RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer);
-        }
-    }
+    if (change.source == ChildChangeSourceParser)
+        return;
+    ContainerNode* parent = parentNode();
+    if (!parent)
+        return;
+    RenderElement* renderer = parent->renderer();
+    if (renderer && renderer->isSVGResourceFilterPrimitive())
+        RenderSVGResource::markForLayoutAndParentResourceInvalidation(*renderer);
 }
 
 }
-
-#endif // ENABLE(SVG)