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/RefCounted.h> 27#include <wtf/RefPtr.h> 28#include <wtf/Vector.h> 29#include <wtf/text/WTFString.h> 30 31namespace WebCore { 32 33class CSSRule; 34class CSSStyleSheet; 35 36class CSSRuleList { 37 WTF_MAKE_NONCOPYABLE(CSSRuleList); WTF_MAKE_FAST_ALLOCATED; 38public: 39 virtual ~CSSRuleList(); 40 41 virtual void ref() = 0; 42 virtual void deref() = 0; 43 44 virtual unsigned length() const = 0; 45 virtual CSSRule* item(unsigned index) const = 0; 46 47 virtual CSSStyleSheet* styleSheet() const = 0; 48 49protected: 50 CSSRuleList(); 51}; 52 53class StaticCSSRuleList : public CSSRuleList { 54public: 55 static PassRefPtr<StaticCSSRuleList> create() { return adoptRef(new StaticCSSRuleList()); } 56 57 virtual void ref() { ++m_refCount; } 58 virtual void deref(); 59 60 Vector<RefPtr<CSSRule> >& rules() { return m_rules; } 61 62 virtual CSSStyleSheet* styleSheet() const { return 0; } 63 64private: 65 StaticCSSRuleList(); 66 ~StaticCSSRuleList(); 67 68 virtual unsigned length() const { return m_rules.size(); } 69 virtual CSSRule* item(unsigned index) const { return index < m_rules.size() ? m_rules[index].get() : 0; } 70 71 Vector<RefPtr<CSSRule> > m_rules; 72 unsigned m_refCount; 73}; 74 75// The rule owns the live list. 76template <class Rule> 77class LiveCSSRuleList : public CSSRuleList { 78public: 79 LiveCSSRuleList(Rule* rule) : m_rule(rule) { } 80 81 virtual void ref() { m_rule->ref(); } 82 virtual void deref() { m_rule->deref(); } 83 84private: 85 virtual unsigned length() const { return m_rule->length(); } 86 virtual CSSRule* item(unsigned index) const { return m_rule->item(index); } 87 virtual CSSStyleSheet* styleSheet() const { return m_rule->parentStyleSheet(); } 88 89 Rule* m_rule; 90}; 91 92} // namespace WebCore 93 94#endif // CSSRuleList_h 95