#include "config.h"
#include "CSSImportRule.h"
#include "CSSStyleSheet.h"
#include "MediaList.h"
#include "StyleRuleImport.h"
#include "StyleSheetContents.h"
#include <wtf/text/StringBuilder.h>
namespace WebCore {
CSSImportRule::CSSImportRule(StyleRuleImport& importRule, CSSStyleSheet* parent)
: CSSRule(parent)
, m_importRule(importRule)
{
}
CSSImportRule::~CSSImportRule()
{
if (m_styleSheetCSSOMWrapper)
m_styleSheetCSSOMWrapper->clearOwnerRule();
if (m_mediaCSSOMWrapper)
m_mediaCSSOMWrapper->clearParentRule();
}
String CSSImportRule::href() const
{
return m_importRule.get().href();
}
MediaList& CSSImportRule::media() const
{
if (!m_mediaCSSOMWrapper)
m_mediaCSSOMWrapper = MediaList::create(m_importRule.get().mediaQueries(), const_cast<CSSImportRule*>(this));
return *m_mediaCSSOMWrapper;
}
String CSSImportRule::cssText() const
{
StringBuilder result;
result.appendLiteral("@import url(\"");
result.append(m_importRule.get().href());
result.appendLiteral("\")");
if (m_importRule.get().mediaQueries()) {
String mediaText = m_importRule.get().mediaQueries()->mediaText();
if (!mediaText.isEmpty()) {
result.append(' ');
result.append(mediaText);
}
}
result.append(';');
return result.toString();
}
CSSStyleSheet* CSSImportRule::styleSheet() const
{
if (!m_importRule.get().styleSheet())
return 0;
if (!m_styleSheetCSSOMWrapper)
m_styleSheetCSSOMWrapper = CSSStyleSheet::create(*m_importRule.get().styleSheet(), const_cast<CSSImportRule*>(this));
return m_styleSheetCSSOMWrapper.get();
}
void CSSImportRule::reattach(StyleRuleBase&)
{
ASSERT_NOT_REACHED();
}
}