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 13 matching lines...) Expand all Loading... |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 "config.h" | 31 #include "config.h" |
32 #include "core/animation/animatable/AnimatableStrokeDasharrayList.h" | 32 #include "core/animation/animatable/AnimatableStrokeDasharrayList.h" |
33 | 33 |
34 #include "core/animation/animatable/AnimatableSVGLength.h" | 34 #include "core/animation/animatable/AnimatableLength.h" |
35 | 35 |
36 namespace blink { | 36 namespace blink { |
37 | 37 |
38 AnimatableStrokeDasharrayList::AnimatableStrokeDasharrayList(PassRefPtrWillBeRaw
Ptr<SVGLengthList> passLengths) | 38 AnimatableStrokeDasharrayList::AnimatableStrokeDasharrayList(PassRefPtr<SVGDashA
rray> passLengths, float zoom) |
39 { | 39 { |
40 RefPtrWillBeRawPtr<SVGLengthList> lengths = passLengths; | 40 RefPtr<SVGDashArray> lengths = passLengths; |
41 SVGLengthList::ConstIterator it = lengths->begin(); | 41 for (const Length& dashLength : lengths->vector()) |
42 SVGLengthList::ConstIterator itEnd = lengths->end(); | 42 m_values.append(AnimatableLength::create(dashLength, zoom)); |
43 for (; it != itEnd; ++it) | |
44 m_values.append(AnimatableSVGLength::create(*it)); | |
45 } | 43 } |
46 | 44 |
47 PassRefPtrWillBeRawPtr<SVGLengthList> AnimatableStrokeDasharrayList::toSVGLength
List() const | 45 PassRefPtr<SVGDashArray> AnimatableStrokeDasharrayList::toSVGDashArray(float zoo
m) const |
48 { | 46 { |
49 RefPtrWillBeRawPtr<SVGLengthList> lengths = SVGLengthList::create(); | 47 RefPtr<SVGDashArray> lengths = SVGDashArray::create(); |
50 for (size_t i = 0; i < m_values.size(); ++i) { | 48 for (const auto& dashLength : m_values) |
51 RefPtrWillBeRawPtr<SVGLength> length = toAnimatableSVGLength(m_values[i]
.get())->toSVGLength()->clone(); | 49 lengths->append(toAnimatableLength(dashLength.get())->length(zoom, Value
RangeNonNegative)); |
52 if (length->valueInSpecifiedUnits() < 0) | |
53 length->setValueInSpecifiedUnits(0); | |
54 lengths->append(length); | |
55 } | |
56 return lengths.release(); | 50 return lengths.release(); |
57 } | 51 } |
58 | 52 |
59 bool AnimatableStrokeDasharrayList::usesDefaultInterpolationWith(const Animatabl
eValue* value) const | 53 bool AnimatableStrokeDasharrayList::usesDefaultInterpolationWith(const Animatabl
eValue* value) const |
60 { | 54 { |
61 WillBeHeapVector<RefPtrWillBeMember<AnimatableValue>> from = m_values; | 55 WillBeHeapVector<RefPtrWillBeMember<AnimatableValue>> from = m_values; |
62 WillBeHeapVector<RefPtrWillBeMember<AnimatableValue>> to = toAnimatableStrok
eDasharrayList(value)->m_values; | 56 WillBeHeapVector<RefPtrWillBeMember<AnimatableValue>> to = toAnimatableStrok
eDasharrayList(value)->m_values; |
63 return !from.isEmpty() && !to.isEmpty() && AnimatableRepeatable::usesDefault
InterpolationWith(value); | 57 return !from.isEmpty() && !to.isEmpty() && AnimatableRepeatable::usesDefault
InterpolationWith(value); |
64 } | 58 } |
65 | 59 |
66 PassRefPtrWillBeRawPtr<AnimatableValue> AnimatableStrokeDasharrayList::interpola
teTo(const AnimatableValue* value, double fraction) const | 60 PassRefPtrWillBeRawPtr<AnimatableValue> AnimatableStrokeDasharrayList::interpola
teTo(const AnimatableValue* value, double fraction) const |
67 { | 61 { |
68 if (usesDefaultInterpolationWith(value)) | 62 if (usesDefaultInterpolationWith(value)) |
69 return defaultInterpolateTo(this, value, fraction); | 63 return defaultInterpolateTo(this, value, fraction); |
70 | 64 |
71 WillBeHeapVector<RefPtrWillBeMember<AnimatableValue>> from = m_values; | 65 WillBeHeapVector<RefPtrWillBeMember<AnimatableValue>> from = m_values; |
72 WillBeHeapVector<RefPtrWillBeMember<AnimatableValue>> to = toAnimatableStrok
eDasharrayList(value)->m_values; | 66 WillBeHeapVector<RefPtrWillBeMember<AnimatableValue>> to = toAnimatableStrok
eDasharrayList(value)->m_values; |
73 | 67 |
74 // The spec states that if the sum of all values is zero, this should be | 68 // The spec states that if the sum of all values is zero, this should be |
75 // treated like a value of 'none', which means that a solid line is drawn. | 69 // treated like a value of 'none', which means that a solid line is drawn. |
76 // Since we animate to and from values of zero, treat a value of 'none' the | 70 // Since we animate to and from values of zero, treat a value of 'none' the |
77 // same. If both the two and from values are 'none', we return 'none' | 71 // same. If both the two and from values are 'none', we return 'none' |
78 // rather than '0 0'. | 72 // rather than '0 0'. |
79 if (from.isEmpty() && to.isEmpty()) | 73 if (from.isEmpty() && to.isEmpty()) |
80 return takeConstRef(this); | 74 return takeConstRef(this); |
81 if (from.isEmpty() || to.isEmpty()) { | 75 if (from.isEmpty() || to.isEmpty()) { |
82 DEFINE_STATIC_REF_WILL_BE_PERSISTENT(AnimatableSVGLength, zeroPixels, (A
nimatableSVGLength::create(SVGLength::create()))); | 76 DEFINE_STATIC_REF_WILL_BE_PERSISTENT(AnimatableLength, zeroPixels, (Anim
atableLength::create(Length(Fixed), 1))); |
83 if (from.isEmpty()) { | 77 if (from.isEmpty()) { |
84 from.append(zeroPixels); | 78 from.append(zeroPixels); |
85 from.append(zeroPixels); | 79 from.append(zeroPixels); |
86 } | 80 } |
87 if (to.isEmpty()) { | 81 if (to.isEmpty()) { |
88 to.append(zeroPixels); | 82 to.append(zeroPixels); |
89 to.append(zeroPixels); | 83 to.append(zeroPixels); |
90 } | 84 } |
91 } | 85 } |
92 | 86 |
93 WillBeHeapVector<RefPtrWillBeMember<AnimatableValue> > interpolatedValues; | 87 WillBeHeapVector<RefPtrWillBeMember<AnimatableValue> > interpolatedValues; |
94 bool success = interpolateLists(from, to, fraction, interpolatedValues); | 88 bool success = interpolateLists(from, to, fraction, interpolatedValues); |
95 ASSERT_UNUSED(success, success); | 89 ASSERT_UNUSED(success, success); |
96 return adoptRefWillBeNoop(new AnimatableStrokeDasharrayList(interpolatedValu
es)); | 90 return adoptRefWillBeNoop(new AnimatableStrokeDasharrayList(interpolatedValu
es)); |
97 } | 91 } |
98 | 92 |
99 DEFINE_TRACE(AnimatableStrokeDasharrayList) | 93 DEFINE_TRACE(AnimatableStrokeDasharrayList) |
100 { | 94 { |
101 AnimatableRepeatable::trace(visitor); | 95 AnimatableRepeatable::trace(visitor); |
102 } | 96 } |
103 | 97 |
104 } // namespace blink | 98 } // namespace blink |
OLD | NEW |