]> git.saurik.com Git - iphone-api.git/blob - WebCore/ScriptElement.h
Adding the WebCore headers (for Cydget).
[iphone-api.git] / WebCore / ScriptElement.h
1 /*
2 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 *
19 */
20
21 #ifndef ScriptElement_h
22 #define ScriptElement_h
23
24 #include "CachedResourceClient.h"
25 #include "CachedResourceHandle.h"
26
27 namespace WebCore {
28
29 class CachedScript;
30 class Element;
31 class ScriptElementData;
32 class ScriptSourceCode;
33
34 class ScriptElement {
35 public:
36 ScriptElement() { }
37 virtual ~ScriptElement() { }
38
39 virtual String scriptContent() const = 0;
40
41 virtual String sourceAttributeValue() const = 0;
42 virtual String charsetAttributeValue() const = 0;
43 virtual String typeAttributeValue() const = 0;
44 virtual String languageAttributeValue() const = 0;
45
46 virtual void dispatchLoadEvent() = 0;
47 virtual void dispatchErrorEvent() = 0;
48
49 // A charset for loading the script (may be overridden by HTTP headers or a BOM).
50 virtual String scriptCharset() const = 0;
51
52 protected:
53 // Helper functions used by our parent classes.
54 static void insertedIntoDocument(ScriptElementData&, const String& sourceUrl);
55 static void removedFromDocument(ScriptElementData&);
56 static void childrenChanged(ScriptElementData&);
57 static void finishParsingChildren(ScriptElementData&, const String& sourceUrl);
58 static void handleSourceAttribute(ScriptElementData&, const String& sourceUrl);
59 };
60
61 // HTML/SVGScriptElement hold this struct as member variable
62 // and pass it to the static helper functions in ScriptElement
63 class ScriptElementData : private CachedResourceClient {
64 public:
65 ScriptElementData(ScriptElement*, Element*);
66 virtual ~ScriptElementData();
67
68 bool ignoresLoadRequest() const;
69 bool shouldExecuteAsJavaScript() const;
70
71 String scriptContent() const;
72 String scriptCharset() const;
73
74 Element* element() const { return m_element; }
75 bool createdByParser() const { return m_createdByParser; }
76 void setCreatedByParser(bool value) { m_createdByParser = value; }
77 bool haveFiredLoadEvent() const { return m_firedLoad; }
78 void setHaveFiredLoadEvent(bool firedLoad) { m_firedLoad = firedLoad; }
79
80 void requestScript(const String& sourceUrl);
81 void evaluateScript(const ScriptSourceCode&);
82 void stopLoadRequest();
83
84 private:
85 virtual void notifyFinished(CachedResource*);
86
87 private:
88 ScriptElement* m_scriptElement;
89 Element* m_element;
90 CachedResourceHandle<CachedScript> m_cachedScript;
91 bool m_createdByParser;
92 bool m_evaluated;
93 bool m_firedLoad;
94 };
95
96 ScriptElement* toScriptElement(Element*);
97
98 }
99
100 #endif