OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde
.org> |
| 3 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> |
| 4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> |
| 5 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
| 6 * |
| 7 * This library is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Library General Public |
| 9 * License as published by the Free Software Foundation; either |
| 10 * version 2 of the License, or (at your option) any later version. |
| 11 * |
| 12 * This library is distributed in the hope that it will be useful, |
| 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 * Library General Public License for more details. |
| 16 * |
| 17 * You should have received a copy of the GNU Library General Public License |
| 18 * along with this library; see the file COPYING.LIB. If not, write to |
| 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 20 * Boston, MA 02110-1301, USA. |
| 21 */ |
| 22 |
| 23 #include "config.h" |
| 24 #include "core/svg/SVGPath.h" |
| 25 |
| 26 #include "core/SVGNames.h" |
| 27 #include "core/svg/SVGAnimationElement.h" |
| 28 #include "core/svg/SVGPathBlender.h" |
| 29 #include "core/svg/SVGPathByteStream.h" |
| 30 #include "core/svg/SVGPathByteStreamBuilder.h" |
| 31 #include "core/svg/SVGPathByteStreamSource.h" |
| 32 #include "core/svg/SVGPathParser.h" |
| 33 #include "core/svg/SVGPathUtilities.h" |
| 34 |
| 35 namespace blink { |
| 36 |
| 37 SVGPath::SVGPath() |
| 38 : SVGPropertyBase(classType()) |
| 39 { |
| 40 } |
| 41 |
| 42 SVGPath::SVGPath(PassOwnPtr<SVGPathByteStream> byteStream) |
| 43 : SVGPropertyBase(classType()) |
| 44 , m_byteStream(byteStream) |
| 45 { |
| 46 } |
| 47 |
| 48 SVGPath::~SVGPath() |
| 49 { |
| 50 } |
| 51 |
| 52 PassRefPtrWillBeRawPtr<SVGPath> SVGPath::clone() const |
| 53 { |
| 54 return adoptRefWillBeNoop(new SVGPath(byteStream().copy())); |
| 55 } |
| 56 |
| 57 PassRefPtrWillBeRawPtr<SVGPropertyBase> SVGPath::cloneForAnimation(const String&
value) const |
| 58 { |
| 59 RefPtrWillBeRawPtr<SVGPath> svgPath = SVGPath::create(); |
| 60 svgPath->setValueAsString(value, IGNORE_EXCEPTION); |
| 61 return svgPath; |
| 62 } |
| 63 |
| 64 const SVGPathByteStream& SVGPath::byteStream() const |
| 65 { |
| 66 return const_cast<SVGPath*>(this)->mutableByteStream(); |
| 67 } |
| 68 |
| 69 SVGPathByteStream& SVGPath::mutableByteStream() |
| 70 { |
| 71 if (!m_byteStream) |
| 72 m_byteStream = SVGPathByteStream::create(); |
| 73 return *m_byteStream.get(); |
| 74 } |
| 75 |
| 76 String SVGPath::valueAsString() const |
| 77 { |
| 78 String string; |
| 79 buildStringFromByteStream(byteStream(), string, UnalteredParsing); |
| 80 return string; |
| 81 } |
| 82 |
| 83 void SVGPath::setValueAsString(const String& string, ExceptionState& exceptionSt
ate) |
| 84 { |
| 85 if (!buildSVGPathByteStreamFromString(string, mutableByteStream(), Unaltered
Parsing)) |
| 86 exceptionState.throwDOMException(SyntaxError, "Problem parsing path \""
+ string + "\""); |
| 87 } |
| 88 |
| 89 void SVGPath::add(PassRefPtrWillBeRawPtr<SVGPropertyBase> other, SVGElement*) |
| 90 { |
| 91 RefPtrWillBeRawPtr<SVGPath> otherList = toSVGPath(other); |
| 92 if (byteStream().size() != otherList->byteStream().size()) |
| 93 return; |
| 94 |
| 95 addToSVGPathByteStream(mutableByteStream(), otherList->byteStream()); |
| 96 } |
| 97 |
| 98 void SVGPath::calculateAnimatedValue(SVGAnimationElement* animationElement, floa
t percentage, unsigned repeatCount, PassRefPtrWillBeRawPtr<SVGPropertyBase> from
Value, PassRefPtrWillBeRawPtr<SVGPropertyBase> toValue, PassRefPtrWillBeRawPtr<S
VGPropertyBase> toAtEndOfDurationValue, SVGElement*) |
| 99 { |
| 100 ASSERT(animationElement); |
| 101 bool isToAnimation = animationElement->animationMode() == ToAnimation; |
| 102 |
| 103 const RefPtrWillBeRawPtr<SVGPath> from = toSVGPath(fromValue); |
| 104 const RefPtrWillBeRawPtr<SVGPath> to = toSVGPath(toValue); |
| 105 const RefPtrWillBeRawPtr<SVGPath> toAtEndOfDuration = toSVGPath(toAtEndOfDur
ationValue); |
| 106 |
| 107 const SVGPathByteStream& toStream = to->byteStream(); |
| 108 const SVGPathByteStream* fromStream = &from->byteStream(); |
| 109 OwnPtr<SVGPathByteStream> copy; |
| 110 |
| 111 // If no 'to' value is given, nothing to animate. |
| 112 if (!toStream.size()) |
| 113 return; |
| 114 |
| 115 if (isToAnimation) { |
| 116 copy = byteStream().copy(); |
| 117 fromStream = copy.get(); |
| 118 } |
| 119 |
| 120 // If the 'from' value is given and it's length doesn't match the 'to' value
list length, fallback to a discrete animation. |
| 121 if (fromStream->size() != toStream.size() && fromStream->size()) { |
| 122 if (percentage < 0.5) { |
| 123 if (!isToAnimation) { |
| 124 m_byteStream = fromStream->copy(); |
| 125 return; |
| 126 } |
| 127 } else { |
| 128 m_byteStream = toStream.copy(); |
| 129 return; |
| 130 } |
| 131 } |
| 132 |
| 133 OwnPtr<SVGPathByteStream> lastAnimatedStream = m_byteStream.release(); |
| 134 |
| 135 m_byteStream = SVGPathByteStream::create(); |
| 136 SVGPathByteStreamBuilder builder(*m_byteStream); |
| 137 |
| 138 SVGPathByteStreamSource fromSource(*fromStream); |
| 139 SVGPathByteStreamSource toSource(toStream); |
| 140 |
| 141 SVGPathBlender blender(&fromSource, &toSource, &builder); |
| 142 blender.blendAnimatedPath(percentage); |
| 143 |
| 144 // Handle additive='sum'. |
| 145 if (!fromStream->size() || (animationElement->isAdditive() && !isToAnimation
)) |
| 146 addToSVGPathByteStream(*m_byteStream, *lastAnimatedStream); |
| 147 |
| 148 // Handle accumulate='sum'. |
| 149 if (animationElement->isAccumulated() && repeatCount) |
| 150 addToSVGPathByteStream(*m_byteStream, toAtEndOfDuration->byteStream(), r
epeatCount); |
| 151 } |
| 152 |
| 153 float SVGPath::calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> to, SVG
Element*) |
| 154 { |
| 155 // FIXME: Support paced animations. |
| 156 return -1; |
| 157 } |
| 158 |
| 159 } |
OLD | NEW |