| 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> |
| 33 | 34 |
| 34 namespace blink { | 35 namespace blink { |
| 35 | 36 |
| 36 namespace { | 37 namespace { |
| 37 | 38 |
| 38 PassOwnPtr<SVGPathByteStream> blendPathByteStreams(const SVGPathByteStream& from
Stream, const SVGPathByteStream& toStream, float progress) | 39 std::unique_ptr<SVGPathByteStream> blendPathByteStreams(const SVGPathByteStream&
fromStream, const SVGPathByteStream& toStream, float progress) |
| 39 { | 40 { |
| 40 OwnPtr<SVGPathByteStream> resultStream = SVGPathByteStream::create(); | 41 std::unique_ptr<SVGPathByteStream> resultStream = SVGPathByteStream::create(
); |
| 41 SVGPathByteStreamBuilder builder(*resultStream); | 42 SVGPathByteStreamBuilder builder(*resultStream); |
| 42 SVGPathByteStreamSource fromSource(fromStream); | 43 SVGPathByteStreamSource fromSource(fromStream); |
| 43 SVGPathByteStreamSource toSource(toStream); | 44 SVGPathByteStreamSource toSource(toStream); |
| 44 SVGPathBlender blender(&fromSource, &toSource, &builder); | 45 SVGPathBlender blender(&fromSource, &toSource, &builder); |
| 45 blender.blendAnimatedPath(progress); | 46 blender.blendAnimatedPath(progress); |
| 46 return resultStream; | 47 return resultStream; |
| 47 } | 48 } |
| 48 | 49 |
| 49 PassOwnPtr<SVGPathByteStream> addPathByteStreams(const SVGPathByteStream& fromSt
ream, const SVGPathByteStream& byStream, unsigned repeatCount = 1) | 50 std::unique_ptr<SVGPathByteStream> addPathByteStreams(const SVGPathByteStream& f
romStream, const SVGPathByteStream& byStream, unsigned repeatCount = 1) |
| 50 { | 51 { |
| 51 OwnPtr<SVGPathByteStream> resultStream = SVGPathByteStream::create(); | 52 std::unique_ptr<SVGPathByteStream> resultStream = SVGPathByteStream::create(
); |
| 52 SVGPathByteStreamBuilder builder(*resultStream); | 53 SVGPathByteStreamBuilder builder(*resultStream); |
| 53 SVGPathByteStreamSource fromSource(fromStream); | 54 SVGPathByteStreamSource fromSource(fromStream); |
| 54 SVGPathByteStreamSource bySource(byStream); | 55 SVGPathByteStreamSource bySource(byStream); |
| 55 SVGPathBlender blender(&fromSource, &bySource, &builder); | 56 SVGPathBlender blender(&fromSource, &bySource, &builder); |
| 56 blender.addAnimatedPath(repeatCount); | 57 blender.addAnimatedPath(repeatCount); |
| 57 return resultStream; | 58 return resultStream; |
| 58 } | 59 } |
| 59 | 60 |
| 60 PassOwnPtr<SVGPathByteStream> conditionallyAddPathByteStreams(PassOwnPtr<SVGPath
ByteStream> fromStream, const SVGPathByteStream& byStream, unsigned repeatCount
= 1) | 61 std::unique_ptr<SVGPathByteStream> conditionallyAddPathByteStreams(std::unique_p
tr<SVGPathByteStream> fromStream, const SVGPathByteStream& byStream, unsigned re
peatCount = 1) |
| 61 { | 62 { |
| 62 if (fromStream->isEmpty() || byStream.isEmpty()) | 63 if (fromStream->isEmpty() || byStream.isEmpty()) |
| 63 return fromStream; | 64 return fromStream; |
| 64 return addPathByteStreams(*fromStream, byStream, repeatCount); | 65 return addPathByteStreams(*fromStream, byStream, repeatCount); |
| 65 } | 66 } |
| 66 | 67 |
| 67 } // namespace | 68 } // namespace |
| 68 | 69 |
| 69 SVGPath::SVGPath() : m_pathValue(CSSPathValue::emptyPathValue()) {} | 70 SVGPath::SVGPath() : m_pathValue(CSSPathValue::emptyPathValue()) {} |
| 70 | 71 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 84 } | 85 } |
| 85 | 86 |
| 86 | 87 |
| 87 SVGPath* SVGPath::clone() const | 88 SVGPath* SVGPath::clone() const |
| 88 { | 89 { |
| 89 return SVGPath::create(m_pathValue); | 90 return SVGPath::create(m_pathValue); |
| 90 } | 91 } |
| 91 | 92 |
| 92 SVGParsingError SVGPath::setValueAsString(const String& string) | 93 SVGParsingError SVGPath::setValueAsString(const String& string) |
| 93 { | 94 { |
| 94 OwnPtr<SVGPathByteStream> byteStream = SVGPathByteStream::create(); | 95 std::unique_ptr<SVGPathByteStream> byteStream = SVGPathByteStream::create(); |
| 95 SVGParsingError parseStatus = buildByteStreamFromString(string, *byteStream)
; | 96 SVGParsingError parseStatus = buildByteStreamFromString(string, *byteStream)
; |
| 96 m_pathValue = CSSPathValue::create(std::move(byteStream)); | 97 m_pathValue = CSSPathValue::create(std::move(byteStream)); |
| 97 return parseStatus; | 98 return parseStatus; |
| 98 } | 99 } |
| 99 | 100 |
| 100 SVGPropertyBase* SVGPath::cloneForAnimation(const String& value) const | 101 SVGPropertyBase* SVGPath::cloneForAnimation(const String& value) const |
| 101 { | 102 { |
| 102 OwnPtr<SVGPathByteStream> byteStream = SVGPathByteStream::create(); | 103 std::unique_ptr<SVGPathByteStream> byteStream = SVGPathByteStream::create(); |
| 103 buildByteStreamFromString(value, *byteStream); | 104 buildByteStreamFromString(value, *byteStream); |
| 104 return SVGPath::create(CSSPathValue::create(std::move(byteStream))); | 105 return SVGPath::create(CSSPathValue::create(std::move(byteStream))); |
| 105 } | 106 } |
| 106 | 107 |
| 107 void SVGPath::add(SVGPropertyBase* other, SVGElement*) | 108 void SVGPath::add(SVGPropertyBase* other, SVGElement*) |
| 108 { | 109 { |
| 109 const SVGPathByteStream& otherPathByteStream = toSVGPath(other)->byteStream(
); | 110 const SVGPathByteStream& otherPathByteStream = toSVGPath(other)->byteStream(
); |
| 110 if (byteStream().size() != otherPathByteStream.size() | 111 if (byteStream().size() != otherPathByteStream.size() |
| 111 || byteStream().isEmpty() | 112 || byteStream().isEmpty() |
| 112 || otherPathByteStream.isEmpty()) | 113 || otherPathByteStream.isEmpty()) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 123 const SVGPath& to = toSVGPath(*toValue); | 124 const SVGPath& to = toSVGPath(*toValue); |
| 124 const SVGPathByteStream& toStream = to.byteStream(); | 125 const SVGPathByteStream& toStream = to.byteStream(); |
| 125 | 126 |
| 126 // If no 'to' value is given, nothing to animate. | 127 // If no 'to' value is given, nothing to animate. |
| 127 if (!toStream.size()) | 128 if (!toStream.size()) |
| 128 return; | 129 return; |
| 129 | 130 |
| 130 const SVGPath& from = toSVGPath(*fromValue); | 131 const SVGPath& from = toSVGPath(*fromValue); |
| 131 const SVGPathByteStream* fromStream = &from.byteStream(); | 132 const SVGPathByteStream* fromStream = &from.byteStream(); |
| 132 | 133 |
| 133 OwnPtr<SVGPathByteStream> copy; | 134 std::unique_ptr<SVGPathByteStream> copy; |
| 134 if (isToAnimation) { | 135 if (isToAnimation) { |
| 135 copy = byteStream().clone(); | 136 copy = byteStream().clone(); |
| 136 fromStream = copy.get(); | 137 fromStream = copy.get(); |
| 137 } | 138 } |
| 138 | 139 |
| 139 // If the 'from' value is given and it's length doesn't match the 'to' value
list length, fallback to a discrete animation. | 140 // If the 'from' value is given and it's length doesn't match the 'to' value
list length, fallback to a discrete animation. |
| 140 if (fromStream->size() != toStream.size() && fromStream->size()) { | 141 if (fromStream->size() != toStream.size() && fromStream->size()) { |
| 141 if (percentage < 0.5) { | 142 if (percentage < 0.5) { |
| 142 if (!isToAnimation) { | 143 if (!isToAnimation) { |
| 143 m_pathValue = from.pathValue(); | 144 m_pathValue = from.pathValue(); |
| 144 return; | 145 return; |
| 145 } | 146 } |
| 146 } else { | 147 } else { |
| 147 m_pathValue = to.pathValue(); | 148 m_pathValue = to.pathValue(); |
| 148 return; | 149 return; |
| 149 } | 150 } |
| 150 } | 151 } |
| 151 | 152 |
| 152 OwnPtr<SVGPathByteStream> newStream = blendPathByteStreams(*fromStream, toSt
ream, percentage); | 153 std::unique_ptr<SVGPathByteStream> newStream = blendPathByteStreams(*fromStr
eam, toStream, percentage); |
| 153 | 154 |
| 154 // Handle additive='sum'. | 155 // Handle additive='sum'. |
| 155 if (animationElement->isAdditive() && !isToAnimation) | 156 if (animationElement->isAdditive() && !isToAnimation) |
| 156 newStream = conditionallyAddPathByteStreams(std::move(newStream), byteSt
ream()); | 157 newStream = conditionallyAddPathByteStreams(std::move(newStream), byteSt
ream()); |
| 157 | 158 |
| 158 // Handle accumulate='sum'. | 159 // Handle accumulate='sum'. |
| 159 if (animationElement->isAccumulated() && repeatCount) | 160 if (animationElement->isAccumulated() && repeatCount) |
| 160 newStream = conditionallyAddPathByteStreams(std::move(newStream), toSVGP
ath(toAtEndOfDurationValue)->byteStream(), repeatCount); | 161 newStream = conditionallyAddPathByteStreams(std::move(newStream), toSVGP
ath(toAtEndOfDurationValue)->byteStream(), repeatCount); |
| 161 | 162 |
| 162 m_pathValue = CSSPathValue::create(std::move(newStream)); | 163 m_pathValue = CSSPathValue::create(std::move(newStream)); |
| 163 } | 164 } |
| 164 | 165 |
| 165 float SVGPath::calculateDistance(SVGPropertyBase* to, SVGElement*) | 166 float SVGPath::calculateDistance(SVGPropertyBase* to, SVGElement*) |
| 166 { | 167 { |
| 167 // FIXME: Support paced animations. | 168 // FIXME: Support paced animations. |
| 168 return -1; | 169 return -1; |
| 169 } | 170 } |
| 170 | 171 |
| 171 DEFINE_TRACE(SVGPath) | 172 DEFINE_TRACE(SVGPath) |
| 172 { | 173 { |
| 173 visitor->trace(m_pathValue); | 174 visitor->trace(m_pathValue); |
| 174 SVGPropertyBase::trace(visitor); | 175 SVGPropertyBase::trace(visitor); |
| 175 } | 176 } |
| 176 | 177 |
| 177 } // namespace blink | 178 } // namespace blink |
| OLD | NEW |