1/* 2 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Library General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Library General Public License for more details. 13 * 14 * You should have received a copy of the GNU Library General Public License 15 * along with this library; see the file COPYING.LIB. If not, write to 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * Boston, MA 02110-1301, USA. 18 */ 19 20#include "config.h" 21#include "SVGAnimatedRect.h" 22 23#include "SVGAnimateElement.h" 24#include "SVGParserUtilities.h" 25 26namespace WebCore { 27 28SVGAnimatedRectAnimator::SVGAnimatedRectAnimator(SVGAnimationElement* animationElement, SVGElement* contextElement) 29 : SVGAnimatedTypeAnimator(AnimatedRect, animationElement, contextElement) 30{ 31} 32 33std::unique_ptr<SVGAnimatedType> SVGAnimatedRectAnimator::constructFromString(const String& string) 34{ 35 auto animatedType = SVGAnimatedType::createRect(std::make_unique<FloatRect>()); 36 parseRect(string, animatedType->rect()); 37 return animatedType; 38} 39 40std::unique_ptr<SVGAnimatedType> SVGAnimatedRectAnimator::startAnimValAnimation(const SVGElementAnimatedPropertyList& animatedTypes) 41{ 42 return SVGAnimatedType::createRect(constructFromBaseValue<SVGAnimatedRect>(animatedTypes)); 43} 44 45void SVGAnimatedRectAnimator::stopAnimValAnimation(const SVGElementAnimatedPropertyList& animatedTypes) 46{ 47 stopAnimValAnimationForType<SVGAnimatedRect>(animatedTypes); 48} 49 50void SVGAnimatedRectAnimator::resetAnimValToBaseVal(const SVGElementAnimatedPropertyList& animatedTypes, SVGAnimatedType* type) 51{ 52 resetFromBaseValue<SVGAnimatedRect>(animatedTypes, type, &SVGAnimatedType::rect); 53} 54 55void SVGAnimatedRectAnimator::animValWillChange(const SVGElementAnimatedPropertyList& animatedTypes) 56{ 57 animValWillChangeForType<SVGAnimatedRect>(animatedTypes); 58} 59 60void SVGAnimatedRectAnimator::animValDidChange(const SVGElementAnimatedPropertyList& animatedTypes) 61{ 62 animValDidChangeForType<SVGAnimatedRect>(animatedTypes); 63} 64 65void SVGAnimatedRectAnimator::addAnimatedTypes(SVGAnimatedType* from, SVGAnimatedType* to) 66{ 67 ASSERT(from->type() == AnimatedRect); 68 ASSERT(from->type() == to->type()); 69 70 to->rect() += from->rect(); 71} 72 73void SVGAnimatedRectAnimator::calculateAnimatedValue(float percentage, unsigned repeatCount, SVGAnimatedType* from, SVGAnimatedType* to, SVGAnimatedType* toAtEndOfDuration, SVGAnimatedType* animated) 74{ 75 ASSERT(m_animationElement); 76 ASSERT(m_contextElement); 77 78 const FloatRect& fromRect = m_animationElement->animationMode() == ToAnimation ? animated->rect() : from->rect(); 79 const FloatRect& toRect = to->rect(); 80 const FloatRect& toAtEndOfDurationRect = toAtEndOfDuration->rect(); 81 FloatRect& animatedRect = animated->rect(); 82 83 float animatedX = animatedRect.x(); 84 float animatedY = animatedRect.y(); 85 float animatedWidth = animatedRect.width(); 86 float animatedHeight = animatedRect.height(); 87 m_animationElement->animateAdditiveNumber(percentage, repeatCount, fromRect.x(), toRect.x(), toAtEndOfDurationRect.x(), animatedX); 88 m_animationElement->animateAdditiveNumber(percentage, repeatCount, fromRect.y(), toRect.y(), toAtEndOfDurationRect.y(), animatedY); 89 m_animationElement->animateAdditiveNumber(percentage, repeatCount, fromRect.width(), toRect.width(), toAtEndOfDurationRect.width(), animatedWidth); 90 m_animationElement->animateAdditiveNumber(percentage, repeatCount, fromRect.height(), toRect.height(), toAtEndOfDurationRect.height(), animatedHeight); 91 92 animatedRect = FloatRect(animatedX, animatedY, animatedWidth, animatedHeight); 93} 94 95float SVGAnimatedRectAnimator::calculateDistance(const String&, const String&) 96{ 97 // FIXME: Distance calculation is not possible for SVGRect right now. We need the distance of for every single value. 98 return -1; 99} 100 101} 102