Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / css / StyleRuleKeyframe.cpp
blobd2d1b4454883bd8bf1ebcd1de4c2c568a24e6012
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "config.h"
6 #include "core/css/StyleRuleKeyframe.h"
8 #include "core/css/StylePropertySet.h"
9 #include "core/css/parser/CSSParser.h"
10 #include "wtf/text/StringBuilder.h"
12 namespace blink {
14 StyleRuleKeyframe::StyleRuleKeyframe(PassOwnPtr<Vector<double>> keys, PassRefPtrWillBeRawPtr<StylePropertySet> properties)
15 : StyleRuleBase(Keyframe)
16 , m_properties(properties)
17 , m_keys(*keys)
21 String StyleRuleKeyframe::keyText() const
23 ASSERT(!m_keys.isEmpty());
25 StringBuilder keyText;
26 for (unsigned i = 0; i < m_keys.size(); ++i) {
27 if (i)
28 keyText.append(',');
29 keyText.appendNumber(m_keys.at(i) * 100);
30 keyText.append('%');
33 return keyText.toString();
36 bool StyleRuleKeyframe::setKeyText(const String& keyText)
38 ASSERT(!keyText.isNull());
40 OwnPtr<Vector<double>> keys = CSSParser::parseKeyframeKeyList(keyText);
41 if (!keys || keys->isEmpty())
42 return false;
44 m_keys = *keys;
45 return true;
48 const Vector<double>& StyleRuleKeyframe::keys() const
50 return m_keys;
53 MutableStylePropertySet& StyleRuleKeyframe::mutableProperties()
55 if (!m_properties->isMutable())
56 m_properties = m_properties->mutableCopy();
57 return *toMutableStylePropertySet(m_properties.get());
60 String StyleRuleKeyframe::cssText() const
62 StringBuilder result;
63 result.append(keyText());
64 result.appendLiteral(" { ");
65 String decls = m_properties->asText();
66 result.append(decls);
67 if (!decls.isEmpty())
68 result.append(' ');
69 result.append('}');
70 return result.toString();
73 DEFINE_TRACE_AFTER_DISPATCH(StyleRuleKeyframe)
75 visitor->trace(m_properties);
76 StyleRuleBase::traceAfterDispatch(visitor);
79 } // namespace blink