2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2006 Apple Computer, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
21 #include "StyleSheet.h"
24 #include "CSSStyleSheet.h"
26 #include "MediaList.h"
31 StyleSheet::StyleSheet(Node* parentNode, const String& originalURL, const KURL& finalURL)
34 , m_parentNode(parentNode)
35 , m_originalURL(originalURL)
36 , m_finalURL(finalURL)
40 StyleSheet::StyleSheet(CSSRule* parentRule, const String& originalURL, const KURL& finalURL)
42 , m_parentRule(parentRule)
44 , m_originalURL(originalURL)
45 , m_finalURL(finalURL)
49 StyleSheet::~StyleSheet()
52 m_media->setParentStyleSheet(0);
55 StyleSheet* StyleSheet::parentStyleSheet() const
57 ASSERT(isCSSStyleSheet());
58 return m_parentRule ? m_parentRule->parentStyleSheet() : 0;
61 void StyleSheet::setMedia(PassRefPtr<MediaList> media)
63 ASSERT(isCSSStyleSheet());
64 ASSERT(!media->parentStyleSheet() || media->parentStyleSheet() == this);
67 m_media->setParentStyleSheet(0);
70 m_media->setParentStyleSheet(static_cast<CSSStyleSheet*>(this));
73 KURL StyleSheet::baseURL() const
75 if (!m_finalURL.isNull())
77 if (StyleSheet* parentSheet = parentStyleSheet())
78 return parentSheet->baseURL();
81 return m_parentNode->document()->baseURL();
84 void StyleSheet::setDisabled(bool disabled)
86 m_disabled = disabled;
87 if (isCSSStyleSheet())
88 static_cast<CSSStyleSheet*>(this)->styleSheetChanged();