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