2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * (C) 2002-2003 Dirk Mueller (mueller@kde.org)
4 * Copyright (C) 2002, 2005, 2006, 2008 Apple Inc. All rights reserved.
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 "CSSStyleRule.h"
25 #include "CSSMutableStyleDeclaration.h"
26 #include "CSSPageRule.h"
27 #include "CSSParser.h"
28 #include "CSSSelector.h"
29 #include "CSSStyleSheet.h"
31 #include "StyledElement.h"
32 #include "StyleSheet.h"
36 CSSStyleRule::CSSStyleRule(CSSStyleSheet* parent, int sourceLine, CSSRule::Type type)
37 : CSSRule(parent, type)
39 m_sourceLine = sourceLine;
41 // m_sourceLine is a bitfield, so let's catch any overflow early in debug mode.
42 ASSERT(m_sourceLine == sourceLine);
45 CSSStyleRule::~CSSStyleRule()
48 m_style->setParentRule(0);
51 String CSSStyleRule::selectorText() const
54 return static_cast<const CSSPageRule*>(this)->pageSelectorText();
57 for (CSSSelector* s = selectorList().first(); s; s = CSSSelectorList::next(s)) {
58 if (s != selectorList().first())
60 str += s->selectorText();
65 void CSSStyleRule::setSelectorText(const String& selectorText)
69 if (CSSStyleSheet* styleSheet = m_style->parentStyleSheet())
70 doc = styleSheet->findDocument();
72 if (!doc && m_style->isElementStyleDeclaration()) {
73 if (StyledElement* element = static_cast<CSSElementStyleDeclaration*>(m_style.get())->element())
74 doc = element->document();
81 CSSSelectorList selectorList;
82 p.parseSelector(selectorText, doc, selectorList);
83 if (!selectorList.first())
86 String oldSelectorText = this->selectorText();
87 m_selectorList.adopt(selectorList);
88 if (this->selectorText() == oldSelectorText)
91 doc->styleSelectorChanged(DeferRecalcStyle);
94 String CSSStyleRule::cssText() const
96 String result = selectorText();
99 result += m_style->cssText();
105 void CSSStyleRule::addSubresourceStyleURLs(ListHashSet<KURL>& urls)
108 m_style->addSubresourceStyleURLs(urls);
111 } // namespace WebCore