2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2007 Rob Buis <buis@kde.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
23 #include "core/svg/SVGScriptElement.h"
25 #include "HTMLNames.h"
26 #include "XLinkNames.h"
27 #include "bindings/v8/ScriptEventListener.h"
28 #include "core/dom/Attribute.h"
29 #include "core/dom/Document.h"
30 #include "core/dom/ScriptLoader.h"
31 #include "core/events/ThreadLocalEventNames.h"
32 #include "core/svg/SVGElementInstance.h"
33 #include "core/svg/properties/SVGAnimatedStaticPropertyTearOff.h"
37 // Animated property definitions
38 DEFINE_ANIMATED_STRING(SVGScriptElement, XLinkNames::hrefAttr, Href, href)
39 DEFINE_ANIMATED_BOOLEAN(SVGScriptElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired)
41 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGScriptElement)
42 REGISTER_LOCAL_ANIMATED_PROPERTY(href)
43 REGISTER_LOCAL_ANIMATED_PROPERTY(externalResourcesRequired)
44 END_REGISTER_ANIMATED_PROPERTIES
46 inline SVGScriptElement::SVGScriptElement(const QualifiedName& tagName, Document& document, bool wasInsertedByParser, bool alreadyStarted)
47 : SVGElement(tagName, document)
48 , m_svgLoadEventTimer(this, &SVGElement::svgLoadEventTimerFired)
49 , m_loader(ScriptLoader::create(this, wasInsertedByParser, alreadyStarted))
51 ASSERT(hasTagName(SVGNames::scriptTag));
52 ScriptWrappable::init(this);
53 registerAnimatedPropertiesForSVGScriptElement();
56 PassRefPtr<SVGScriptElement> SVGScriptElement::create(const QualifiedName& tagName, Document& document, bool insertedByParser)
58 return adoptRef(new SVGScriptElement(tagName, document, insertedByParser, false));
61 bool SVGScriptElement::isSupportedAttribute(const QualifiedName& attrName)
63 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
64 if (supportedAttributes.isEmpty()) {
65 SVGURIReference::addSupportedAttributes(supportedAttributes);
66 SVGExternalResourcesRequired::addSupportedAttributes(supportedAttributes);
67 supportedAttributes.add(SVGNames::typeAttr);
68 supportedAttributes.add(HTMLNames::onerrorAttr);
70 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
73 void SVGScriptElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
75 if (!isSupportedAttribute(name)) {
76 SVGElement::parseAttribute(name, value);
80 if (name == SVGNames::typeAttr) {
85 if (name == HTMLNames::onerrorAttr) {
86 setAttributeEventListener(EventTypeNames::error, createAttributeEventListener(this, name, value));
90 if (SVGURIReference::parseAttribute(name, value))
92 if (SVGExternalResourcesRequired::parseAttribute(name, value))
98 void SVGScriptElement::svgAttributeChanged(const QualifiedName& attrName)
100 if (!isSupportedAttribute(attrName)) {
101 SVGElement::svgAttributeChanged(attrName);
105 SVGElementInstance::InvalidationGuard invalidationGuard(this);
107 if (attrName == SVGNames::typeAttr || attrName == HTMLNames::onerrorAttr)
110 if (SVGURIReference::isKnownAttribute(attrName)) {
111 m_loader->handleSourceAttribute(hrefCurrentValue());
115 if (SVGExternalResourcesRequired::handleAttributeChange(this, attrName))
118 ASSERT_NOT_REACHED();
121 Node::InsertionNotificationRequest SVGScriptElement::insertedInto(ContainerNode* rootParent)
123 SVGElement::insertedInto(rootParent);
124 return InsertionShouldCallDidNotifySubtreeInsertions;
127 void SVGScriptElement::didNotifySubtreeInsertionsToDocument()
129 m_loader->didNotifySubtreeInsertionsToDocument();
130 SVGExternalResourcesRequired::insertedIntoDocument(this);
133 void SVGScriptElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
135 SVGElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
136 m_loader->childrenChanged();
139 bool SVGScriptElement::isURLAttribute(const Attribute& attribute) const
141 return attribute.name() == sourceAttributeValue();
144 void SVGScriptElement::finishParsingChildren()
146 SVGElement::finishParsingChildren();
147 SVGExternalResourcesRequired::finishParsingChildren();
150 String SVGScriptElement::type() const
155 void SVGScriptElement::setType(const String& type)
160 void SVGScriptElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const
162 SVGElement::addSubresourceAttributeURLs(urls);
164 addSubresourceURL(urls, document().completeURL(hrefCurrentValue()));
167 String SVGScriptElement::sourceAttributeValue() const
169 return hrefCurrentValue();
172 String SVGScriptElement::charsetAttributeValue() const
177 String SVGScriptElement::typeAttributeValue() const
182 String SVGScriptElement::languageAttributeValue() const
187 String SVGScriptElement::forAttributeValue() const
192 String SVGScriptElement::eventAttributeValue() const
197 bool SVGScriptElement::asyncAttributeValue() const
202 bool SVGScriptElement::deferAttributeValue() const
207 bool SVGScriptElement::hasSourceAttribute() const
209 return hasAttribute(XLinkNames::hrefAttr);
212 PassRefPtr<Element> SVGScriptElement::cloneElementWithoutAttributesAndChildren()
214 return adoptRef(new SVGScriptElement(tagQName(), document(), false, m_loader->alreadyStarted()));
217 void SVGScriptElement::setHaveFiredLoadEvent(bool haveFiredLoadEvent)
219 m_loader->setHaveFiredLoadEvent(haveFiredLoadEvent);
222 bool SVGScriptElement::isParserInserted() const
224 return m_loader->isParserInserted();
227 bool SVGScriptElement::haveFiredLoadEvent() const
229 return m_loader->haveFiredLoadEvent();
232 Timer<SVGElement>* SVGScriptElement::svgLoadEventTimer()
234 return &m_svgLoadEventTimer;