Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / svg / SVGScriptElement.cpp
1 /*
2  * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3  * Copyright (C) 2004, 2005, 2007 Rob Buis <buis@kde.org>
4  *
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.
9  *
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.
14  *
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.
19  */
20
21 #include "config.h"
22
23 #include "core/svg/SVGScriptElement.h"
24
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"
32
33 namespace blink {
34
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))
40 {
41 }
42
43 SVGScriptElement::~SVGScriptElement()
44 {
45 }
46
47 PassRefPtrWillBeRawPtr<SVGScriptElement> SVGScriptElement::create(Document& document, bool insertedByParser)
48 {
49     return adoptRefWillBeNoop(new SVGScriptElement(document, insertedByParser, false));
50 }
51
52 void SVGScriptElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
53 {
54     if (name == HTMLNames::onerrorAttr)
55         setAttributeEventListener(EventTypeNames::error, createAttributeEventListener(this, name, value, eventParameterName()));
56     else
57         parseAttributeNew(name, value);
58 }
59
60 void SVGScriptElement::svgAttributeChanged(const QualifiedName& attrName)
61 {
62     if (SVGURIReference::isKnownAttribute(attrName)) {
63         SVGElement::InvalidationGuard invalidationGuard(this);
64         m_loader->handleSourceAttribute(hrefString());
65         return;
66     }
67
68     SVGElement::svgAttributeChanged(attrName);
69 }
70
71 Node::InsertionNotificationRequest SVGScriptElement::insertedInto(ContainerNode* rootParent)
72 {
73     SVGElement::insertedInto(rootParent);
74     return InsertionShouldCallDidNotifySubtreeInsertions;
75 }
76
77 void SVGScriptElement::didNotifySubtreeInsertionsToDocument()
78 {
79     m_loader->didNotifySubtreeInsertionsToDocument();
80
81     if (!m_loader->isParserInserted()) {
82         m_loader->setHaveFiredLoadEvent(true);
83         sendSVGLoadEventIfPossibleAsynchronously();
84     }
85 }
86
87 void SVGScriptElement::childrenChanged(const ChildrenChange& change)
88 {
89     SVGElement::childrenChanged(change);
90     m_loader->childrenChanged();
91 }
92
93 void SVGScriptElement::didMoveToNewDocument(Document& oldDocument)
94 {
95     if (RefPtrWillBeRawPtr<Document> contextDocument = document().contextDocument().get())
96         oldDocument.scriptRunner()->movePendingAsyncScript(contextDocument->scriptRunner(), m_loader.get());
97     SVGElement::didMoveToNewDocument(oldDocument);
98 }
99
100 bool SVGScriptElement::isURLAttribute(const Attribute& attribute) const
101 {
102     return attribute.name() == AtomicString(sourceAttributeValue());
103 }
104
105 void SVGScriptElement::finishParsingChildren()
106 {
107     SVGElement::finishParsingChildren();
108     m_loader->setHaveFiredLoadEvent(true);
109 }
110
111 bool SVGScriptElement::haveLoadedRequiredResources()
112 {
113     return m_loader->haveFiredLoadEvent();
114 }
115
116 String SVGScriptElement::sourceAttributeValue() const
117 {
118     return hrefString();
119 }
120
121 String SVGScriptElement::charsetAttributeValue() const
122 {
123     return String();
124 }
125
126 String SVGScriptElement::typeAttributeValue() const
127 {
128     return getAttribute(SVGNames::typeAttr).string();
129 }
130
131 String SVGScriptElement::languageAttributeValue() const
132 {
133     return String();
134 }
135
136 String SVGScriptElement::forAttributeValue() const
137 {
138     return String();
139 }
140
141 String SVGScriptElement::eventAttributeValue() const
142 {
143     return String();
144 }
145
146 bool SVGScriptElement::asyncAttributeValue() const
147 {
148     return false;
149 }
150
151 bool SVGScriptElement::deferAttributeValue() const
152 {
153     return false;
154 }
155
156 bool SVGScriptElement::hasSourceAttribute() const
157 {
158     return href()->isSpecified();
159 }
160
161 PassRefPtrWillBeRawPtr<Element> SVGScriptElement::cloneElementWithoutAttributesAndChildren()
162 {
163     return adoptRefWillBeNoop(new SVGScriptElement(document(), false, m_loader->alreadyStarted()));
164 }
165
166 void SVGScriptElement::dispatchLoadEvent()
167 {
168     dispatchEvent(Event::create(EventTypeNames::load));
169 }
170
171 #if ENABLE(ASSERT)
172 bool SVGScriptElement::isAnimatableAttribute(const QualifiedName& name) const
173 {
174     if (name == SVGNames::typeAttr)
175         return false;
176
177     return SVGElement::isAnimatableAttribute(name);
178 }
179 #endif
180
181 void SVGScriptElement::trace(Visitor* visitor)
182 {
183     visitor->trace(m_loader);
184     SVGElement::trace(visitor);
185 }
186
187 } // namespace blink