- add third_party src.
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / css / StyleSheetContents.h
1 /*
2  * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3  * Copyright (C) 2004, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All rights reserved.
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 #ifndef StyleSheetContents_h
22 #define StyleSheetContents_h
23
24 #include "core/css/CSSParserMode.h"
25 #include "weborigin/KURL.h"
26 #include "wtf/HashMap.h"
27 #include "wtf/ListHashSet.h"
28 #include "wtf/RefCounted.h"
29 #include "wtf/Vector.h"
30 #include "wtf/text/AtomicStringHash.h"
31 #include "wtf/text/TextPosition.h"
32
33
34 namespace WebCore {
35
36 class CSSStyleSheet;
37 class CSSStyleSheetResource;
38 class Document;
39 class Node;
40 class SecurityOrigin;
41 class StyleRuleBase;
42 class StyleRuleImport;
43
44 class StyleSheetContents : public RefCounted<StyleSheetContents> {
45 public:
46     static PassRefPtr<StyleSheetContents> create(const CSSParserContext& context = CSSParserContext(HTMLStandardMode))
47     {
48         return adoptRef(new StyleSheetContents(0, String(), context));
49     }
50     static PassRefPtr<StyleSheetContents> create(const String& originalURL, const CSSParserContext& context)
51     {
52         return adoptRef(new StyleSheetContents(0, originalURL, context));
53     }
54     static PassRefPtr<StyleSheetContents> create(StyleRuleImport* ownerRule, const String& originalURL, const CSSParserContext& context)
55     {
56         return adoptRef(new StyleSheetContents(ownerRule, originalURL, context));
57     }
58
59     ~StyleSheetContents();
60
61     const CSSParserContext& parserContext() const { return m_parserContext; }
62
63     const AtomicString& determineNamespace(const AtomicString& prefix);
64
65     void parseAuthorStyleSheet(const CSSStyleSheetResource*, const SecurityOrigin*);
66     bool parseString(const String&);
67     bool parseStringAtPosition(const String&, const TextPosition&, bool);
68
69     bool isCacheable() const;
70
71     bool isLoading() const;
72
73     void checkLoaded();
74     void startLoadingDynamicSheet();
75
76     StyleSheetContents* rootStyleSheet() const;
77     bool hasSingleOwnerNode() const;
78     Node* singleOwnerNode() const;
79     Document* singleOwnerDocument() const;
80
81     const String& charset() const { return m_parserContext.charset; }
82
83     bool loadCompleted() const { return m_loadCompleted; }
84     bool hasFailedOrCanceledSubresources() const;
85
86     KURL completeURL(const String& url) const;
87     void addSubresourceStyleURLs(ListHashSet<KURL>&);
88
89     void setIsUserStyleSheet(bool b) { m_isUserStyleSheet = b; }
90     bool isUserStyleSheet() const { return m_isUserStyleSheet; }
91     void setHasSyntacticallyValidCSSHeader(bool b) { m_hasSyntacticallyValidCSSHeader = b; }
92     bool hasSyntacticallyValidCSSHeader() const { return m_hasSyntacticallyValidCSSHeader; }
93
94     void parserAddNamespace(const AtomicString& prefix, const AtomicString& uri);
95     void parserAppendRule(PassRefPtr<StyleRuleBase>);
96     void parserSetEncodingFromCharsetRule(const String& encoding);
97     void parserSetUsesRemUnits(bool b) { m_usesRemUnits = b; }
98
99     void clearRules();
100
101     bool hasCharsetRule() const { return !m_encodingFromCharsetRule.isNull(); }
102     String encodingFromCharsetRule() const { return m_encodingFromCharsetRule; }
103     // Rules other than @charset and @import.
104     const Vector<RefPtr<StyleRuleBase> >& childRules() const { return m_childRules; }
105     const Vector<RefPtr<StyleRuleImport> >& importRules() const { return m_importRules; }
106
107     void notifyLoadedSheet(const CSSStyleSheetResource*);
108
109     StyleSheetContents* parentStyleSheet() const;
110     StyleRuleImport* ownerRule() const { return m_ownerRule; }
111     void clearOwnerRule() { m_ownerRule = 0; }
112
113     // Note that href is the URL that started the redirect chain that led to
114     // this style sheet. This property probably isn't useful for much except
115     // the JavaScript binding (which needs to use this value for security).
116     String originalURL() const { return m_originalURL; }
117     const KURL& baseURL() const { return m_parserContext.baseURL; }
118
119     unsigned ruleCount() const;
120     StyleRuleBase* ruleAt(unsigned index) const;
121
122     bool usesRemUnits() const { return m_usesRemUnits; }
123
124     unsigned estimatedSizeInBytes() const;
125
126     bool wrapperInsertRule(PassRefPtr<StyleRuleBase>, unsigned index);
127     void wrapperDeleteRule(unsigned index);
128
129     PassRefPtr<StyleSheetContents> copy() const { return adoptRef(new StyleSheetContents(*this)); }
130
131     void registerClient(CSSStyleSheet*);
132     void unregisterClient(CSSStyleSheet*);
133     bool hasOneClient() { return m_clients.size() == 1; }
134
135     bool isMutable() const { return m_isMutable; }
136     void setMutable() { m_isMutable = true; }
137
138     bool isInMemoryCache() const { return m_isInMemoryCache; }
139     void addedToMemoryCache();
140     void removedFromMemoryCache();
141
142     void shrinkToFit();
143
144 private:
145     StyleSheetContents(StyleRuleImport* ownerRule, const String& originalURL, const CSSParserContext&);
146     StyleSheetContents(const StyleSheetContents&);
147
148     void clearCharsetRule();
149
150     StyleRuleImport* m_ownerRule;
151
152     String m_originalURL;
153
154     String m_encodingFromCharsetRule;
155     Vector<RefPtr<StyleRuleImport> > m_importRules;
156     Vector<RefPtr<StyleRuleBase> > m_childRules;
157     typedef HashMap<AtomicString, AtomicString> PrefixNamespaceURIMap;
158     PrefixNamespaceURIMap m_namespaces;
159
160     bool m_loadCompleted : 1;
161     bool m_isUserStyleSheet : 1;
162     bool m_hasSyntacticallyValidCSSHeader : 1;
163     bool m_didLoadErrorOccur : 1;
164     bool m_usesRemUnits : 1;
165     bool m_isMutable : 1;
166     bool m_isInMemoryCache : 1;
167
168     CSSParserContext m_parserContext;
169
170     Vector<CSSStyleSheet*> m_clients;
171 };
172
173 } // namespace
174
175 #endif