Merge "[CherryPick] [WEBGL] Rename WEBKIT_WEBGL_compressed_texture_s3tc to WEBGL_comp...
[framework/web/webkit-efl.git] / Source / WebCore / css / CSSStyleSheet.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 CSSStyleSheet_h
22 #define CSSStyleSheet_h
23
24 #include "CSSParserMode.h"
25 #include "CSSRule.h"
26 #include "StyleSheet.h"
27 #include <wtf/HashMap.h>
28 #include <wtf/Noncopyable.h>
29 #include <wtf/text/AtomicStringHash.h>
30
31 namespace WebCore {
32
33 class CSSCharsetRule;
34 class CSSImportRule;
35 class CSSParser;
36 class CSSRule;
37 class CSSRuleList;
38 class CSSStyleSheet;
39 class CachedCSSStyleSheet;
40 class Document;
41 class MediaQuerySet;
42 class SecurityOrigin;
43 class StyleSheetContents;
44
45 typedef int ExceptionCode;
46
47 class CSSStyleSheet : public StyleSheet {
48 public:
49     static PassRefPtr<CSSStyleSheet> create(PassRefPtr<StyleSheetContents>, CSSImportRule* ownerRule = 0);
50     static PassRefPtr<CSSStyleSheet> create(PassRefPtr<StyleSheetContents>, Node* ownerNode);
51     static PassRefPtr<CSSStyleSheet> createInline(Node*, const KURL&, const String& encoding = String());
52
53     virtual ~CSSStyleSheet();
54
55     virtual CSSStyleSheet* parentStyleSheet() const OVERRIDE;
56     virtual Node* ownerNode() const OVERRIDE { return m_ownerNode; }
57     virtual MediaList* media() const OVERRIDE;
58     virtual String href() const OVERRIDE;
59     virtual String title() const OVERRIDE { return m_title; }
60     virtual bool disabled() const OVERRIDE { return m_isDisabled; }
61     virtual void setDisabled(bool) OVERRIDE;
62     
63     PassRefPtr<CSSRuleList> cssRules();
64     unsigned insertRule(const String& rule, unsigned index, ExceptionCode&);
65     void deleteRule(unsigned index, ExceptionCode&);
66     
67     // IE Extensions
68     PassRefPtr<CSSRuleList> rules();
69     int addRule(const String& selector, const String& style, int index, ExceptionCode&);
70     int addRule(const String& selector, const String& style, ExceptionCode&);
71     void removeRule(unsigned index, ExceptionCode& ec) { deleteRule(index, ec); }
72     
73     // For CSSRuleList.
74     unsigned length() const;
75     CSSRule* item(unsigned index);
76
77     virtual void clearOwnerNode() OVERRIDE { m_ownerNode = 0; }
78     virtual CSSImportRule* ownerRule() const OVERRIDE { return m_ownerRule; }
79     virtual KURL baseURL() const OVERRIDE;
80     virtual bool isLoading() const OVERRIDE;
81     
82     void clearOwnerRule() { m_ownerRule = 0; }
83     Document* ownerDocument() const;
84     MediaQuerySet* mediaQueries() const { return m_mediaQueries.get(); }
85     void setMediaQueries(PassRefPtr<MediaQuerySet>);
86     void setTitle(const String& title) { m_title = title; }
87
88     class RuleMutationScope {
89         WTF_MAKE_NONCOPYABLE(RuleMutationScope);
90     public:
91         RuleMutationScope(CSSStyleSheet*);
92         RuleMutationScope(CSSRule*);
93         ~RuleMutationScope();
94
95     private:
96         CSSStyleSheet* m_styleSheet;
97     };
98
99     void willMutateRules();
100     void didMutateRules();
101     void didMutate();
102     
103     void clearChildRuleCSSOMWrappers();
104     void reattachChildRuleCSSOMWrappers();
105
106     StyleSheetContents* contents() const { return m_contents.get(); }
107
108 private:
109     CSSStyleSheet(PassRefPtr<StyleSheetContents>, CSSImportRule* ownerRule);
110     CSSStyleSheet(PassRefPtr<StyleSheetContents>, Node* ownerNode);
111
112     virtual bool isCSSStyleSheet() const { return true; }
113     virtual String type() const { return "text/css"; }
114     
115     RefPtr<StyleSheetContents> m_contents;
116     bool m_isDisabled;
117     String m_title;
118     RefPtr<MediaQuerySet> m_mediaQueries;
119
120     Node* m_ownerNode;
121     CSSImportRule* m_ownerRule;
122
123     mutable RefPtr<MediaList> m_mediaCSSOMWrapper;
124     mutable Vector<RefPtr<CSSRule> > m_childRuleCSSOMWrappers;
125     mutable OwnPtr<CSSRuleList> m_ruleListCSSOMWrapper;
126 };
127
128 inline CSSStyleSheet::RuleMutationScope::RuleMutationScope(CSSStyleSheet* sheet)
129     : m_styleSheet(sheet)
130 {
131     if (m_styleSheet)
132         m_styleSheet->willMutateRules();
133 }
134
135 inline CSSStyleSheet::RuleMutationScope::RuleMutationScope(CSSRule* rule)
136     : m_styleSheet(rule ? rule->parentStyleSheet() : 0)
137 {
138     if (m_styleSheet)
139         m_styleSheet->willMutateRules();
140 }
141
142 inline CSSStyleSheet::RuleMutationScope::~RuleMutationScope()
143 {
144     if (m_styleSheet)
145         m_styleSheet->didMutateRules();
146 }
147
148 } // namespace
149
150 #endif