Load event must be fired only for the SVG structurally external elements and the...
[WebKit-https.git] / Source / WebCore / svg / SVGExternalResourcesRequired.cpp
index 61c5743..b233b55 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
  * Copyright (C) 2004, 2005, 2007 Rob Buis <buis@kde.org>
+ * 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)
 #include "SVGExternalResourcesRequired.h"
 
-#include "Attr.h"
+#include "RenderSVGResource.h"
+#include "RenderSVGShape.h"
+#include "SVGElement.h"
 #include "SVGNames.h"
 
 namespace WebCore {
 
-bool SVGExternalResourcesRequired::parseMappedAttribute(Attribute* attr)
+SVGExternalResourcesRequired::SVGExternalResourcesRequired(SVGElement* contextElement)
+    : m_contextElement(*contextElement)
+    , m_externalResourcesRequired(SVGAnimatedBoolean::create(contextElement))
 {
-    if (attr->name() == SVGNames::externalResourcesRequiredAttr) {
-        setExternalResourcesRequiredBaseValue(attr->value() == "true");
-        return true;
-    }
+    static std::once_flag onceFlag;
+    std::call_once(onceFlag, [] {
+        PropertyRegistry::registerProperty<SVGNames::externalResourcesRequiredAttr, &SVGExternalResourcesRequired::m_externalResourcesRequired>();
+    });
+}
 
-    return false;
+void SVGExternalResourcesRequired::parseAttribute(const QualifiedName& name, const AtomString& value)
+{
+    if (name == SVGNames::externalResourcesRequiredAttr)
+        m_externalResourcesRequired->setBaseValInternal(value == "true");
 }
 
-bool SVGExternalResourcesRequired::isKnownAttribute(const QualifiedName& attrName)
+void SVGExternalResourcesRequired::svgAttributeChanged(const QualifiedName& attrName)
 {
-    return attrName == SVGNames::externalResourcesRequiredAttr;
+    if (!isKnownAttribute(attrName))
+        return;
+    if (!m_contextElement.isConnected())
+        return;
+
+    auto* renderer = m_contextElement.renderer();
+    if (renderer && is<RenderSVGShape>(renderer)) {
+        SVGElement::InstanceInvalidationGuard guard(m_contextElement);
+        RenderSVGResource::markForLayoutAndParentResourceInvalidation(*renderer);
+    }
 }
 
 void SVGExternalResourcesRequired::addSupportedAttributes(HashSet<QualifiedName>& supportedAttributes)
@@ -49,5 +65,3 @@ void SVGExternalResourcesRequired::addSupportedAttributes(HashSet<QualifiedName>
 }
 
 }
-
-#endif // ENABLE(SVG)