• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * This file is part of the DOM implementation for KDE.
3  *
4  * (C) 1999-2003 Lars Knoll (knoll@kde.org)
5  * (C) 2002-2003 Dirk Mueller (mueller@kde.org)
6  * Copyright (C) 2002, 2005, 2006 Apple Computer, Inc.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public License
19  * along with this library; see the file COPYING.LIB.  If not, write to
20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  */
23 
24 #include "config.h"
25 #include "CSSRuleList.h"
26 
27 #include "CSSRule.h"
28 #include "StyleList.h"
29 
30 namespace WebCore {
31 
CSSRuleList()32 CSSRuleList::CSSRuleList()
33 {
34 }
35 
CSSRuleList(StyleList * list,bool omitCharsetRules)36 CSSRuleList::CSSRuleList(StyleList* list, bool omitCharsetRules)
37 {
38     m_list = list;
39     if (list && omitCharsetRules) {
40         m_list = 0;
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));
46         }
47     }
48 }
49 
~CSSRuleList()50 CSSRuleList::~CSSRuleList()
51 {
52 }
53 
length() const54 unsigned CSSRuleList::length() const
55 {
56     return m_list ? m_list->length() : m_lstCSSRules.size();
57 }
58 
item(unsigned index)59 CSSRule* CSSRuleList::item(unsigned index)
60 {
61     if (m_list) {
62         StyleBase* rule = m_list->item(index);
63         ASSERT(!rule || rule->isRule());
64         return static_cast<CSSRule*>(rule);
65     }
66 
67     if (index < m_lstCSSRules.size())
68         return m_lstCSSRules[index].get();
69     return 0;
70 }
71 
deleteRule(unsigned index)72 void CSSRuleList::deleteRule(unsigned index)
73 {
74     ASSERT(!m_list);
75 
76     if (index >= m_lstCSSRules.size()) {
77         // FIXME: Should we throw an INDEX_SIZE_ERR exception here?
78         return;
79     }
80 
81     m_lstCSSRules.remove(index);
82 }
83 
append(CSSRule * rule)84 void CSSRuleList::append(CSSRule* rule)
85 {
86     ASSERT(!m_list);
87     if (!rule) {
88         // FIXME: Should we throw an exception?
89         return;
90     }
91 
92     m_lstCSSRules.append(rule);
93 }
94 
insertRule(CSSRule * rule,unsigned index)95 unsigned CSSRuleList::insertRule(CSSRule* rule, unsigned index)
96 {
97     ASSERT(!m_list);
98     if (!rule) {
99         // FIXME: Should we throw an exception?
100         return 0;
101     }
102 
103     if (index > m_lstCSSRules.size()) {
104         // FIXME: Should we throw an INDEX_SIZE_ERR exception here?
105         return 0;
106     }
107 
108     m_lstCSSRules.insert(index, rule);
109     return index;
110 }
111 
112 } // namespace WebCore
113