OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "core/animation/animatable/AnimatablePath.h" | 5 #include "core/animation/animatable/AnimatablePath.h" |
6 | 6 |
7 #include "core/style/DataEquivalency.h" | 7 #include "core/style/DataEquivalency.h" |
8 #include "core/svg/SVGPathBlender.h" | |
9 #include "core/svg/SVGPathByteStreamBuilder.h" | |
10 #include "core/svg/SVGPathByteStreamSource.h" | |
11 #include <memory> | |
12 | 8 |
13 namespace blink { | 9 namespace blink { |
14 | 10 |
15 bool AnimatablePath::usesDefaultInterpolationWith( | |
16 const AnimatableValue* value) const { | |
17 // Default interpolation is used if the paths have different lengths, | |
18 // or the paths have a segment with different types (ignoring "relativeness"). | |
19 | |
20 const StylePath* toPath = toAnimatablePath(value)->path(); | |
21 if (!m_path || !toPath) | |
22 return true; | |
23 SVGPathByteStreamSource fromSource(path()->byteStream()); | |
24 SVGPathByteStreamSource toSource(toPath->byteStream()); | |
25 | |
26 while (fromSource.hasMoreData()) { | |
27 if (!toSource.hasMoreData()) | |
28 return true; | |
29 | |
30 PathSegmentData fromSeg = fromSource.parseSegment(); | |
31 PathSegmentData toSeg = toSource.parseSegment(); | |
32 DCHECK_NE(fromSeg.command, PathSegUnknown); | |
33 DCHECK_NE(toSeg.command, PathSegUnknown); | |
34 | |
35 if (toAbsolutePathSegType(fromSeg.command) != | |
36 toAbsolutePathSegType(toSeg.command)) | |
37 return true; | |
38 } | |
39 | |
40 return toSource.hasMoreData(); | |
41 } | |
42 | |
43 PassRefPtr<AnimatableValue> AnimatablePath::interpolateTo( | |
44 const AnimatableValue* value, | |
45 double fraction) const { | |
46 if (usesDefaultInterpolationWith(value)) | |
47 return defaultInterpolateTo(this, value, fraction); | |
48 | |
49 std::unique_ptr<SVGPathByteStream> byteStream = SVGPathByteStream::create(); | |
50 SVGPathByteStreamBuilder builder(*byteStream); | |
51 | |
52 SVGPathByteStreamSource fromSource(path()->byteStream()); | |
53 SVGPathByteStreamSource toSource( | |
54 toAnimatablePath(value)->path()->byteStream()); | |
55 | |
56 SVGPathBlender blender(&fromSource, &toSource, &builder); | |
57 bool ok = blender.blendAnimatedPath(fraction); | |
58 ALLOW_UNUSED_LOCAL(ok); | |
59 return AnimatablePath::create(StylePath::create(std::move(byteStream))); | |
60 } | |
61 | |
62 bool AnimatablePath::equalTo(const AnimatableValue* value) const { | 11 bool AnimatablePath::equalTo(const AnimatableValue* value) const { |
63 return dataEquivalent(m_path.get(), toAnimatablePath(value)->path()); | 12 return dataEquivalent(m_path.get(), toAnimatablePath(value)->m_path.get()); |
64 } | 13 } |
65 | 14 |
66 } // namespace blink | 15 } // namespace blink |
OLD | NEW |