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

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

Issue 19500005: [SVG] Refactoring accumulate logic for animateMotion (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 5 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
« no previous file with comments | « Source/core/svg/SVGAnimateMotionElement.h ('k') | no next file » | 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) 2007 Eric Seidel <eric@webkit.org> 2 * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
3 * Copyright (C) 2007 Rob Buis <buis@kde.org> 3 * Copyright (C) 2007 Rob Buis <buis@kde.org>
4 * Copyright (C) 2008 Apple Inc. All rights reserved. 4 * Copyright (C) 2008 Apple Inc. All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 m_hasToPointAtEndOfDuration = false; 224 m_hasToPointAtEndOfDuration = false;
225 if (animationMode() == ByAnimation && !isAdditive()) 225 if (animationMode() == ByAnimation && !isAdditive())
226 return false; 226 return false;
227 parsePoint(fromString, m_fromPoint); 227 parsePoint(fromString, m_fromPoint);
228 FloatPoint byPoint; 228 FloatPoint byPoint;
229 parsePoint(byString, byPoint); 229 parsePoint(byString, byPoint);
230 m_toPoint = FloatPoint(m_fromPoint.x() + byPoint.x(), m_fromPoint.y() + byPo int.y()); 230 m_toPoint = FloatPoint(m_fromPoint.x() + byPoint.x(), m_fromPoint.y() + byPo int.y());
231 return true; 231 return true;
232 } 232 }
233 233
234 void SVGAnimateMotionElement::buildTransformForProgress(AffineTransform* transfo rm, float percentage)
235 {
236 ASSERT(!m_animationPath.isEmpty());
237
238 bool ok = false;
239 float positionOnPath = m_animationPath.length() * percentage;
240 FloatPoint position = m_animationPath.pointAtLength(positionOnPath, ok);
241 if (!ok)
242 return;
243 transform->translate(position.x(), position.y());
244 }
245
246 void SVGAnimateMotionElement::calculateAnimatedValue(float percentage, unsigned repeatCount, SVGSMILElement*) 234 void SVGAnimateMotionElement::calculateAnimatedValue(float percentage, unsigned repeatCount, SVGSMILElement*)
247 { 235 {
248 SVGElement* targetElement = this->targetElement(); 236 SVGElement* targetElement = this->targetElement();
249 if (!targetElement) 237 if (!targetElement)
250 return; 238 return;
251 AffineTransform* transform = targetElement->supplementalTransform(); 239 AffineTransform* transform = targetElement->supplementalTransform();
252 if (!transform) 240 if (!transform)
253 return; 241 return;
254 242
255 if (RenderObject* targetRenderer = targetElement->renderer()) 243 if (RenderObject* targetRenderer = targetElement->renderer())
(...skipping 10 matching lines...) Expand all
266 float animatedX = 0; 254 float animatedX = 0;
267 animateAdditiveNumber(percentage, repeatCount, m_fromPoint.x(), m_toPoin t.x(), toPointAtEndOfDuration.x(), animatedX); 255 animateAdditiveNumber(percentage, repeatCount, m_fromPoint.x(), m_toPoin t.x(), toPointAtEndOfDuration.x(), animatedX);
268 256
269 float animatedY = 0; 257 float animatedY = 0;
270 animateAdditiveNumber(percentage, repeatCount, m_fromPoint.y(), m_toPoin t.y(), toPointAtEndOfDuration.y(), animatedY); 258 animateAdditiveNumber(percentage, repeatCount, m_fromPoint.y(), m_toPoin t.y(), toPointAtEndOfDuration.y(), animatedY);
271 259
272 transform->translate(animatedX, animatedY); 260 transform->translate(animatedX, animatedY);
273 return; 261 return;
274 } 262 }
275 263
276 buildTransformForProgress(transform, percentage); 264 ASSERT(!m_animationPath.isEmpty());
265
266 bool ok = false;
267 float positionOnPath = m_animationPath.length() * percentage;
268 FloatPoint position;
269 float angle;
270 ok = m_animationPath.pointAndNormalAtLength(positionOnPath, position, angle) ;
271 if (!ok)
272 return;
277 273
278 // Handle accumulate="sum". 274 // Handle accumulate="sum".
279 if (isAccumulated() && repeatCount) { 275 if (isAccumulated() && repeatCount) {
280 for (unsigned i = 0; i < repeatCount; ++i) 276 FloatPoint positionAtEndOfDuration = m_animationPath.pointAtLength(m_ani mationPath.length(), ok);
281 buildTransformForProgress(transform, 1); 277 if (ok)
278 position.move(positionAtEndOfDuration.x() * repeatCount, positionAtE ndOfDuration.y() * repeatCount);
282 } 279 }
283 280
284 bool ok = false; 281 transform->translate(position.x(), position.y());
285 float positionOnPath = m_animationPath.length() * percentage;
286 float angle = m_animationPath.normalAngleAtLength(positionOnPath, ok);
287 if (!ok)
288 return;
289 RotateMode rotateMode = this->rotateMode(); 282 RotateMode rotateMode = this->rotateMode();
290 if (rotateMode != RotateAuto && rotateMode != RotateAutoReverse) 283 if (rotateMode != RotateAuto && rotateMode != RotateAutoReverse)
291 return; 284 return;
292 if (rotateMode == RotateAutoReverse) 285 if (rotateMode == RotateAutoReverse)
293 angle += 180; 286 angle += 180;
294 transform->rotate(angle); 287 transform->rotate(angle);
295 } 288 }
296 289
297 void SVGAnimateMotionElement::applyResultsToTarget() 290 void SVGAnimateMotionElement::applyResultsToTarget()
298 { 291 {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 332
340 void SVGAnimateMotionElement::updateAnimationMode() 333 void SVGAnimateMotionElement::updateAnimationMode()
341 { 334 {
342 if (!m_animationPath.isEmpty()) 335 if (!m_animationPath.isEmpty())
343 setAnimationMode(PathAnimation); 336 setAnimationMode(PathAnimation);
344 else 337 else
345 SVGAnimationElement::updateAnimationMode(); 338 SVGAnimationElement::updateAnimationMode();
346 } 339 }
347 340
348 } 341 }
OLDNEW
« no previous file with comments | « Source/core/svg/SVGAnimateMotionElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698