2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
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.
21 #ifndef CSSStyleSheet_h
22 #define CSSStyleSheet_h
24 #include "CSSParserMode.h"
25 #include "StyleSheet.h"
35 class CachedCSSStyleSheet;
36 class CachedResourceLoader;
40 typedef int ExceptionCode;
42 class CSSStyleSheet : public StyleSheet {
44 static PassRefPtr<CSSStyleSheet> create()
46 return adoptRef(new CSSStyleSheet(static_cast<CSSImportRule*>(0), String(), KURL(), String()));
48 static PassRefPtr<CSSStyleSheet> create(Node* ownerNode)
50 return adoptRef(new CSSStyleSheet(ownerNode, String(), KURL(), String()));
52 static PassRefPtr<CSSStyleSheet> create(Node* ownerNode, const String& originalURL, const KURL& finalURL, const String& charset)
54 return adoptRef(new CSSStyleSheet(ownerNode, originalURL, finalURL, charset));
56 static PassRefPtr<CSSStyleSheet> create(CSSImportRule* ownerRule, const String& originalURL, const KURL& finalURL, const String& charset)
58 return adoptRef(new CSSStyleSheet(ownerRule, originalURL, finalURL, charset));
60 static PassRefPtr<CSSStyleSheet> createInline(Node* ownerNode, const KURL& finalURL)
62 return adoptRef(new CSSStyleSheet(ownerNode, finalURL.string(), finalURL, String()));
65 virtual ~CSSStyleSheet();
67 CSSStyleSheet* parentStyleSheet() const
69 StyleSheet* parentSheet = StyleSheet::parentStyleSheet();
70 ASSERT(!parentSheet || parentSheet->isCSSStyleSheet());
71 return static_cast<CSSStyleSheet*>(parentSheet);
74 PassRefPtr<CSSRuleList> cssRules();
75 unsigned insertRule(const String& rule, unsigned index, ExceptionCode&);
76 void deleteRule(unsigned index, ExceptionCode&);
79 PassRefPtr<CSSRuleList> rules();
80 int addRule(const String& selector, const String& style, int index, ExceptionCode&);
81 int addRule(const String& selector, const String& style, ExceptionCode&);
82 void removeRule(unsigned index, ExceptionCode& ec) { deleteRule(index, ec); }
84 void addNamespace(CSSParser*, const AtomicString& prefix, const AtomicString& uri);
85 const AtomicString& determineNamespace(const AtomicString& prefix);
87 void styleSheetChanged();
89 virtual bool parseString(const String&, CSSParserMode = CSSStrictMode);
91 bool parseStringAtLine(const String&, CSSParserMode, int startLineNumber);
93 virtual bool isLoading();
96 void startLoadingDynamicSheet();
98 Node* findStyleSheetOwnerNode() const;
99 Document* findDocument();
101 const String& charset() const { return m_charset; }
103 bool loadCompleted() const { return m_loadCompleted; }
105 KURL completeURL(const String& url) const;
106 void addSubresourceStyleURLs(ListHashSet<KURL>&);
108 void setCSSParserMode(CSSParserMode cssParserMode) { m_cssParserMode = cssParserMode; }
109 CSSParserMode cssParserMode() const { return m_cssParserMode; }
111 void setIsUserStyleSheet(bool b) { m_isUserStyleSheet = b; }
112 bool isUserStyleSheet() const { return m_isUserStyleSheet; }
113 void setHasSyntacticallyValidCSSHeader(bool b) { m_hasSyntacticallyValidCSSHeader = b; }
114 bool hasSyntacticallyValidCSSHeader() const { return m_hasSyntacticallyValidCSSHeader; }
116 void parserAppendRule(PassRefPtr<CSSRule>);
117 void parserSetEncodingFromCharsetRule(const String& encoding);
121 unsigned length() const;
122 CSSRule* item(unsigned index);
124 // Rules other than @charset and @import.
125 const Vector<RefPtr<CSSRule> >& childRules() const { return m_childRules; }
126 const Vector<RefPtr<CSSImportRule> >& importRules() const { return m_importRules; }
128 virtual MediaList* media() const OVERRIDE;
130 MediaQuerySet* mediaQueries() const { return m_mediaQueries.get(); }
131 void setMediaQueries(PassRefPtr<MediaQuerySet>);
133 void notifyLoadedSheet(const CachedCSSStyleSheet*);
136 CSSStyleSheet(Node* ownerNode, const String& originalURL, const KURL& finalURL, const String& charset);
137 CSSStyleSheet(CSSImportRule* ownerRule, const String& originalURL, const KURL& finalURL, const String& charset);
139 virtual bool isCSSStyleSheet() const { return true; }
140 virtual String type() const { return "text/css"; }
142 void clearCharsetRule();
143 bool hasCharsetRule() const { return !m_encodingFromCharsetRule.isNull() || m_charsetRuleCSSOMWrapper; }
144 CSSCharsetRule* ensureCharsetRule();
146 String m_encodingFromCharsetRule;
147 RefPtr<CSSCharsetRule> m_charsetRuleCSSOMWrapper;
148 Vector<RefPtr<CSSImportRule> > m_importRules;
149 Vector<RefPtr<CSSRule> > m_childRules;
150 OwnPtr<CSSNamespace> m_namespaces;
152 RefPtr<MediaQuerySet> m_mediaQueries;
154 bool m_loadCompleted : 1;
155 CSSParserMode m_cssParserMode;
156 bool m_isUserStyleSheet : 1;
157 bool m_hasSyntacticallyValidCSSHeader : 1;
158 bool m_didLoadErrorOccur : 1;
160 OwnPtr<CSSRuleList> m_ruleListCSSOMWrapper;