• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3  * (C) 2002-2003 Dirk Mueller (mueller@kde.org)
4  * Copyright (C) 2002, 2006, 2012 Apple Computer, Inc.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB.  If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21 
22 #ifndef CSSRuleList_h
23 #define CSSRuleList_h
24 
25 #include "wtf/PassRefPtr.h"
26 #include "wtf/RefPtr.h"
27 #include "wtf/Vector.h"
28 
29 namespace WebCore {
30 
31 class CSSRule;
32 class CSSStyleSheet;
33 
34 class CSSRuleList {
35     WTF_MAKE_NONCOPYABLE(CSSRuleList); WTF_MAKE_FAST_ALLOCATED;
36 public:
37     virtual ~CSSRuleList();
38 
39     virtual void ref() = 0;
40     virtual void deref() = 0;
41 
42     virtual unsigned length() const = 0;
43     virtual CSSRule* item(unsigned index) const = 0;
44 
45     virtual CSSStyleSheet* styleSheet() const = 0;
46 
47 protected:
48     CSSRuleList();
49 };
50 
51 class StaticCSSRuleList : public CSSRuleList {
52 public:
create()53     static PassRefPtr<StaticCSSRuleList> create() { return adoptRef(new StaticCSSRuleList()); }
54 
ref()55     virtual void ref() { ++m_refCount; }
56     virtual void deref();
57 
rules()58     Vector<RefPtr<CSSRule> >& rules() { return m_rules; }
59 
styleSheet()60     virtual CSSStyleSheet* styleSheet() const { return 0; }
61 
62 private:
63     StaticCSSRuleList();
64     ~StaticCSSRuleList();
65 
length()66     virtual unsigned length() const { return m_rules.size(); }
item(unsigned index)67     virtual CSSRule* item(unsigned index) const { return index < m_rules.size() ? m_rules[index].get() : 0; }
68 
69     Vector<RefPtr<CSSRule> > m_rules;
70     unsigned m_refCount;
71 };
72 
73 // The rule owns the live list.
74 template <class Rule>
75 class LiveCSSRuleList : public CSSRuleList {
76 public:
LiveCSSRuleList(Rule * rule)77     LiveCSSRuleList(Rule* rule) : m_rule(rule) { }
78 
ref()79     virtual void ref() { m_rule->ref(); }
deref()80     virtual void deref() { m_rule->deref(); }
81 
82 private:
length()83     virtual unsigned length() const { return m_rule->length(); }
item(unsigned index)84     virtual CSSRule* item(unsigned index) const  { return m_rule->item(index); }
styleSheet()85     virtual CSSStyleSheet* styleSheet() const { return m_rule->parentStyleSheet(); }
86 
87     Rule* m_rule;
88 };
89 
90 } // namespace WebCore
91 
92 #endif // CSSRuleList_h
93