2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2006, 2007, 2008, 2009, 2010, 2012 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"
26 #include "StyleSheet.h"
27 #include <wtf/HashMap.h>
28 #include <wtf/Noncopyable.h>
29 #include <wtf/text/AtomicStringHash.h>
39 class CachedCSSStyleSheet;
43 class StyleSheetContents;
45 typedef int ExceptionCode;
47 class CSSStyleSheet : public StyleSheet {
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());
53 virtual ~CSSStyleSheet();
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;
63 PassRefPtr<CSSRuleList> cssRules();
64 unsigned insertRule(const String& rule, unsigned index, ExceptionCode&);
65 void deleteRule(unsigned index, ExceptionCode&);
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); }
74 unsigned length() const;
75 CSSRule* item(unsigned index);
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;
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; }
88 class RuleMutationScope {
89 WTF_MAKE_NONCOPYABLE(RuleMutationScope);
91 RuleMutationScope(CSSStyleSheet*);
92 RuleMutationScope(CSSRule*);
96 CSSStyleSheet* m_styleSheet;
99 void willMutateRules();
100 void didMutateRules();
103 void clearChildRuleCSSOMWrappers();
104 void reattachChildRuleCSSOMWrappers();
106 StyleSheetContents* contents() const { return m_contents.get(); }
109 CSSStyleSheet(PassRefPtr<StyleSheetContents>, CSSImportRule* ownerRule);
110 CSSStyleSheet(PassRefPtr<StyleSheetContents>, Node* ownerNode);
112 virtual bool isCSSStyleSheet() const { return true; }
113 virtual String type() const { return "text/css"; }
115 RefPtr<StyleSheetContents> m_contents;
118 RefPtr<MediaQuerySet> m_mediaQueries;
121 CSSImportRule* m_ownerRule;
123 mutable RefPtr<MediaList> m_mediaCSSOMWrapper;
124 mutable Vector<RefPtr<CSSRule> > m_childRuleCSSOMWrappers;
125 mutable OwnPtr<CSSRuleList> m_ruleListCSSOMWrapper;
128 inline CSSStyleSheet::RuleMutationScope::RuleMutationScope(CSSStyleSheet* sheet)
129 : m_styleSheet(sheet)
132 m_styleSheet->willMutateRules();
135 inline CSSStyleSheet::RuleMutationScope::RuleMutationScope(CSSRule* rule)
136 : m_styleSheet(rule ? rule->parentStyleSheet() : 0)
139 m_styleSheet->willMutateRules();
142 inline CSSStyleSheet::RuleMutationScope::~RuleMutationScope()
145 m_styleSheet->didMutateRules();