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.
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.
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.
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.
25 #include "bindings/core/v8/ScriptWrappable.h"
26 #include "platform/heap/Handle.h"
27 #include "wtf/PassRefPtr.h"
28 #include "wtf/RefPtr.h"
29 #include "wtf/Vector.h"
36 class CSSRuleList : public NoBaseWillBeGarbageCollectedFinalized<CSSRuleList>, public ScriptWrappable {
37 DEFINE_WRAPPERTYPEINFO();
38 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
39 WTF_MAKE_NONCOPYABLE(CSSRuleList);
41 virtual ~CSSRuleList();
44 virtual void ref() = 0;
45 virtual void deref() = 0;
48 virtual unsigned length() const = 0;
49 virtual CSSRule* item(unsigned index) const = 0;
51 virtual CSSStyleSheet* styleSheet() const = 0;
53 virtual void trace(Visitor*) { }
59 class StaticCSSRuleList final : public CSSRuleList {
61 static PassRefPtrWillBeRawPtr<StaticCSSRuleList> create()
63 return adoptRefWillBeNoop(new StaticCSSRuleList());
67 virtual void ref() override { ++m_refCount; }
68 virtual void deref() override;
71 WillBeHeapVector<RefPtrWillBeMember<CSSRule> >& rules() { return m_rules; }
73 virtual CSSStyleSheet* styleSheet() const override { return 0; }
75 virtual void trace(Visitor*) override;
79 virtual ~StaticCSSRuleList();
81 virtual unsigned length() const override { return m_rules.size(); }
82 virtual CSSRule* item(unsigned index) const override { return index < m_rules.size() ? m_rules[index].get() : 0; }
84 WillBeHeapVector<RefPtrWillBeMember<CSSRule> > m_rules;
91 class LiveCSSRuleList final : public CSSRuleList {
93 static PassOwnPtrWillBeRawPtr<LiveCSSRuleList> create(Rule* rule)
95 return adoptPtrWillBeNoop(new LiveCSSRuleList(rule));
99 virtual void ref() override { m_rule->ref(); }
100 virtual void deref() override { m_rule->deref(); }
103 virtual void trace(Visitor* visitor) override
105 visitor->trace(m_rule);
106 CSSRuleList::trace(visitor);
110 LiveCSSRuleList(Rule* rule) : m_rule(rule) { }
112 virtual unsigned length() const override { return m_rule->length(); }
113 virtual CSSRule* item(unsigned index) const override { return m_rule->item(index); }
114 virtual CSSStyleSheet* styleSheet() const override { return m_rule->parentStyleSheet(); }
116 RawPtrWillBeMember<Rule> m_rule;
121 #endif // CSSRuleList_h