2
* This file is part of the DOM implementation for KDE.
4
* (C) 1999-2003 Lars Knoll (knoll@kde.org)
5
* (C) 2002-2003 Dirk Mueller (mueller@kde.org)
6
* Copyright (C) 2002, 2005, 2006 Apple Computer, Inc.
8
* This library is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU Library General Public
10
* License as published by the Free Software Foundation; either
11
* version 2 of the License, or (at your option) any later version.
13
* This library is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* Library General Public License for more details.
18
* You should have received a copy of the GNU Library General Public License
19
* along with this library; see the file COPYING.LIB. If not, write to
20
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21
* Boston, MA 02111-1307, USA.
25
#include "CSSImportRule.h"
27
#include "CachedCSSStyleSheet.h"
28
#include "CSSStyleSheet.h"
29
#include "DocLoader.h"
32
#include "MediaList.h"
36
CSSImportRule::CSSImportRule(StyleBase* parent, const String& href, MediaList* media)
44
m_lstMedia->setParent(this);
46
m_lstMedia = new MediaList(this, String());
49
CSSImportRule::~CSSImportRule()
52
m_lstMedia->setParent(0);
54
m_styleSheet->setParent(0);
56
m_cachedSheet->deref(this);
59
void CSSImportRule::setCSSStyleSheet(const String& url, const String& charset, const String& sheet)
62
m_styleSheet->setParent(0);
63
m_styleSheet = new CSSStyleSheet(this, url, charset);
65
CSSStyleSheet* parent = parentStyleSheet();
66
m_styleSheet->parseString(sheet, !parent || parent->useStrictParsing());
72
bool CSSImportRule::isLoading() const
74
return m_loading || (m_styleSheet && m_styleSheet->isLoading());
77
void CSSImportRule::insertedIntoParent()
79
StyleBase* root = this;
81
while ((parent = root->parent()))
83
if (!root->isCSSStyleSheet())
85
DocLoader* docLoader = static_cast<CSSStyleSheet*>(root)->docLoader();
89
String absHref = m_strHref;
90
CSSStyleSheet* parentSheet = parentStyleSheet();
91
if (!parentSheet->href().isNull())
92
// use parent styleheet's URL as the base URL
93
absHref = KURL(parentSheet->href().deprecatedString(), m_strHref.deprecatedString()).url();
95
// Check for a cycle in our import chain. If we encounter a stylesheet
96
// in our parent chain with the same URL, then just bail.
97
for (parent = static_cast<StyleBase*>(this)->parent(); parent; parent = parent->parent()) {
98
if (absHref == parent->baseURL())
102
m_cachedSheet = docLoader->requestCSSStyleSheet(absHref, parentSheet->charset());
104
// if the import rule is issued dynamically, the sheet may be
105
// removed from the pending sheet count, so let the doc know
106
// the sheet being imported is pending.
107
if (parentSheet && parentSheet->loadCompleted() && parentSheet->doc())
108
parentSheet->doc()->addPendingSheet();
110
m_cachedSheet->ref(this);
114
String CSSImportRule::cssText() const
116
String result = "@import url(\"";
122
result += m_lstMedia->mediaText();
129
} // namespace WebCore