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 30 matching lines...) Expand all Loading... |
41 size_t lowestCommonMultiple(size_t a, size_t b) | 41 size_t lowestCommonMultiple(size_t a, size_t b) |
42 { | 42 { |
43 ASSERT(a && b); | 43 ASSERT(a && b); |
44 return a / greatestCommonDivisor(a, b) * b; | 44 return a / greatestCommonDivisor(a, b) * b; |
45 } | 45 } |
46 | 46 |
47 } // namespace | 47 } // namespace |
48 | 48 |
49 namespace WebCore { | 49 namespace WebCore { |
50 | 50 |
| 51 bool AnimatableRepeatable::interpolateLists(const Vector<RefPtr<AnimatableValue>
>& fromValues, const Vector<RefPtr<AnimatableValue> >& toValues, double fractio
n, Vector<RefPtr<AnimatableValue> >& interpolatedValues) |
| 52 { |
| 53 // Interpolation behaviour spec: http://www.w3.org/TR/css3-transitions/#anim
type-repeatable-list |
| 54 ASSERT(interpolatedValues.isEmpty()); |
| 55 ASSERT(!fromValues.isEmpty() && !toValues.isEmpty()); |
| 56 size_t size = lowestCommonMultiple(fromValues.size(), toValues.size()); |
| 57 for (size_t i = 0; i < size; ++i) { |
| 58 const AnimatableValue* from = fromValues[i % fromValues.size()].get(); |
| 59 const AnimatableValue* to = toValues[i % toValues.size()].get(); |
| 60 // Spec: If a pair of values cannot be interpolated, then the lists are
not interpolable. |
| 61 if (!from->isSameType(to)) |
| 62 return false; |
| 63 interpolatedValues.append(interpolate(from, to, fraction)); |
| 64 } |
| 65 return true; |
| 66 } |
| 67 |
51 PassRefPtr<AnimatableValue> AnimatableRepeatable::interpolateTo(const Animatable
Value* value, double fraction) const | 68 PassRefPtr<AnimatableValue> AnimatableRepeatable::interpolateTo(const Animatable
Value* value, double fraction) const |
52 { | 69 { |
53 // Interpolation behaviour spec: http://www.w3.org/TR/css3-transitions/#anim
type-repeatable-list | 70 Vector<RefPtr<AnimatableValue> > interpolatedValues; |
54 const Vector<RefPtr<AnimatableValue> >& otherValues = toAnimatableRepeatable
(value)->m_values; | 71 bool success = interpolateLists(m_values, toAnimatableRepeatable(value)->m_v
alues, fraction, interpolatedValues); |
55 ASSERT(!m_values.isEmpty() && !otherValues.isEmpty()); | 72 return success ? create(interpolatedValues) : defaultInterpolateTo(this, val
ue, fraction); |
56 Vector<RefPtr<AnimatableValue> > interpolatedValues(lowestCommonMultiple(m_v
alues.size(), otherValues.size())); | |
57 for (size_t i = 0; i < interpolatedValues.size(); ++i) { | |
58 const AnimatableValue* from = m_values[i % m_values.size()].get(); | |
59 const AnimatableValue* to = otherValues[i % otherValues.size()].get(); | |
60 // Spec: If a pair of values cannot be interpolated, then the lists are
not interpolable. | |
61 if (!from->isSameType(to)) | |
62 return defaultInterpolateTo(this, value, fraction); | |
63 interpolatedValues[i] = interpolate(from, to, fraction); | |
64 } | |
65 return create(interpolatedValues); | |
66 } | 73 } |
67 | 74 |
68 PassRefPtr<AnimatableValue> AnimatableRepeatable::addWith(const AnimatableValue*
value) const | 75 PassRefPtr<AnimatableValue> AnimatableRepeatable::addWith(const AnimatableValue*
value) const |
69 { | 76 { |
70 const Vector<RefPtr<AnimatableValue> >& otherValues = toAnimatableRepeatable
(value)->m_values; | 77 const Vector<RefPtr<AnimatableValue> >& otherValues = toAnimatableRepeatable
(value)->m_values; |
71 ASSERT(!m_values.isEmpty() && !otherValues.isEmpty()); | 78 ASSERT(!m_values.isEmpty() && !otherValues.isEmpty()); |
72 Vector<RefPtr<AnimatableValue> > addedValues(lowestCommonMultiple(m_values.s
ize(), otherValues.size())); | 79 Vector<RefPtr<AnimatableValue> > addedValues(lowestCommonMultiple(m_values.s
ize(), otherValues.size())); |
73 for (size_t i = 0; i < addedValues.size(); ++i) { | 80 for (size_t i = 0; i < addedValues.size(); ++i) { |
74 const AnimatableValue* left = m_values[i % m_values.size()].get(); | 81 const AnimatableValue* left = m_values[i % m_values.size()].get(); |
75 const AnimatableValue* right = otherValues[i % otherValues.size()].get()
; | 82 const AnimatableValue* right = otherValues[i % otherValues.size()].get()
; |
(...skipping 10 matching lines...) Expand all Loading... |
86 if (m_values.size() != otherValues.size()) | 93 if (m_values.size() != otherValues.size()) |
87 return false; | 94 return false; |
88 for (size_t i = 0; i < m_values.size(); ++i) { | 95 for (size_t i = 0; i < m_values.size(); ++i) { |
89 if (!m_values[i]->equals(otherValues[i].get())) | 96 if (!m_values[i]->equals(otherValues[i].get())) |
90 return false; | 97 return false; |
91 } | 98 } |
92 return true; | 99 return true; |
93 } | 100 } |
94 | 101 |
95 } // namespace WebCore | 102 } // namespace WebCore |
OLD | NEW |