WebKitCSSViewportRule.cpp [plain text]
#include "config.h"
#include "WebKitCSSViewportRule.h"
#if ENABLE(CSS_DEVICE_ADAPTATION)
#include "PropertySetCSSStyleDeclaration.h"
#include "StyleProperties.h"
#include "StyleRule.h"
#include <wtf/text/StringBuilder.h>
namespace WebCore {
WebKitCSSViewportRule::WebKitCSSViewportRule(StyleRuleViewport* viewportRule, CSSStyleSheet* sheet)
: CSSRule(sheet)
, m_viewportRule(viewportRule)
{
}
WebKitCSSViewportRule::~WebKitCSSViewportRule()
{
if (m_propertiesCSSOMWrapper)
m_propertiesCSSOMWrapper->clearParentRule();
}
CSSStyleDeclaration* WebKitCSSViewportRule::style()
{
if (!m_propertiesCSSOMWrapper)
m_propertiesCSSOMWrapper = StyleRuleCSSStyleDeclaration::create(m_viewportRule->mutableProperties(), *this);
return m_propertiesCSSOMWrapper.get();
}
String WebKitCSSViewportRule::cssText() const
{
StringBuilder result;
result.appendLiteral("@-webkit-viewport { ");
String decls = m_viewportRule->properties().asText();
result.append(decls);
if (!decls.isEmpty())
result.append(' ');
result.append('}');
return result.toString();
}
void WebKitCSSViewportRule::reattach(StyleRuleBase* rule)
{
ASSERT(rule);
ASSERT_WITH_SECURITY_IMPLICATION(rule->isViewportRule());
m_viewportRule = static_cast<StyleRuleViewport*>(rule);
if (m_propertiesCSSOMWrapper)
m_propertiesCSSOMWrapper->reattach(m_viewportRule->mutableProperties());
}
}
#endif // ENABLE(CSS_DEVICE_ADAPTATION)