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

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: 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
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> ret = SVGPointList::create();
haraken 2014/01/17 11:50:18 ret => svgPointList
kouhei (in TOK) 2014/01/20 01:10:26 Done.
50 ret->deepCopy(this);
51 return ret.release();
52 }
53
54 PassRefPtr<NewSVGPropertyBase> SVGPointList::cloneForAnimation(const String& val ue) const
55 {
56 RefPtr<SVGPointList> ret = SVGPointList::create();
haraken 2014/01/17 11:50:18 Ditto.
kouhei (in TOK) 2014/01/20 01:10:26 Done.
57 ret->setValueAsString(value, IGNORE_EXCEPTION);
58 return ret.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 Vector<RefPtr<SVGPoint> >::const_iterator it = m_values.begin();
35 for (unsigned i = 0; i < size; ++i) { 66 Vector<RefPtr<SVGPoint> >::const_iterator itEnd = m_values.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());
38 69
39 const FloatPoint& point = at(i); 70 for (; it != itEnd; ++it) {
40 builder.append(String::number(point.x()) + ' ' + String::number(point.y( ))); 71 builder.append(' ');
72 builder.append((*it)->valueAsString());
73 }
41 } 74 }
42 75
43 return builder.toString(); 76 return builder.toString();
44 } 77 }
45 78
79 template <typename CharType>
80 bool SVGPointList::parse(const CharType*& ptr, const CharType* end)
81 {
82 m_values.clear();
83
84 skipOptionalSVGSpaces(ptr, end);
85 if (ptr >= end)
86 return true;
87
88 for (;;) {
haraken 2014/01/17 11:50:18 You can change this to: while(ptr < end) { ...
kouhei (in TOK) 2014/01/20 01:10:26 No.
89 float x = 0.0f;
90 float y = 0.0f;
91 bool valid = parseNumber(ptr, end, x) && parseNumber(ptr, end, y, false) ;
92 if (!valid) {
93 return false;
94 }
95 m_values.append(SVGPoint::create(FloatPoint(x, y)));
96
97 skipOptionalSVGSpaces(ptr, end);
98 if (ptr < end && *ptr == ',') {
haraken 2014/01/17 11:50:18 The previous code has |delimParsed| but the new co
kouhei (in TOK) 2014/01/20 01:10:26 Yes. The logic we want to have here is to require
99 ++ptr;
100 skipOptionalSVGSpaces(ptr, end);
101
102 // ',' requires the list to be continued
103 continue;
104 }
105
106 // check end of list
107 skipOptionalSVGSpaces(ptr, end);
108 if (ptr >= end)
109 return true;
110 }
46 } 111 }
112
113 void SVGPointList::setValueAsString(const String& value, ExceptionState& excepti onState)
114 {
115 if (value.isEmpty()) {
116 m_values.clear();
117 return;
118 }
119
120 bool valid = false;
121 if (value.is8Bit()) {
122 const LChar* ptr = value.characters8();
123 const LChar* end = ptr + value.length();
124 valid = parse(ptr, end);
125 } else {
126 const UChar* ptr = value.characters16();
127 const UChar* end = ptr + value.length();
128 valid = parse(ptr, end);
129 }
130
131 if (!valid)
132 exceptionState.throwDOMException(SyntaxError, "Problem parsing points=\" "+value+"\"");
133 }
134
135 void SVGPointList::add(PassRefPtr<NewSVGPropertyBase> other, SVGElement* context Element)
136 {
137 RefPtr<SVGPointList> otherList = toSVGPointList(other);
138
139 if (m_values.size() != otherList->m_values.size())
140 return;
141
142 for (size_t i = 0; i < m_values.size(); ++i)
143 m_values[i]->setValue(m_values[i]->value() + otherList->m_values[i]->val ue());
144 }
145
146 bool SVGPointList::adjustFromToListValues(PassRefPtr<SVGPointList> passFromList, PassRefPtr<SVGPointList> passToList, float percentage, bool isToAnimation, bool resizeAnimatedListIfNeeded)
147 {
148 RefPtr<SVGPointList> fromList = passFromList;
149 RefPtr<SVGPointList> toList = passToList;
150
151 // If no 'to' value is given, nothing to animate.
152 size_t toListSize = toList->m_values.size();
153 if (!toListSize)
154 return false;
155
156 // If the 'from' value is given and it's length doesn't match the 'to' value list length, fallback to a discrete animation.
157 size_t fromListSize = fromList->m_values.size();
158 if (fromListSize != toListSize && fromListSize) {
159 if (percentage < 0.5) {
160 if (!isToAnimation)
161 deepCopy(fromList);
162 } else {
163 deepCopy(toList);
164 }
165
166 return false;
167 }
168
169 ASSERT(!fromListSize || fromListSize == toListSize);
170 if (resizeAnimatedListIfNeeded && m_values.size() < toListSize) {
171 size_t paddingCount = toListSize - m_values.size();
172 for (size_t i = 0; i < paddingCount; ++i)
173 m_values.append(SVGPoint::create());
174 }
175
176 return true;
177 }
178
179 void SVGPointList::calculateAnimatedValue(SVGAnimationElement* animationElement, float percentage, unsigned repeatCount, PassRefPtr<NewSVGPropertyBase> fromValu e, PassRefPtr<NewSVGPropertyBase> toValue, PassRefPtr<NewSVGPropertyBase> toAtEn dOfDurationValue, SVGElement* contextElement)
180 {
181 RefPtr<SVGPointList> fromList = toSVGPointList(fromValue);
182 RefPtr<SVGPointList> toList = toSVGPointList(toValue);
183 RefPtr<SVGPointList> toAtEndOfDurationList = toSVGPointList(toAtEndOfDuratio nValue);
184
185 size_t fromPointListSize = fromList->m_values.size();
186 size_t toPointListSize = toList->m_values.size();
187 size_t toAtEndOfDurationListSize = toAtEndOfDurationList->m_values.size();
188
189 if (!adjustFromToListValues(fromList, toList, percentage, animationElement-> animationMode() == ToAnimation, true))
190 return;
191
192 for (size_t i = 0; i < toPointListSize; ++i) {
193 float animatedX = m_values[i]->x();
194 float animatedY = m_values[i]->y();
195
196 FloatPoint effectiveFrom;
197 if (fromPointListSize)
198 effectiveFrom = fromList->m_values[i]->value();
199 FloatPoint effectiveTo = toList->m_values[i]->value();
200 FloatPoint effectiveToAtEnd;
201 if (i < toAtEndOfDurationListSize)
202 effectiveToAtEnd = toAtEndOfDurationList->m_values[i]->value();
203
204 animationElement->animateAdditiveNumber(percentage, repeatCount, effecti veFrom.x(), effectiveTo.x(), effectiveToAtEnd.x(), animatedX);
205 animationElement->animateAdditiveNumber(percentage, repeatCount, effecti veFrom.y(), effectiveTo.y(), effectiveToAtEnd.y(), animatedY);
206 m_values[i]->setValue(FloatPoint(animatedX, animatedY));
207 }
208 }
209
210 float SVGPointList::calculateDistance(PassRefPtr<NewSVGPropertyBase> to, SVGElem ent*)
211 {
212 // FIXME: Distance calculation is not possible for SVGPointList right now. W e need the distance for every single value.
213 return -1;
214 }
215
216 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698