tizen beta release
[profile/ivi/webkit-efl.git] / Source / WebCore / css / StyleSheet.cpp
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 "CSSRule.h"
24 #include "CSSStyleSheet.h"
25 #include "Document.h"
26 #include "MediaList.h"
27 #include "Node.h"
28
29 namespace WebCore {
30
31 StyleSheet::StyleSheet(Node* parentNode, const String& originalURL, const KURL& finalURL)
32     : m_disabled(false)
33     , m_parentRule(0)
34     , m_parentNode(parentNode)
35     , m_originalURL(originalURL)
36     , m_finalURL(finalURL)
37 {
38 }
39
40 StyleSheet::StyleSheet(CSSRule* parentRule, const String& originalURL, const KURL& finalURL)
41     : m_disabled(false)
42     , m_parentRule(parentRule)
43     , m_parentNode(0)
44     , m_originalURL(originalURL)
45     , m_finalURL(finalURL)
46 {
47 }
48
49 StyleSheet::~StyleSheet()
50 {
51     if (m_media)
52         m_media->setParentStyleSheet(0);
53 }
54
55 StyleSheet* StyleSheet::parentStyleSheet() const
56 {
57     ASSERT(isCSSStyleSheet());
58     return m_parentRule ? m_parentRule->parentStyleSheet() : 0;
59 }
60
61 void StyleSheet::setMedia(PassRefPtr<MediaList> media)
62 {
63     ASSERT(isCSSStyleSheet());
64     ASSERT(!media->parentStyleSheet() || media->parentStyleSheet() == this);
65
66     if (m_media)
67         m_media->setParentStyleSheet(0);
68
69     m_media = media;
70     m_media->setParentStyleSheet(static_cast<CSSStyleSheet*>(this));
71 }
72
73 KURL StyleSheet::baseURL() const
74 {
75     if (!m_finalURL.isNull())
76         return m_finalURL;
77     if (StyleSheet* parentSheet = parentStyleSheet())
78         return parentSheet->baseURL();
79     if (!m_parentNode)
80         return KURL();
81     return m_parentNode->document()->baseURL();
82 }
83
84 void StyleSheet::setDisabled(bool disabled)
85 {
86      m_disabled = disabled;
87      if (isCSSStyleSheet())
88          static_cast<CSSStyleSheet*>(this)->styleSheetChanged();
89 }
90
91 }