Home | History | Annotate | Download | only in css
      1 /*
      2  * (C) 1999-2003 Lars Knoll (knoll (at) kde.org)
      3  * (C) 2002-2003 Dirk Mueller (mueller (at) 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 "platform/heap/Handle.h"
     26 #include "wtf/PassRefPtr.h"
     27 #include "wtf/RefPtr.h"
     28 #include "wtf/Vector.h"
     29 
     30 namespace WebCore {
     31 
     32 class CSSRule;
     33 class CSSStyleSheet;
     34 
     35 class CSSRuleList : public NoBaseWillBeGarbageCollectedFinalized<CSSRuleList> {
     36     WTF_MAKE_NONCOPYABLE(CSSRuleList);
     37     WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
     38 public:
     39     virtual ~CSSRuleList();
     40 
     41 #if !ENABLE(OILPAN)
     42     virtual void ref() = 0;
     43     virtual void deref() = 0;
     44 #endif
     45 
     46     virtual unsigned length() const = 0;
     47     virtual CSSRule* item(unsigned index) const = 0;
     48 
     49     virtual CSSStyleSheet* styleSheet() const = 0;
     50 
     51     virtual void trace(Visitor*) { }
     52 
     53 protected:
     54     CSSRuleList();
     55 };
     56 
     57 class StaticCSSRuleList FINAL : public CSSRuleList {
     58 public:
     59     static PassRefPtrWillBeRawPtr<StaticCSSRuleList> create()
     60     {
     61         return adoptRefWillBeNoop(new StaticCSSRuleList());
     62     }
     63 
     64 #if !ENABLE(OILPAN)
     65     virtual void ref() OVERRIDE { ++m_refCount; }
     66     virtual void deref() OVERRIDE;
     67 #endif
     68 
     69     WillBeHeapVector<RefPtrWillBeMember<CSSRule> >& rules() { return m_rules; }
     70 
     71     virtual CSSStyleSheet* styleSheet() const OVERRIDE { return 0; }
     72 
     73     virtual void trace(Visitor*) OVERRIDE;
     74 
     75 private:
     76     StaticCSSRuleList();
     77     virtual ~StaticCSSRuleList();
     78 
     79     virtual unsigned length() const OVERRIDE { return m_rules.size(); }
     80     virtual CSSRule* item(unsigned index) const OVERRIDE { return index < m_rules.size() ? m_rules[index].get() : 0; }
     81 
     82     WillBeHeapVector<RefPtrWillBeMember<CSSRule> > m_rules;
     83 #if !ENABLE(OILPAN)
     84     unsigned m_refCount;
     85 #endif
     86 };
     87 
     88 template <class Rule>
     89 class LiveCSSRuleList FINAL : public CSSRuleList {
     90 public:
     91     static PassOwnPtrWillBeRawPtr<LiveCSSRuleList> create(Rule* rule)
     92     {
     93         return adoptPtrWillBeNoop(new LiveCSSRuleList(rule));
     94     }
     95 
     96 #if !ENABLE(OILPAN)
     97     virtual void ref() OVERRIDE { m_rule->ref(); }
     98     virtual void deref() OVERRIDE { m_rule->deref(); }
     99 #endif
    100 
    101     virtual void trace(Visitor* visitor) OVERRIDE
    102     {
    103         visitor->trace(m_rule);
    104         CSSRuleList::trace(visitor);
    105     }
    106 
    107 private:
    108     LiveCSSRuleList(Rule* rule) : m_rule(rule) { }
    109 
    110     virtual unsigned length() const OVERRIDE { return m_rule->length(); }
    111     virtual CSSRule* item(unsigned index) const OVERRIDE { return m_rule->item(index); }
    112     virtual CSSStyleSheet* styleSheet() const OVERRIDE { return m_rule->parentStyleSheet(); }
    113 
    114     RawPtrWillBeMember<Rule> m_rule;
    115 };
    116 
    117 } // namespace WebCore
    118 
    119 #endif // CSSRuleList_h
    120