Improve use of NeverDestroyed
[WebKit-https.git] / Source / WebCore / svg / SVGMaskElement.cpp
index 56cba9d..d44988e 100644 (file)
 #include "config.h"
 #include "SVGMaskElement.h"
 
-#include "Attribute.h"
 #include "RenderSVGResourceMasker.h"
-#include "SVGElementInstance.h"
 #include "SVGNames.h"
 #include "SVGRenderSupport.h"
+#include "SVGStringList.h"
 #include "SVGUnitTypes.h"
 #include "StyleResolver.h"
 #include <wtf/NeverDestroyed.h>
@@ -79,52 +78,56 @@ Ref<SVGMaskElement> SVGMaskElement::create(const QualifiedName& tagName, Documen
 
 bool SVGMaskElement::isSupportedAttribute(const QualifiedName& attrName)
 {
-    static NeverDestroyed<HashSet<QualifiedName>> supportedAttributes;
-    if (supportedAttributes.get().isEmpty()) {
-        SVGTests::addSupportedAttributes(supportedAttributes);
-        SVGLangSpace::addSupportedAttributes(supportedAttributes);
-        SVGExternalResourcesRequired::addSupportedAttributes(supportedAttributes);
-        supportedAttributes.get().add(SVGNames::maskUnitsAttr);
-        supportedAttributes.get().add(SVGNames::maskContentUnitsAttr);
-        supportedAttributes.get().add(SVGNames::xAttr);
-        supportedAttributes.get().add(SVGNames::yAttr);
-        supportedAttributes.get().add(SVGNames::widthAttr);
-        supportedAttributes.get().add(SVGNames::heightAttr);
-    }
+    static const auto supportedAttributes = makeNeverDestroyed([] {
+        HashSet<QualifiedName> set;
+        SVGTests::addSupportedAttributes(set);
+        SVGLangSpace::addSupportedAttributes(set);
+        SVGExternalResourcesRequired::addSupportedAttributes(set);
+        set.add({
+            SVGNames::maskUnitsAttr,
+            SVGNames::maskContentUnitsAttr,
+            SVGNames::refYAttr,
+            SVGNames::xAttr,
+            SVGNames::yAttr,
+            SVGNames::widthAttr,
+            SVGNames::heightAttr,
+        });
+        return set;
+    }());
     return supportedAttributes.get().contains<SVGAttributeHashTranslator>(attrName);
 }
 
 void SVGMaskElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
 {
-    SVGParsingError parseError = NoError;
-
-    if (!isSupportedAttribute(name))
-        SVGElement::parseAttribute(name, value);
-    else if (name == SVGNames::maskUnitsAttr) {
-        SVGUnitTypes::SVGUnitType propertyValue = SVGPropertyTraits<SVGUnitTypes::SVGUnitType>::fromString(value);
+    if (name == SVGNames::maskUnitsAttr) {
+        auto propertyValue = SVGPropertyTraits<SVGUnitTypes::SVGUnitType>::fromString(value);
         if (propertyValue > 0)
             setMaskUnitsBaseValue(propertyValue);
         return;
-    } else if (name == SVGNames::maskContentUnitsAttr) {
-        SVGUnitTypes::SVGUnitType propertyValue = SVGPropertyTraits<SVGUnitTypes::SVGUnitType>::fromString(value);
+    }
+    if (name == SVGNames::maskContentUnitsAttr) {
+        auto propertyValue = SVGPropertyTraits<SVGUnitTypes::SVGUnitType>::fromString(value);
         if (propertyValue > 0)
             setMaskContentUnitsBaseValue(propertyValue);
         return;
-    } else if (name == SVGNames::xAttr)
-        setXBaseValue(SVGLength::construct(LengthModeWidth, value, parseError));
+    }
+
+    SVGParsingError parseError = NoError;
+
+    if (name == SVGNames::xAttr)
+        setXBaseValue(SVGLengthValue::construct(LengthModeWidth, value, parseError));
     else if (name == SVGNames::yAttr)
-        setYBaseValue(SVGLength::construct(LengthModeHeight, value, parseError));
+        setYBaseValue(SVGLengthValue::construct(LengthModeHeight, value, parseError));
     else if (name == SVGNames::widthAttr)
-        setWidthBaseValue(SVGLength::construct(LengthModeWidth, value, parseError));
+        setWidthBaseValue(SVGLengthValue::construct(LengthModeWidth, value, parseError));
     else if (name == SVGNames::heightAttr)
-        setHeightBaseValue(SVGLength::construct(LengthModeHeight, value, parseError));
-    else if (SVGTests::parseAttribute(name, value)
-             || SVGLangSpace::parseAttribute(name, value)
-             || SVGExternalResourcesRequired::parseAttribute(name, value)) {
-    } else
-        ASSERT_NOT_REACHED();
+        setHeightBaseValue(SVGLengthValue::construct(LengthModeHeight, value, parseError));
 
     reportAttributeParsingError(parseError, name, value);
+
+    SVGElement::parseAttribute(name, value);
+    SVGTests::parseAttribute(name, value);
+    SVGExternalResourcesRequired::parseAttribute(name, value);
 }
 
 void SVGMaskElement::svgAttributeChanged(const QualifiedName& attrName)
@@ -134,7 +137,7 @@ void SVGMaskElement::svgAttributeChanged(const QualifiedName& attrName)
         return;
     }
 
-    SVGElementInstance::InvalidationGuard invalidationGuard(this);
+    InstanceInvalidationGuard guard(*this);
 
     if (attrName == SVGNames::xAttr
         || attrName == SVGNames::yAttr
@@ -159,35 +162,24 @@ void SVGMaskElement::childrenChanged(const ChildChange& change)
         object->setNeedsLayout();
 }
 
-RenderPtr<RenderElement> SVGMaskElement::createElementRenderer(Ref<RenderStyle>&& style)
+RenderPtr<RenderElement> SVGMaskElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&)
 {
-    RenderPtr<RenderElement> maskRenderer = createRenderer<RenderSVGResourceMasker>(*this, WTF::move(style));
-    
-    // Pass along existing render layer clients.
-    for (auto* clientLayer : m_clientLayers)
-        static_cast<RenderSVGResourceMasker*>(maskRenderer.get())->addClientRenderLayer(clientLayer);
-    
-    return maskRenderer;
+    return createRenderer<RenderSVGResourceMasker>(*this, WTFMove(style));
 }
 
-void SVGMaskElement::addClientRenderLayer(RenderLayer* client)
+Ref<SVGStringList> SVGMaskElement::requiredFeatures()
 {
-    ASSERT(client);
-    m_clientLayers.add(client);
-    
-    // Pass it along to the renderer.
-    if (renderer())
-        static_cast<RenderSVGResourceMasker*>(renderer())->addClientRenderLayer(client);
+    return SVGTests::requiredFeatures(*this);
+}
+
+Ref<SVGStringList> SVGMaskElement::requiredExtensions()
+{ 
+    return SVGTests::requiredExtensions(*this);
 }
 
-void SVGMaskElement::removeClientRenderLayer(RenderLayer* client)
+Ref<SVGStringList> SVGMaskElement::systemLanguage()
 {
-    ASSERT(client);
-    m_clientLayers.remove(client);
-    
-    // Pass it along to the renderer.
-    if (renderer())
-        static_cast<RenderSVGResourceMasker*>(renderer())->removeClientRenderLayer(client);
+    return SVGTests::systemLanguage(*this);
 }
 
 }