예제 #1
0
void SVGAnimatedLengthListAnimator::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.
    SVGLengthList& fromLengthList = from->lengthList();
    SVGLengthList& animatedLengthList = animated->lengthList();
    if (animationMode == ToAnimation)
        fromLengthList = animatedLengthList;
    
    // Replace 'inherit' by their computed property values.    
    SVGLengthList& toLengthList = to->lengthList();
    if (animationElement->fromPropertyValueType() == InheritValue) {
        String fromLengthString;
        animationElement->adjustForInheritance(m_contextElement, animationElement->attributeName(), fromLengthString);
        fromLengthList.parse(fromLengthString, m_lengthMode);
    }
    if (animationElement->toPropertyValueType() == InheritValue) {
        String toLengthString;
        animationElement->adjustForInheritance(m_contextElement, animationElement->attributeName(), toLengthString);
        toLengthList.parse(toLengthString, m_lengthMode);
    }

    unsigned itemsCount = fromLengthList.size();
    if (itemsCount != toLengthList.size()) {
        if (percentage < 0.5) {
            if (animationMode != ToAnimation)
                animatedLengthList = fromLengthList;
        } else
            animatedLengthList = toLengthList;
        return;
    }
    
    bool animatedListSizeEqual = itemsCount == animatedLengthList.size();
    if (!animatedListSizeEqual)
        animatedLengthList.clear();
    SVGLengthContext lengthContext(m_contextElement);
    ExceptionCode ec = 0;
    for (unsigned i = 0; i < itemsCount; ++i) {
        float result = animatedListSizeEqual ? animatedLengthList[i].value(lengthContext) : 0;
        SVGLengthType unitType = percentage < 0.5 ? fromLengthList[i].unitType() : toLengthList[i].unitType();
        SVGAnimatedNumberAnimator::calculateAnimatedNumber(animationElement, percentage, repeatCount, result, fromLengthList[i].value(lengthContext), toLengthList[i].value(lengthContext));
        if (!animatedListSizeEqual)
            animatedLengthList.append(SVGLength(lengthContext, result, m_lengthMode, unitType));
        else {
            animatedLengthList[i].setValue(lengthContext, result, m_lengthMode, unitType, ec);
            ASSERT(!ec);
        }
    }
}
예제 #2
0
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;
}