SVGScriptElement.cpp [plain text]
#include "config.h"
#if ENABLE(SVG)
#include "SVGScriptElement.h"
#include "Document.h"
#include "Event.h"
#include "EventNames.h"
#include "MappedAttribute.h"
#include "SVGNames.h"
namespace WebCore {
SVGScriptElement::SVGScriptElement(const QualifiedName& tagName, Document* doc, bool createdByParser)
: SVGElement(tagName, doc)
, SVGURIReference()
, SVGExternalResourcesRequired()
, m_data(this, this)
{
m_data.setCreatedByParser(createdByParser);
}
SVGScriptElement::~SVGScriptElement()
{
}
String SVGScriptElement::scriptContent() const
{
return m_data.scriptContent();
}
void SVGScriptElement::parseMappedAttribute(MappedAttribute* attr)
{
const QualifiedName& attrName = attr->name();
if (attrName == SVGNames::typeAttr)
setType(attr->value());
else {
if (SVGURIReference::parseMappedAttribute(attr))
return;
if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
return;
SVGElement::parseMappedAttribute(attr);
}
}
void SVGScriptElement::svgAttributeChanged(const QualifiedName& attrName)
{
SVGElement::svgAttributeChanged(attrName);
if (SVGURIReference::isKnownAttribute(attrName))
handleSourceAttribute(m_data, href());
else if (SVGExternalResourcesRequired::isKnownAttribute(attrName)) {
if (!externalResourcesRequiredBaseValue() && !m_data.haveFiredLoadEvent() && !m_data.createdByParser()) {
m_data.setHaveFiredLoadEvent(true);
ASSERT(haveLoadedRequiredResources());
sendSVGLoadEventIfPossible();
}
}
}
void SVGScriptElement::synchronizeProperty(const QualifiedName& attrName)
{
SVGElement::synchronizeProperty(attrName);
if (attrName == anyQName()) {
synchronizeExternalResourcesRequired();
synchronizeHref();
return;
}
if (SVGExternalResourcesRequired::isKnownAttribute(attrName))
synchronizeExternalResourcesRequired();
else if (SVGURIReference::isKnownAttribute(attrName))
synchronizeHref();
}
void SVGScriptElement::insertedIntoDocument()
{
SVGElement::insertedIntoDocument();
ScriptElement::insertedIntoDocument(m_data, sourceAttributeValue());
if (m_data.createdByParser())
return;
if (!externalResourcesRequiredBaseValue()) {
m_data.setHaveFiredLoadEvent(true);
sendSVGLoadEventIfPossible();
}
}
void SVGScriptElement::removedFromDocument()
{
SVGElement::removedFromDocument();
ScriptElement::removedFromDocument(m_data);
}
void SVGScriptElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
{
ScriptElement::childrenChanged(m_data);
SVGElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
}
bool SVGScriptElement::isURLAttribute(Attribute* attr) const
{
return attr->name() == sourceAttributeValue();
}
void SVGScriptElement::finishParsingChildren()
{
ScriptElement::finishParsingChildren(m_data, sourceAttributeValue());
SVGElement::finishParsingChildren();
if (!externalResourcesRequiredBaseValue())
m_data.setHaveFiredLoadEvent(true);
}
String SVGScriptElement::type() const
{
return m_type;
}
void SVGScriptElement::setType(const String& type)
{
m_type = type;
}
String SVGScriptElement::scriptCharset() const
{
return m_data.scriptCharset();
}
void SVGScriptElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const
{
SVGElement::addSubresourceAttributeURLs(urls);
addSubresourceURL(urls, document()->completeURL(href()));
}
bool SVGScriptElement::haveLoadedRequiredResources()
{
return !externalResourcesRequiredBaseValue() || m_data.haveFiredLoadEvent();
}
String SVGScriptElement::sourceAttributeValue() const
{
return href();
}
String SVGScriptElement::charsetAttributeValue() const
{
return String();
}
String SVGScriptElement::typeAttributeValue() const
{
return type();
}
String SVGScriptElement::languageAttributeValue() const
{
return String();
}
String SVGScriptElement::forAttributeValue() const
{
return String();
}
String SVGScriptElement::eventAttributeValue() const
{
return String();
}
void SVGScriptElement::dispatchLoadEvent()
{
bool externalResourcesRequired = externalResourcesRequiredBaseValue();
if (m_data.createdByParser())
ASSERT(externalResourcesRequired != m_data.haveFiredLoadEvent());
else if (m_data.haveFiredLoadEvent()) {
if (externalResourcesRequired)
return;
}
if (externalResourcesRequired) {
ASSERT(!m_data.haveFiredLoadEvent());
m_data.setHaveFiredLoadEvent(true);
ASSERT(haveLoadedRequiredResources());
sendSVGLoadEventIfPossible();
}
}
void SVGScriptElement::dispatchErrorEvent()
{
dispatchEvent(Event::create(eventNames().errorEvent, true, false));
}
}
#endif // ENABLE(SVG)