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
39 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGScriptElement)
40 END_REGISTER_ANIMATED_PROPERTIES
42 inline SVGScriptElement::SVGScriptElement(Document& document, bool wasInsertedByParser, bool alreadyStarted)
43 : SVGElement(SVGNames::scriptTag, document)
44 , SVGURIReference(this)
45 , m_svgLoadEventTimer(this, &SVGElement::svgLoadEventTimerFired)
46 , m_loader(ScriptLoader::create(this, wasInsertedByParser, alreadyStarted))
48 ScriptWrappable::init(this);
49 registerAnimatedPropertiesForSVGScriptElement();
52 PassRefPtr<SVGScriptElement> SVGScriptElement::create(Document& document, bool insertedByParser)
54 return adoptRef(new SVGScriptElement(document, insertedByParser, false));
57 bool SVGScriptElement::isSupportedAttribute(const QualifiedName& attrName)
59 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
60 if (supportedAttributes.isEmpty()) {
61 SVGURIReference::addSupportedAttributes(supportedAttributes);
62 supportedAttributes.add(SVGNames::typeAttr);
63 supportedAttributes.add(HTMLNames::onerrorAttr);
65 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
68 void SVGScriptElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
70 if (!isSupportedAttribute(name)) {
71 SVGElement::parseAttribute(name, value);
75 SVGParsingError parseError = NoError;
76 if (name == SVGNames::typeAttr)
79 if (name == HTMLNames::onerrorAttr) {
80 setAttributeEventListener(EventTypeNames::error, createAttributeEventListener(this, name, value));
81 } else if (SVGURIReference::parseAttribute(name, value, parseError)) {
86 reportAttributeParsingError(parseError, name, value);
89 void SVGScriptElement::svgAttributeChanged(const QualifiedName& attrName)
91 if (!isSupportedAttribute(attrName)) {
92 SVGElement::svgAttributeChanged(attrName);
96 SVGElementInstance::InvalidationGuard invalidationGuard(this);
98 if (attrName == SVGNames::typeAttr || attrName == HTMLNames::onerrorAttr)
101 if (SVGURIReference::isKnownAttribute(attrName)) {
102 m_loader->handleSourceAttribute(hrefString());
106 ASSERT_NOT_REACHED();
109 Node::InsertionNotificationRequest SVGScriptElement::insertedInto(ContainerNode* rootParent)
111 SVGElement::insertedInto(rootParent);
112 return InsertionShouldCallDidNotifySubtreeInsertions;
115 void SVGScriptElement::didNotifySubtreeInsertionsToDocument()
117 m_loader->didNotifySubtreeInsertionsToDocument();
119 if (!m_loader->isParserInserted()) {
120 m_loader->setHaveFiredLoadEvent(true);
121 sendSVGLoadEventIfPossibleAsynchronously();
125 void SVGScriptElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
127 SVGElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
128 m_loader->childrenChanged();
131 bool SVGScriptElement::isURLAttribute(const Attribute& attribute) const
133 return attribute.name() == AtomicString(sourceAttributeValue());
136 void SVGScriptElement::finishParsingChildren()
138 SVGElement::finishParsingChildren();
139 m_loader->setHaveFiredLoadEvent(true);
142 bool SVGScriptElement::haveLoadedRequiredResources()
144 return m_loader->haveFiredLoadEvent();
147 String SVGScriptElement::sourceAttributeValue() const
152 String SVGScriptElement::charsetAttributeValue() const
157 String SVGScriptElement::typeAttributeValue() const
159 return getAttribute(SVGNames::typeAttr).string();
162 String SVGScriptElement::languageAttributeValue() const
167 String SVGScriptElement::forAttributeValue() const
172 String SVGScriptElement::eventAttributeValue() const
177 bool SVGScriptElement::asyncAttributeValue() const
182 bool SVGScriptElement::deferAttributeValue() const
187 bool SVGScriptElement::hasSourceAttribute() const
189 return href()->isSpecified();
192 PassRefPtr<Element> SVGScriptElement::cloneElementWithoutAttributesAndChildren()
194 return adoptRef(new SVGScriptElement(document(), false, m_loader->alreadyStarted()));
197 void SVGScriptElement::dispatchLoadEvent()
199 dispatchEvent(Event::create(EventTypeNames::load));
203 bool SVGScriptElement::isAnimatableAttribute(const QualifiedName& name) const
205 if (name == SVGNames::typeAttr)
208 return SVGElement::isAnimatableAttribute(name);