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"
25 #include "CSSMutableStyleDeclaration.h"
27 #include "StyleList.h"
28 #include "WebKitCSSKeyframeRule.h"
32 CSSRuleList::CSSRuleList()
36 CSSRuleList::CSSRuleList(StyleList* list, bool omitCharsetRules)
39 if (list && omitCharsetRules) {
41 unsigned len = list->length();
42 for (unsigned i = 0; i < len; ++i) {
43 StyleBase* style = list->item(i);
44 if (style->isRule() && !style->isCharsetRule())
45 append(static_cast<CSSRule*>(style));
50 CSSRuleList::~CSSRuleList()
54 unsigned CSSRuleList::length() const
56 return m_list ? m_list->length() : m_lstCSSRules.size();
59 CSSRule* CSSRuleList::item(unsigned index)
62 StyleBase* rule = m_list->item(index);
63 ASSERT(!rule || rule->isRule());
64 return static_cast<CSSRule*>(rule);
67 if (index < m_lstCSSRules.size())
68 return m_lstCSSRules[index].get();
72 void CSSRuleList::deleteRule(unsigned index)
76 if (index >= m_lstCSSRules.size()) {
77 // FIXME: Should we throw an INDEX_SIZE_ERR exception here?
81 if (m_lstCSSRules[index]->isKeyframeRule()) {
82 if (CSSMutableStyleDeclaration* style = static_cast<WebKitCSSKeyframeRule*>(m_lstCSSRules[index].get())->style())
86 m_lstCSSRules[index]->setParent(0);
87 m_lstCSSRules.remove(index);
90 void CSSRuleList::append(CSSRule* rule)
94 // FIXME: Should we throw an exception?
98 m_lstCSSRules.append(rule);
101 unsigned CSSRuleList::insertRule(CSSRule* rule, unsigned index)
105 // FIXME: Should we throw an exception?
109 if (index > m_lstCSSRules.size()) {
110 // FIXME: Should we throw an INDEX_SIZE_ERR exception here?
114 m_lstCSSRules.insert(index, rule);
118 } // namespace WebCore