1/**
2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2006 Apple Computer, Inc.
4 *
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.
9 *
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.
14 *
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.
19 */
20#include "config.h"
21#include "StyleSheet.h"
22
23#include "MediaList.h"
24
25namespace WebCore {
26
27StyleSheet::StyleSheet(StyleSheet* parentSheet, const String& originalURL, const KURL& finalURL)
28    : StyleList(parentSheet)
29    , m_parentNode(0)
30    , m_originalURL(originalURL)
31    , m_finalURL(finalURL)
32    , m_disabled(false)
33{
34}
35
36StyleSheet::StyleSheet(Node* parentNode, const String& originalURL, const KURL& finalURL)
37    : StyleList(0)
38    , m_parentNode(parentNode)
39    , m_originalURL(originalURL)
40    , m_finalURL(finalURL)
41    , m_disabled(false)
42{
43}
44
45StyleSheet::StyleSheet(StyleBase* owner, const String& originalURL, const KURL& finalURL)
46    : StyleList(owner)
47    , m_parentNode(0)
48    , m_originalURL(originalURL)
49    , m_finalURL(finalURL)
50    , m_disabled(false)
51{
52}
53
54StyleSheet::~StyleSheet()
55{
56    if (m_media)
57        m_media->setParent(0);
58}
59
60StyleSheet* StyleSheet::parentStyleSheet() const
61{
62    return (parent() && parent()->isStyleSheet()) ? static_cast<StyleSheet*>(parent()) : 0;
63}
64
65void StyleSheet::setMedia(PassRefPtr<MediaList> media)
66{
67    if (m_media)
68        m_media->setParent(0);
69
70    m_media = media;
71    m_media->setParent(this);
72}
73
74KURL StyleSheet::completeURL(const String& url) const
75{
76    // Always return a null URL when passed a null string.
77    // FIXME: Should we change the KURL constructor to have this behavior?
78    // See also Document::completeURL(const String&)
79    if (url.isNull())
80        return KURL();
81    return KURL(baseURL(), url);
82}
83
84}
85