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 "bindings/core/v8/ExceptionState.h" |
| 27 #include "core/SVGNames.h" |
| 28 #include "core/svg/SVGAnimationElement.h" |
| 29 #include "core/svg/SVGPathBlender.h" |
| 30 #include "core/svg/SVGPathByteStream.h" |
| 31 #include "core/svg/SVGPathByteStreamBuilder.h" |
| 32 #include "core/svg/SVGPathByteStreamSource.h" |
| 33 #include "core/svg/SVGPathParser.h" |
| 34 #include "core/svg/SVGPathUtilities.h" |
| 35 |
| 36 namespace blink { |
| 37 |
| 38 SVGPath::SVGPath() |
| 39 : SVGPropertyBase(classType()) |
| 40 { |
| 41 } |
| 42 |
| 43 SVGPath::SVGPath(PassOwnPtr<SVGPathByteStream> byteStream) |
| 44 : SVGPropertyBase(classType()) |
| 45 , m_byteStream(byteStream) |
| 46 { |
| 47 } |
| 48 |
| 49 SVGPath::~SVGPath() |
| 50 { |
| 51 } |
| 52 |
| 53 PassRefPtrWillBeRawPtr<SVGPath> SVGPath::clone() const |
| 54 { |
| 55 return adoptRefWillBeNoop(new SVGPath(byteStream().copy())); |
| 56 } |
| 57 |
| 58 PassRefPtrWillBeRawPtr<SVGPropertyBase> SVGPath::cloneForAnimation(const String&
value) const |
| 59 { |
| 60 RefPtrWillBeRawPtr<SVGPath> svgPath = SVGPath::create(); |
| 61 svgPath->setValueAsString(value, IGNORE_EXCEPTION); |
| 62 return svgPath; |
| 63 } |
| 64 |
| 65 const SVGPathByteStream& SVGPath::byteStream() const |
| 66 { |
| 67 return const_cast<SVGPath*>(this)->mutableByteStream(); |
| 68 } |
| 69 |
| 70 SVGPathByteStream& SVGPath::mutableByteStream() |
| 71 { |
| 72 if (!m_byteStream) |
| 73 m_byteStream = SVGPathByteStream::create(); |
| 74 return *m_byteStream.get(); |
| 75 } |
| 76 |
| 77 String SVGPath::valueAsString() const |
| 78 { |
| 79 String string; |
| 80 buildStringFromByteStream(byteStream(), string, UnalteredParsing); |
| 81 return string; |
| 82 } |
| 83 |
| 84 void SVGPath::setValueAsString(const String& string, ExceptionState& exceptionSt
ate) |
| 85 { |
| 86 if (!buildSVGPathByteStreamFromString(string, mutableByteStream(), Unaltered
Parsing)) |
| 87 exceptionState.throwDOMException(SyntaxError, "Problem parsing path \""
+ string + "\""); |
| 88 } |
| 89 |
| 90 void SVGPath::add(PassRefPtrWillBeRawPtr<SVGPropertyBase> other, SVGElement*) |
| 91 { |
| 92 RefPtrWillBeRawPtr<SVGPath> otherList = toSVGPath(other); |
| 93 if (byteStream().size() != otherList->byteStream().size()) |
| 94 return; |
| 95 |
| 96 addToSVGPathByteStream(mutableByteStream(), otherList->byteStream()); |
| 97 } |
| 98 |
| 99 void SVGPath::calculateAnimatedValue(SVGAnimationElement* animationElement, floa
t percentage, unsigned repeatCount, PassRefPtrWillBeRawPtr<SVGPropertyBase> from
Value, PassRefPtrWillBeRawPtr<SVGPropertyBase> toValue, PassRefPtrWillBeRawPtr<S
VGPropertyBase> toAtEndOfDurationValue, SVGElement*) |
| 100 { |
| 101 ASSERT(animationElement); |
| 102 bool isToAnimation = animationElement->animationMode() == ToAnimation; |
| 103 |
| 104 const RefPtrWillBeRawPtr<SVGPath> from = toSVGPath(fromValue); |
| 105 const RefPtrWillBeRawPtr<SVGPath> to = toSVGPath(toValue); |
| 106 const RefPtrWillBeRawPtr<SVGPath> toAtEndOfDuration = toSVGPath(toAtEndOfDur
ationValue); |
| 107 |
| 108 const SVGPathByteStream& toStream = to->byteStream(); |
| 109 const SVGPathByteStream* fromStream = &from->byteStream(); |
| 110 OwnPtr<SVGPathByteStream> copy; |
| 111 |
| 112 // If no 'to' value is given, nothing to animate. |
| 113 if (!toStream.size()) |
| 114 return; |
| 115 |
| 116 if (isToAnimation) { |
| 117 copy = byteStream().copy(); |
| 118 fromStream = copy.get(); |
| 119 } |
| 120 |
| 121 // If the 'from' value is given and it's length doesn't match the 'to' value
list length, fallback to a discrete animation. |
| 122 if (fromStream->size() != toStream.size() && fromStream->size()) { |
| 123 if (percentage < 0.5) { |
| 124 if (!isToAnimation) { |
| 125 m_byteStream = fromStream->copy(); |
| 126 return; |
| 127 } |
| 128 } else { |
| 129 m_byteStream = toStream.copy(); |
| 130 return; |
| 131 } |
| 132 } |
| 133 |
| 134 OwnPtr<SVGPathByteStream> lastAnimatedStream = m_byteStream.release(); |
| 135 |
| 136 m_byteStream = SVGPathByteStream::create(); |
| 137 SVGPathByteStreamBuilder builder(*m_byteStream); |
| 138 |
| 139 SVGPathByteStreamSource fromSource(*fromStream); |
| 140 SVGPathByteStreamSource toSource(toStream); |
| 141 |
| 142 SVGPathBlender blender(&fromSource, &toSource, &builder); |
| 143 blender.blendAnimatedPath(percentage); |
| 144 |
| 145 // Handle additive='sum'. |
| 146 if (!fromStream->size() || (animationElement->isAdditive() && !isToAnimation
)) |
| 147 addToSVGPathByteStream(*m_byteStream, *lastAnimatedStream); |
| 148 |
| 149 // Handle accumulate='sum'. |
| 150 if (animationElement->isAccumulated() && repeatCount) |
| 151 addToSVGPathByteStream(*m_byteStream, toAtEndOfDuration->byteStream(), r
epeatCount); |
| 152 } |
| 153 |
| 154 float SVGPath::calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> to, SVG
Element*) |
| 155 { |
| 156 // FIXME: Support paced animations. |
| 157 return -1; |
| 158 } |
| 159 |
| 160 } |
OLD | NEW |