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.
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.
23 #include "CSSRuleList.h"
26 #include "StyleList.h"
30 CSSRuleList::CSSRuleList()
34 CSSRuleList::CSSRuleList(StyleList* list, bool omitCharsetRules)
37 if (list && omitCharsetRules) {
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));
48 CSSRuleList::~CSSRuleList()
52 unsigned CSSRuleList::length() const
54 return m_list ? m_list->length() : m_lstCSSRules.size();
57 CSSRule* CSSRuleList::item(unsigned index)
60 StyleBase* rule = m_list->item(index);
61 ASSERT(!rule || rule->isRule());
62 return static_cast<CSSRule*>(rule);
65 if (index < m_lstCSSRules.size())
66 return m_lstCSSRules[index].get();
70 void CSSRuleList::deleteRule(unsigned index)
74 if (index >= m_lstCSSRules.size()) {
75 // FIXME: Should we throw an INDEX_SIZE_ERR exception here?
79 m_lstCSSRules.remove(index);
82 void CSSRuleList::append(CSSRule* rule)
86 // FIXME: Should we throw an exception?
90 m_lstCSSRules.append(rule);
93 unsigned CSSRuleList::insertRule(CSSRule* rule, unsigned index)
97 // FIXME: Should we throw an exception?
101 if (index > m_lstCSSRules.size()) {
102 // FIXME: Should we throw an INDEX_SIZE_ERR exception here?
106 m_lstCSSRules.insert(index, rule);
110 } // namespace WebCore