Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(327)

Side by Side Diff: Source/core/svg/SVGPointList.cpp

Issue 132233016: [SVG] SVGAnimatedPointList migration to new SVG property impl. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: set NeedsRebaseline Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/svg/SVGPointList.h ('k') | Source/core/svg/SVGPointList.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2004, 2005, 2006, 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 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details. 13 * Library General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU Library General Public License 15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to 16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA. 18 * Boston, MA 02110-1301, USA.
19 */ 19 */
20 20
21 #include "config.h" 21 #include "config.h"
22 #include "core/svg/SVGPointList.h" 22 #include "core/svg/SVGPointList.h"
23 23
24 #include "core/svg/SVGAnimationElement.h"
25 #include "core/svg/SVGParserUtilities.h"
24 #include "platform/geometry/FloatPoint.h" 26 #include "platform/geometry/FloatPoint.h"
25 #include "wtf/text/StringBuilder.h" 27 #include "wtf/text/StringBuilder.h"
26 #include "wtf/text/WTFString.h" 28 #include "wtf/text/WTFString.h"
27 29
28 namespace WebCore { 30 namespace WebCore {
29 31
32 inline PassRefPtr<SVGPointList> toSVGPointList(PassRefPtr<NewSVGPropertyBase> pa ssBase)
33 {
34 RefPtr<NewSVGPropertyBase> base = passBase;
35 ASSERT(base->type() == SVGPointList::classType());
36 return static_pointer_cast<SVGPointList>(base.release());
37 }
38
39 SVGPointList::SVGPointList()
40 {
41 }
42
43 SVGPointList::~SVGPointList()
44 {
45 }
46
47 PassRefPtr<SVGPointList> SVGPointList::clone()
48 {
49 RefPtr<SVGPointList> svgPointList = SVGPointList::create();
50 svgPointList->deepCopy(this);
51 return svgPointList.release();
52 }
53
54 PassRefPtr<NewSVGPropertyBase> SVGPointList::cloneForAnimation(const String& val ue) const
55 {
56 RefPtr<SVGPointList> svgPointList = SVGPointList::create();
57 svgPointList->setValueAsString(value, IGNORE_EXCEPTION);
58 return svgPointList.release();
59 }
60
30 String SVGPointList::valueAsString() const 61 String SVGPointList::valueAsString() const
31 { 62 {
32 StringBuilder builder; 63 StringBuilder builder;
33 64
34 unsigned size = this->size(); 65 ConstIterator it = begin();
35 for (unsigned i = 0; i < size; ++i) { 66 ConstIterator itEnd = end();
36 if (i > 0) 67 if (it != itEnd) {
37 builder.append(' '); // FIXME: Shouldn't we use commas to seperate? 68 builder.append(it->valueAsString());
69 ++it;
38 70
39 const FloatPoint& point = at(i); 71 for (; it != itEnd; ++it) {
40 builder.append(String::number(point.x()) + ' ' + String::number(point.y( ))); 72 builder.append(' ');
73 builder.append(it->valueAsString());
74 }
41 } 75 }
42 76
43 return builder.toString(); 77 return builder.toString();
44 } 78 }
45 79
80 template <typename CharType>
81 bool SVGPointList::parse(const CharType*& ptr, const CharType* end)
82 {
83 clear();
84
85 skipOptionalSVGSpaces(ptr, end);
86 if (ptr >= end)
87 return true;
88
89 for (;;) {
90 float x = 0.0f;
91 float y = 0.0f;
92 bool valid = parseNumber(ptr, end, x) && parseNumber(ptr, end, y, false) ;
93 if (!valid) {
94 return false;
95 }
96 append(SVGPoint::create(FloatPoint(x, y)));
97
98 skipOptionalSVGSpaces(ptr, end);
99 if (ptr < end && *ptr == ',') {
100 ++ptr;
101 skipOptionalSVGSpaces(ptr, end);
102
103 // ',' requires the list to be continued
104 continue;
105 }
106
107 // check end of list
108 skipOptionalSVGSpaces(ptr, end);
109 if (ptr >= end)
110 return true;
111 }
46 } 112 }
113
114 void SVGPointList::setValueAsString(const String& value, ExceptionState& excepti onState)
115 {
116 if (value.isEmpty()) {
117 clear();
118 return;
119 }
120
121 bool valid = false;
122 if (value.is8Bit()) {
123 const LChar* ptr = value.characters8();
124 const LChar* end = ptr + value.length();
125 valid = parse(ptr, end);
126 } else {
127 const UChar* ptr = value.characters16();
128 const UChar* end = ptr + value.length();
129 valid = parse(ptr, end);
130 }
131
132 if (!valid)
133 exceptionState.throwDOMException(SyntaxError, "Problem parsing points=\" "+value+"\"");
134 }
135
136 void SVGPointList::add(PassRefPtr<NewSVGPropertyBase> other, SVGElement* context Element)
137 {
138 RefPtr<SVGPointList> otherList = toSVGPointList(other);
139
140 if (numberOfItems() != otherList->numberOfItems())
141 return;
142
143 for (size_t i = 0; i < numberOfItems(); ++i)
144 at(i)->setValue(at(i)->value() + otherList->at(i)->value());
145 }
146
147 bool SVGPointList::adjustFromToListValues(PassRefPtr<SVGPointList> passFromList, PassRefPtr<SVGPointList> passToList, float percentage, bool isToAnimation, bool resizeAnimatedListIfNeeded)
148 {
149 RefPtr<SVGPointList> fromList = passFromList;
150 RefPtr<SVGPointList> toList = passToList;
151
152 // If no 'to' value is given, nothing to animate.
153 size_t toListSize = toList->numberOfItems();
154 if (!toListSize)
155 return false;
156
157 // If the 'from' value is given and it's length doesn't match the 'to' value list length, fallback to a discrete animation.
158 size_t fromListSize = fromList->numberOfItems();
159 if (fromListSize != toListSize && fromListSize) {
160 if (percentage < 0.5) {
161 if (!isToAnimation)
162 deepCopy(fromList);
163 } else {
164 deepCopy(toList);
165 }
166
167 return false;
168 }
169
170 ASSERT(!fromListSize || fromListSize == toListSize);
171 if (resizeAnimatedListIfNeeded && numberOfItems() < toListSize) {
172 size_t paddingCount = toListSize - numberOfItems();
173 for (size_t i = 0; i < paddingCount; ++i)
174 append(SVGPoint::create());
175 }
176
177 return true;
178 }
179
180 void SVGPointList::calculateAnimatedValue(SVGAnimationElement* animationElement, float percentage, unsigned repeatCount, PassRefPtr<NewSVGPropertyBase> fromValu e, PassRefPtr<NewSVGPropertyBase> toValue, PassRefPtr<NewSVGPropertyBase> toAtEn dOfDurationValue, SVGElement* contextElement)
181 {
182 RefPtr<SVGPointList> fromList = toSVGPointList(fromValue);
183 RefPtr<SVGPointList> toList = toSVGPointList(toValue);
184 RefPtr<SVGPointList> toAtEndOfDurationList = toSVGPointList(toAtEndOfDuratio nValue);
185
186 size_t fromPointListSize = fromList->numberOfItems();
187 size_t toPointListSize = toList->numberOfItems();
188 size_t toAtEndOfDurationListSize = toAtEndOfDurationList->numberOfItems();
189
190 if (!adjustFromToListValues(fromList, toList, percentage, animationElement-> animationMode() == ToAnimation, true))
191 return;
192
193 for (size_t i = 0; i < toPointListSize; ++i) {
194 float animatedX = at(i)->x();
195 float animatedY = at(i)->y();
196
197 FloatPoint effectiveFrom;
198 if (fromPointListSize)
199 effectiveFrom = fromList->at(i)->value();
200 FloatPoint effectiveTo = toList->at(i)->value();
201 FloatPoint effectiveToAtEnd;
202 if (i < toAtEndOfDurationListSize)
203 effectiveToAtEnd = toAtEndOfDurationList->at(i)->value();
204
205 animationElement->animateAdditiveNumber(percentage, repeatCount, effecti veFrom.x(), effectiveTo.x(), effectiveToAtEnd.x(), animatedX);
206 animationElement->animateAdditiveNumber(percentage, repeatCount, effecti veFrom.y(), effectiveTo.y(), effectiveToAtEnd.y(), animatedY);
207 at(i)->setValue(FloatPoint(animatedX, animatedY));
208 }
209 }
210
211 float SVGPointList::calculateDistance(PassRefPtr<NewSVGPropertyBase> to, SVGElem ent*)
212 {
213 // FIXME: Distance calculation is not possible for SVGPointList right now. W e need the distance for every single value.
214 return -1;
215 }
216
217 }
OLDNEW
« no previous file with comments | « Source/core/svg/SVGPointList.h ('k') | Source/core/svg/SVGPointList.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698