Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> |
| 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> | 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> |
| 4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> | 4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> |
| 5 * Copyright (C) 2008 Apple Inc. All rights reserved. | 5 * Copyright (C) 2008 Apple Inc. All rights reserved. |
| 6 * Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au> | 6 * Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au> |
| 7 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 7 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
| 8 * | 8 * |
| 9 * This library is free software; you can redistribute it and/or | 9 * This library is free software; you can redistribute it and/or |
| 10 * modify it under the terms of the GNU Library General Public | 10 * modify it under the terms of the GNU Library General Public |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 #include "wtf/MathExtras.h" | 32 #include "wtf/MathExtras.h" |
| 33 | 33 |
| 34 namespace blink { | 34 namespace blink { |
| 35 | 35 |
| 36 SVGAnimationElement::SVGAnimationElement(const QualifiedName& tagName, | 36 SVGAnimationElement::SVGAnimationElement(const QualifiedName& tagName, |
| 37 Document& document) | 37 Document& document) |
| 38 : SVGSMILElement(tagName, document), | 38 : SVGSMILElement(tagName, document), |
| 39 m_animationValid(false), | 39 m_animationValid(false), |
| 40 m_calcMode(CalcModeLinear), | 40 m_calcMode(CalcModeLinear), |
| 41 m_animationMode(NoAnimation) { | 41 m_animationMode(NoAnimation) { |
| 42 ASSERT(RuntimeEnabledFeatures::smilEnabled()); | 42 DCHECK(RuntimeEnabledFeatures::smilEnabled()); |
| 43 UseCounter::count(document, UseCounter::SVGAnimationElement); | 43 UseCounter::count(document, UseCounter::SVGAnimationElement); |
| 44 } | 44 } |
| 45 | 45 |
| 46 bool SVGAnimationElement::parseValues(const String& value, | 46 bool SVGAnimationElement::parseValues(const String& value, |
| 47 Vector<String>& result) { | 47 Vector<String>& result) { |
| 48 // Per the SMIL specification, leading and trailing white space, and white | 48 // Per the SMIL specification, leading and trailing white space, and white |
| 49 // space before and after semicolon separators, is allowed and will be | 49 // space before and after semicolon separators, is allowed and will be |
| 50 // ignored. | 50 // ignored. |
| 51 // http://www.w3.org/TR/SVG11/animate.html#ValuesAttribute | 51 // http://www.w3.org/TR/SVG11/animate.html#ValuesAttribute |
| 52 result.clear(); | 52 result.clear(); |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 return value == sum || getAnimationMode() == ByAnimation; | 319 return value == sum || getAnimationMode() == ByAnimation; |
| 320 } | 320 } |
| 321 | 321 |
| 322 bool SVGAnimationElement::isAccumulated() const { | 322 bool SVGAnimationElement::isAccumulated() const { |
| 323 DEFINE_STATIC_LOCAL(const AtomicString, sum, ("sum")); | 323 DEFINE_STATIC_LOCAL(const AtomicString, sum, ("sum")); |
| 324 const AtomicString& value = fastGetAttribute(SVGNames::accumulateAttr); | 324 const AtomicString& value = fastGetAttribute(SVGNames::accumulateAttr); |
| 325 return value == sum && getAnimationMode() != ToAnimation; | 325 return value == sum && getAnimationMode() != ToAnimation; |
| 326 } | 326 } |
| 327 | 327 |
| 328 void SVGAnimationElement::calculateKeyTimesForCalcModePaced() { | 328 void SVGAnimationElement::calculateKeyTimesForCalcModePaced() { |
| 329 ASSERT(getCalcMode() == CalcModePaced); | 329 DCHECK_EQ(getCalcMode(), CalcModePaced); |
| 330 ASSERT(getAnimationMode() == ValuesAnimation); | 330 DCHECK_EQ(getAnimationMode(), ValuesAnimation); |
| 331 | 331 |
| 332 unsigned valuesCount = m_values.size(); | 332 unsigned valuesCount = m_values.size(); |
| 333 ASSERT(valuesCount >= 1); | 333 DCHECK_GE(valuesCount, static_cast<unsigned>(1)); |
|
fs
2017/03/14 21:50:23
Nit: 1u
| |
| 334 if (valuesCount == 1) | 334 if (valuesCount == 1) |
| 335 return; | 335 return; |
| 336 | 336 |
| 337 // FIXME, webkit.org/b/109010: m_keyTimes should not be modified in this | 337 // FIXME, webkit.org/b/109010: m_keyTimes should not be modified in this |
| 338 // function. | 338 // function. |
| 339 m_keyTimes.clear(); | 339 m_keyTimes.clear(); |
| 340 | 340 |
| 341 Vector<float> keyTimesForPaced; | 341 Vector<float> keyTimesForPaced; |
| 342 float totalDistance = 0; | 342 float totalDistance = 0; |
| 343 keyTimesForPaced.push_back(0); | 343 keyTimesForPaced.push_back(0); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 377 for (index = 1; index < keyTimesCount; ++index) { | 377 for (index = 1; index < keyTimesCount; ++index) { |
| 378 if (m_keyTimes[index] > percent) | 378 if (m_keyTimes[index] > percent) |
| 379 break; | 379 break; |
| 380 } | 380 } |
| 381 return --index; | 381 return --index; |
| 382 } | 382 } |
| 383 | 383 |
| 384 float SVGAnimationElement::calculatePercentForSpline( | 384 float SVGAnimationElement::calculatePercentForSpline( |
| 385 float percent, | 385 float percent, |
| 386 unsigned splineIndex) const { | 386 unsigned splineIndex) const { |
| 387 ASSERT(getCalcMode() == CalcModeSpline); | 387 DCHECK_EQ(getCalcMode(), CalcModeSpline); |
| 388 SECURITY_DCHECK(splineIndex < m_keySplines.size()); | 388 SECURITY_DCHECK(splineIndex < m_keySplines.size()); |
| 389 gfx::CubicBezier bezier = m_keySplines[splineIndex]; | 389 gfx::CubicBezier bezier = m_keySplines[splineIndex]; |
| 390 SMILTime duration = simpleDuration(); | 390 SMILTime duration = simpleDuration(); |
| 391 if (!duration.isFinite()) | 391 if (!duration.isFinite()) |
| 392 duration = 100.0; | 392 duration = 100.0; |
| 393 return clampTo<float>( | 393 return clampTo<float>( |
| 394 bezier.SolveWithEpsilon(percent, solveEpsilon(duration.value()))); | 394 bezier.SolveWithEpsilon(percent, solveEpsilon(duration.value()))); |
| 395 } | 395 } |
| 396 | 396 |
| 397 float SVGAnimationElement::calculatePercentFromKeyPoints(float percent) const { | 397 float SVGAnimationElement::calculatePercentFromKeyPoints(float percent) const { |
| 398 ASSERT(!m_keyPoints.isEmpty()); | 398 DCHECK(!m_keyPoints.isEmpty()); |
| 399 ASSERT(getCalcMode() != CalcModePaced); | 399 DCHECK_NE(getCalcMode(), CalcModePaced); |
| 400 ASSERT(m_keyTimes.size() > 1); | 400 DCHECK_GT(m_keyTimes.size(), static_cast<unsigned>(1)); |
|
fs
2017/03/14 21:50:23
Nit: 1u
| |
| 401 ASSERT(m_keyPoints.size() == m_keyTimes.size()); | 401 DCHECK_EQ(m_keyPoints.size(), m_keyTimes.size()); |
| 402 | 402 |
| 403 if (percent == 1) | 403 if (percent == 1) |
| 404 return m_keyPoints[m_keyPoints.size() - 1]; | 404 return m_keyPoints[m_keyPoints.size() - 1]; |
| 405 | 405 |
| 406 unsigned index = calculateKeyTimesIndex(percent); | 406 unsigned index = calculateKeyTimesIndex(percent); |
| 407 float fromKeyPoint = m_keyPoints[index]; | 407 float fromKeyPoint = m_keyPoints[index]; |
| 408 | 408 |
| 409 if (getCalcMode() == CalcModeDiscrete) | 409 if (getCalcMode() == CalcModeDiscrete) |
| 410 return fromKeyPoint; | 410 return fromKeyPoint; |
| 411 | 411 |
| 412 ASSERT(index + 1 < m_keyTimes.size()); | 412 DCHECK_LT(index + 1, m_keyTimes.size()); |
| 413 float fromPercent = m_keyTimes[index]; | 413 float fromPercent = m_keyTimes[index]; |
| 414 float toPercent = m_keyTimes[index + 1]; | 414 float toPercent = m_keyTimes[index + 1]; |
| 415 float toKeyPoint = m_keyPoints[index + 1]; | 415 float toKeyPoint = m_keyPoints[index + 1]; |
| 416 float keyPointPercent = (percent - fromPercent) / (toPercent - fromPercent); | 416 float keyPointPercent = (percent - fromPercent) / (toPercent - fromPercent); |
| 417 | 417 |
| 418 if (getCalcMode() == CalcModeSpline) { | 418 if (getCalcMode() == CalcModeSpline) { |
| 419 ASSERT(m_keySplines.size() == m_keyPoints.size() - 1); | 419 DCHECK_EQ(m_keySplines.size(), m_keyPoints.size() - 1); |
| 420 keyPointPercent = calculatePercentForSpline(keyPointPercent, index); | 420 keyPointPercent = calculatePercentForSpline(keyPointPercent, index); |
| 421 } | 421 } |
| 422 return (toKeyPoint - fromKeyPoint) * keyPointPercent + fromKeyPoint; | 422 return (toKeyPoint - fromKeyPoint) * keyPointPercent + fromKeyPoint; |
| 423 } | 423 } |
| 424 | 424 |
| 425 float SVGAnimationElement::calculatePercentForFromTo(float percent) const { | 425 float SVGAnimationElement::calculatePercentForFromTo(float percent) const { |
| 426 if (getCalcMode() == CalcModeDiscrete && m_keyTimes.size() == 2) | 426 if (getCalcMode() == CalcModeDiscrete && m_keyTimes.size() == 2) |
| 427 return percent > m_keyTimes[1] ? 1 : 0; | 427 return percent > m_keyTimes[1] ? 1 : 0; |
| 428 | 428 |
| 429 return percent; | 429 return percent; |
| 430 } | 430 } |
| 431 | 431 |
| 432 void SVGAnimationElement::currentValuesFromKeyPoints(float percent, | 432 void SVGAnimationElement::currentValuesFromKeyPoints(float percent, |
| 433 float& effectivePercent, | 433 float& effectivePercent, |
| 434 String& from, | 434 String& from, |
| 435 String& to) const { | 435 String& to) const { |
| 436 ASSERT(!m_keyPoints.isEmpty()); | 436 DCHECK(!m_keyPoints.isEmpty()); |
| 437 ASSERT(m_keyPoints.size() == m_keyTimes.size()); | 437 DCHECK_EQ(m_keyPoints.size(), m_keyTimes.size()); |
| 438 ASSERT(getCalcMode() != CalcModePaced); | 438 DCHECK_NE(getCalcMode(), CalcModePaced); |
| 439 effectivePercent = calculatePercentFromKeyPoints(percent); | 439 effectivePercent = calculatePercentFromKeyPoints(percent); |
| 440 unsigned index = | 440 unsigned index = |
| 441 effectivePercent == 1 | 441 effectivePercent == 1 |
| 442 ? m_values.size() - 2 | 442 ? m_values.size() - 2 |
| 443 : static_cast<unsigned>(effectivePercent * (m_values.size() - 1)); | 443 : static_cast<unsigned>(effectivePercent * (m_values.size() - 1)); |
| 444 from = m_values[index]; | 444 from = m_values[index]; |
| 445 to = m_values[index + 1]; | 445 to = m_values[index + 1]; |
| 446 } | 446 } |
| 447 | 447 |
| 448 void SVGAnimationElement::currentValuesForValuesAnimation( | 448 void SVGAnimationElement::currentValuesForValuesAnimation( |
| 449 float percent, | 449 float percent, |
| 450 float& effectivePercent, | 450 float& effectivePercent, |
| 451 String& from, | 451 String& from, |
| 452 String& to) { | 452 String& to) { |
| 453 unsigned valuesCount = m_values.size(); | 453 unsigned valuesCount = m_values.size(); |
| 454 ASSERT(m_animationValid); | 454 DCHECK(m_animationValid); |
| 455 ASSERT(valuesCount >= 1); | 455 DCHECK_GE(valuesCount, static_cast<unsigned>(1)); |
|
fs
2017/03/14 21:50:23
1u
| |
| 456 | 456 |
| 457 if (percent == 1 || valuesCount == 1) { | 457 if (percent == 1 || valuesCount == 1) { |
| 458 from = m_values[valuesCount - 1]; | 458 from = m_values[valuesCount - 1]; |
| 459 to = m_values[valuesCount - 1]; | 459 to = m_values[valuesCount - 1]; |
| 460 effectivePercent = 1; | 460 effectivePercent = 1; |
| 461 return; | 461 return; |
| 462 } | 462 } |
| 463 | 463 |
| 464 CalcMode calcMode = this->getCalcMode(); | 464 CalcMode calcMode = this->getCalcMode(); |
| 465 if (isSVGAnimateElement(*this)) { | 465 if (isSVGAnimateElement(*this)) { |
| 466 SVGAnimateElement& animateElement = toSVGAnimateElement(*this); | 466 SVGAnimateElement& animateElement = toSVGAnimateElement(*this); |
| 467 if (!animateElement.animatedPropertyTypeSupportsAddition()) | 467 if (!animateElement.animatedPropertyTypeSupportsAddition()) |
| 468 calcMode = CalcModeDiscrete; | 468 calcMode = CalcModeDiscrete; |
| 469 } | 469 } |
| 470 if (!m_keyPoints.isEmpty() && calcMode != CalcModePaced) | 470 if (!m_keyPoints.isEmpty() && calcMode != CalcModePaced) |
| 471 return currentValuesFromKeyPoints(percent, effectivePercent, from, to); | 471 return currentValuesFromKeyPoints(percent, effectivePercent, from, to); |
| 472 | 472 |
| 473 unsigned keyTimesCount = m_keyTimes.size(); | 473 unsigned keyTimesCount = m_keyTimes.size(); |
| 474 ASSERT(!keyTimesCount || valuesCount == keyTimesCount); | 474 DCHECK(!keyTimesCount || valuesCount == keyTimesCount); |
| 475 ASSERT(!keyTimesCount || (keyTimesCount > 1 && !m_keyTimes[0])); | 475 DCHECK(!keyTimesCount || (keyTimesCount > 1 && !m_keyTimes[0])); |
| 476 | 476 |
| 477 unsigned index = calculateKeyTimesIndex(percent); | 477 unsigned index = calculateKeyTimesIndex(percent); |
| 478 if (calcMode == CalcModeDiscrete) { | 478 if (calcMode == CalcModeDiscrete) { |
| 479 if (!keyTimesCount) | 479 if (!keyTimesCount) |
| 480 index = static_cast<unsigned>(percent * valuesCount); | 480 index = static_cast<unsigned>(percent * valuesCount); |
| 481 from = m_values[index]; | 481 from = m_values[index]; |
| 482 to = m_values[index]; | 482 to = m_values[index]; |
| 483 effectivePercent = 0; | 483 effectivePercent = 0; |
| 484 return; | 484 return; |
| 485 } | 485 } |
| 486 | 486 |
| 487 float fromPercent; | 487 float fromPercent; |
| 488 float toPercent; | 488 float toPercent; |
| 489 if (keyTimesCount) { | 489 if (keyTimesCount) { |
| 490 fromPercent = m_keyTimes[index]; | 490 fromPercent = m_keyTimes[index]; |
| 491 toPercent = m_keyTimes[index + 1]; | 491 toPercent = m_keyTimes[index + 1]; |
| 492 } else { | 492 } else { |
| 493 index = static_cast<unsigned>(floorf(percent * (valuesCount - 1))); | 493 index = static_cast<unsigned>(floorf(percent * (valuesCount - 1))); |
| 494 fromPercent = static_cast<float>(index) / (valuesCount - 1); | 494 fromPercent = static_cast<float>(index) / (valuesCount - 1); |
| 495 toPercent = static_cast<float>(index + 1) / (valuesCount - 1); | 495 toPercent = static_cast<float>(index + 1) / (valuesCount - 1); |
| 496 } | 496 } |
| 497 | 497 |
| 498 if (index == valuesCount - 1) | 498 if (index == valuesCount - 1) |
| 499 --index; | 499 --index; |
| 500 from = m_values[index]; | 500 from = m_values[index]; |
| 501 to = m_values[index + 1]; | 501 to = m_values[index + 1]; |
| 502 ASSERT(toPercent > fromPercent); | 502 DCHECK_GT(toPercent, fromPercent); |
| 503 effectivePercent = (percent - fromPercent) / (toPercent - fromPercent); | 503 effectivePercent = (percent - fromPercent) / (toPercent - fromPercent); |
| 504 | 504 |
| 505 if (calcMode == CalcModeSpline) { | 505 if (calcMode == CalcModeSpline) { |
| 506 ASSERT(m_keySplines.size() == m_values.size() - 1); | 506 DCHECK_EQ(m_keySplines.size(), m_values.size() - 1); |
| 507 effectivePercent = calculatePercentForSpline(effectivePercent, index); | 507 effectivePercent = calculatePercentForSpline(effectivePercent, index); |
| 508 } | 508 } |
| 509 } | 509 } |
| 510 | 510 |
| 511 void SVGAnimationElement::startedActiveInterval() { | 511 void SVGAnimationElement::startedActiveInterval() { |
| 512 m_animationValid = false; | 512 m_animationValid = false; |
| 513 | 513 |
| 514 if (!isValid() || !hasValidTarget()) | 514 if (!isValid() || !hasValidTarget()) |
| 515 return; | 515 return; |
| 516 | 516 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 611 calculatePercentForSpline(percent, calculateKeyTimesIndex(percent)); | 611 calculatePercentForSpline(percent, calculateKeyTimesIndex(percent)); |
| 612 else if (animationMode == FromToAnimation || animationMode == ToAnimation) | 612 else if (animationMode == FromToAnimation || animationMode == ToAnimation) |
| 613 effectivePercent = calculatePercentForFromTo(percent); | 613 effectivePercent = calculatePercentForFromTo(percent); |
| 614 else | 614 else |
| 615 effectivePercent = percent; | 615 effectivePercent = percent; |
| 616 | 616 |
| 617 calculateAnimatedValue(effectivePercent, repeatCount, resultElement); | 617 calculateAnimatedValue(effectivePercent, repeatCount, resultElement); |
| 618 } | 618 } |
| 619 | 619 |
| 620 } // namespace blink | 620 } // namespace blink |
| OLD | NEW |