This source file includes following definitions.
- keyText
- setKeyText
- keys
- setKeys
- mutableProperties
- setProperties
- cssText
- createKeyList
- m_keyframe
- style
- reattach
- trace
#include "config.h"
#include "core/css/CSSKeyframeRule.h"
#include "core/css/CSSKeyframesRule.h"
#include "core/css/parser/BisonCSSParser.h"
#include "core/css/PropertySetCSSStyleDeclaration.h"
#include "core/css/StylePropertySet.h"
#include "core/frame/UseCounter.h"
#include "wtf/text/StringBuilder.h"
namespace WebCore {
StyleKeyframe::StyleKeyframe()
{
}
StyleKeyframe::~StyleKeyframe()
{
}
String StyleKeyframe::keyText() const
{
if (m_keyText.isNull()) {
ASSERT(m_keys && !m_keys->isEmpty());
StringBuilder keyText;
for (unsigned i = 0; i < m_keys->size(); ++i) {
if (i)
keyText.append(',');
keyText.append(String::number(m_keys->at(i) * 100));
keyText.append('%');
}
m_keyText = keyText.toString();
}
ASSERT(!m_keyText.isNull());
return m_keyText;
}
void StyleKeyframe::setKeyText(const String& keyText)
{
ASSERT(!keyText.isNull());
m_keyText = keyText;
m_keys.clear();
}
const Vector<double>& StyleKeyframe::keys() const
{
if (!m_keys) {
ASSERT(!m_keyText.isNull());
m_keys = BisonCSSParser(strictCSSParserContext()).parseKeyframeKeyList(m_keyText);
}
ASSERT(m_keys);
return *m_keys;
}
void StyleKeyframe::setKeys(PassOwnPtr<Vector<double> > keys)
{
ASSERT(keys && !keys->isEmpty());
m_keys = keys;
m_keyText = String();
ASSERT(m_keyText.isNull());
}
MutableStylePropertySet& StyleKeyframe::mutableProperties()
{
if (!m_properties->isMutable())
m_properties = m_properties->mutableCopy();
return *toMutableStylePropertySet(m_properties);
}
void StyleKeyframe::setProperties(PassRefPtr<StylePropertySet> properties)
{
ASSERT(properties);
m_properties = properties;
}
String StyleKeyframe::cssText() const
{
StringBuilder result;
result.append(keyText());
result.appendLiteral(" { ");
String decls = m_properties->asText();
result.append(decls);
if (!decls.isEmpty())
result.append(' ');
result.append('}');
return result.toString();
}
PassOwnPtr<Vector<double> > StyleKeyframe::createKeyList(CSSParserValueList* keys)
{
OwnPtr<Vector<double> > keyVector = adoptPtr(new Vector<double>(keys->size()));
for (unsigned i = 0; i < keys->size(); ++i) {
ASSERT(keys->valueAt(i)->unit == WebCore::CSSPrimitiveValue::CSS_NUMBER);
double key = keys->valueAt(i)->fValue;
if (key < 0 || key > 100) {
keyVector->clear();
break;
}
keyVector->at(i) = key / 100;
}
return keyVector.release();
}
CSSKeyframeRule::CSSKeyframeRule(StyleKeyframe* keyframe, CSSKeyframesRule* parent)
: CSSRule(0)
, m_keyframe(keyframe)
{
setParentRule(parent);
}
CSSKeyframeRule::~CSSKeyframeRule()
{
if (m_propertiesCSSOMWrapper)
m_propertiesCSSOMWrapper->clearParentRule();
}
CSSStyleDeclaration* CSSKeyframeRule::style() const
{
if (!m_propertiesCSSOMWrapper)
m_propertiesCSSOMWrapper = StyleRuleCSSStyleDeclaration::create(m_keyframe->mutableProperties(), const_cast<CSSKeyframeRule*>(this));
return m_propertiesCSSOMWrapper.get();
}
void CSSKeyframeRule::reattach(StyleRuleBase*)
{
ASSERT_NOT_REACHED();
}
void CSSKeyframeRule::trace(Visitor* visitor)
{
visitor->trace(m_keyframe);
CSSRule::trace(visitor);
}
}