| 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 30 matching lines...) Expand all Loading... |
| 41 { | 41 { |
| 42 OwnPtr<SVGPathByteStream> resultStream = SVGPathByteStream::create(); | 42 OwnPtr<SVGPathByteStream> resultStream = SVGPathByteStream::create(); |
| 43 SVGPathByteStreamBuilder builder(*resultStream); | 43 SVGPathByteStreamBuilder builder(*resultStream); |
| 44 SVGPathByteStreamSource fromSource(fromStream); | 44 SVGPathByteStreamSource fromSource(fromStream); |
| 45 SVGPathByteStreamSource toSource(toStream); | 45 SVGPathByteStreamSource toSource(toStream); |
| 46 SVGPathBlender blender(&fromSource, &toSource, &builder); | 46 SVGPathBlender blender(&fromSource, &toSource, &builder); |
| 47 blender.blendAnimatedPath(progress); | 47 blender.blendAnimatedPath(progress); |
| 48 return resultStream.release(); | 48 return resultStream.release(); |
| 49 } | 49 } |
| 50 | 50 |
| 51 PassOwnPtr<SVGPathByteStream> addPathByteStreams(PassOwnPtr<SVGPathByteStream> f
romStream, const SVGPathByteStream& byStream, unsigned repeatCount = 1) | 51 PassOwnPtr<SVGPathByteStream> addPathByteStreams(const SVGPathByteStream& fromSt
ream, const SVGPathByteStream& byStream, unsigned repeatCount = 1) |
| 52 { | 52 { |
| 53 if (fromStream->isEmpty() || byStream.isEmpty()) | |
| 54 return fromStream; | |
| 55 OwnPtr<SVGPathByteStream> tempFromStream = fromStream; | |
| 56 OwnPtr<SVGPathByteStream> resultStream = SVGPathByteStream::create(); | 53 OwnPtr<SVGPathByteStream> resultStream = SVGPathByteStream::create(); |
| 57 SVGPathByteStreamBuilder builder(*resultStream); | 54 SVGPathByteStreamBuilder builder(*resultStream); |
| 58 SVGPathByteStreamSource fromSource(*tempFromStream); | 55 SVGPathByteStreamSource fromSource(fromStream); |
| 59 SVGPathByteStreamSource bySource(byStream); | 56 SVGPathByteStreamSource bySource(byStream); |
| 60 SVGPathBlender blender(&fromSource, &bySource, &builder); | 57 SVGPathBlender blender(&fromSource, &bySource, &builder); |
| 61 blender.addAnimatedPath(repeatCount); | 58 blender.addAnimatedPath(repeatCount); |
| 62 return resultStream.release(); | 59 return resultStream.release(); |
| 63 } | 60 } |
| 64 | 61 |
| 62 PassOwnPtr<SVGPathByteStream> conditionallyAddPathByteStreams(PassOwnPtr<SVGPath
ByteStream> fromStream, const SVGPathByteStream& byStream, unsigned repeatCount
= 1) |
| 63 { |
| 64 if (fromStream->isEmpty() || byStream.isEmpty()) |
| 65 return fromStream; |
| 66 return addPathByteStreams(*fromStream, byStream, repeatCount); |
| 67 } |
| 68 |
| 65 } | 69 } |
| 66 | 70 |
| 67 SVGPath::SVGPath() | 71 SVGPath::SVGPath() |
| 68 : SVGPropertyBase(classType()) | 72 : SVGPropertyBase(classType()) |
| 73 , m_pathValue(CSSPathValue::emptyPathValue()) |
| 69 { | 74 { |
| 70 } | 75 } |
| 71 | 76 |
| 72 SVGPath::SVGPath(PassOwnPtr<SVGPathByteStream> byteStream) | 77 SVGPath::SVGPath(PassRefPtrWillBeRawPtr<CSSPathValue> pathValue) |
| 73 : SVGPropertyBase(classType()) | 78 : SVGPropertyBase(classType()) |
| 74 , m_byteStream(byteStream) | 79 , m_pathValue(pathValue) |
| 75 { | 80 { |
| 76 } | 81 } |
| 77 | 82 |
| 78 SVGPath::~SVGPath() | 83 SVGPath::~SVGPath() |
| 79 { | 84 { |
| 80 } | 85 } |
| 81 | 86 |
| 82 const Path& SVGPath::path() const | 87 String SVGPath::valueAsString() const |
| 83 { | 88 { |
| 84 if (!m_cachedPath) { | 89 return m_pathValue->pathString(); |
| 85 m_cachedPath = adoptPtr(new Path); | 90 } |
| 86 buildPathFromByteStream(byteStream(), *m_cachedPath); | |
| 87 } | |
| 88 | 91 |
| 89 return *m_cachedPath; | |
| 90 } | |
| 91 | 92 |
| 92 PassRefPtrWillBeRawPtr<SVGPath> SVGPath::clone() const | 93 PassRefPtrWillBeRawPtr<SVGPath> SVGPath::clone() const |
| 93 { | 94 { |
| 94 return SVGPath::create(byteStream().copy()); | 95 return SVGPath::create(m_pathValue); |
| 96 } |
| 97 |
| 98 |
| 99 void SVGPath::setValueAsString(const String& string, ExceptionState& exceptionSt
ate) |
| 100 { |
| 101 OwnPtr<SVGPathByteStream> byteStream = SVGPathByteStream::create(); |
| 102 if (!buildByteStreamFromString(string, *byteStream)) |
| 103 exceptionState.throwDOMException(SyntaxError, "Problem parsing path \""
+ string + "\""); |
| 104 m_pathValue = CSSPathValue::create(byteStream.release()); |
| 95 } | 105 } |
| 96 | 106 |
| 97 PassRefPtrWillBeRawPtr<SVGPropertyBase> SVGPath::cloneForAnimation(const String&
value) const | 107 PassRefPtrWillBeRawPtr<SVGPropertyBase> SVGPath::cloneForAnimation(const String&
value) const |
| 98 { | 108 { |
| 99 RefPtrWillBeRawPtr<SVGPath> svgPath = SVGPath::create(); | 109 return SVGPath::create(CSSPathValue::create(value)); |
| 100 svgPath->setValueAsString(value, IGNORE_EXCEPTION); | |
| 101 return svgPath; | |
| 102 } | |
| 103 | |
| 104 SVGPathByteStream& SVGPath::ensureByteStream() | |
| 105 { | |
| 106 if (!m_byteStream) | |
| 107 m_byteStream = SVGPathByteStream::create(); | |
| 108 | |
| 109 return *m_byteStream.get(); | |
| 110 } | |
| 111 | |
| 112 void SVGPath::byteStreamChanged() | |
| 113 { | |
| 114 m_cachedPath.clear(); | |
| 115 } | |
| 116 | |
| 117 const SVGPathByteStream& SVGPath::byteStream() const | |
| 118 { | |
| 119 return const_cast<SVGPath*>(this)->ensureByteStream(); | |
| 120 } | |
| 121 | |
| 122 String SVGPath::valueAsString() const | |
| 123 { | |
| 124 return buildStringFromByteStream(byteStream()); | |
| 125 } | |
| 126 | |
| 127 void SVGPath::setValueAsString(const String& string, ExceptionState& exceptionSt
ate) | |
| 128 { | |
| 129 if (!buildByteStreamFromString(string, ensureByteStream())) | |
| 130 exceptionState.throwDOMException(SyntaxError, "Problem parsing path \""
+ string + "\""); | |
| 131 byteStreamChanged(); | |
| 132 } | |
| 133 | |
| 134 void SVGPath::setValueAsByteStream(PassOwnPtr<SVGPathByteStream> byteStream) | |
| 135 { | |
| 136 m_byteStream = byteStream; | |
| 137 byteStreamChanged(); | |
| 138 } | 110 } |
| 139 | 111 |
| 140 void SVGPath::add(PassRefPtrWillBeRawPtr<SVGPropertyBase> other, SVGElement*) | 112 void SVGPath::add(PassRefPtrWillBeRawPtr<SVGPropertyBase> other, SVGElement*) |
| 141 { | 113 { |
| 142 const SVGPathByteStream& otherPathByteStream = toSVGPath(other)->byteStream(
); | 114 const SVGPathByteStream& otherPathByteStream = toSVGPath(other)->byteStream(
); |
| 143 if (byteStream().size() != otherPathByteStream.size()) | 115 if (byteStream().size() != otherPathByteStream.size() |
| 116 || byteStream().isEmpty() |
| 117 || otherPathByteStream.isEmpty()) |
| 144 return; | 118 return; |
| 145 | 119 |
| 146 setValueAsByteStream(addPathByteStreams(m_byteStream.release(), otherPathByt
eStream)); | 120 m_pathValue = CSSPathValue::create(addPathByteStreams(byteStream(), otherPat
hByteStream)); |
| 147 } | 121 } |
| 148 | 122 |
| 149 void SVGPath::calculateAnimatedValue(SVGAnimationElement* animationElement, floa
t percentage, unsigned repeatCount, PassRefPtrWillBeRawPtr<SVGPropertyBase> from
Value, PassRefPtrWillBeRawPtr<SVGPropertyBase> toValue, PassRefPtrWillBeRawPtr<S
VGPropertyBase> toAtEndOfDurationValue, SVGElement*) | 123 void SVGPath::calculateAnimatedValue(SVGAnimationElement* animationElement, floa
t percentage, unsigned repeatCount, PassRefPtrWillBeRawPtr<SVGPropertyBase> from
Value, PassRefPtrWillBeRawPtr<SVGPropertyBase> toValue, PassRefPtrWillBeRawPtr<S
VGPropertyBase> toAtEndOfDurationValue, SVGElement*) |
| 150 { | 124 { |
| 151 ASSERT(animationElement); | 125 ASSERT(animationElement); |
| 152 bool isToAnimation = animationElement->animationMode() == ToAnimation; | 126 bool isToAnimation = animationElement->animationMode() == ToAnimation; |
| 153 | 127 |
| 154 const RefPtrWillBeRawPtr<SVGPath> to = toSVGPath(toValue); | 128 const RefPtrWillBeRawPtr<SVGPath> to = toSVGPath(toValue); |
| 155 const SVGPathByteStream& toStream = to->byteStream(); | 129 const SVGPathByteStream& toStream = to->byteStream(); |
| 156 | 130 |
| 157 // If no 'to' value is given, nothing to animate. | 131 // If no 'to' value is given, nothing to animate. |
| 158 if (!toStream.size()) | 132 if (!toStream.size()) |
| 159 return; | 133 return; |
| 160 | 134 |
| 161 const RefPtrWillBeRawPtr<SVGPath> from = toSVGPath(fromValue); | 135 const RefPtrWillBeRawPtr<SVGPath> from = toSVGPath(fromValue); |
| 162 const SVGPathByteStream* fromStream = &from->byteStream(); | 136 const SVGPathByteStream* fromStream = &from->byteStream(); |
| 163 | 137 |
| 164 OwnPtr<SVGPathByteStream> copy; | 138 OwnPtr<SVGPathByteStream> copy; |
| 165 if (isToAnimation) { | 139 if (isToAnimation) { |
| 166 copy = byteStream().copy(); | 140 copy = byteStream().copy(); |
| 167 fromStream = copy.get(); | 141 fromStream = copy.get(); |
| 168 } | 142 } |
| 169 | 143 |
| 170 // If the 'from' value is given and it's length doesn't match the 'to' value
list length, fallback to a discrete animation. | 144 // If the 'from' value is given and it's length doesn't match the 'to' value
list length, fallback to a discrete animation. |
| 171 if (fromStream->size() != toStream.size() && fromStream->size()) { | 145 if (fromStream->size() != toStream.size() && fromStream->size()) { |
| 172 if (percentage < 0.5) { | 146 if (percentage < 0.5) { |
| 173 if (!isToAnimation) { | 147 if (!isToAnimation) { |
| 174 setValueAsByteStream(fromStream->copy()); | 148 m_pathValue = from->pathValue(); |
| 175 return; | 149 return; |
| 176 } | 150 } |
| 177 } else { | 151 } else { |
| 178 setValueAsByteStream(toStream.copy()); | 152 m_pathValue = to->pathValue(); |
| 179 return; | 153 return; |
| 180 } | 154 } |
| 181 } | 155 } |
| 182 | 156 |
| 183 OwnPtr<SVGPathByteStream> lastAnimatedStream = m_byteStream.release(); | |
| 184 OwnPtr<SVGPathByteStream> newStream = blendPathByteStreams(*fromStream, toSt
ream, percentage); | 157 OwnPtr<SVGPathByteStream> newStream = blendPathByteStreams(*fromStream, toSt
ream, percentage); |
| 185 | 158 |
| 186 // Handle additive='sum'. | 159 // Handle additive='sum'. |
| 187 if (!fromStream->size() || (animationElement->isAdditive() && !isToAnimation
)) | 160 if (animationElement->isAdditive() && !isToAnimation) |
| 188 newStream = addPathByteStreams(newStream.release(), *lastAnimatedStream)
; | 161 newStream = conditionallyAddPathByteStreams(newStream.release(), byteStr
eam()); |
| 189 | 162 |
| 190 // Handle accumulate='sum'. | 163 // Handle accumulate='sum'. |
| 191 if (animationElement->isAccumulated() && repeatCount) | 164 if (animationElement->isAccumulated() && repeatCount) |
| 192 newStream = addPathByteStreams(newStream.release(), toSVGPath(toAtEndOfD
urationValue)->byteStream(), repeatCount); | 165 newStream = conditionallyAddPathByteStreams(newStream.release(), toSVGPa
th(toAtEndOfDurationValue)->byteStream(), repeatCount); |
| 193 | 166 |
| 194 setValueAsByteStream(newStream.release()); | 167 m_pathValue = CSSPathValue::create(newStream.release()); |
| 195 } | 168 } |
| 196 | 169 |
| 197 float SVGPath::calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> to, SVG
Element*) | 170 float SVGPath::calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> to, SVG
Element*) |
| 198 { | 171 { |
| 199 // FIXME: Support paced animations. | 172 // FIXME: Support paced animations. |
| 200 return -1; | 173 return -1; |
| 201 } | 174 } |
| 202 | 175 |
| 176 DEFINE_TRACE(SVGPath) |
| 177 { |
| 178 visitor->trace(m_pathValue); |
| 179 SVGPropertyBase::trace(visitor); |
| 203 } | 180 } |
| 181 |
| 182 } |
| OLD | NEW |