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 * Copyright (C) 2006 Samuel Weinig (sam@webkit.org)
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
24 #include "CSSMediaRule.h"
26 #include "CSSParser.h"
27 #include "ExceptionCode.h"
31 CSSMediaRule::CSSMediaRule(CSSStyleSheet* parent, PassRefPtr<MediaList> media, PassRefPtr<CSSRuleList> rules)
34 , m_lstCSSRules(rules)
38 CSSMediaRule::~CSSMediaRule()
41 m_lstMedia->setParent(0);
43 int length = m_lstCSSRules->length();
44 for (int i = 0; i < length; i++)
45 m_lstCSSRules->item(i)->setParent(0);
48 unsigned CSSMediaRule::append(CSSRule* rule)
53 rule->setParent(this);
54 return m_lstCSSRules->insertRule(rule, m_lstCSSRules->length());
57 unsigned CSSMediaRule::insertRule(const String& rule, unsigned index, ExceptionCode& ec)
59 if (index > m_lstCSSRules->length()) {
60 // INDEX_SIZE_ERR: Raised if the specified index is not a valid insertion point.
65 CSSParser p(useStrictParsing());
66 RefPtr<CSSRule> newRule = p.parseRule(parentStyleSheet(), rule);
68 // SYNTAX_ERR: Raised if the specified rule has a syntax error and is unparsable.
73 if (newRule->isImportRule()) {
74 // FIXME: an HIERARCHY_REQUEST_ERR should also be thrown for a @charset or a nested
75 // @media rule. They are currently not getting parsed, resulting in a SYNTAX_ERR
76 // to get raised above.
78 // HIERARCHY_REQUEST_ERR: Raised if the rule cannot be inserted at the specified
79 // index, e.g., if an @import rule is inserted after a standard rule set or other
81 ec = HIERARCHY_REQUEST_ERR;
85 newRule->setParent(this);
86 unsigned returnedIndex = m_lstCSSRules->insertRule(newRule.get(), index);
88 // stylesheet() can only return 0 for computed style declarations.
89 stylesheet()->styleSheetChanged();
94 void CSSMediaRule::deleteRule(unsigned index, ExceptionCode& ec)
96 if (index >= m_lstCSSRules->length()) {
97 // INDEX_SIZE_ERR: Raised if the specified index does not correspond to a
98 // rule in the media rule list.
103 m_lstCSSRules->deleteRule(index);
105 // stylesheet() can only return 0 for computed style declarations.
106 stylesheet()->styleSheetChanged();
109 String CSSMediaRule::cssText() const
111 String result = "@media ";
113 result += m_lstMedia->mediaText();
119 unsigned len = m_lstCSSRules->length();
120 for (unsigned i = 0; i < len; i++) {
122 result += m_lstCSSRules->item(i)->cssText();
131 } // namespace WebCore