• 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, 2005, 2006 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 #include "config.h"
23 #include "CSSRuleList.h"
24 
25 #include "CSSRule.h"
26 #include "StyleList.h"
27 
28 namespace WebCore {
29 
CSSRuleList()30 CSSRuleList::CSSRuleList()
31 {
32 }
33 
CSSRuleList(StyleList * list,bool omitCharsetRules)34 CSSRuleList::CSSRuleList(StyleList* list, bool omitCharsetRules)
35 {
36     m_list = list;
37     if (list && omitCharsetRules) {
38         m_list = 0;
39         unsigned len = list->length();
40         for (unsigned i = 0; i < len; ++i) {
41             StyleBase* style = list->item(i);
42             if (style->isRule() && !style->isCharsetRule())
43                 append(static_cast<CSSRule*>(style));
44         }
45     }
46 }
47 
~CSSRuleList()48 CSSRuleList::~CSSRuleList()
49 {
50 }
51 
length() const52 unsigned CSSRuleList::length() const
53 {
54     return m_list ? m_list->length() : m_lstCSSRules.size();
55 }
56 
item(unsigned index)57 CSSRule* CSSRuleList::item(unsigned index)
58 {
59     if (m_list) {
60         StyleBase* rule = m_list->item(index);
61         ASSERT(!rule || rule->isRule());
62         return static_cast<CSSRule*>(rule);
63     }
64 
65     if (index < m_lstCSSRules.size())
66         return m_lstCSSRules[index].get();
67     return 0;
68 }
69 
deleteRule(unsigned index)70 void CSSRuleList::deleteRule(unsigned index)
71 {
72     ASSERT(!m_list);
73 
74     if (index >= m_lstCSSRules.size()) {
75         // FIXME: Should we throw an INDEX_SIZE_ERR exception here?
76         return;
77     }
78 
79     m_lstCSSRules.remove(index);
80 }
81 
append(CSSRule * rule)82 void CSSRuleList::append(CSSRule* rule)
83 {
84     ASSERT(!m_list);
85     if (!rule) {
86         // FIXME: Should we throw an exception?
87         return;
88     }
89 
90     m_lstCSSRules.append(rule);
91 }
92 
insertRule(CSSRule * rule,unsigned index)93 unsigned CSSRuleList::insertRule(CSSRule* rule, unsigned index)
94 {
95     ASSERT(!m_list);
96     if (!rule) {
97         // FIXME: Should we throw an exception?
98         return 0;
99     }
100 
101     if (index > m_lstCSSRules.size()) {
102         // FIXME: Should we throw an INDEX_SIZE_ERR exception here?
103         return 0;
104     }
105 
106     m_lstCSSRules.insert(index, rule);
107     return index;
108 }
109 
110 } // namespace WebCore
111