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 "SVGAnimatedPreserveAspectRatio.h" 22 23#include "SVGAnimateElement.h" 24 25namespace WebCore { 26 27SVGAnimatedPreserveAspectRatioAnimator::SVGAnimatedPreserveAspectRatioAnimator(SVGAnimationElement* animationElement, SVGElement* contextElement) 28 : SVGAnimatedTypeAnimator(AnimatedPreserveAspectRatio, animationElement, contextElement) 29{ 30} 31 32std::unique_ptr<SVGAnimatedType> SVGAnimatedPreserveAspectRatioAnimator::constructFromString(const String& string) 33{ 34 auto animatedType = SVGAnimatedType::createPreserveAspectRatio(std::make_unique<SVGPreserveAspectRatio>()); 35 animatedType->preserveAspectRatio().parse(string); 36 return animatedType; 37} 38 39std::unique_ptr<SVGAnimatedType> SVGAnimatedPreserveAspectRatioAnimator::startAnimValAnimation(const SVGElementAnimatedPropertyList& animatedTypes) 40{ 41 return SVGAnimatedType::createPreserveAspectRatio(constructFromBaseValue<SVGAnimatedPreserveAspectRatio>(animatedTypes)); 42} 43 44void SVGAnimatedPreserveAspectRatioAnimator::stopAnimValAnimation(const SVGElementAnimatedPropertyList& animatedTypes) 45{ 46 stopAnimValAnimationForType<SVGAnimatedPreserveAspectRatio>(animatedTypes); 47} 48 49void SVGAnimatedPreserveAspectRatioAnimator::resetAnimValToBaseVal(const SVGElementAnimatedPropertyList& animatedTypes, SVGAnimatedType* type) 50{ 51 resetFromBaseValue<SVGAnimatedPreserveAspectRatio>(animatedTypes, type, &SVGAnimatedType::preserveAspectRatio); 52} 53 54void SVGAnimatedPreserveAspectRatioAnimator::animValWillChange(const SVGElementAnimatedPropertyList& animatedTypes) 55{ 56 animValWillChangeForType<SVGAnimatedPreserveAspectRatio>(animatedTypes); 57} 58 59void SVGAnimatedPreserveAspectRatioAnimator::animValDidChange(const SVGElementAnimatedPropertyList& animatedTypes) 60{ 61 animValDidChangeForType<SVGAnimatedPreserveAspectRatio>(animatedTypes); 62} 63 64void SVGAnimatedPreserveAspectRatioAnimator::addAnimatedTypes(SVGAnimatedType*, SVGAnimatedType*) 65{ 66 ASSERT_NOT_REACHED(); 67} 68 69void SVGAnimatedPreserveAspectRatioAnimator::calculateAnimatedValue(float percentage, unsigned, SVGAnimatedType* from, SVGAnimatedType* to, SVGAnimatedType*, SVGAnimatedType* animated) 70{ 71 ASSERT(m_animationElement); 72 ASSERT(m_contextElement); 73 74 const SVGPreserveAspectRatio& fromPreserveAspectRatio = m_animationElement->animationMode() == ToAnimation ? animated->preserveAspectRatio() : from->preserveAspectRatio(); 75 const SVGPreserveAspectRatio& toPreserveAspectRatio = to->preserveAspectRatio(); 76 SVGPreserveAspectRatio& animatedPreserveAspectRatio = animated->preserveAspectRatio(); 77 78 m_animationElement->animateDiscreteType<SVGPreserveAspectRatio>(percentage, fromPreserveAspectRatio, toPreserveAspectRatio, animatedPreserveAspectRatio); 79} 80 81float SVGAnimatedPreserveAspectRatioAnimator::calculateDistance(const String&, const String&) 82{ 83 // No paced animations for SVGPreserveAspectRatio. 84 return -1; 85} 86 87} 88