OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde
.org> | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde
.org> |
3 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> | 3 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> |
4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> | 4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> |
5 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 5 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
6 * | 6 * |
7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "core/svg/SVGPath.h" | 23 #include "core/svg/SVGPath.h" |
24 | 24 |
25 #include "core/SVGNames.h" | 25 #include "core/SVGNames.h" |
26 #include "core/svg/SVGAnimationElement.h" | 26 #include "core/svg/SVGAnimationElement.h" |
27 #include "core/svg/SVGPathBlender.h" | 27 #include "core/svg/SVGPathBlender.h" |
28 #include "core/svg/SVGPathByteStream.h" | 28 #include "core/svg/SVGPathByteStream.h" |
29 #include "core/svg/SVGPathByteStreamBuilder.h" | 29 #include "core/svg/SVGPathByteStreamBuilder.h" |
30 #include "core/svg/SVGPathByteStreamSource.h" | 30 #include "core/svg/SVGPathByteStreamSource.h" |
31 #include "core/svg/SVGPathUtilities.h" | 31 #include "core/svg/SVGPathUtilities.h" |
32 #include "platform/graphics/Path.h" | 32 #include "platform/graphics/Path.h" |
33 #include <memory> | |
34 | 33 |
35 namespace blink { | 34 namespace blink { |
36 | 35 |
37 namespace { | 36 namespace { |
38 | 37 |
39 std::unique_ptr<SVGPathByteStream> blendPathByteStreams(const SVGPathByteStream&
fromStream, const SVGPathByteStream& toStream, float progress) | 38 PassOwnPtr<SVGPathByteStream> blendPathByteStreams(const SVGPathByteStream& from
Stream, const SVGPathByteStream& toStream, float progress) |
40 { | 39 { |
41 std::unique_ptr<SVGPathByteStream> resultStream = SVGPathByteStream::create(
); | 40 OwnPtr<SVGPathByteStream> resultStream = SVGPathByteStream::create(); |
42 SVGPathByteStreamBuilder builder(*resultStream); | 41 SVGPathByteStreamBuilder builder(*resultStream); |
43 SVGPathByteStreamSource fromSource(fromStream); | 42 SVGPathByteStreamSource fromSource(fromStream); |
44 SVGPathByteStreamSource toSource(toStream); | 43 SVGPathByteStreamSource toSource(toStream); |
45 SVGPathBlender blender(&fromSource, &toSource, &builder); | 44 SVGPathBlender blender(&fromSource, &toSource, &builder); |
46 blender.blendAnimatedPath(progress); | 45 blender.blendAnimatedPath(progress); |
47 return resultStream; | 46 return resultStream; |
48 } | 47 } |
49 | 48 |
50 std::unique_ptr<SVGPathByteStream> addPathByteStreams(const SVGPathByteStream& f
romStream, const SVGPathByteStream& byStream, unsigned repeatCount = 1) | 49 PassOwnPtr<SVGPathByteStream> addPathByteStreams(const SVGPathByteStream& fromSt
ream, const SVGPathByteStream& byStream, unsigned repeatCount = 1) |
51 { | 50 { |
52 std::unique_ptr<SVGPathByteStream> resultStream = SVGPathByteStream::create(
); | 51 OwnPtr<SVGPathByteStream> resultStream = SVGPathByteStream::create(); |
53 SVGPathByteStreamBuilder builder(*resultStream); | 52 SVGPathByteStreamBuilder builder(*resultStream); |
54 SVGPathByteStreamSource fromSource(fromStream); | 53 SVGPathByteStreamSource fromSource(fromStream); |
55 SVGPathByteStreamSource bySource(byStream); | 54 SVGPathByteStreamSource bySource(byStream); |
56 SVGPathBlender blender(&fromSource, &bySource, &builder); | 55 SVGPathBlender blender(&fromSource, &bySource, &builder); |
57 blender.addAnimatedPath(repeatCount); | 56 blender.addAnimatedPath(repeatCount); |
58 return resultStream; | 57 return resultStream; |
59 } | 58 } |
60 | 59 |
61 std::unique_ptr<SVGPathByteStream> conditionallyAddPathByteStreams(std::unique_p
tr<SVGPathByteStream> fromStream, const SVGPathByteStream& byStream, unsigned re
peatCount = 1) | 60 PassOwnPtr<SVGPathByteStream> conditionallyAddPathByteStreams(PassOwnPtr<SVGPath
ByteStream> fromStream, const SVGPathByteStream& byStream, unsigned repeatCount
= 1) |
62 { | 61 { |
63 if (fromStream->isEmpty() || byStream.isEmpty()) | 62 if (fromStream->isEmpty() || byStream.isEmpty()) |
64 return fromStream; | 63 return fromStream; |
65 return addPathByteStreams(*fromStream, byStream, repeatCount); | 64 return addPathByteStreams(*fromStream, byStream, repeatCount); |
66 } | 65 } |
67 | 66 |
68 } // namespace | 67 } // namespace |
69 | 68 |
70 SVGPath::SVGPath() : m_pathValue(CSSPathValue::emptyPathValue()) {} | 69 SVGPath::SVGPath() : m_pathValue(CSSPathValue::emptyPathValue()) {} |
71 | 70 |
(...skipping 13 matching lines...) Expand all Loading... |
85 } | 84 } |
86 | 85 |
87 | 86 |
88 SVGPath* SVGPath::clone() const | 87 SVGPath* SVGPath::clone() const |
89 { | 88 { |
90 return SVGPath::create(m_pathValue); | 89 return SVGPath::create(m_pathValue); |
91 } | 90 } |
92 | 91 |
93 SVGParsingError SVGPath::setValueAsString(const String& string) | 92 SVGParsingError SVGPath::setValueAsString(const String& string) |
94 { | 93 { |
95 std::unique_ptr<SVGPathByteStream> byteStream = SVGPathByteStream::create(); | 94 OwnPtr<SVGPathByteStream> byteStream = SVGPathByteStream::create(); |
96 SVGParsingError parseStatus = buildByteStreamFromString(string, *byteStream)
; | 95 SVGParsingError parseStatus = buildByteStreamFromString(string, *byteStream)
; |
97 m_pathValue = CSSPathValue::create(std::move(byteStream)); | 96 m_pathValue = CSSPathValue::create(std::move(byteStream)); |
98 return parseStatus; | 97 return parseStatus; |
99 } | 98 } |
100 | 99 |
101 SVGPropertyBase* SVGPath::cloneForAnimation(const String& value) const | 100 SVGPropertyBase* SVGPath::cloneForAnimation(const String& value) const |
102 { | 101 { |
103 std::unique_ptr<SVGPathByteStream> byteStream = SVGPathByteStream::create(); | 102 OwnPtr<SVGPathByteStream> byteStream = SVGPathByteStream::create(); |
104 buildByteStreamFromString(value, *byteStream); | 103 buildByteStreamFromString(value, *byteStream); |
105 return SVGPath::create(CSSPathValue::create(std::move(byteStream))); | 104 return SVGPath::create(CSSPathValue::create(std::move(byteStream))); |
106 } | 105 } |
107 | 106 |
108 void SVGPath::add(SVGPropertyBase* other, SVGElement*) | 107 void SVGPath::add(SVGPropertyBase* other, SVGElement*) |
109 { | 108 { |
110 const SVGPathByteStream& otherPathByteStream = toSVGPath(other)->byteStream(
); | 109 const SVGPathByteStream& otherPathByteStream = toSVGPath(other)->byteStream(
); |
111 if (byteStream().size() != otherPathByteStream.size() | 110 if (byteStream().size() != otherPathByteStream.size() |
112 || byteStream().isEmpty() | 111 || byteStream().isEmpty() |
113 || otherPathByteStream.isEmpty()) | 112 || otherPathByteStream.isEmpty()) |
(...skipping 10 matching lines...) Expand all Loading... |
124 const SVGPath& to = toSVGPath(*toValue); | 123 const SVGPath& to = toSVGPath(*toValue); |
125 const SVGPathByteStream& toStream = to.byteStream(); | 124 const SVGPathByteStream& toStream = to.byteStream(); |
126 | 125 |
127 // If no 'to' value is given, nothing to animate. | 126 // If no 'to' value is given, nothing to animate. |
128 if (!toStream.size()) | 127 if (!toStream.size()) |
129 return; | 128 return; |
130 | 129 |
131 const SVGPath& from = toSVGPath(*fromValue); | 130 const SVGPath& from = toSVGPath(*fromValue); |
132 const SVGPathByteStream* fromStream = &from.byteStream(); | 131 const SVGPathByteStream* fromStream = &from.byteStream(); |
133 | 132 |
134 std::unique_ptr<SVGPathByteStream> copy; | 133 OwnPtr<SVGPathByteStream> copy; |
135 if (isToAnimation) { | 134 if (isToAnimation) { |
136 copy = byteStream().clone(); | 135 copy = byteStream().clone(); |
137 fromStream = copy.get(); | 136 fromStream = copy.get(); |
138 } | 137 } |
139 | 138 |
140 // If the 'from' value is given and it's length doesn't match the 'to' value
list length, fallback to a discrete animation. | 139 // If the 'from' value is given and it's length doesn't match the 'to' value
list length, fallback to a discrete animation. |
141 if (fromStream->size() != toStream.size() && fromStream->size()) { | 140 if (fromStream->size() != toStream.size() && fromStream->size()) { |
142 if (percentage < 0.5) { | 141 if (percentage < 0.5) { |
143 if (!isToAnimation) { | 142 if (!isToAnimation) { |
144 m_pathValue = from.pathValue(); | 143 m_pathValue = from.pathValue(); |
145 return; | 144 return; |
146 } | 145 } |
147 } else { | 146 } else { |
148 m_pathValue = to.pathValue(); | 147 m_pathValue = to.pathValue(); |
149 return; | 148 return; |
150 } | 149 } |
151 } | 150 } |
152 | 151 |
153 std::unique_ptr<SVGPathByteStream> newStream = blendPathByteStreams(*fromStr
eam, toStream, percentage); | 152 OwnPtr<SVGPathByteStream> newStream = blendPathByteStreams(*fromStream, toSt
ream, percentage); |
154 | 153 |
155 // Handle additive='sum'. | 154 // Handle additive='sum'. |
156 if (animationElement->isAdditive() && !isToAnimation) | 155 if (animationElement->isAdditive() && !isToAnimation) |
157 newStream = conditionallyAddPathByteStreams(std::move(newStream), byteSt
ream()); | 156 newStream = conditionallyAddPathByteStreams(std::move(newStream), byteSt
ream()); |
158 | 157 |
159 // Handle accumulate='sum'. | 158 // Handle accumulate='sum'. |
160 if (animationElement->isAccumulated() && repeatCount) | 159 if (animationElement->isAccumulated() && repeatCount) |
161 newStream = conditionallyAddPathByteStreams(std::move(newStream), toSVGP
ath(toAtEndOfDurationValue)->byteStream(), repeatCount); | 160 newStream = conditionallyAddPathByteStreams(std::move(newStream), toSVGP
ath(toAtEndOfDurationValue)->byteStream(), repeatCount); |
162 | 161 |
163 m_pathValue = CSSPathValue::create(std::move(newStream)); | 162 m_pathValue = CSSPathValue::create(std::move(newStream)); |
164 } | 163 } |
165 | 164 |
166 float SVGPath::calculateDistance(SVGPropertyBase* to, SVGElement*) | 165 float SVGPath::calculateDistance(SVGPropertyBase* to, SVGElement*) |
167 { | 166 { |
168 // FIXME: Support paced animations. | 167 // FIXME: Support paced animations. |
169 return -1; | 168 return -1; |
170 } | 169 } |
171 | 170 |
172 DEFINE_TRACE(SVGPath) | 171 DEFINE_TRACE(SVGPath) |
173 { | 172 { |
174 visitor->trace(m_pathValue); | 173 visitor->trace(m_pathValue); |
175 SVGPropertyBase::trace(visitor); | 174 SVGPropertyBase::trace(visitor); |
176 } | 175 } |
177 | 176 |
178 } // namespace blink | 177 } // namespace blink |
OLD | NEW |