1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "config.h"
#include "core/css/StyleRuleKeyframe.h"
#include "core/css/StylePropertySet.h"
#include "core/css/parser/CSSParser.h"
#include "wtf/text/StringBuilder.h"
namespace blink {
StyleRuleKeyframe::StyleRuleKeyframe()
: StyleRuleBase(Keyframe)
{
}
String StyleRuleKeyframe::keyText() const
{
ASSERT(!m_keys.isEmpty());
StringBuilder keyText;
for (unsigned i = 0; i < m_keys.size(); ++i) {
if (i)
keyText.append(',');
keyText.appendNumber(m_keys.at(i) * 100);
keyText.append('%');
}
return keyText.toString();
}
bool StyleRuleKeyframe::setKeyText(const String& keyText)
{
ASSERT(!keyText.isNull());
OwnPtr<Vector<double> > keys = CSSParser::parseKeyframeKeyList(keyText);
if (!keys || keys->isEmpty())
return false;
m_keys = *keys;
return true;
}
const Vector<double>& StyleRuleKeyframe::keys() const
{
return m_keys;
}
void StyleRuleKeyframe::setKeys(PassOwnPtr<Vector<double> > keys)
{
ASSERT(keys && !keys->isEmpty());
m_keys = *keys;
}
MutableStylePropertySet& StyleRuleKeyframe::mutableProperties()
{
if (!m_properties->isMutable())
m_properties = m_properties->mutableCopy();
return *toMutableStylePropertySet(m_properties.get());
}
void StyleRuleKeyframe::setProperties(PassRefPtrWillBeRawPtr<StylePropertySet> properties)
{
ASSERT(properties);
m_properties = properties;
}
String StyleRuleKeyframe::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> > StyleRuleKeyframe::createKeyList(CSSParserValueList* keys)
{
size_t numKeys = keys ? keys->size() : 0;
OwnPtr<Vector<double> > keyVector = adoptPtr(new Vector<double>(numKeys));
for (size_t i = 0; i < numKeys; ++i) {
ASSERT(keys->valueAt(i)->unit == blink::CSSPrimitiveValue::CSS_NUMBER);
double key = keys->valueAt(i)->fValue;
if (key < 0 || key > 100) {
// As per http://www.w3.org/TR/css3-animations/#keyframes,
// "If a keyframe selector specifies negative percentage values
// or values higher than 100%, then the keyframe will be ignored."
keyVector->clear();
break;
}
keyVector->at(i) = key / 100;
}
return keyVector.release();
}
void StyleRuleKeyframe::traceAfterDispatch(Visitor* visitor)
{
visitor->trace(m_properties);
StyleRuleBase::traceAfterDispatch(visitor);
}
} // namespace blink
|