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