OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 16 matching lines...) Expand all Loading... |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "core/animation/animatable/AnimatableRepeatable.h" | 31 #include "core/animation/animatable/AnimatableRepeatable.h" |
32 | 32 |
33 #include "wtf/MathExtras.h" | 33 #include "wtf/MathExtras.h" |
34 | 34 |
35 namespace blink { | 35 namespace blink { |
36 | 36 |
37 bool AnimatableRepeatable::usesDefaultInterpolationWith( | |
38 const AnimatableValue* value) const { | |
39 const Vector<RefPtr<AnimatableValue>>& fromValues = m_values; | |
40 const Vector<RefPtr<AnimatableValue>>& toValues = | |
41 toAnimatableRepeatable(value)->m_values; | |
42 DCHECK(!fromValues.isEmpty() && !toValues.isEmpty()); | |
43 size_t size = lowestCommonMultiple(fromValues.size(), toValues.size()); | |
44 DCHECK_GT(size, 0U); | |
45 for (size_t i = 0; i < size; ++i) { | |
46 const AnimatableValue* from = fromValues[i % fromValues.size()].get(); | |
47 const AnimatableValue* to = toValues[i % toValues.size()].get(); | |
48 // Spec: If a pair of values cannot be interpolated, then the lists are not | |
49 // interpolable. | |
50 if (AnimatableValue::usesDefaultInterpolation(from, to)) | |
51 return true; | |
52 } | |
53 return false; | |
54 } | |
55 | |
56 bool AnimatableRepeatable::interpolateLists( | |
57 const Vector<RefPtr<AnimatableValue>>& fromValues, | |
58 const Vector<RefPtr<AnimatableValue>>& toValues, | |
59 double fraction, | |
60 Vector<RefPtr<AnimatableValue>>& interpolatedValues) { | |
61 // Interpolation behaviour spec: | |
62 // http://www.w3.org/TR/css3-transitions/#animtype-repeatable-list | |
63 DCHECK(interpolatedValues.isEmpty()); | |
64 DCHECK(!fromValues.isEmpty() && !toValues.isEmpty()); | |
65 size_t size = lowestCommonMultiple(fromValues.size(), toValues.size()); | |
66 DCHECK_GT(size, 0U); | |
67 for (size_t i = 0; i < size; ++i) { | |
68 const AnimatableValue* from = fromValues[i % fromValues.size()].get(); | |
69 const AnimatableValue* to = toValues[i % toValues.size()].get(); | |
70 // Spec: If a pair of values cannot be interpolated, then the lists are not | |
71 // interpolable. | |
72 if (AnimatableValue::usesDefaultInterpolation(from, to)) | |
73 return false; | |
74 interpolatedValues.push_back(interpolate(from, to, fraction)); | |
75 } | |
76 return true; | |
77 } | |
78 | |
79 PassRefPtr<AnimatableValue> AnimatableRepeatable::interpolateTo( | |
80 const AnimatableValue* value, | |
81 double fraction) const { | |
82 Vector<RefPtr<AnimatableValue>> interpolatedValues; | |
83 bool success = | |
84 interpolateLists(m_values, toAnimatableRepeatable(value)->m_values, | |
85 fraction, interpolatedValues); | |
86 if (success) | |
87 return create(interpolatedValues); | |
88 return defaultInterpolateTo(this, value, fraction); | |
89 } | |
90 | |
91 bool AnimatableRepeatable::equalTo(const AnimatableValue* value) const { | 37 bool AnimatableRepeatable::equalTo(const AnimatableValue* value) const { |
92 const Vector<RefPtr<AnimatableValue>>& otherValues = | 38 const Vector<RefPtr<AnimatableValue>>& otherValues = |
93 toAnimatableRepeatable(value)->m_values; | 39 toAnimatableRepeatable(value)->m_values; |
94 if (m_values.size() != otherValues.size()) | 40 if (m_values.size() != otherValues.size()) |
95 return false; | 41 return false; |
96 for (size_t i = 0; i < m_values.size(); ++i) { | 42 for (size_t i = 0; i < m_values.size(); ++i) { |
97 if (!m_values[i]->equals(otherValues[i].get())) | 43 if (!m_values[i]->equals(otherValues[i].get())) |
98 return false; | 44 return false; |
99 } | 45 } |
100 return true; | 46 return true; |
101 } | 47 } |
102 | 48 |
103 } // namespace blink | 49 } // namespace blink |
OLD | NEW |