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"
34 class CachedCSSStyleSheet;
35 class CachedResourceLoader;
39 class StyleRuleImport;
42 typedef int ExceptionCode;
44 class CSSStyleSheet : public StyleSheet {
46 static PassRefPtr<CSSStyleSheet> create()
48 return adoptRef(new CSSStyleSheet(static_cast<StyleRuleImport*>(0), String(), KURL(), String()));
50 static PassRefPtr<CSSStyleSheet> create(Node* ownerNode)
52 return adoptRef(new CSSStyleSheet(ownerNode, String(), KURL(), String()));
54 static PassRefPtr<CSSStyleSheet> create(Node* ownerNode, const String& originalURL, const KURL& finalURL, const String& charset)
56 return adoptRef(new CSSStyleSheet(ownerNode, originalURL, finalURL, charset));
58 static PassRefPtr<CSSStyleSheet> create(StyleRuleImport* ownerRule, const String& originalURL, const KURL& finalURL, const String& charset)
60 return adoptRef(new CSSStyleSheet(ownerRule, originalURL, finalURL, charset));
62 static PassRefPtr<CSSStyleSheet> createInline(Node* ownerNode, const KURL& finalURL)
64 return adoptRef(new CSSStyleSheet(ownerNode, finalURL.string(), finalURL, String()));
67 virtual ~CSSStyleSheet();
69 virtual CSSStyleSheet* parentStyleSheet() const OVERRIDE;
71 PassRefPtr<CSSRuleList> cssRules();
72 unsigned insertRule(const String& rule, unsigned index, ExceptionCode&);
73 void deleteRule(unsigned index, ExceptionCode&);
76 PassRefPtr<CSSRuleList> rules();
77 int addRule(const String& selector, const String& style, int index, ExceptionCode&);
78 int addRule(const String& selector, const String& style, ExceptionCode&);
79 void removeRule(unsigned index, ExceptionCode& ec) { deleteRule(index, ec); }
81 void addNamespace(CSSParser*, const AtomicString& prefix, const AtomicString& uri);
82 const AtomicString& determineNamespace(const AtomicString& prefix);
84 void styleSheetChanged();
86 virtual bool parseString(const String&, CSSParserMode = CSSStrictMode);
88 bool parseStringAtLine(const String&, CSSParserMode, int startLineNumber);
90 virtual bool isLoading();
93 void startLoadingDynamicSheet();
95 Node* findStyleSheetOwnerNode() const;
96 Document* findDocument();
98 const String& charset() const { return m_charset; }
100 bool loadCompleted() const { return m_loadCompleted; }
102 KURL completeURL(const String& url) const;
103 void addSubresourceStyleURLs(ListHashSet<KURL>&);
105 void setCSSParserMode(CSSParserMode cssParserMode) { m_cssParserMode = cssParserMode; }
106 CSSParserMode cssParserMode() const { return m_cssParserMode; }
108 void setIsUserStyleSheet(bool b) { m_isUserStyleSheet = b; }
109 bool isUserStyleSheet() const { return m_isUserStyleSheet; }
110 void setHasSyntacticallyValidCSSHeader(bool b) { m_hasSyntacticallyValidCSSHeader = b; }
111 bool hasSyntacticallyValidCSSHeader() const { return m_hasSyntacticallyValidCSSHeader; }
113 void parserAppendRule(PassRefPtr<StyleRuleBase>);
114 void parserSetEncodingFromCharsetRule(const String& encoding);
118 unsigned length() const;
119 CSSRule* item(unsigned index);
121 // Rules other than @charset and @import.
122 const Vector<RefPtr<StyleRuleBase> >& childRules() const { return m_childRules; }
123 const Vector<RefPtr<StyleRuleImport> >& importRules() const { return m_importRules; }
125 virtual MediaList* media() const OVERRIDE;
127 MediaQuerySet* mediaQueries() const { return m_mediaQueries.get(); }
128 void setMediaQueries(PassRefPtr<MediaQuerySet>);
130 void notifyLoadedSheet(const CachedCSSStyleSheet*);
132 virtual CSSImportRule* ownerRule() const OVERRIDE;
133 void clearOwnerRule() { m_ownerRule = 0; }
135 CSSImportRule* ensureCSSOMWrapper(StyleRuleImport*);
138 CSSStyleSheet(Node* ownerNode, const String& originalURL, const KURL& finalURL, const String& charset);
139 CSSStyleSheet(StyleRuleImport* ownerRule, const String& originalURL, const KURL& finalURL, const String& charset);
141 virtual bool isCSSStyleSheet() const { return true; }
142 virtual String type() const { return "text/css"; }
144 void clearCharsetRule();
145 bool hasCharsetRule() const { return !m_encodingFromCharsetRule.isNull(); }
147 PassRefPtr<CSSRule> createChildRuleCSSOMWrapper(unsigned index);
149 StyleRuleImport* m_ownerRule;
150 String m_encodingFromCharsetRule;
151 Vector<RefPtr<StyleRuleImport> > m_importRules;
152 Vector<RefPtr<StyleRuleBase> > m_childRules;
153 OwnPtr<CSSNamespace> m_namespaces;
155 RefPtr<MediaQuerySet> m_mediaQueries;
157 bool m_loadCompleted : 1;
158 CSSParserMode m_cssParserMode;
159 bool m_isUserStyleSheet : 1;
160 bool m_hasSyntacticallyValidCSSHeader : 1;
161 bool m_didLoadErrorOccur : 1;
163 mutable Vector<RefPtr<CSSRule> > m_childRuleCSSOMWrappers;
164 mutable OwnPtr<CSSRuleList> m_ruleListCSSOMWrapper;