1/* 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. 5 * 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. 10 * 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. 15 * 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. 20 */ 21 22#include "config.h" 23#include "CSSStyleRule.h" 24 25#include "CSSMutableStyleDeclaration.h" 26#include "CSSParser.h" 27#include "CSSSelector.h" 28#include "CSSStyleSheet.h" 29#include "Document.h" 30#include "StyleSheet.h" 31 32namespace WebCore { 33 34CSSStyleRule::CSSStyleRule(CSSStyleSheet* parent, int sourceLine) 35 : CSSRule(parent) 36 , m_sourceLine(sourceLine) 37{ 38} 39 40CSSStyleRule::~CSSStyleRule() 41{ 42 if (m_style) 43 m_style->setParent(0); 44} 45 46String CSSStyleRule::selectorText() const 47{ 48 String str; 49 for (CSSSelector* s = selectorList().first(); s; s = CSSSelectorList::next(s)) { 50 if (s != selectorList().first()) 51 str += ", "; 52 str += s->selectorText(); 53 } 54 return str; 55} 56 57void CSSStyleRule::setSelectorText(const String& selectorText) 58{ 59 Document* doc = 0; 60 StyleSheet* ownerStyleSheet = m_style->stylesheet(); 61 if (ownerStyleSheet) { 62 if (ownerStyleSheet->isCSSStyleSheet()) 63 doc = static_cast<CSSStyleSheet*>(ownerStyleSheet)->document(); 64 if (!doc) 65 doc = ownerStyleSheet->ownerNode() ? ownerStyleSheet->ownerNode()->document() : 0; 66 } 67 if (!doc) 68 doc = m_style->node() ? m_style->node()->document() : 0; 69 70 if (!doc) 71 return; 72 73 CSSParser p; 74 CSSSelectorList selectorList; 75 p.parseSelector(selectorText, doc, selectorList); 76 if (!selectorList.first()) 77 return; 78 79 String oldSelectorText = this->selectorText(); 80 m_selectorList.adopt(selectorList); 81 if (this->selectorText() == oldSelectorText) 82 return; 83 84 doc->styleSelectorChanged(DeferRecalcStyle); 85} 86 87String CSSStyleRule::cssText() const 88{ 89 String result = selectorText(); 90 91 result += " { "; 92 result += m_style->cssText(); 93 result += "}"; 94 95 return result; 96} 97 98bool CSSStyleRule::parseString(const String& /*string*/, bool /*strict*/) 99{ 100 // FIXME 101 return false; 102} 103 104void CSSStyleRule::setDeclaration(PassRefPtr<CSSMutableStyleDeclaration> style) 105{ 106 m_style = style; 107} 108 109void CSSStyleRule::addSubresourceStyleURLs(ListHashSet<KURL>& urls) 110{ 111 if (m_style) 112 m_style->addSubresourceStyleURLs(urls); 113} 114 115} // namespace WebCore 116