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 "bindings/core/v8/ScriptEventListener.h"
26 #include "core/HTMLNames.h"
27 #include "core/XLinkNames.h"
28 #include "core/dom/Attribute.h"
29 #include "core/dom/ScriptLoader.h"
30 #include "core/dom/ScriptRunner.h"
31 #include "core/events/Event.h"
35 inline SVGScriptElement::SVGScriptElement(Document& document, bool wasInsertedByParser, bool alreadyStarted)
36 : SVGElement(SVGNames::scriptTag, document)
37 , SVGURIReference(this)
38 , m_svgLoadEventTimer(this, &SVGElement::svgLoadEventTimerFired)
39 , m_loader(ScriptLoader::create(this, wasInsertedByParser, alreadyStarted))
43 SVGScriptElement::~SVGScriptElement()
47 PassRefPtrWillBeRawPtr<SVGScriptElement> SVGScriptElement::create(Document& document, bool insertedByParser)
49 return adoptRefWillBeNoop(new SVGScriptElement(document, insertedByParser, false));
52 void SVGScriptElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
54 if (name == HTMLNames::onerrorAttr)
55 setAttributeEventListener(EventTypeNames::error, createAttributeEventListener(this, name, value, eventParameterName()));
57 parseAttributeNew(name, value);
60 void SVGScriptElement::svgAttributeChanged(const QualifiedName& attrName)
62 if (SVGURIReference::isKnownAttribute(attrName)) {
63 SVGElement::InvalidationGuard invalidationGuard(this);
64 m_loader->handleSourceAttribute(hrefString());
68 SVGElement::svgAttributeChanged(attrName);
71 Node::InsertionNotificationRequest SVGScriptElement::insertedInto(ContainerNode* rootParent)
73 SVGElement::insertedInto(rootParent);
74 return InsertionShouldCallDidNotifySubtreeInsertions;
77 void SVGScriptElement::didNotifySubtreeInsertionsToDocument()
79 m_loader->didNotifySubtreeInsertionsToDocument();
81 if (!m_loader->isParserInserted()) {
82 m_loader->setHaveFiredLoadEvent(true);
83 sendSVGLoadEventIfPossibleAsynchronously();
87 void SVGScriptElement::childrenChanged(const ChildrenChange& change)
89 SVGElement::childrenChanged(change);
90 m_loader->childrenChanged();
93 void SVGScriptElement::didMoveToNewDocument(Document& oldDocument)
95 if (RefPtrWillBeRawPtr<Document> contextDocument = document().contextDocument().get())
96 oldDocument.scriptRunner()->movePendingAsyncScript(contextDocument->scriptRunner(), m_loader.get());
97 SVGElement::didMoveToNewDocument(oldDocument);
100 bool SVGScriptElement::isURLAttribute(const Attribute& attribute) const
102 return attribute.name() == AtomicString(sourceAttributeValue());
105 void SVGScriptElement::finishParsingChildren()
107 SVGElement::finishParsingChildren();
108 m_loader->setHaveFiredLoadEvent(true);
111 bool SVGScriptElement::haveLoadedRequiredResources()
113 return m_loader->haveFiredLoadEvent();
116 String SVGScriptElement::sourceAttributeValue() const
121 String SVGScriptElement::charsetAttributeValue() const
126 String SVGScriptElement::typeAttributeValue() const
128 return getAttribute(SVGNames::typeAttr).string();
131 String SVGScriptElement::languageAttributeValue() const
136 String SVGScriptElement::forAttributeValue() const
141 String SVGScriptElement::eventAttributeValue() const
146 bool SVGScriptElement::asyncAttributeValue() const
151 bool SVGScriptElement::deferAttributeValue() const
156 bool SVGScriptElement::hasSourceAttribute() const
158 return href()->isSpecified();
161 PassRefPtrWillBeRawPtr<Element> SVGScriptElement::cloneElementWithoutAttributesAndChildren()
163 return adoptRefWillBeNoop(new SVGScriptElement(document(), false, m_loader->alreadyStarted()));
166 void SVGScriptElement::dispatchLoadEvent()
168 dispatchEvent(Event::create(EventTypeNames::load));
172 bool SVGScriptElement::isAnimatableAttribute(const QualifiedName& name) const
174 if (name == SVGNames::typeAttr)
177 return SVGElement::isAnimatableAttribute(name);
181 void SVGScriptElement::trace(Visitor* visitor)
183 visitor->trace(m_loader);
184 SVGElement::trace(visitor);