#include "config.h"
#include "XSLImportRule.h"
#if ENABLE(XSLT)
#include "CachedXSLStyleSheet.h"
#include "DocLoader.h"
#include "XSLStyleSheet.h"
namespace WebCore {
XSLImportRule::XSLImportRule(XSLStyleSheet* parent, const String& href)
: StyleBase(parent)
, m_strHref(href)
, m_cachedSheet(0)
, m_loading(false)
{
}
XSLImportRule::~XSLImportRule()
{
if (m_styleSheet)
m_styleSheet->setParent(0);
if (m_cachedSheet)
m_cachedSheet->removeClient(this);
}
XSLStyleSheet* XSLImportRule::parentStyleSheet() const
{
return (parent() && parent()->isXSLStyleSheet()) ? static_cast<XSLStyleSheet*>(parent()) : 0;
}
void XSLImportRule::setXSLStyleSheet(const String& url, const String& sheet)
{
if (m_styleSheet)
m_styleSheet->setParent(0);
m_styleSheet = XSLStyleSheet::create(this, url);
XSLStyleSheet* parent = parentStyleSheet();
if (parent)
m_styleSheet->setParentStyleSheet(parent);
m_styleSheet->parseString(sheet);
m_loading = false;
if (parent)
parent->checkLoaded();
}
bool XSLImportRule::isLoading()
{
return (m_loading || (m_styleSheet && m_styleSheet->isLoading()));
}
void XSLImportRule::loadSheet()
{
DocLoader* docLoader = 0;
StyleBase* root = this;
StyleBase* parent;
while ((parent = root->parent()))
root = parent;
if (root->isXSLStyleSheet())
docLoader = static_cast<XSLStyleSheet*>(root)->docLoader();
String absHref = m_strHref;
XSLStyleSheet* parentSheet = parentStyleSheet();
if (!parentSheet->href().isNull())
absHref = KURL(KURL(parentSheet->href()), m_strHref).string();
for (parent = this->parent(); parent; parent = parent->parent()) {
if (parent->isXSLStyleSheet() && absHref == static_cast<XSLStyleSheet*>(parent)->href())
return;
}
m_cachedSheet = docLoader->requestXSLStyleSheet(absHref);
if (m_cachedSheet) {
m_cachedSheet->addClient(this);
if (!m_styleSheet)
m_loading = true;
}
}
}
#endif // ENABLE(XSLT)