Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(420)

Side by Side Diff: Source/core/svg/SVGAnimatedLength.cpp

Issue 112003003: [SVG] SVGLength{,List} migration to new SVG property impl. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: fix tests Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
haraken 2014/01/09 00:58:53 Nit: 2014 The same comment for all other newly ad
kouhei (in TOK) 2014/01/09 02:24:51 Done. Happy new year!
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * Redistribution and use in source and binary forms, with or without
5 * modify it under the terms of the GNU Library General Public 5 * modification, are permitted provided that the following conditions are
6 * License as published by the Free Software Foundation; either 6 * met:
7 * version 2 of the License, or (at your option) any later version.
8 * 7 *
9 * This library is distributed in the hope that it will be useful, 8 * * Redistributions of source code must retain the above copyright
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * notice, this list of conditions and the following disclaimer.
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 * * Redistributions in binary form must reproduce the above
12 * Library General Public License for more details. 11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
13 * 17 *
14 * You should have received a copy of the GNU Library General Public License 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 * along with this library; see the file COPYING.LIB. If not, write to 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 * Boston, MA 02110-1301, USA. 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
18 */ 29 */
19 30
20 #include "config.h" 31 #include "config.h"
32
21 #include "core/svg/SVGAnimatedLength.h" 33 #include "core/svg/SVGAnimatedLength.h"
22 34
23 #include "bindings/v8/ExceptionStatePlaceholder.h"
24 #include "core/svg/SVGAnimateElement.h"
25 #include "core/svg/SVGAnimatedNumber.h"
26
27 namespace WebCore { 35 namespace WebCore {
28 36
29 SVGAnimatedLengthAnimator::SVGAnimatedLengthAnimator(SVGAnimationElement* animat ionElement, SVGElement* contextElement) 37 void SVGAnimatedLength::setDefaultValueAsString(const String& value)
30 : SVGAnimatedTypeAnimator(AnimatedLength, animationElement, contextElement)
31 , m_lengthMode(SVGLength::lengthModeForAnimatedLengthAttribute(animationElem ent->attributeName()))
32 { 38 {
39 baseValue()->setValueAsString(value, ASSERT_NO_EXCEPTION);
33 } 40 }
34 41
35 static inline SVGLength& sharedSVGLength(SVGLengthMode mode, const String& value AsString) 42 void SVGAnimatedLength::setBaseValueAsString(const String& value, SVGLengthNegat iveValuesMode mode, SVGParsingError& parseError)
36 { 43 {
37 DEFINE_STATIC_LOCAL(SVGLength, sharedLength, ()); 44 TrackExceptionState es;
38 sharedLength.setValueAsString(valueAsString, mode, ASSERT_NO_EXCEPTION);
39 return sharedLength;
40 }
41 45
42 PassOwnPtr<SVGAnimatedType> SVGAnimatedLengthAnimator::constructFromString(const String& string) 46 baseValue()->setValueAsString(value, es);
43 {
44 return SVGAnimatedType::createLength(new SVGLength(m_lengthMode, string));
45 }
46 47
47 PassOwnPtr<SVGAnimatedType> SVGAnimatedLengthAnimator::startAnimValAnimation(con st SVGElementAnimatedPropertyList& animatedTypes) 48 if (es.hadException()) {
48 { 49 parseError = ParsingAttributeFailedError;
49 return SVGAnimatedType::createLength(constructFromBaseValue<SVGAnimatedLengt h>(animatedTypes)); 50 baseValue()->newValueSpecifiedUnits(LengthTypeNumber, 0);
50 } 51 } else if (mode == ForbidNegativeLengths && baseValue()->valueInSpecifiedUni ts() < 0) {
51 52 parseError = NegativeValueForbiddenError;
52 void SVGAnimatedLengthAnimator::stopAnimValAnimation(const SVGElementAnimatedPro pertyList& animatedTypes) 53 }
53 {
54 stopAnimValAnimationForType<SVGAnimatedLength>(animatedTypes);
55 }
56
57 void SVGAnimatedLengthAnimator::resetAnimValToBaseVal(const SVGElementAnimatedPr opertyList& animatedTypes, SVGAnimatedType* type)
58 {
59 resetFromBaseValue<SVGAnimatedLength>(animatedTypes, type, &SVGAnimatedType: :length);
60 }
61
62 void SVGAnimatedLengthAnimator::animValWillChange(const SVGElementAnimatedProper tyList& animatedTypes)
63 {
64 animValWillChangeForType<SVGAnimatedLength>(animatedTypes);
65 }
66
67 void SVGAnimatedLengthAnimator::animValDidChange(const SVGElementAnimatedPropert yList& animatedTypes)
68 {
69 animValDidChangeForType<SVGAnimatedLength>(animatedTypes);
70 }
71
72 void SVGAnimatedLengthAnimator::addAnimatedTypes(SVGAnimatedType* from, SVGAnima tedType* to)
73 {
74 ASSERT(from->type() == AnimatedLength);
75 ASSERT(from->type() == to->type());
76
77 SVGLengthContext lengthContext(m_contextElement);
78 const SVGLength& fromLength = from->length();
79 SVGLength& toLength = to->length();
80
81 toLength.setValue(toLength.value(lengthContext) + fromLength.value(lengthCon text), lengthContext, ASSERT_NO_EXCEPTION);
82 }
83
84 static SVGLength parseLengthFromString(SVGAnimationElement* animationElement, co nst String& string)
85 {
86 return sharedSVGLength(SVGLength::lengthModeForAnimatedLengthAttribute(anima tionElement->attributeName()), string);
87 }
88
89 void SVGAnimatedLengthAnimator::calculateAnimatedValue(float percentage, unsigne d repeatCount, SVGAnimatedType* from, SVGAnimatedType* to, SVGAnimatedType* toAt EndOfDuration, SVGAnimatedType* animated)
90 {
91 ASSERT(m_animationElement);
92 ASSERT(m_contextElement);
93
94 SVGLength fromSVGLength = m_animationElement->animationMode() == ToAnimation ? animated->length() : from->length();
95 SVGLength toSVGLength = to->length();
96 const SVGLength& toAtEndOfDurationSVGLength = toAtEndOfDuration->length();
97 SVGLength& animatedSVGLength = animated->length();
98
99 // Apply CSS inheritance rules.
100 m_animationElement->adjustForInheritance<SVGLength>(parseLengthFromString, m _animationElement->fromPropertyValueType(), fromSVGLength, m_contextElement);
101 m_animationElement->adjustForInheritance<SVGLength>(parseLengthFromString, m _animationElement->toPropertyValueType(), toSVGLength, m_contextElement);
102
103 SVGLengthContext lengthContext(m_contextElement);
104 float animatedNumber = animatedSVGLength.value(lengthContext);
105 SVGLengthType unitType = percentage < 0.5 ? fromSVGLength.unitType() : toSVG Length.unitType();
106 m_animationElement->animateAdditiveNumber(percentage, repeatCount, fromSVGLe ngth.value(lengthContext), toSVGLength.value(lengthContext), toAtEndOfDurationSV GLength.value(lengthContext), animatedNumber);
107
108 animatedSVGLength.setValue(lengthContext, animatedNumber, m_lengthMode, unit Type, ASSERT_NO_EXCEPTION);
109 }
110
111 float SVGAnimatedLengthAnimator::calculateDistance(const String& fromString, con st String& toString)
112 {
113 ASSERT(m_animationElement);
114 ASSERT(m_contextElement);
115 SVGLengthMode lengthMode = SVGLength::lengthModeForAnimatedLengthAttribute(m _animationElement->attributeName());
116 SVGLength from = SVGLength(lengthMode, fromString);
117 SVGLength to = SVGLength(lengthMode, toString);
118 SVGLengthContext lengthContext(m_contextElement);
119 return fabsf(to.value(lengthContext) - from.value(lengthContext));
120 } 54 }
121 55
122 } 56 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698