void SVGAnimatedColorAnimator::calculateAnimatedValue(float percentage, unsigned, OwnPtr<SVGAnimatedType>& from, OwnPtr<SVGAnimatedType>& to, OwnPtr<SVGAnimatedType>& animated) { ASSERT(m_animationElement); ASSERT(m_contextElement); SVGAnimateElement* animationElement = static_cast<SVGAnimateElement*>(m_animationElement); AnimationMode animationMode = animationElement->animationMode(); Color& fromColor = from->color(); Color& toColor = to->color(); Color& animatedColor = animated->color(); // To animation uses contributions from the lower priority animations as the base value. if (animationMode == ToAnimation) fromColor = animatedColor; // Replace 'currentColor' / 'inherit' by their computed property values. AnimatedPropertyValueType fromPropertyValueType = animationElement->fromPropertyValueType(); if (fromPropertyValueType == CurrentColorValue) animationElement->adjustForCurrentColor(m_contextElement, fromColor); else if (fromPropertyValueType == InheritValue) { String fromColorString; animationElement->adjustForInheritance(m_contextElement, animationElement->attributeName(), fromColorString); fromColor = SVGColor::colorFromRGBColorString(fromColorString); } AnimatedPropertyValueType toPropertyValueType = animationElement->toPropertyValueType(); if (toPropertyValueType == CurrentColorValue) animationElement->adjustForCurrentColor(m_contextElement, toColor); else if (toPropertyValueType == InheritValue) { String toColorString; animationElement->adjustForInheritance(m_contextElement, animationElement->attributeName(), toColorString); toColor = SVGColor::colorFromRGBColorString(toColorString); } Color color; if (animationElement->calcMode() == CalcModeDiscrete) color = percentage < 0.5 ? fromColor : toColor; else color = ColorDistance(fromColor, toColor).scaledDistance(percentage).addToColorAndClamp(fromColor); // FIXME: Accumulate colors. if (animationElement->isAdditive() && animationMode != ToAnimation) animatedColor = ColorDistance::addColorsAndClamp(animatedColor, color); else animatedColor = color; return; }
void SVGAnimatedRectAnimator::calculateAnimatedValue(float percentage, unsigned repeatCount, OwnPtr<SVGAnimatedType>& from, OwnPtr<SVGAnimatedType>& to, OwnPtr<SVGAnimatedType>& animated) { ASSERT(m_animationElement); ASSERT(m_contextElement); SVGAnimateElement* animationElement = static_cast<SVGAnimateElement*>(m_animationElement); AnimationMode animationMode = animationElement->animationMode(); // To animation uses contributions from the lower priority animations as the base value. FloatRect& animatedRect = animated->rect(); if (animationMode == ToAnimation) from->rect() = animatedRect; const FloatRect& fromRect = from->rect(); const FloatRect& toRect = to->rect(); FloatRect newRect; if (animationElement->calcMode() == CalcModeDiscrete) newRect = percentage < 0.5 ? fromRect : toRect; else newRect = FloatRect((toRect.x() - fromRect.x()) * percentage + fromRect.x(), (toRect.y() - fromRect.y()) * percentage + fromRect.y(), (toRect.width() - fromRect.width()) * percentage + fromRect.width(), (toRect.height() - fromRect.height()) * percentage + fromRect.height()); // FIXME: This is not correct for values animation. Right now we transform values-animation to multiple from-to-animations and // accumulate every single value to the previous one. But accumulation should just take into account after a complete cycle // of values-animaiton. See example at: http://www.w3.org/TR/2001/REC-smil-animation-20010904/#RepeatingAnim if (animationElement->isAccumulated() && repeatCount) { newRect += toRect; newRect.scale(repeatCount); } if (animationElement->isAdditive() && animationMode != ToAnimation) animatedRect += newRect; else animatedRect = newRect; }