#include "config.h"
#include "CSSMediaRule.h"
#include "CSSParser.h"
#include "CSSRuleList.h"
#include "CSSStyleSheet.h"
#include "ExceptionCode.h"
#include "StyleRule.h"
#include <wtf/text/StringBuilder.h>
namespace WebCore {
CSSMediaRule::CSSMediaRule(StyleRuleMedia& mediaRule, CSSStyleSheet* parent)
: CSSGroupingRule(mediaRule, parent)
{
}
CSSMediaRule::~CSSMediaRule()
{
if (m_mediaCSSOMWrapper)
m_mediaCSSOMWrapper->clearParentRule();
}
MediaQuerySet* CSSMediaRule::mediaQueries() const
{
return downcast<StyleRuleMedia>(m_groupRule.get()).mediaQueries();
}
String CSSMediaRule::cssText() const
{
StringBuilder result;
result.appendLiteral("@media ");
if (mediaQueries()) {
result.append(mediaQueries()->mediaText());
result.append(' ');
}
result.appendLiteral("{ \n");
appendCssTextForItems(result);
result.append('}');
return result.toString();
}
MediaList* CSSMediaRule::media() const
{
if (!mediaQueries())
return 0;
if (!m_mediaCSSOMWrapper)
m_mediaCSSOMWrapper = MediaList::create(mediaQueries(), const_cast<CSSMediaRule*>(this));
return m_mediaCSSOMWrapper.get();
}
void CSSMediaRule::reattach(StyleRuleBase& rule)
{
CSSGroupingRule::reattach(rule);
if (m_mediaCSSOMWrapper && mediaQueries())
m_mediaCSSOMWrapper->reattach(mediaQueries());
}
}